pic_gc_arena_preserve -> pic_enter

This commit is contained in:
Yuichi Nishiwaki 2016-02-19 16:17:13 +09:00
parent f0386657be
commit 4d38e08c98
14 changed files with 73 additions and 73 deletions

View File

@ -19,10 +19,10 @@ pic_system_cmdline(pic_state *pic)
pic_get_args(pic, "");
for (i = 0; i < picrin_argc; ++i) {
size_t ai = pic_gc_arena_preserve(pic);
size_t ai = pic_enter(pic);
v = pic_cons(pic, pic_obj_value(pic_cstr_value(pic, picrin_argv[i])), v);
pic_gc_arena_restore(pic, ai);
pic_leave(pic, ai);
}
return pic_reverse(pic, v);
@ -96,7 +96,7 @@ pic_system_getenvs(pic_state *pic)
{
char **envp;
pic_value data = pic_nil_value(pic);
size_t ai = pic_gc_arena_preserve(pic);
size_t ai = pic_enter(pic);
pic_get_args(pic, "");
@ -117,8 +117,8 @@ pic_system_getenvs(pic_state *pic)
/* push */
data = pic_cons(pic, pic_cons(pic, pic_obj_value(key), pic_obj_value(val)), data);
pic_gc_arena_restore(pic, ai);
pic_gc_protect(pic, data);
pic_leave(pic, ai);
pic_protect(pic, data);
}
return data;

View File

@ -8,7 +8,7 @@
struct pic_string *
pic_get_backtrace(pic_state *pic)
{
size_t ai = pic_gc_arena_preserve(pic);
size_t ai = pic_enter(pic);
pic_callinfo *ci;
struct pic_string *trace;
@ -27,8 +27,8 @@ pic_get_backtrace(pic_state *pic)
}
}
pic_gc_arena_restore(pic, ai);
pic_gc_protect(pic, pic_obj_value(trace));
pic_leave(pic, ai);
pic_protect(pic, pic_obj_value(trace));
return trace;
}

View File

@ -117,7 +117,7 @@ pic_raise_continuable(pic_state *pic, pic_value err)
handler = pic_pop_handler(pic);
pic_gc_protect(pic, pic_obj_value(handler));
pic_protect(pic, pic_obj_value(handler));
v = pic_call(pic, handler, 1, err);

View File

