From 90e2fdb1f5dbf7d7593f63eb7d5bc496cccdf889 Mon Sep 17 00:00:00 2001 From: Justin Ethier Date: Mon, 19 Oct 2015 22:41:28 -0400 Subject: [PATCH] Finished adding types to new GC functions --- gc.c | 20 +++++++++++++++++++- runtime.c | 16 +++++++++++++++- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/gc.c b/gc.c index f0021df9..fd657823 100644 --- a/gc.c +++ b/gc.c @@ -116,10 +116,28 @@ size_t gc_allocated_bytes(object obj) return gc_heap_align(1); t = type_of(obj); if (t == cons_tag) return gc_heap_align(sizeof(cons_type)); + if (t == macro_tag) return gc_heap_align(sizeof(macro_type)); + if (t == closure0_tag) return gc_heap_align(sizeof(closure0_type)); + if (t == closure1_tag) return gc_heap_align(sizeof(closure1_type)); + if (t == closure2_tag) return gc_heap_align(sizeof(closure2_type)); + if (t == closure3_tag) return gc_heap_align(sizeof(closure3_type)); + if (t == closure4_tag) return gc_heap_align(sizeof(closure4_type)); + if (t == closureN_tag){ + return gc_heap_align(sizeof(closureN_type) + sizeof(object) * ((closureN_type *)obj)->num_elt); + } + if (t == vector_tag){ + return gc_heap_align(sizeof(vector_type) + sizeof(object) * ((vector_type *)obj)->num_elt); + } + if (t == string_tag){ + return gc_heap_align(sizeof(string_type) + string_len(obj) + 1); + } if (t == integer_tag) return gc_heap_align(sizeof(integer_type)); + if (t == double_tag) return gc_heap_align(sizeof(double_type)); + if (t == port_tag) return gc_heap_align(sizeof(port_type)); + if (t == cvar_tag) return gc_heap_align(sizeof(cvar_type)); #if GC_DEBUG_PRINTFS - fprintf(stderr, "cannot get size of object %ld\n", t); + fprintf(stderr, "gc_allocated_bytes: unexpected object %p of type %ld\n", obj, t); #endif return 0; } diff --git a/runtime.c b/runtime.c index 1121ec70..a9ecdaef 100644 --- a/runtime.c +++ b/runtime.c @@ -2505,7 +2505,21 @@ char *gc_move(char *obj, gc_thread_data *thd, int *alloci, int *heap_grown) { gc_thr_add_to_move_buffer(thd, alloci, hobj); return (char *)hobj; } - TODO case string_tag: { + case string_tag: { + char *s; + string_type *hobj = gc_alloc(Cyc_heap, + sizeof(string_type) + ((string_len(obj) + 1)), + heap_grown); + s = ((char *)hobj) + sizeof(string_type); + memcpy(s, string_str(obj), string_len(obj) + 1); + mark(hobj) = 0; + type_of(hobj) = string_tag; + string_len(hobj) = string_len(obj); + string_str(hobj) = s; + forward(obj) = hobj; + type_of(obj) = forward_tag; + gc_thr_add_to_move_buffer(thd, alloci, hobj); + return (char *)hobj; } case integer_tag: { integer_type *hobj = gc_alloc(Cyc_heap, sizeof(integer_type), heap_grown);