Get rid of make_empty_bignum

This commit is contained in:
Justin Ethier 2017-02-17 13:58:48 +00:00
parent 97d3acb3af
commit 6d02427d1b
2 changed files with 12 additions and 22 deletions

View file

@ -370,15 +370,6 @@ typedef struct {
#define alloc_bignum(data, p) \ #define alloc_bignum(data, p) \
bignum_type *p = gc_alloc_bignum((gc_thread_data *)data); 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; \
n.hdr.grayed = 0; \
n.tag = bignum_tag; \
mp_init(&(n.bn));
/* TODO: check return value of mp_init */
typedef struct { typedef struct {
gc_header_type hdr; gc_header_type hdr;
tag_type tag; tag_type tag;

View file

@ -1898,12 +1898,11 @@ object Cyc_string2number_(void *data, object cont, object str)
if (rv == STR2INT_SUCCESS) { if (rv == STR2INT_SUCCESS) {
_return_closcall1(data, cont, obj_int2obj(result)); _return_closcall1(data, cont, obj_int2obj(result));
} else if (str_is_bignum(rv, s)) { } else if (str_is_bignum(rv, s)) {
make_empty_bignum(bn); alloc_bignum(data, bn);
if (MP_OKAY != mp_read_radix(&(bignum_value(bn)), s, 10)) {
// TODO: check return value Cyc_rt_raise2(data, "Error converting string to bignum", str);
mp_read_radix(&(bignum_value(&bn)), s, 10); }
_return_closcall1(data, cont, bn);
_return_closcall1(data, cont, &bn);
} else { } else {
char *str_end; char *str_end;
n = strtold(s, &str_end); n = strtold(s, &str_end);
@ -3153,10 +3152,10 @@ void Cyc_expt(void *data, object cont, object x, object y)
if (obj_obj2int(y) < 0) { if (obj_obj2int(y) < 0) {
Cyc_expt_double(data, cont, (double)obj_obj2int(x), (double)obj_obj2int(y)); Cyc_expt_double(data, cont, (double)obj_obj2int(x), (double)obj_obj2int(y));
} else { } else {
make_empty_bignum(bn); alloc_bignum(data, bn);
Cyc_int2bignum(obj_obj2int(x), &(bn.bn)); Cyc_int2bignum(obj_obj2int(x), &(bn->bn));
mp_expt_d(&bignum_value(&bn), obj_obj2int(y), &bignum_value(&bn)); mp_expt_d(&bignum_value(bn), obj_obj2int(y), &bignum_value(bn));
return_closcall1(data, cont, Cyc_bignum_normalize(data, &bn)); return_closcall1(data, cont, Cyc_bignum_normalize(data, bn));
} }
} else if (is_object_type(y) && type_of(y) == double_tag) { } else if (is_object_type(y) && type_of(y) == double_tag) {
Cyc_expt_double(data, cont, (double)obj_obj2int(x), double_value(y)); Cyc_expt_double(data, cont, (double)obj_obj2int(x), double_value(y));
@ -3181,9 +3180,9 @@ void Cyc_expt(void *data, object cont, object x, object y)
if (obj_obj2int(y) < 0) { if (obj_obj2int(y) < 0) {
Cyc_expt_double(data, cont, mp_get_double(&bignum_value(x)), (double)obj_obj2int(y)); Cyc_expt_double(data, cont, mp_get_double(&bignum_value(x)), (double)obj_obj2int(y));
} else { } else {
make_empty_bignum(bn); alloc_bignum(data, bn);
mp_expt_d(&bignum_value(x), obj_obj2int(y), &bignum_value(&bn)); mp_expt_d(&bignum_value(x), obj_obj2int(y), &bignum_value(bn));
return_closcall1(data, cont, Cyc_bignum_normalize(data, &bn)); return_closcall1(data, cont, Cyc_bignum_normalize(data, bn));
} }
} else if (is_object_type(y) && type_of(y) == double_tag) { } else if (is_object_type(y) && type_of(y) == double_tag) {
Cyc_expt_double(data, cont, mp_get_double(&bignum_value(x)), double_value(y)); Cyc_expt_double(data, cont, mp_get_double(&bignum_value(x)), double_value(y));