@ -9,7 +9,7 @@
static pic_value
optimize_beta(pic_state *pic, pic_value expr)
{
size_t ai = pic_gc_arena_preserve(pic);
size_t ai = pic_enter(pic);
pic_value functor, formals, args, tmp, val, it, defs;
if (! pic_list_p(pic, expr))
@ -34,8 +34,8 @@ optimize_beta(pic_state *pic, pic_value expr)
}
expr = pic_reverse(pic, tmp);
pic_gc_arena_restore(pic, ai);
pic_gc_protect(pic, expr);
pic_leave(pic, ai);
pic_protect(pic, expr);
functor = pic_list_ref(pic, expr, 0);
if (pic_pair_p(pic, functor) && pic_eq_p(pic, pic_car(pic, functor), pic_obj_value(pic->sLAMBDA))) {
@ -57,8 +57,8 @@ optimize_beta(pic_state *pic, pic_value expr)
}
exit:
pic_gc_arena_restore(pic, ai);
pic_gc_protect(pic, expr);
pic_leave(pic, ai);
pic_protect(pic, expr);
return expr;
}
@ -332,13 +332,13 @@ analyze_node(pic_state *pic, analyze_scope *scope, pic_value obj)
static pic_value
analyze(pic_state *pic, analyze_scope *scope, pic_value obj)
{
size_t ai = pic_gc_arena_preserve(pic);
size_t ai = pic_enter(pic);
pic_value res;
res = analyze_node(pic, scope, obj);
pic_gc_arena_restore(pic, ai);
pic_gc_protect(pic, res);
pic_leave(pic, ai);
pic_protect(pic, res);
return res;
}
@ -828,23 +828,23 @@ pic_codegen(pic_state *pic, pic_value obj)
return codegen_context_destroy(pic, cxt);
}
#define SAVE(pic, ai, obj) pic_gc_arena_restore(pic, ai); pic_gc_protect(pic, obj)
#define SAVE(pic, ai, obj) pic_leave(pic, ai); pic_protect(pic, obj)
struct pic_proc *
pic_compile(pic_state *pic, pic_value obj)
{
struct pic_irep *irep;
struct pic_proc *proc;
size_t ai = pic_gc_arena_preserve(pic);
size_t ai = pic_enter(pic);
#if DEBUG
fprintf(stdout, "ai = %zu\n", pic_gc_arena_preserve(pic));
fprintf(stdout, "ai = %zu\n", pic_enter(pic));
fprintf(stdout, "# input expression\n");
pic_write(pic, obj);
fprintf(stdout, "\n");
fprintf(stdout, "ai = %zu\n", pic_gc_arena_preserve(pic));
fprintf(stdout, "ai = %zu\n", pic_enter(pic));
#endif
/* optimize */
@ -853,7 +853,7 @@ pic_compile(pic_state *pic, pic_value obj)
fprintf(stdout, "## optimize completed\n");
pic_write(pic, obj);
fprintf(stdout, "\n");
fprintf(stdout, "ai = %zu\n", pic_gc_arena_preserve(pic));
fprintf(stdout, "ai = %zu\n", pic_enter(pic));
#endif
SAVE(pic, ai, obj);
@ -864,7 +864,7 @@ pic_compile(pic_state *pic, pic_value obj)
fprintf(stdout, "## analyzer completed\n");
pic_write(pic, obj);
fprintf(stdout, "\n");
fprintf(stdout, "ai = %zu\n", pic_gc_arena_preserve(pic));
fprintf(stdout, "ai = %zu\n", pic_enter(pic));
#endif
SAVE(pic, ai, obj);

View File

@ -142,7 +142,7 @@ gc_protect(pic_state *pic, struct pic_object *obj)
}
pic_value
pic_gc_protect(pic_state *pic, pic_value v)
pic_protect(pic_state *pic, pic_value v)
{
if (! pic_obj_p(pic, v))
return v;
@ -153,13 +153,13 @@ pic_gc_protect(pic_state *pic, pic_value v)
}
size_t
pic_gc_arena_preserve(pic_state *pic)
pic_enter(pic_state *pic)
{
return pic->arena_idx;
}
void
pic_gc_arena_restore(pic_state *pic, size_t state)
pic_leave(pic_state *pic, size_t state)
{
pic->arena_idx = state;
}

View File

@ -83,9 +83,9 @@ void pic_free(pic_state *, void *);
typedef pic_value (*pic_func_t)(pic_state *);
void *pic_alloca(pic_state *, size_t);
pic_value pic_gc_protect(pic_state *, pic_value);
size_t pic_gc_arena_preserve(pic_state *);
void pic_gc_arena_restore(pic_state *, size_t);
size_t pic_enter(pic_state *);
void pic_leave(pic_state *, size_t);
pic_value pic_protect(pic_state *, pic_value);
void pic_gc(pic_state *);
void pic_add_feature(pic_state *, const char *feature);
@ -289,9 +289,9 @@ void pic_close_port(pic_state *, struct pic_port *port);
#define pic_void(exec) \
pic_void_(PIC_GENSYM(ai), exec)
#define pic_void_(ai,exec) do { \
size_t ai = pic_gc_arena_preserve(pic); \
size_t ai = pic_enter(pic); \
exec; \
pic_gc_arena_restore(pic, ai); \
pic_leave(pic, ai); \
} while (0)
pic_value pic_read(pic_state *, struct pic_port *);

View File

@ -8,12 +8,12 @@ void
pic_load(pic_state *pic, struct pic_port *port)
{
pic_value form;
size_t ai = pic_gc_arena_preserve(pic);
size_t ai = pic_enter(pic);
while (! pic_eof_p(pic, form = pic_read(pic, port))) {
pic_eval(pic, form, pic_current_library(pic));
pic_gc_arena_restore(pic, ai);
pic_leave(pic, ai);
}
}

View File

