2013-10-10 03:44:51 -04:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include "picrin.h"
|
2013-10-13 02:14:15 -04:00
|
|
|
#include "picrin/gc.h"
|
2013-10-13 06:00:39 -04:00
|
|
|
#include "picrin/irep.h"
|
2013-10-15 00:21:40 -04:00
|
|
|
#include "picrin/proc.h"
|
2013-10-20 20:29:56 -04:00
|
|
|
#include "picrin/symbol.h"
|
2013-10-22 02:40:36 -04:00
|
|
|
#include "picrin/port.h"
|
2013-10-13 02:14:15 -04:00
|
|
|
|
2013-10-14 20:07:55 -04:00
|
|
|
#if GC_DEBUG
|
|
|
|
# include <stdio.h>
|
|
|
|
#endif
|
|
|
|
|
2013-10-13 02:14:15 -04:00
|
|
|
void
|
|
|
|
init_heap_page(struct heap_page *heap)
|
|
|
|
{
|
2013-10-13 03:02:08 -04:00
|
|
|
union header *base, *freep;
|
2013-10-13 02:14:15 -04:00
|
|
|
void *p;
|
|
|
|
|
2013-10-13 03:02:08 -04:00
|
|
|
p = (union header *)malloc(PIC_HEAP_SIZE);
|
2013-10-13 02:14:15 -04:00
|
|
|
|
2013-10-13 03:02:08 -04:00
|
|
|
heap->base = base = (union header *)
|
|
|
|
(((unsigned long)p + sizeof(union header) -1) & ~(sizeof(union header) - 1));
|
|
|
|
base->s.ptr = base + 1;
|
2013-10-15 20:17:44 -04:00
|
|
|
base->s.size = 1;
|
2013-10-13 02:14:15 -04:00
|
|
|
|
2013-10-13 03:02:08 -04:00
|
|
|
heap->freep = freep = base->s.ptr;
|
|
|
|
freep->s.ptr = base;
|
|
|
|
freep->s.size = ((char *)p + PIC_HEAP_SIZE - (char *)freep) / sizeof(union header);
|
2013-10-14 05:21:56 -04:00
|
|
|
|
|
|
|
heap->endp = freep + freep->s.size;
|
2013-10-15 20:21:57 -04:00
|
|
|
|
2013-10-17 07:55:33 -04:00
|
|
|
#if GC_DEBUG
|
2013-10-15 20:21:57 -04:00
|
|
|
printf("base = %p\nbase->s.ptr = %p\n", base, base->s.ptr);
|
2013-10-17 07:55:33 -04:00
|
|
|
#endif
|
2013-10-13 02:14:15 -04:00
|
|
|
}
|
2013-10-10 03:44:51 -04:00
|
|
|
|
|
|
|
void *
|
|
|
|
pic_alloc(pic_state *pic, size_t size)
|
2013-10-13 03:56:30 -04:00
|
|
|
{
|
|
|
|
void *ptr;
|
|
|
|
|
|
|
|
ptr = malloc(size);
|
|
|
|
if (ptr == NULL) {
|
2013-10-20 04:41:48 -04:00
|
|
|
pic_abort(pic, "memory exhausted");
|
2013-10-13 03:56:30 -04:00
|
|
|
}
|
|
|
|
return ptr;
|
|
|
|
}
|
|
|
|
|
2013-10-15 22:21:41 -04:00
|
|
|
void *
|
|
|
|
pic_realloc(pic_state *pic, void *ptr, size_t size)
|
|
|
|
{
|
|
|
|
ptr = realloc(ptr, size);
|
|
|
|
if (ptr == NULL) {
|
2013-10-20 04:41:48 -04:00
|
|
|
pic_abort(pic, "memory exhausted");
|
2013-10-15 22:21:41 -04:00
|
|
|
}
|
|
|
|
return ptr;
|
|
|
|
}
|
|
|
|
|
2013-10-23 11:32:03 -04:00
|
|
|
void *
|
|
|
|
pic_calloc(pic_state *pic, unsigned count, size_t size)
|
|
|
|
{
|
|
|
|
void *ptr;
|
|
|
|
|
|
|
|
ptr = calloc(count ,size);
|
|
|
|
if (ptr == NULL) {
|
|
|
|
pic_abort(pic, "memory exhausted");
|
|
|
|
}
|
|
|
|
return ptr;
|
|
|
|
}
|
|
|
|
|
2013-10-13 03:56:30 -04:00
|
|
|
void
|
|
|
|
pic_free(pic_state *pic, void *ptr)
|
|
|
|
{
|
|
|
|
free(ptr);
|
|
|
|
}
|
|
|
|
|
2013-10-13 04:25:36 -04:00
|
|
|
static void
|
|
|
|
gc_protect(pic_state *pic, struct pic_object *obj)
|
|
|
|
{
|
|
|
|
if (pic->arena_idx >= PIC_ARENA_SIZE) {
|
2013-10-20 04:41:48 -04:00
|
|
|
pic_abort(pic, "arena overflow");
|
2013-10-13 04:25:36 -04:00
|
|
|
}
|
|
|
|
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;
|
|
|
|
}
|
2013-10-17 09:42:20 -04:00
|
|
|
obj = pic_obj_ptr(v);
|
2013-10-13 04:25:36 -04:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2013-10-13 03:56:30 -04:00
|
|
|
static void *
|
2013-10-13 06:00:12 -04:00
|
|
|
gc_alloc(pic_state *pic, size_t size)
|
2013-10-10 03:44:51 -04:00
|
|
|
{
|
2013-10-13 03:02:08 -04:00
|
|
|
union header *freep, *p, *prevp;
|
2013-10-13 02:14:15 -04:00
|
|
|
size_t nunits;
|
|
|
|
|
2013-10-13 03:02:08 -04:00
|
|
|
nunits = (size + sizeof(union header) - 1) / sizeof(union header) + 1;
|
2013-10-13 02:14:15 -04:00
|
|
|
|
|
|
|
freep = pic->heap->freep;
|
|
|
|
prevp = freep;
|
2013-10-13 03:02:08 -04:00
|
|
|
for (p = prevp->s.ptr; ; prevp = p, p = p->s.ptr) {
|
|
|
|
if (p->s.size >= nunits)
|
2013-10-13 02:14:15 -04:00
|
|
|
break;
|
2013-10-13 03:02:08 -04:00
|
|
|
if (p == freep) {
|
2013-10-13 02:14:15 -04:00
|
|
|
return 0;
|
2013-10-13 03:02:08 -04:00
|
|
|
}
|
2013-10-13 02:14:15 -04:00
|
|
|
}
|
2013-10-13 03:02:08 -04:00
|
|
|
if (p->s.size == nunits) {
|
|
|
|
prevp->s.ptr = p->s.ptr;
|
2013-10-13 02:14:15 -04:00
|
|
|
}
|
|
|
|
else {
|
2013-10-13 03:02:08 -04:00
|
|
|
p->s.size -= nunits;
|
|
|
|
p += p->s.size;
|
|
|
|
p->s.size = nunits;
|
2013-10-13 02:14:15 -04:00
|
|
|
}
|
|
|
|
pic->heap->freep = prevp;
|
|
|
|
|
2013-10-13 06:00:12 -04:00
|
|
|
p->s.mark = PIC_GC_UNMARK;
|
2013-10-13 02:14:15 -04:00
|
|
|
return (void *)(p + 1);
|
|
|
|
}
|
|
|
|
|
2013-10-13 06:00:12 -04:00
|
|
|
static void gc_mark(pic_state *, pic_value);
|
|
|
|
|
2013-10-13 03:56:30 -04:00
|
|
|
static void
|
2013-10-13 06:00:12 -04:00
|
|
|
gc_mark_object(pic_state *pic, struct pic_object *obj)
|
2013-10-13 02:14:15 -04:00
|
|
|
{
|
2013-10-13 06:00:12 -04:00
|
|
|
union header *p;
|
2013-10-13 02:14:15 -04:00
|
|
|
|
2013-10-13 06:00:12 -04:00
|
|
|
p = (union header *)obj - 1;
|
|
|
|
p->s.mark = PIC_GC_MARK;
|
2013-10-13 02:14:15 -04:00
|
|
|
|
2013-10-13 06:00:12 -04:00
|
|
|
switch (obj->tt) {
|
|
|
|
case PIC_TT_PAIR: {
|
|
|
|
gc_mark(pic, ((struct pic_pair *)obj)->car);
|
|
|
|
gc_mark(pic, ((struct pic_pair *)obj)->cdr);
|
|
|
|
break;
|
2013-10-13 02:14:15 -04:00
|
|
|
}
|
2013-10-13 06:00:12 -04:00
|
|
|
case PIC_TT_SYMBOL: {
|
|
|
|
break;
|
2013-10-13 02:14:15 -04:00
|
|
|
}
|
2013-10-23 13:02:07 -04:00
|
|
|
case PIC_TT_ENV: {
|
|
|
|
struct pic_env *env = (struct pic_env *)obj;
|
|
|
|
int i;
|
|
|
|
|
2013-10-23 14:41:48 -04:00
|
|
|
for (i = 0; i < env->num_val; ++i) {
|
2013-10-23 13:02:07 -04:00
|
|
|
gc_mark(pic, env->values[i]);
|
|
|
|
}
|
|
|
|
gc_mark_object(pic, (struct pic_object *)env->up);
|
|
|
|
break;
|
|
|
|
}
|
2013-10-13 06:00:12 -04:00
|
|
|
case PIC_TT_PROC: {
|
2013-10-23 13:02:07 -04:00
|
|
|
struct pic_proc *proc = (struct pic_proc *)obj;
|
|
|
|
if (proc->env) {
|
|
|
|
gc_mark_object(pic, (struct pic_object *)proc->env);
|
|
|
|
}
|
|
|
|
gc_mark(pic, proc->aux);
|
2013-10-13 06:00:12 -04:00
|
|
|
break;
|
|
|
|
}
|
2013-10-20 19:48:55 -04:00
|
|
|
case PIC_TT_PORT: {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case PIC_TT_STRING: {
|
|
|
|
}
|
|
|
|
case PIC_TT_NIL:
|
|
|
|
case PIC_TT_BOOL:
|
|
|
|
case PIC_TT_FLOAT:
|
2013-10-27 11:21:24 -04:00
|
|
|
case PIC_TT_INT:
|
2013-10-22 03:02:20 -04:00
|
|
|
case PIC_TT_EOF:
|
2013-10-20 19:48:55 -04:00
|
|
|
case PIC_TT_UNDEF:
|
2013-10-20 04:41:48 -04:00
|
|
|
pic_abort(pic, "logic flaw");
|
2013-10-13 06:00:12 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gc_mark(pic_state *pic, pic_value v)
|
|
|
|
{
|
|
|
|
struct pic_object *obj;
|
|
|
|
|
|
|
|
if (v.type != PIC_VTYPE_HEAP)
|
|
|
|
return;
|
2013-10-17 09:42:20 -04:00
|
|
|
obj = pic_obj_ptr(v);
|
2013-10-13 06:00:12 -04:00
|
|
|
|
|
|
|
gc_mark_object(pic, obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gc_mark_phase(pic_state *pic)
|
|
|
|
{
|
|
|
|
pic_value *stack;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* stack */
|
|
|
|
for (stack = pic->stbase; stack != pic->sp; ++stack) {
|
|
|
|
gc_mark(pic, *stack);
|
|
|
|
}
|
2013-10-17 10:29:18 -04:00
|
|
|
gc_mark(pic, *stack);
|
2013-10-13 06:00:12 -04:00
|
|
|
|
|
|
|
/* arena */
|
|
|
|
for (i = 0; i < pic->arena_idx; ++i) {
|
|
|
|
gc_mark_object(pic, pic->arena[i]);
|
2013-10-13 02:14:15 -04:00
|
|
|
}
|
2013-10-13 06:00:12 -04:00
|
|
|
|
2013-10-17 11:17:55 -04:00
|
|
|
/* globals */
|
|
|
|
for (i = 0; i < pic->glen; ++i) {
|
|
|
|
gc_mark(pic, pic->globals[i]);
|
|
|
|
}
|
|
|
|
|
2013-10-20 20:29:56 -04:00
|
|
|
/* pool */
|
|
|
|
for (i = 0; i < pic->plen; ++i) {
|
|
|
|
gc_mark(pic, pic->pool[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* symbol table */
|
|
|
|
for (i = 0; i < pic->sym_tbl->size; ++i) {
|
|
|
|
gc_mark(pic, pic->sym_tbl->tbl[i]);
|
|
|
|
}
|
|
|
|
|
2013-10-15 20:29:39 -04:00
|
|
|
gc_mark(pic, pic->sDEFINE);
|
2013-10-15 22:32:30 -04:00
|
|
|
gc_mark(pic, pic->sLAMBDA);
|
2013-10-20 20:29:56 -04:00
|
|
|
gc_mark(pic, pic->sIF);
|
|
|
|
gc_mark(pic, pic->sBEGIN);
|
2013-10-23 14:14:32 -04:00
|
|
|
gc_mark(pic, pic->sSETBANG);
|
2013-10-20 20:29:56 -04:00
|
|
|
gc_mark(pic, pic->sQUOTE);
|
2013-10-22 23:39:48 -04:00
|
|
|
gc_mark(pic, pic->sQUASIQUOTE);
|
|
|
|
gc_mark(pic, pic->sUNQUOTE);
|
|
|
|
gc_mark(pic, pic->sUNQUOTE_SPLICING);
|
2013-10-15 20:29:39 -04:00
|
|
|
gc_mark(pic, pic->sCONS);
|
2013-10-20 20:29:56 -04:00
|
|
|
gc_mark(pic, pic->sCAR);
|
|
|
|
gc_mark(pic, pic->sCDR);
|
|
|
|
gc_mark(pic, pic->sNILP);
|
2013-10-15 20:29:39 -04:00
|
|
|
gc_mark(pic, pic->sADD);
|
|
|
|
gc_mark(pic, pic->sSUB);
|
|
|
|
gc_mark(pic, pic->sMUL);
|
2013-10-24 08:10:13 -04:00
|
|
|
gc_mark(pic, pic->sEQ);
|
|
|
|
gc_mark(pic, pic->sLT);
|
|
|
|
gc_mark(pic, pic->sLE);
|
|
|
|
gc_mark(pic, pic->sGT);
|
|
|
|
gc_mark(pic, pic->sGE);
|
2013-10-15 20:29:39 -04:00
|
|
|
gc_mark(pic, pic->sDIV);
|
2013-10-13 06:00:12 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
is_marked(union header *p)
|
|
|
|
{
|
|
|
|
return p->s.mark == PIC_GC_MARK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gc_unmark(union header *p)
|
|
|
|
{
|
|
|
|
p->s.mark = PIC_GC_UNMARK;
|
|
|
|
}
|
|
|
|
|
2013-10-13 06:00:39 -04:00
|
|
|
static void
|
|
|
|
gc_finalize_object(pic_state *pic, struct pic_object *obj)
|
|
|
|
{
|
2013-10-14 05:22:14 -04:00
|
|
|
#if GC_DEBUG
|
|
|
|
printf("finalizing object type %d\n", obj->tt);
|
|
|
|
#endif
|
|
|
|
|
2013-10-13 06:00:39 -04:00
|
|
|
switch (obj->tt) {
|
|
|
|
case PIC_TT_SYMBOL: {
|
|
|
|
char *name;
|
|
|
|
name = ((struct pic_symbol *)obj)->name;
|
2013-10-14 04:04:59 -04:00
|
|
|
pic_free(pic, name);
|
2013-10-13 06:00:39 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case PIC_TT_PAIR: {
|
|
|
|
break;
|
|
|
|
}
|
2013-10-23 13:02:07 -04:00
|
|
|
case PIC_TT_ENV: {
|
|
|
|
pic_free(pic, ((struct pic_env *)obj)->values);
|
|
|
|
break;
|
|
|
|
}
|
2013-10-13 06:00:39 -04:00
|
|
|
case PIC_TT_PROC: {
|
2013-10-14 04:32:24 -04:00
|
|
|
break;
|
2013-10-13 06:00:39 -04:00
|
|
|
}
|
2013-10-20 19:48:55 -04:00
|
|
|
case PIC_TT_STRING: {
|
|
|
|
pic_free(pic, (void*)((struct pic_string *)obj)->str);
|
|
|
|
break;
|
|
|
|
}
|
2013-10-22 02:40:36 -04:00
|
|
|
case PIC_TT_PORT: {
|
|
|
|
struct pic_port *port = (struct pic_port *)obj;
|
2013-10-22 02:44:03 -04:00
|
|
|
if (port->status == PIC_PORT_OPEN) {
|
2013-10-22 02:40:36 -04:00
|
|
|
fclose(port->file);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2013-10-20 19:48:55 -04:00
|
|
|
case PIC_TT_NIL:
|
|
|
|
case PIC_TT_BOOL:
|
|
|
|
case PIC_TT_FLOAT:
|
2013-10-27 11:21:24 -04:00
|
|
|
case PIC_TT_INT:
|
2013-10-22 03:02:20 -04:00
|
|
|
case PIC_TT_EOF:
|
2013-10-20 19:48:55 -04:00
|
|
|
case PIC_TT_UNDEF:
|
2013-10-20 04:41:48 -04:00
|
|
|
pic_abort(pic, "logic flaw");
|
2013-10-13 06:00:39 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-13 06:00:12 -04:00
|
|
|
static void
|
|
|
|
gc_sweep_phase(pic_state *pic)
|
|
|
|
{
|
2013-10-14 04:34:04 -04:00
|
|
|
union header *base, *bp, *p;
|
2013-10-13 06:00:12 -04:00
|
|
|
|
2013-10-14 05:22:14 -04:00
|
|
|
#if GC_DEBUG
|
2013-10-15 20:22:15 -04:00
|
|
|
int freed = 0;
|
|
|
|
|
2013-10-14 05:22:14 -04:00
|
|
|
puts("sweep started");
|
|
|
|
#endif
|
|
|
|
|
2013-10-14 04:34:04 -04:00
|
|
|
base = pic->heap->base;
|
2013-10-17 07:55:33 -04:00
|
|
|
#if GC_DEBUG
|
2013-10-15 20:21:57 -04:00
|
|
|
printf("base = %p\nbase->s.ptr = %p\n", base, base->s.ptr);
|
2013-10-17 07:55:33 -04:00
|
|
|
#endif
|
2013-10-15 20:21:13 -04:00
|
|
|
for (p = base->s.ptr; ; p = p->s.ptr) {
|
2013-10-14 05:22:14 -04:00
|
|
|
|
|
|
|
#if GC_DEBUG
|
|
|
|
puts("sweeping block");
|
|
|
|
#endif
|
|
|
|
|
2013-10-14 19:58:23 -04:00
|
|
|
retry:
|
|
|
|
|
2013-10-13 06:00:12 -04:00
|
|
|
for (bp = p + p->s.size; bp != p->s.ptr; bp += bp->s.size) {
|
2013-10-14 05:22:14 -04:00
|
|
|
|
|
|
|
#if GC_DEBUG
|
|
|
|
printf(" bp = %p\n p = %p\n p->s.ptr = %p\n endp = %p\n",bp, p, p->s.ptr, pic->heap->endp);
|
|
|
|
#endif
|
|
|
|
|
2013-10-14 05:21:56 -04:00
|
|
|
if (p >= p->s.ptr && bp == pic->heap->endp)
|
|
|
|
break;
|
2013-10-13 06:00:12 -04:00
|
|
|
if (is_marked(bp)) {
|
2013-10-14 05:22:14 -04:00
|
|
|
|
|
|
|
#if GC_DEBUG
|
|
|
|
printf("marked:\t\t\t");
|
|
|
|
pic_debug(pic, pic_obj_value((struct pic_object *)(bp + 1)));
|
|
|
|
printf("\n");
|
|
|
|
#endif
|
|
|
|
|
2013-10-13 06:00:12 -04:00
|
|
|
gc_unmark(bp);
|
|
|
|
continue;
|
|
|
|
}
|
2013-10-14 05:22:14 -04:00
|
|
|
|
|
|
|
#if GC_DEBUG
|
|
|
|
puts("unmarked");
|
|
|
|
#endif
|
|
|
|
|
2013-10-13 06:00:12 -04:00
|
|
|
/* free! */
|
2013-10-13 06:00:39 -04:00
|
|
|
gc_finalize_object(pic, (struct pic_object *)(bp + 1));
|
2013-10-13 06:00:12 -04:00
|
|
|
if (bp + bp->s.size == p->s.ptr) {
|
|
|
|
bp->s.size += p->s.ptr->s.size;
|
|
|
|
bp->s.ptr = p->s.ptr->s.ptr;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
bp->s.ptr = p->s.ptr;
|
|
|
|
}
|
|
|
|
if (p + p->s.size == bp) {
|
|
|
|
p->s.size += bp->s.size;
|
|
|
|
p->s.ptr = bp->s.ptr;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
p->s.ptr = bp;
|
2013-10-14 19:58:23 -04:00
|
|
|
/* retry with next p */
|
|
|
|
p = p->s.ptr;
|
2013-10-13 06:00:12 -04:00
|
|
|
}
|
2013-10-14 19:58:23 -04:00
|
|
|
|
2013-10-15 20:22:15 -04:00
|
|
|
#if GC_DEBUG
|
|
|
|
freed++;
|
|
|
|
#endif
|
|
|
|
|
2013-10-14 19:58:23 -04:00
|
|
|
goto retry;
|
2013-10-13 06:00:12 -04:00
|
|
|
}
|
2013-10-15 20:21:13 -04:00
|
|
|
|
|
|
|
if (p->s.ptr == base)
|
|
|
|
break;
|
2013-10-13 02:14:15 -04:00
|
|
|
}
|
2013-10-15 20:22:15 -04:00
|
|
|
|
|
|
|
#if GC_DEBUG
|
|
|
|
printf("freed: %d counts\n", freed);
|
|
|
|
#endif
|
2013-10-13 06:00:12 -04:00
|
|
|
}
|
|
|
|
|
2013-10-14 04:07:09 -04:00
|
|
|
void
|
2013-10-13 06:00:12 -04:00
|
|
|
pic_gc_run(pic_state *pic)
|
|
|
|
{
|
2013-10-14 05:22:14 -04:00
|
|
|
#if GC_DEBUG
|
2013-10-14 04:07:09 -04:00
|
|
|
puts("gc run!");
|
2013-10-14 05:22:14 -04:00
|
|
|
#endif
|
2013-10-13 06:00:12 -04:00
|
|
|
gc_mark_phase(pic);
|
|
|
|
gc_sweep_phase(pic);
|
2013-10-10 03:44:51 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
struct pic_object *
|
2013-10-13 03:55:07 -04:00
|
|
|
pic_obj_alloc(pic_state *pic, size_t size, enum pic_tt tt)
|
2013-10-10 03:44:51 -04:00
|
|
|
{
|
|
|
|
struct pic_object *obj;
|
|
|
|
|
2013-10-13 06:00:12 -04:00
|
|
|
obj = (struct pic_object *)gc_alloc(pic, size);
|
|
|
|
if (obj == NULL) {
|
|
|
|
pic_gc_run(pic);
|
|
|
|
obj = (struct pic_object *)gc_alloc(pic, size);
|
|
|
|
if (obj == NULL)
|
2013-10-20 04:41:48 -04:00
|
|
|
pic_abort(pic, "GC memory exhausted");
|
2013-10-13 06:00:12 -04:00
|
|
|
}
|
2013-10-10 03:44:51 -04:00
|
|
|
obj->tt = tt;
|
|
|
|
|
2013-10-13 04:25:36 -04:00
|
|
|
gc_protect(pic, obj);
|
2013-10-10 03:44:51 -04:00
|
|
|
return obj;
|
|
|
|
}
|