From 97d3acb3afe603056b26b7dabe89adb8fe26d36b Mon Sep 17 00:00:00 2001 From: Justin Ethier Date: Fri, 17 Feb 2017 13:49:36 +0000 Subject: [PATCH] Remove assign_empty_bignum --- include/cyclone/types.h | 8 +--- runtime.c | 89 +++++++++++++++++++++-------------------- 2 files changed, 46 insertions(+), 51 deletions(-) diff --git a/include/cyclone/types.h b/include/cyclone/types.h index 68153ba3..74805d05 100644 --- a/include/cyclone/types.h +++ b/include/cyclone/types.h @@ -370,6 +370,7 @@ typedef struct { #define alloc_bignum(data, p) \ bignum_type *p = gc_alloc_bignum((gc_thread_data *)data); +// TODO: the following macro is obsolete #define make_empty_bignum(n) \ bignum_type n; \ n.hdr.mark = gc_color_red; \ @@ -378,13 +379,6 @@ typedef struct { mp_init(&(n.bn)); /* TODO: check return value of mp_init */ -#define assign_empty_bignum(pobj) \ - ((bignum_type *)pobj)->hdr.mark = gc_color_red; \ - ((bignum_type *)pobj)->hdr.grayed = 0; \ - ((bignum_type *)pobj)->tag = bignum_tag; \ - mp_init(&(((bignum_type *)pobj)->bn)); -/* TODO: check return value of mp_init */ - typedef struct { gc_header_type hdr; tag_type tag; diff --git a/runtime.c b/runtime.c index 25ed15aa..440c015b 100644 --- a/runtime.c +++ b/runtime.c @@ -2681,11 +2681,11 @@ object Cyc_fast_sum(void *data, object ptr, object x, object y) { mp_init(&bny); Cyc_int2bignum(xx, &bnx); Cyc_int2bignum(yy, &bny); - assign_empty_bignum(ptr) - mp_add(&bnx, &bny, &bignum_value(ptr)); + alloc_bignum(data, bn); + mp_add(&bnx, &bny, &bignum_value(bn)); mp_clear(&bnx); mp_clear(&bny); - return ptr; + return bn; } } else if (is_object_type(y) && type_of(y) == double_tag) { assign_double(ptr, (double)(obj_obj2int(x)) + double_value(y)); @@ -2694,10 +2694,10 @@ object Cyc_fast_sum(void *data, object ptr, object x, object y) { mp_int bnx; mp_init(&bnx); Cyc_int2bignum(obj_obj2int(x), &bnx); - assign_empty_bignum(ptr) - mp_add(&bnx, &bignum_value(y), &bignum_value(ptr)); + alloc_bignum(data, bn); + mp_add(&bnx, &bignum_value(y), &bignum_value(bn)); mp_clear(&bnx); - return ptr; + return bn; } } // x is double @@ -2719,17 +2719,17 @@ object Cyc_fast_sum(void *data, object ptr, object x, object y) { mp_int bny; mp_init(&bny); Cyc_int2bignum(obj_obj2int(y), &bny); - assign_empty_bignum(ptr) - mp_add(&bignum_value(x), &bny, &bignum_value(ptr)); + alloc_bignum(data, bn); + mp_add(&bignum_value(x), &bny, &bignum_value(bn)); mp_clear(&bny); - return ptr; + return bn; } else if (is_object_type(y) && type_of(y) == double_tag) { assign_double(ptr, mp_get_double(&bignum_value(x)) + double_value(y)); return ptr; } else if (is_object_type(y) && type_of(y) == bignum_tag) { - assign_empty_bignum(ptr) - mp_add(&bignum_value(x), &bignum_value(y), &bignum_value(ptr)); - return ptr; + alloc_bignum(data, bn); + mp_add(&bignum_value(x), &bignum_value(y), &bignum_value(bn)); + return bn; } } // still here, raise an error @@ -2756,10 +2756,11 @@ object Cyc_fast_sub(void *data, object ptr, object x, object y) { mp_init(&bny); Cyc_int2bignum(xx, &bnx); Cyc_int2bignum(yy, &bny); - assign_empty_bignum(ptr) - mp_sub(&bnx, &bny, &bignum_value(ptr)); + alloc_bignum(data, bn); + mp_sub(&bnx, &bny, &bignum_value(bn)); mp_clear(&bnx); mp_clear(&bny); + return bn; } } else if (is_object_type(y) && type_of(y) == double_tag) { assign_double(ptr, (double)(obj_obj2int(x)) - double_value(y)); @@ -2768,10 +2769,10 @@ object Cyc_fast_sub(void *data, object ptr, object x, object y) { mp_int bnx; mp_init(&bnx); Cyc_int2bignum(obj_obj2int(x), &bnx); - assign_empty_bignum(ptr) - mp_sub(&bnx, &bignum_value(y), &bignum_value(ptr)); + alloc_bignum(data, bn); + mp_sub(&bnx, &bignum_value(y), &bignum_value(bn)); mp_clear(&bnx); - return ptr; + return bn; } } // x is double @@ -2793,17 +2794,17 @@ object Cyc_fast_sub(void *data, object ptr, object x, object y) { mp_int bny; mp_init(&bny); Cyc_int2bignum(obj_obj2int(y), &bny); - assign_empty_bignum(ptr) - mp_sub(&bignum_value(x), &bny, &bignum_value(ptr)); + alloc_bignum(data, bn); + mp_sub(&bignum_value(x), &bny, &bignum_value(bn)); mp_clear(&bny); - return ptr; + return bn; } else if (is_object_type(y) && type_of(y) == double_tag) { assign_double(ptr, mp_get_double(&bignum_value(x)) - double_value(y)); return ptr; } else if (is_object_type(y) && type_of(y) == bignum_tag) { - assign_empty_bignum(ptr) - mp_sub(&bignum_value(x), &bignum_value(y), &bignum_value(ptr)); - return ptr; + alloc_bignum(data, bn); + mp_sub(&bignum_value(x), &bignum_value(y), &bignum_value(bn)); + return bn; } } // still here, raise an error @@ -2830,11 +2831,11 @@ object Cyc_fast_mul(void *data, object ptr, object x, object y) { mp_init(&bny); Cyc_int2bignum(xx, &bnx); Cyc_int2bignum(yy, &bny); - assign_empty_bignum(ptr) - mp_mul(&bnx, &bny, &bignum_value(ptr)); + alloc_bignum(data, bn); + mp_mul(&bnx, &bny, &bignum_value(bn)); mp_clear(&bnx); mp_clear(&bny); - return ptr; + return bn; } } else if (is_object_type(y) && type_of(y) == double_tag) { assign_double(ptr, (double)(obj_obj2int(x)) * double_value(y)); @@ -2843,10 +2844,10 @@ object Cyc_fast_mul(void *data, object ptr, object x, object y) { mp_int bnx; mp_init(&bnx); Cyc_int2bignum(obj_obj2int(x), &bnx); - assign_empty_bignum(ptr) - mp_mul(&bnx, &bignum_value(y), &bignum_value(ptr)); + alloc_bignum(data, bn); + mp_mul(&bnx, &bignum_value(y), &bignum_value(bn)); mp_clear(&bnx); - return ptr; + return bn; } } // x is double @@ -2868,17 +2869,17 @@ object Cyc_fast_mul(void *data, object ptr, object x, object y) { mp_int bny; mp_init(&bny); Cyc_int2bignum(obj_obj2int(y), &bny); - assign_empty_bignum(ptr) - mp_mul(&bignum_value(x), &bny, &bignum_value(ptr)); + alloc_bignum(data, bn); + mp_mul(&bignum_value(x), &bny, &bignum_value(bn)); mp_clear(&bny); - return ptr; + return bn; } else if (is_object_type(y) && type_of(y) == double_tag) { assign_double(ptr, mp_get_double(&bignum_value(x)) * double_value(y)); return ptr; } else if (is_object_type(y) && type_of(y) == bignum_tag) { - assign_empty_bignum(ptr) - mp_mul(&bignum_value(x), &bignum_value(y), &bignum_value(ptr)); - return ptr; + alloc_bignum(data, bn); + mp_mul(&bignum_value(x), &bignum_value(y), &bignum_value(bn)); + return bn; } } // still here, raise an error @@ -2906,10 +2907,10 @@ object Cyc_fast_div(void *data, object ptr, object x, object y) { mp_int bnx; mp_init(&bnx); Cyc_int2bignum(obj_obj2int(x), &bnx); - assign_empty_bignum(ptr) - mp_div(&bnx, &bignum_value(y), &bignum_value(ptr), NULL); + alloc_bignum(data, bn); + mp_div(&bnx, &bignum_value(y), &bignum_value(bn), NULL); mp_clear(&bnx); - return ptr; + return bn; } } // x is double @@ -2931,17 +2932,17 @@ object Cyc_fast_div(void *data, object ptr, object x, object y) { mp_int bny; mp_init(&bny); Cyc_int2bignum(obj_obj2int(y), &bny); - assign_empty_bignum(ptr) - mp_div(&bignum_value(x), &bny, &bignum_value(ptr), NULL); + alloc_bignum(data, bn); + mp_div(&bignum_value(x), &bny, &bignum_value(bn), NULL); mp_clear(&bny); - return ptr; + return bn; } else if (is_object_type(y) && type_of(y) == double_tag) { assign_double(ptr, mp_get_double(&bignum_value(x)) / double_value(y)); return ptr; } else if (is_object_type(y) && type_of(y) == bignum_tag) { - assign_empty_bignum(ptr) - mp_div(&bignum_value(x), &bignum_value(y), &bignum_value(ptr), NULL); - return ptr; + alloc_bignum(data, bn); + mp_div(&bignum_value(x), &bignum_value(y), &bignum_value(bn), NULL); + return bn; } } // still here, raise an error