diff --git a/gc.c b/gc.c index 7bc21109..ed408b03 100644 --- a/gc.c +++ b/gc.c @@ -910,6 +910,15 @@ char *gc_copy_obj(object dest, char *obj, gc_thread_data * thd) ((bignum_type *)hp)->bn.dp = ((bignum_type *)obj)->bn.dp; return (char *)hp; } + case bignum2_tag: { + bignum2_type *hp = dest; + mark(hp) = thd->gc_alloc_color; + type_of(hp) = bignum2_tag; + ((bignum2_type *)hp)->num_digits = ((bignum2_type *)obj)->num_digits; + ((bignum2_type *)hp)->sign = ((bignum2_type *)obj)->sign; + // Don't copy digits, caller will populate them + return (char *)hp; + } case cvar_tag:{ cvar_type *hp = dest; mark(hp) = thd->gc_alloc_color; @@ -1308,6 +1317,24 @@ hrt_log_delta("gc sweep fixed size", tstamp); return result; } +/** + * @brief A convenience function for allocating bignums + * @param data The mutator's thread data object + * @return Pointer to a heap object for the bignum + */ +void *gc_alloc_bignum2(gc_thread_data *data) +{ + int heap_grown, result; + bignum2_type *bn; + bignum2_type tmp; + // No need to do this since tmp is always local + //tmp.hdr.mark = gc_color_red; + //tmp.hdr.grayed = 0; + tmp.tag = bignum2_tag; + bn = gc_alloc(((gc_thread_data *)data)->heap, sizeof(bignum2_type), (char *)(&tmp), (gc_thread_data *)data, &heap_grown); + return bn; +} + /** * @brief A convenience function for allocating bignums * @param data The mutator's thread data object @@ -1500,6 +1527,8 @@ size_t gc_allocated_bytes(object obj, gc_free_list * q, gc_free_list * r) return gc_heap_align(sizeof(macro_type)); if (t == bignum_tag) return gc_heap_align(sizeof(bignum_type)); + if (t == bignum2_tag) + return gc_heap_align(sizeof(bignum2_type) + ((bignum2_type *)obj)->num_digits * sizeof(uint32_t)); if (t == port_tag) return gc_heap_align(sizeof(port_type)); if (t == cvar_tag) diff --git a/include/cyclone/types.h b/include/cyclone/types.h index a2023073..01fad73b 100644 --- a/include/cyclone/types.h +++ b/include/cyclone/types.h @@ -71,6 +71,7 @@ enum object_tag { , atomic_tag = 22 , void_tag = 23 , record_tag = 24 + , bignum2_tag = 25 }; /** @@ -414,6 +415,7 @@ void *gc_try_alloc_slow(gc_heap *h_passed, gc_heap *h, size_t size, char *obj, g void *gc_alloc(gc_heap_root * h, size_t size, char *obj, gc_thread_data * thd, int *heap_grown); void *gc_alloc_bignum(gc_thread_data *data); +void *gc_alloc_bignum2(gc_thread_data *data); size_t gc_allocated_bytes(object obj, gc_free_list * q, gc_free_list * r); gc_heap *gc_heap_last(gc_heap * h); diff --git a/runtime.c b/runtime.c index 6330d026..5fea9056 100644 --- a/runtime.c +++ b/runtime.c @@ -55,6 +55,7 @@ const char *tag_names[] = { /*atomic_tag*/ , "atomic" /*void_tag*/ , "void" /*record_tag*/ , "record" + /*bignum2_tag*/ , "bignum2" , "Reserved for future use" };