Merge branch 'auto-arena-extend'

This commit is contained in:
Yuichi Nishiwaki 2014-05-26 16:09:41 +09:00
commit d71666624b
15 changed files with 47 additions and 35 deletions

View File

@ -105,8 +105,8 @@ typedef struct {
struct pic_jmpbuf *try_jmps;
struct pic_heap *heap;
struct pic_object *arena[PIC_ARENA_SIZE];
int arena_idx;
struct pic_object **arena;
size_t arena_size, arena_idx;
char *native_stack_start;
} pic_state;
@ -123,8 +123,8 @@ void pic_free(pic_state *, void *);
void pic_gc_run(pic_state *);
pic_value pic_gc_protect(pic_state *, pic_value);
int pic_gc_arena_preserve(pic_state *);
void pic_gc_arena_restore(pic_state *, int);
size_t pic_gc_arena_preserve(pic_state *);
void pic_gc_arena_restore(pic_state *, size_t);
pic_state *pic_open(int argc, char *argv[], char **envp);
void pic_close(pic_state *);

View File

@ -26,7 +26,8 @@ struct pic_cont {
pic_code *ip;
struct pic_object *arena[PIC_ARENA_SIZE];
struct pic_object **arena;
size_t arena_size;
int arena_idx;
pic_value results;

View File

@ -266,7 +266,7 @@ static pic_value
analyze(analyze_state *state, pic_value obj, bool tailpos)
{
pic_state *pic = state->pic;
int ai = pic_gc_arena_preserve(pic);
size_t ai = pic_gc_arena_preserve(pic);
pic_value res;
pic_sym tag;
@ -1438,7 +1438,7 @@ struct pic_proc *
pic_compile(pic_state *pic, pic_value obj)
{
struct pic_irep *irep;
int ai = pic_gc_arena_preserve(pic);
size_t ai = pic_gc_arena_preserve(pic);
#if DEBUG
fprintf(stdout, "ai = %d\n", pic_gc_arena_preserve(pic));

View File

@ -139,7 +139,9 @@ save_cont(pic_state *pic, struct pic_cont **c)
cont->ip = pic->ip;
cont->arena_idx = pic->arena_idx;
memcpy(cont->arena, pic->arena, sizeof(struct pic_object *) * PIC_ARENA_SIZE);
cont->arena_size = pic->arena_size;
cont->arena = (struct pic_object **)pic_alloc(pic, sizeof(struct pic_object *) * pic->arena_size);
memcpy(cont->arena, pic->arena, sizeof(struct pic_object *) * pic->arena_size);
cont->results = pic_undef_value();
}
@ -182,7 +184,9 @@ restore_cont(pic_state *pic, struct pic_cont *cont)
pic->ip = cont->ip;
memcpy(pic->arena, cont->arena, sizeof(struct pic_object *) * PIC_ARENA_SIZE);
pic->arena = (struct pic_object **)pic_realloc(pic, pic->arena, sizeof(struct pic_object *) * cont->arena_size);
memcpy(pic->arena, cont->arena, sizeof(struct pic_object *) * cont->arena_size);
pic->arena_size = cont->arena_size;
pic->arena_idx = cont->arena_idx;
memcpy(cont->stk_pos, cont->stk_ptr, cont->stk_len);

View File

@ -10,7 +10,7 @@
pic_str *
pic_get_backtrace(pic_state *pic)
{
int ai = pic_gc_arena_preserve(pic);
size_t ai = pic_gc_arena_preserve(pic);
pic_callinfo *ci;
pic_str *trace;
@ -38,7 +38,7 @@ pic_get_backtrace(pic_state *pic)
void
pic_print_backtrace(pic_state *pic, struct pic_error *e)
{
int ai = pic_gc_arena_preserve(pic);
size_t ai = pic_gc_arena_preserve(pic);
pic_str *trace;
assert(pic->err != NULL);

View File

@ -179,8 +179,9 @@ pic_free(pic_state *pic, void *ptr)
static void
gc_protect(pic_state *pic, struct pic_object *obj)
{
if (pic->arena_idx >= PIC_ARENA_SIZE) {
pic_abort(pic, "arena overflow");
if (pic->arena_idx >= pic->arena_size) {
pic->arena_size = pic->arena_size * 2 + 1;
pic->arena = pic_realloc(pic, pic->arena, sizeof(struct pic_object *) * pic->arena_size);
}
pic->arena[pic->arena_idx++] = obj;
}
@ -200,14 +201,14 @@ pic_gc_protect(pic_state *pic, pic_value v)
return v;
}
int
size_t
pic_gc_arena_preserve(pic_state *pic)
{
return pic->arena_idx;
}
void
pic_gc_arena_restore(pic_state *pic, int state)
pic_gc_arena_restore(pic_state *pic, size_t state)
{
pic->arena_idx = state;
}
@ -618,6 +619,7 @@ gc_finalize_object(pic_state *pic, struct pic_object *obj)
pic_free(pic, cont->stk_ptr);
pic_free(pic, cont->st_ptr);
pic_free(pic, cont->ci_ptr);
pic_free(pic, cont->arena);
PIC_BLK_DECREF(pic, cont->blk);
break;
}

View File

@ -60,7 +60,7 @@ pic_features(pic_state *pic)
void
pic_init_core(pic_state *pic)
{
int ai = pic_gc_arena_preserve(pic);
size_t ai = pic_gc_arena_preserve(pic);
pic_deflibrary ("(scheme base)") {

View File

@ -8,7 +8,7 @@
pic_value
pic_load_cstr(pic_state *pic, const char *src)
{
int ai;
size_t ai;
pic_value v, exprs;
struct pic_proc *proc;
@ -37,7 +37,7 @@ pic_value
pic_load(pic_state *pic, const char *fn)
{
FILE *file;
int ai;
size_t ai;
pic_value v, exprs;
struct pic_proc *proc;

View File

@ -150,7 +150,7 @@ static pic_value macroexpand_node(pic_state *, pic_value, struct pic_senv *, pic
static pic_value
macroexpand(pic_state *pic, pic_value expr, struct pic_senv *senv, pic_value assoc_box)
{
int ai = pic_gc_arena_preserve(pic);
size_t ai = pic_gc_arena_preserve(pic);
pic_value v;
v = macroexpand_node(pic, expr, senv, assoc_box);
@ -196,7 +196,7 @@ push_scope(pic_state *pic, pic_value formals, struct pic_senv *up, pic_value ass
static pic_value
macroexpand_list(pic_state *pic, pic_value list, struct pic_senv *senv, pic_value assoc_box)
{
int ai = pic_gc_arena_preserve(pic);
size_t ai = pic_gc_arena_preserve(pic);
pic_value v, vs;
/* macroexpand in order */
@ -271,7 +271,7 @@ macroexpand_deflibrary(pic_state *pic, pic_value expr)
pic_in_library(pic, pic_cadr(pic, expr));
pic_for_each (v, pic_cddr(pic, expr)) {
int ai = pic_gc_arena_preserve(pic);
size_t ai = pic_gc_arena_preserve(pic);
pic_eval(pic, v);

View File

@ -734,7 +734,7 @@ pic_number_string_to_number(pic_state *pic)
void
pic_init_number(pic_state *pic)
{
int ai = pic_gc_arena_preserve(pic);
size_t ai = pic_gc_arena_preserve(pic);
pic_defun(pic, "number?", pic_number_real_p);
pic_defun(pic, "complex?", pic_number_real_p);

View File

@ -84,7 +84,7 @@ pic_list1(pic_state *pic, pic_value obj1)
pic_value
pic_list2(pic_state *pic, pic_value obj1, pic_value obj2)
{
int ai = pic_gc_arena_preserve(pic);
size_t ai = pic_gc_arena_preserve(pic);
pic_value val;
val = pic_cons(pic, obj1, pic_list1(pic, obj2));
@ -97,7 +97,7 @@ pic_list2(pic_state *pic, pic_value obj1, pic_value obj2)
pic_value
pic_list3(pic_state *pic, pic_value obj1, pic_value obj2, pic_value obj3)
{
int ai = pic_gc_arena_preserve(pic);
size_t ai = pic_gc_arena_preserve(pic);
pic_value val;
val = pic_cons(pic, obj1, pic_list2(pic, obj2, obj3));
@ -110,7 +110,7 @@ pic_list3(pic_state *pic, pic_value obj1, pic_value obj2, pic_value obj3)
pic_value
pic_list4(pic_state *pic, pic_value obj1, pic_value obj2, pic_value obj3, pic_value obj4)
{
int ai = pic_gc_arena_preserve(pic);
size_t ai = pic_gc_arena_preserve(pic);
pic_value val;
val = pic_cons(pic, obj1, pic_list3(pic, obj2, obj3, obj4));
@ -123,7 +123,7 @@ pic_list4(pic_state *pic, pic_value obj1, pic_value obj2, pic_value obj3, pic_va
pic_value
pic_list5(pic_state *pic, pic_value obj1, pic_value obj2, pic_value obj3, pic_value obj4, pic_value obj5)
{
int ai = pic_gc_arena_preserve(pic);
size_t ai = pic_gc_arena_preserve(pic);
pic_value val;
val = pic_cons(pic, obj1, pic_list4(pic, obj2, obj3, obj4, obj5));
@ -136,7 +136,7 @@ pic_list5(pic_state *pic, pic_value obj1, pic_value obj2, pic_value obj3, pic_va
pic_value
pic_list6(pic_state *pic, pic_value obj1, pic_value obj2, pic_value obj3, pic_value obj4, pic_value obj5, pic_value obj6)
{
int ai = pic_gc_arena_preserve(pic);
size_t ai = pic_gc_arena_preserve(pic);
pic_value val;
val = pic_cons(pic, obj1, pic_list5(pic, obj2, obj3, obj4, obj5, obj6));
@ -149,7 +149,7 @@ pic_list6(pic_state *pic, pic_value obj1, pic_value obj2, pic_value obj3, pic_va
pic_value
pic_list7(pic_state *pic, pic_value obj1, pic_value obj2, pic_value obj3, pic_value obj4, pic_value obj5, pic_value obj6, pic_value obj7)
{
int ai = pic_gc_arena_preserve(pic);
size_t ai = pic_gc_arena_preserve(pic);
pic_value val;
val = pic_cons(pic, obj1, pic_list6(pic, obj2, obj3, obj4, obj5, obj6, obj7));
@ -205,7 +205,7 @@ pic_length(pic_state *pic, pic_value obj)
pic_value
pic_reverse(pic_state *pic, pic_value list)
{
int ai = pic_gc_arena_preserve(pic);
size_t ai = pic_gc_arena_preserve(pic);
pic_value v, acc;
acc = pic_nil_value();
@ -221,7 +221,7 @@ pic_reverse(pic_state *pic, pic_value list)
pic_value
pic_append(pic_state *pic, pic_value xs, pic_value ys)
{
int ai = pic_gc_arena_preserve(pic);
size_t ai = pic_gc_arena_preserve(pic);
pic_value x;
xs = pic_reverse(pic, xs);

View File

@ -217,7 +217,7 @@ read_datum(int tok, yyscan_t scanner)
static pic_value
read(int tok, yyscan_t scanner)
{
int ai = pic_gc_arena_preserve(pic);
size_t ai = pic_gc_arena_preserve(pic);
pic_value val;
val = read_datum(tok, scanner);

View File

@ -18,7 +18,7 @@ pic_open(int argc, char *argv[], char **envp)
char t;
pic_state *pic;
int ai;
size_t ai;
pic = (pic_state *)malloc(sizeof(pic_state));
@ -70,6 +70,8 @@ pic_open(int argc, char *argv[], char **envp)
pic->try_jmps = NULL;
/* GC arena */
pic->arena = (struct pic_object **)calloc(PIC_ARENA_SIZE, sizeof(struct pic_object **));
pic->arena_size = PIC_ARENA_SIZE;
pic->arena_idx = 0;
/* native stack marker */
@ -153,6 +155,9 @@ pic_close(pic_state *pic)
xh_destroy(&pic->global_tbl);
xh_destroy(&pic->macros);
/* free GC arena */
free(pic->arena);
/* free symbol names */
xh_begin(&it, &pic->sym_names);
while (xh_next(&it)) {

View File

@ -18,7 +18,7 @@ pic_system_cmdline(pic_state *pic)
pic_get_args(pic, "");
for (i = 0; i < pic->argc; ++i) {
int ai = pic_gc_arena_preserve(pic);
size_t ai = pic_gc_arena_preserve(pic);
v = pic_cons(pic, pic_obj_value(pic_str_new_cstr(pic, pic->argv[i])), v);
pic_gc_arena_restore(pic, ai);
@ -95,7 +95,7 @@ pic_system_getenvs(pic_state *pic)
{
char **envp;
pic_value data = pic_nil_value();
int ai = pic_gc_arena_preserve(pic);
size_t ai = pic_gc_arena_preserve(pic);
pic_get_args(pic, "");

View File

@ -514,7 +514,7 @@ pic_value
pic_apply(pic_state *pic, struct pic_proc *proc, pic_value argv)
{
pic_code c;
int ai = pic_gc_arena_preserve(pic);
size_t ai = pic_gc_arena_preserve(pic);
size_t argc, i;
pic_code boot[2];