@ -170,7 +170,7 @@ expand_quote(pic_state *pic, pic_value expr)
static pic_value
expand_list(pic_state *pic, pic_value obj, struct pic_env *env, pic_value deferred)
{
size_t ai = pic_gc_arena_preserve(pic);
size_t ai = pic_enter(pic);
pic_value x, head, tail;
if (pic_pair_p(pic, obj)) {
@ -181,8 +181,8 @@ expand_list(pic_state *pic, pic_value obj, struct pic_env *env, pic_value deferr
x = expand(pic, obj, env, deferred);
}
pic_gc_arena_restore(pic, ai);
pic_gc_protect(pic, x);
pic_leave(pic, ai);
pic_protect(pic, x);
return x;
}
@ -329,13 +329,13 @@ expand_node(pic_state *pic, pic_value expr, struct pic_env *env, pic_value defer
static pic_value
expand(pic_state *pic, pic_value expr, struct pic_env *env, pic_value deferred)
{
size_t ai = pic_gc_arena_preserve(pic);
size_t ai = pic_enter(pic);
pic_value v;
v = expand_node(pic, expr, env, deferred);
pic_gc_arena_restore(pic, ai);
pic_gc_protect(pic, v);
pic_leave(pic, ai);
pic_protect(pic, v);
return v;
}

View File

@ -288,33 +288,33 @@ pic_number_string_to_number(pic_state *pic)
void
pic_init_number(pic_state *pic)
{
size_t ai = pic_gc_arena_preserve(pic);
size_t ai = pic_enter(pic);
pic_defun(pic, "number?", pic_number_number_p);
pic_gc_arena_restore(pic, ai);
pic_leave(pic, ai);
pic_defun(pic, "exact?", pic_number_exact_p);
pic_defun(pic, "inexact?", pic_number_inexact_p);
pic_gc_arena_restore(pic, ai);
pic_leave(pic, ai);
pic_defun(pic, "inexact", pic_number_inexact);
pic_defun(pic, "exact", pic_number_exact);
pic_gc_arena_restore(pic, ai);
pic_leave(pic, ai);
pic_defun(pic, "=", pic_number_eq);
pic_defun(pic, "<", pic_number_lt);
pic_defun(pic, ">", pic_number_gt);
pic_defun(pic, "<=", pic_number_le);
pic_defun(pic, ">=", pic_number_ge);
pic_gc_arena_restore(pic, ai);
pic_leave(pic, ai);
pic_defun(pic, "+", pic_number_add);
pic_defun(pic, "-", pic_number_sub);
pic_defun(pic, "*", pic_number_mul);
pic_defun(pic, "/", pic_number_div);
pic_gc_arena_restore(pic, ai);
pic_leave(pic, ai);
pic_defun(pic, "number->string", pic_number_number_to_string);
pic_defun(pic, "string->number", pic_number_string_to_number);
pic_gc_arena_restore(pic, ai);
pic_leave(pic, ai);
}

View File

@ -201,15 +201,15 @@ pic_length(pic_state *pic, pic_value obj)
pic_value
pic_reverse(pic_state *pic, pic_value list)
{
size_t ai = pic_gc_arena_preserve(pic);
size_t ai = pic_enter(pic);
pic_value v, acc, it;
acc = pic_nil_value(pic);
pic_for_each(v, list, it) {
acc = pic_cons(pic, v, acc);
pic_gc_arena_restore(pic, ai);
pic_gc_protect(pic, acc);
pic_leave(pic, ai);
pic_protect(pic, acc);
}
return acc;
}
@ -217,16 +217,16 @@ pic_reverse(pic_state *pic, pic_value list)
pic_value
pic_append(pic_state *pic, pic_value xs, pic_value ys)
{
size_t ai = pic_gc_arena_preserve(pic);
size_t ai = pic_enter(pic);
pic_value x, it;
xs = pic_reverse(pic, xs);
pic_for_each (x, xs, it) {
ys = pic_cons(pic, x, ys);
pic_gc_arena_restore(pic, ai);
pic_gc_protect(pic, xs);
pic_gc_protect(pic, ys);
pic_leave(pic, ai);
pic_protect(pic, xs);
pic_protect(pic, ys);
}
return ys;
}

View File

@ -337,7 +337,7 @@ pic_value
pic_apply(pic_state *pic, struct pic_proc *proc, int argc, pic_value *argv)
{
pic_code c;
size_t ai = pic_gc_arena_preserve(pic);
size_t ai = pic_enter(pic);
pic_code boot[2];
int i;
@ -528,7 +528,7 @@ pic_apply(pic_state *pic, struct pic_proc *proc, int argc, pic_value *argv)
pic->sp[0] = v;
pic->sp += pic->ci->retc;
pic_gc_arena_restore(pic, ai);
pic_leave(pic, ai);
goto L_RET;
}
else {
@ -546,7 +546,7 @@ pic_apply(pic_state *pic, struct pic_proc *proc, int argc, pic_value *argv)
if (irep->varg) {
rest = pic_nil_value(pic);
for (i = 0; i < ci->argc - irep->argc; ++i) {
pic_gc_protect(pic, v = POP());
pic_protect(pic, v = POP());
rest = pic_cons(pic, v, rest);
}
PUSH(rest);
@ -568,7 +568,7 @@ pic_apply(pic_state *pic, struct pic_proc *proc, int argc, pic_value *argv)
ci->regs = ci->fp + irep->argc + irep->localc;
pic->ip = irep->code;
pic_gc_arena_restore(pic, ai);
pic_leave(pic, ai);
JUMP;
}
}
@ -631,7 +631,7 @@ pic_apply(pic_state *pic, struct pic_proc *proc, int argc, pic_value *argv)
proc = pic_make_proc_irep(pic, pic->ci->irep->irep[c.a], pic->ci->cxt);
PUSH(pic_obj_value(proc));
pic_gc_arena_restore(pic, ai);
pic_leave(pic, ai);
NEXT;
}
@ -643,11 +643,11 @@ pic_apply(pic_state *pic, struct pic_proc *proc, int argc, pic_value *argv)
CASE(OP_CONS) {
pic_value a, b;
check_condition(CONS, 2);
pic_gc_protect(pic, b = POP());
pic_gc_protect(pic, a = POP());
pic_protect(pic, b = POP());
pic_protect(pic, a = POP());
(void)POP();
PUSH(pic_cons(pic, a, b));
pic_gc_arena_restore(pic, ai);
pic_leave(pic, ai);
NEXT;
}
CASE(OP_CAR) {
@ -785,7 +785,7 @@ pic_apply(pic_state *pic, struct pic_proc *proc, int argc, pic_value *argv)
VM_END_PRINT;
return pic_gc_protect(pic, POP());
return pic_protect(pic, POP());
}
} VM_LOOP_END;
}

