change the type of argument pic_gc_protect accepts
This commit is contained in:
parent
ee985a31cd
commit
a6f561d66e
|
@ -29,6 +29,10 @@ void *pic_alloc(pic_state *, size_t);
|
|||
struct pic_object *pic_obj_alloc(pic_state *, size_t, enum pic_tt);
|
||||
void pic_free(pic_state *, void *);
|
||||
|
||||
void pic_gc_protect(pic_state *, pic_value);
|
||||
int pic_gc_arena_preserve(pic_state *);
|
||||
void pic_gc_arena_restore(pic_state *, int);
|
||||
|
||||
pic_state *pic_open();
|
||||
void pic_close(pic_state *);
|
||||
|
||||
|
|
|
@ -52,6 +52,7 @@ struct pic_proc {
|
|||
} u;
|
||||
};
|
||||
|
||||
#define pic_object_ptr(o) ((struct pic_object *)o.u.data)
|
||||
#define pic_pair_ptr(o) ((struct pic_pair *)o.u.data)
|
||||
#define pic_symbol_ptr(o) ((struct pic_symbol *)o.u.data)
|
||||
#define pic_proc_ptr(o) ((struct pic_proc *)o.u.data)
|
||||
|
|
57
src/gc.c
57
src/gc.c
|
@ -39,6 +39,40 @@ pic_free(pic_state *pic, void *ptr)
|
|||
free(ptr);
|
||||
}
|
||||
|
||||
static void
|
||||
gc_protect(pic_state *pic, struct pic_object *obj)
|
||||
{
|
||||
if (pic->arena_idx >= PIC_ARENA_SIZE) {
|
||||
pic_raise(pic, "arena overflow");
|
||||
}
|
||||
pic->arena[pic->arena_idx++] = obj;
|
||||
}
|
||||
|
||||
void
|
||||
pic_gc_protect(pic_state *pic, pic_value v)
|
||||
{
|
||||
struct pic_object *obj;
|
||||
|
||||
if (v.type != PIC_VTYPE_HEAP) {
|
||||
return;
|
||||
}
|
||||
obj = pic_object_ptr(v);
|
||||
|
||||
gc_protect(pic, obj);
|
||||
}
|
||||
|
||||
int
|
||||
pic_gc_arena_preserve(pic_state *pic)
|
||||
{
|
||||
return pic->arena_idx;
|
||||
}
|
||||
|
||||
void
|
||||
pic_gc_arena_restore(pic_state *pic, int state)
|
||||
{
|
||||
pic->arena_idx = state;
|
||||
}
|
||||
|
||||
static void *
|
||||
pic_gc_alloc(pic_state *pic, size_t size)
|
||||
{
|
||||
|
@ -104,27 +138,6 @@ pic_obj_alloc(pic_state *pic, size_t size, enum pic_tt tt)
|
|||
obj = (struct pic_object *)malloc(size);
|
||||
obj->tt = tt;
|
||||
|
||||
pic_gc_protect(pic, obj);
|
||||
gc_protect(pic, obj);
|
||||
return obj;
|
||||
}
|
||||
|
||||
void
|
||||
pic_gc_protect(pic_state *pic, struct pic_object *obj)
|
||||
{
|
||||
if (pic->arena_idx >= PIC_ARENA_SIZE) {
|
||||
pic_raise(pic, "arena overflow");
|
||||
}
|
||||
pic->arena[pic->arena_idx++] = obj;
|
||||
}
|
||||
|
||||
int
|
||||
pic_gc_arena_preserve(pic_state *pic)
|
||||
{
|
||||
return pic->arena_idx;
|
||||
}
|
||||
|
||||
void
|
||||
pic_gc_arena_restore(pic_state *pic, int state)
|
||||
{
|
||||
pic->arena_idx = state;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue