mirror of
https://github.com/justinethier/cyclone.git
synced 2025-05-24 04:25:06 +02:00
Remove assign_empty_bignum
This commit is contained in:
parent
876c1f0420
commit
97d3acb3af
2 changed files with 46 additions and 51 deletions
|
@ -370,6 +370,7 @@ 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) \
|
#define make_empty_bignum(n) \
|
||||||
bignum_type n; \
|
bignum_type n; \
|
||||||
n.hdr.mark = gc_color_red; \
|
n.hdr.mark = gc_color_red; \
|
||||||
|
@ -378,13 +379,6 @@ typedef struct {
|
||||||
mp_init(&(n.bn));
|
mp_init(&(n.bn));
|
||||||
/* TODO: check return value of mp_init */
|
/* 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 {
|
typedef struct {
|
||||||
gc_header_type hdr;
|
gc_header_type hdr;
|
||||||
tag_type tag;
|
tag_type tag;
|
||||||
|
|
89
runtime.c
89
runtime.c
|
@ -2681,11 +2681,11 @@ object Cyc_fast_sum(void *data, object ptr, object x, object y) {
|
||||||
mp_init(&bny);
|
mp_init(&bny);
|
||||||
Cyc_int2bignum(xx, &bnx);
|
Cyc_int2bignum(xx, &bnx);
|
||||||
Cyc_int2bignum(yy, &bny);
|
Cyc_int2bignum(yy, &bny);
|
||||||
assign_empty_bignum(ptr)
|
alloc_bignum(data, bn);
|
||||||
mp_add(&bnx, &bny, &bignum_value(ptr));
|
mp_add(&bnx, &bny, &bignum_value(bn));
|
||||||
mp_clear(&bnx);
|
mp_clear(&bnx);
|
||||||
mp_clear(&bny);
|
mp_clear(&bny);
|
||||||
return ptr;
|
return bn;
|
||||||
}
|
}
|
||||||
} else if (is_object_type(y) && type_of(y) == double_tag) {
|
} else if (is_object_type(y) && type_of(y) == double_tag) {
|
||||||
assign_double(ptr, (double)(obj_obj2int(x)) + double_value(y));
|
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_int bnx;
|
||||||
mp_init(&bnx);
|
mp_init(&bnx);
|
||||||
Cyc_int2bignum(obj_obj2int(x), &bnx);
|
Cyc_int2bignum(obj_obj2int(x), &bnx);
|
||||||
assign_empty_bignum(ptr)
|
alloc_bignum(data, bn);
|
||||||
mp_add(&bnx, &bignum_value(y), &bignum_value(ptr));
|
mp_add(&bnx, &bignum_value(y), &bignum_value(bn));
|
||||||
mp_clear(&bnx);
|
mp_clear(&bnx);
|
||||||
return ptr;
|
return bn;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// x is double
|
// x is double
|
||||||
|
@ -2719,17 +2719,17 @@ object Cyc_fast_sum(void *data, object ptr, object x, object y) {
|
||||||
mp_int bny;
|
mp_int bny;
|
||||||
mp_init(&bny);
|
mp_init(&bny);
|
||||||
Cyc_int2bignum(obj_obj2int(y), &bny);
|
Cyc_int2bignum(obj_obj2int(y), &bny);
|
||||||
assign_empty_bignum(ptr)
|
alloc_bignum(data, bn);
|
||||||
mp_add(&bignum_value(x), &bny, &bignum_value(ptr));
|
mp_add(&bignum_value(x), &bny, &bignum_value(bn));
|
||||||
mp_clear(&bny);
|
mp_clear(&bny);
|
||||||
return ptr;
|
return bn;
|
||||||
} else if (is_object_type(y) && type_of(y) == double_tag) {
|
} else if (is_object_type(y) && type_of(y) == double_tag) {
|
||||||
assign_double(ptr, mp_get_double(&bignum_value(x)) + double_value(y));
|
assign_double(ptr, mp_get_double(&bignum_value(x)) + double_value(y));
|
||||||
return ptr;
|
return ptr;
|
||||||
} else if (is_object_type(y) && type_of(y) == bignum_tag) {
|
} else if (is_object_type(y) && type_of(y) == bignum_tag) {
|
||||||
assign_empty_bignum(ptr)
|
alloc_bignum(data, bn);
|
||||||
mp_add(&bignum_value(x), &bignum_value(y), &bignum_value(ptr));
|
mp_add(&bignum_value(x), &bignum_value(y), &bignum_value(bn));
|
||||||
return ptr;
|
return bn;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// still here, raise an error
|
// still here, raise an error
|
||||||
|
@ -2756,10 +2756,11 @@ object Cyc_fast_sub(void *data, object ptr, object x, object y) {
|
||||||
mp_init(&bny);
|
mp_init(&bny);
|
||||||
Cyc_int2bignum(xx, &bnx);
|
Cyc_int2bignum(xx, &bnx);
|
||||||
Cyc_int2bignum(yy, &bny);
|
Cyc_int2bignum(yy, &bny);
|
||||||
assign_empty_bignum(ptr)
|
alloc_bignum(data, bn);
|
||||||
mp_sub(&bnx, &bny, &bignum_value(ptr));
|
mp_sub(&bnx, &bny, &bignum_value(bn));
|
||||||
mp_clear(&bnx);
|
mp_clear(&bnx);
|
||||||
mp_clear(&bny);
|
mp_clear(&bny);
|
||||||
|
return bn;
|
||||||
}
|
}
|
||||||
} else if (is_object_type(y) && type_of(y) == double_tag) {
|
} else if (is_object_type(y) && type_of(y) == double_tag) {
|
||||||
assign_double(ptr, (double)(obj_obj2int(x)) - double_value(y));
|
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_int bnx;
|
||||||
mp_init(&bnx);
|
mp_init(&bnx);
|
||||||
Cyc_int2bignum(obj_obj2int(x), &bnx);
|
Cyc_int2bignum(obj_obj2int(x), &bnx);
|
||||||
assign_empty_bignum(ptr)
|
alloc_bignum(data, bn);
|
||||||
mp_sub(&bnx, &bignum_value(y), &bignum_value(ptr));
|
mp_sub(&bnx, &bignum_value(y), &bignum_value(bn));
|
||||||
mp_clear(&bnx);
|
mp_clear(&bnx);
|
||||||
return ptr;
|
return bn;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// x is double
|
// x is double
|
||||||
|
@ -2793,17 +2794,17 @@ object Cyc_fast_sub(void *data, object ptr, object x, object y) {
|
||||||
mp_int bny;
|
mp_int bny;
|
||||||
mp_init(&bny);
|
mp_init(&bny);
|
||||||
Cyc_int2bignum(obj_obj2int(y), &bny);
|
Cyc_int2bignum(obj_obj2int(y), &bny);
|
||||||
assign_empty_bignum(ptr)
|
alloc_bignum(data, bn);
|
||||||
mp_sub(&bignum_value(x), &bny, &bignum_value(ptr));
|
mp_sub(&bignum_value(x), &bny, &bignum_value(bn));
|
||||||
mp_clear(&bny);
|
mp_clear(&bny);
|
||||||
return ptr;
|
return bn;
|
||||||
} else if (is_object_type(y) && type_of(y) == double_tag) {
|
} else if (is_object_type(y) && type_of(y) == double_tag) {
|
||||||
assign_double(ptr, mp_get_double(&bignum_value(x)) - double_value(y));
|
assign_double(ptr, mp_get_double(&bignum_value(x)) - double_value(y));
|
||||||
return ptr;
|
return ptr;
|
||||||
} else if (is_object_type(y) && type_of(y) == bignum_tag) {
|
} else if (is_object_type(y) && type_of(y) == bignum_tag) {
|
||||||
assign_empty_bignum(ptr)
|
alloc_bignum(data, bn);
|
||||||
mp_sub(&bignum_value(x), &bignum_value(y), &bignum_value(ptr));
|
mp_sub(&bignum_value(x), &bignum_value(y), &bignum_value(bn));
|
||||||
return ptr;
|
return bn;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// still here, raise an error
|
// still here, raise an error
|
||||||
|
@ -2830,11 +2831,11 @@ object Cyc_fast_mul(void *data, object ptr, object x, object y) {
|
||||||
mp_init(&bny);
|
mp_init(&bny);
|
||||||
Cyc_int2bignum(xx, &bnx);
|
Cyc_int2bignum(xx, &bnx);
|
||||||
Cyc_int2bignum(yy, &bny);
|
Cyc_int2bignum(yy, &bny);
|
||||||
assign_empty_bignum(ptr)
|
alloc_bignum(data, bn);
|
||||||
mp_mul(&bnx, &bny, &bignum_value(ptr));
|
mp_mul(&bnx, &bny, &bignum_value(bn));
|
||||||
mp_clear(&bnx);
|
mp_clear(&bnx);
|
||||||
mp_clear(&bny);
|
mp_clear(&bny);
|
||||||
return ptr;
|
return bn;
|
||||||
}
|
}
|
||||||
} else if (is_object_type(y) && type_of(y) == double_tag) {
|
} else if (is_object_type(y) && type_of(y) == double_tag) {
|
||||||
assign_double(ptr, (double)(obj_obj2int(x)) * double_value(y));
|
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_int bnx;
|
||||||
mp_init(&bnx);
|
mp_init(&bnx);
|
||||||
Cyc_int2bignum(obj_obj2int(x), &bnx);
|
Cyc_int2bignum(obj_obj2int(x), &bnx);
|
||||||
assign_empty_bignum(ptr)
|
alloc_bignum(data, bn);
|
||||||
mp_mul(&bnx, &bignum_value(y), &bignum_value(ptr));
|
mp_mul(&bnx, &bignum_value(y), &bignum_value(bn));
|
||||||
mp_clear(&bnx);
|
mp_clear(&bnx);
|
||||||
return ptr;
|
return bn;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// x is double
|
// x is double
|
||||||
|
@ -2868,17 +2869,17 @@ object Cyc_fast_mul(void *data, object ptr, object x, object y) {
|
||||||
mp_int bny;
|
mp_int bny;
|
||||||
mp_init(&bny);
|
mp_init(&bny);
|
||||||
Cyc_int2bignum(obj_obj2int(y), &bny);
|
Cyc_int2bignum(obj_obj2int(y), &bny);
|
||||||
assign_empty_bignum(ptr)
|
alloc_bignum(data, bn);
|
||||||
mp_mul(&bignum_value(x), &bny, &bignum_value(ptr));
|
mp_mul(&bignum_value(x), &bny, &bignum_value(bn));
|
||||||
mp_clear(&bny);
|
mp_clear(&bny);
|
||||||
return ptr;
|
return bn;
|
||||||
} else if (is_object_type(y) && type_of(y) == double_tag) {
|
} else if (is_object_type(y) && type_of(y) == double_tag) {
|
||||||
assign_double(ptr, mp_get_double(&bignum_value(x)) * double_value(y));
|
assign_double(ptr, mp_get_double(&bignum_value(x)) * double_value(y));
|
||||||
return ptr;
|
return ptr;
|
||||||
} else if (is_object_type(y) && type_of(y) == bignum_tag) {
|
} else if (is_object_type(y) && type_of(y) == bignum_tag) {
|
||||||
assign_empty_bignum(ptr)
|
alloc_bignum(data, bn);
|
||||||
mp_mul(&bignum_value(x), &bignum_value(y), &bignum_value(ptr));
|
mp_mul(&bignum_value(x), &bignum_value(y), &bignum_value(bn));
|
||||||
return ptr;
|
return bn;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// still here, raise an error
|
// 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_int bnx;
|
||||||
mp_init(&bnx);
|
mp_init(&bnx);
|
||||||
Cyc_int2bignum(obj_obj2int(x), &bnx);
|
Cyc_int2bignum(obj_obj2int(x), &bnx);
|
||||||
assign_empty_bignum(ptr)
|
alloc_bignum(data, bn);
|
||||||
mp_div(&bnx, &bignum_value(y), &bignum_value(ptr), NULL);
|
mp_div(&bnx, &bignum_value(y), &bignum_value(bn), NULL);
|
||||||
mp_clear(&bnx);
|
mp_clear(&bnx);
|
||||||
return ptr;
|
return bn;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// x is double
|
// x is double
|
||||||
|
@ -2931,17 +2932,17 @@ object Cyc_fast_div(void *data, object ptr, object x, object y) {
|
||||||
mp_int bny;
|
mp_int bny;
|
||||||
mp_init(&bny);
|
mp_init(&bny);
|
||||||
Cyc_int2bignum(obj_obj2int(y), &bny);
|
Cyc_int2bignum(obj_obj2int(y), &bny);
|
||||||
assign_empty_bignum(ptr)
|
alloc_bignum(data, bn);
|
||||||
mp_div(&bignum_value(x), &bny, &bignum_value(ptr), NULL);
|
mp_div(&bignum_value(x), &bny, &bignum_value(bn), NULL);
|
||||||
mp_clear(&bny);
|
mp_clear(&bny);
|
||||||
return ptr;
|
return bn;
|
||||||
} else if (is_object_type(y) && type_of(y) == double_tag) {
|
} else if (is_object_type(y) && type_of(y) == double_tag) {
|
||||||
assign_double(ptr, mp_get_double(&bignum_value(x)) / double_value(y));
|
assign_double(ptr, mp_get_double(&bignum_value(x)) / double_value(y));
|
||||||
return ptr;
|
return ptr;
|
||||||
} else if (is_object_type(y) && type_of(y) == bignum_tag) {
|
} else if (is_object_type(y) && type_of(y) == bignum_tag) {
|
||||||
assign_empty_bignum(ptr)
|
alloc_bignum(data, bn);
|
||||||
mp_div(&bignum_value(x), &bignum_value(y), &bignum_value(ptr), NULL);
|
mp_div(&bignum_value(x), &bignum_value(y), &bignum_value(bn), NULL);
|
||||||
return ptr;
|
return bn;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// still here, raise an error
|
// still here, raise an error
|
||||||
|
|
Loading…
Add table
Reference in a new issue