View File

@ -822,7 +822,7 @@ pic_reader_destroy(pic_state *pic)
pic_value
pic_read(pic_state *pic, struct pic_port *port)
{
size_t ai = pic_gc_arena_preserve(pic);
size_t ai = pic_enter(pic);
pic_value val;
int c;
@ -832,14 +832,14 @@ pic_read(pic_state *pic, struct pic_port *port)
if (! pic_invalid_p(pic, val)) {
break;
}
pic_gc_arena_restore(pic, ai);
pic_leave(pic, ai);
}
if (c == EOF) {
return pic_eof_object(pic);
}
pic_gc_arena_restore(pic, ai);
return pic_gc_protect(pic, val);
pic_leave(pic, ai);
return pic_protect(pic, val);
}
pic_value

View File

@ -123,9 +123,9 @@ pic_init_core(pic_state *pic)
pic_deflibrary(pic, "picrin.base");
ai = pic_gc_arena_preserve(pic);
ai = pic_enter(pic);
#define DONE pic_gc_arena_restore(pic, ai);
#define DONE pic_leave(pic, ai);
import_builtin_syntax("define");
import_builtin_syntax("set!");
@ -298,7 +298,7 @@ pic_open(pic_allocf allocf, void *userdata)
/* native stack marker */
pic->native_stack_start = &t;
ai = pic_gc_arena_preserve(pic);
ai = pic_enter(pic);
#define S(slot,name) pic->slot = pic_intern_lit(pic, name)
@ -338,7 +338,7 @@ pic_open(pic_allocf allocf, void *userdata)
S(sGE, ">=");
S(sNOT, "not");
pic_gc_arena_restore(pic, ai);
pic_leave(pic, ai);
/* root tables */
pic->globals = pic_make_weak(pic);
@ -360,14 +360,14 @@ pic_open(pic_allocf allocf, void *userdata)
pic_make_library(pic, "picrin.user");
pic_in_library(pic, "picrin.user");
pic_gc_arena_restore(pic, ai);
pic_leave(pic, ai);
/* turn on GC */
pic->gc_enable = true;
pic_init_core(pic);
pic_gc_arena_restore(pic, ai);
pic_leave(pic, ai);
return pic;

View File

@ -21,7 +21,7 @@ pic_intern(pic_state *pic, struct pic_string *str)
it = kh_put(oblist, h, str, &ret);
if (ret == 0) { /* if exists */
sym = kh_val(h, it);
pic_gc_protect(pic, pic_obj_value(sym));
pic_protect(pic, pic_obj_value(sym));
return sym;
}