mirror of
https://github.com/justinethier/cyclone.git
synced 2025-07-04 11:46:35 +02:00
Cleanup, added gc_alloc_bignum()
This commit is contained in:
parent
733ae48534
commit
876c1f0420
2 changed files with 23 additions and 6 deletions
19
gc.c
19
gc.c
|
@ -587,6 +587,25 @@ void *gc_try_alloc(gc_heap * h, int heap_type, size_t size, char *obj,
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// A convenience function for allocating bignums
|
||||||
|
void *gc_alloc_bignum(gc_thread_data *data)
|
||||||
|
{
|
||||||
|
int heap_grown, result;
|
||||||
|
bignum_type *bn;
|
||||||
|
bignum_type tmp;
|
||||||
|
tmp.hdr.mark = gc_color_red;
|
||||||
|
tmp.hdr.grayed = 0;
|
||||||
|
tmp.tag = bignum_tag;
|
||||||
|
bn = gc_alloc(((gc_thread_data *)data)->heap, sizeof(bignum_type), (char *)(&tmp), (gc_thread_data *)data, &heap_grown);
|
||||||
|
|
||||||
|
if ((result = mp_init(&bignum_value(bn))) != MP_OKAY) {
|
||||||
|
fprintf(stderr, "Error initializing number %s",
|
||||||
|
mp_error_to_string(result));
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
return bn;
|
||||||
|
}
|
||||||
|
|
||||||
void *gc_alloc(gc_heap_root * hrt, size_t size, char *obj, gc_thread_data * thd,
|
void *gc_alloc(gc_heap_root * hrt, size_t size, char *obj, gc_thread_data * thd,
|
||||||
int *heap_grown)
|
int *heap_grown)
|
||||||
{
|
{
|
||||||
|
|
|
@ -367,6 +367,9 @@ typedef struct {
|
||||||
mp_int bn;
|
mp_int bn;
|
||||||
} bignum_type;
|
} bignum_type;
|
||||||
|
|
||||||
|
#define alloc_bignum(data, p) \
|
||||||
|
bignum_type *p = gc_alloc_bignum((gc_thread_data *)data);
|
||||||
|
|
||||||
#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; \
|
||||||
|
@ -375,12 +378,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 init_empty_bignum(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 */
|
|
||||||
#define assign_empty_bignum(pobj) \
|
#define assign_empty_bignum(pobj) \
|
||||||
((bignum_type *)pobj)->hdr.mark = gc_color_red; \
|
((bignum_type *)pobj)->hdr.mark = gc_color_red; \
|
||||||
((bignum_type *)pobj)->hdr.grayed = 0; \
|
((bignum_type *)pobj)->hdr.grayed = 0; \
|
||||||
|
@ -710,6 +707,7 @@ void *gc_try_alloc(gc_heap * h, int heap_type, size_t size, char *obj,
|
||||||
gc_thread_data * thd);
|
gc_thread_data * thd);
|
||||||
void *gc_alloc(gc_heap_root * h, size_t size, char *obj, gc_thread_data * thd,
|
void *gc_alloc(gc_heap_root * h, size_t size, char *obj, gc_thread_data * thd,
|
||||||
int *heap_grown);
|
int *heap_grown);
|
||||||
|
void *gc_alloc_bignum(gc_thread_data *data);
|
||||||
size_t gc_allocated_bytes(object obj, gc_free_list * q, gc_free_list * r);
|
size_t gc_allocated_bytes(object obj, gc_free_list * q, gc_free_list * r);
|
||||||
gc_heap *gc_heap_last(gc_heap * h);
|
gc_heap *gc_heap_last(gc_heap * h);
|
||||||
size_t gc_heap_total_size(gc_heap * h);
|
size_t gc_heap_total_size(gc_heap * h);
|
||||||
|
|
Loading…
Add table
Reference in a new issue