add another argument to eval

This commit is contained in:
Yuichi Nishiwaki 2014-07-27 13:23:59 +09:00
parent c0fd54d3fc
commit 09efa4715c
6 changed files with 24 additions and 17 deletions

View File

@ -175,9 +175,9 @@ pic_value pic_apply3(pic_state *, struct pic_proc *, pic_value, pic_value, pic_v
pic_value pic_apply4(pic_state *, struct pic_proc *, pic_value, pic_value, pic_value, pic_value);
pic_value pic_apply5(pic_state *, struct pic_proc *, pic_value, pic_value, pic_value, pic_value, pic_value);
pic_value pic_apply_trampoline(pic_state *, struct pic_proc *, pic_value);
pic_value pic_eval(pic_state *, pic_value);
struct pic_proc *pic_compile(pic_state *, pic_value);
pic_value pic_macroexpand(pic_state *, pic_value);
pic_value pic_eval(pic_state *, pic_value, struct pic_lib *);
struct pic_proc *pic_compile(pic_state *, pic_value, struct pic_lib *);
pic_value pic_macroexpand(pic_state *, pic_value, struct pic_lib *);
void pic_in_library(pic_state *, pic_value);
struct pic_lib *pic_make_library(pic_state *, pic_value);

View File

@ -1442,7 +1442,7 @@ pic_codegen(pic_state *pic, pic_value obj)
}
struct pic_proc *
pic_compile(pic_state *pic, pic_value obj)
pic_compile(pic_state *pic, pic_value obj, struct pic_lib *lib)
{
struct pic_irep *irep;
size_t ai = pic_gc_arena_preserve(pic);
@ -1458,7 +1458,7 @@ pic_compile(pic_state *pic, pic_value obj)
#endif
/* macroexpand */
obj = pic_macroexpand(pic, obj);
obj = pic_macroexpand(pic, obj, lib);
#if DEBUG
fprintf(stdout, "## macroexpand completed\n");
pic_debug(pic, obj);

View File

@ -20,7 +20,7 @@ pic_load_cstr(pic_state *pic, const char *src)
pic_for_each (v, exprs) {
ai = pic_gc_arena_preserve(pic);
proc = pic_compile(pic, v);
proc = pic_compile(pic, v, pic->lib);
if (proc == NULL) {
pic_error(pic, "load: compilation failure");
}
@ -54,7 +54,7 @@ pic_load(pic_state *pic, const char *fn)
pic_for_each (v, exprs) {
ai = pic_gc_arena_preserve(pic);
proc = pic_compile(pic, v);
proc = pic_compile(pic, v, pic->lib);
if (proc == NULL) {
pic_error(pic, "load: compilation failure");
}

View File

@ -168,7 +168,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)) {
pic_void(pic_eval(pic, v));
pic_void(pic_eval(pic, v, pic->lib));
}
pic_in_library(pic, prev->name);
@ -293,7 +293,7 @@ macroexpand_defsyntax(pic_state *pic, pic_value expr, struct pic_senv *senv)
val = pic_cadr(pic, pic_cdr(pic, expr));
pic_try {
val = pic_eval(pic, val);
val = pic_eval(pic, val, pic->lib);
} pic_catch {
pic_errorf(pic, "macroexpand error while definition: %s", pic_errmsg(pic));
}
@ -413,8 +413,9 @@ macroexpand(pic_state *pic, pic_value expr, struct pic_senv *senv)
}
pic_value
pic_macroexpand(pic_state *pic, pic_value expr)
pic_macroexpand(pic_state *pic, pic_value expr, struct pic_lib *lib)
{
struct pic_lib *prev;
pic_value v;
#if DEBUG
@ -423,7 +424,13 @@ pic_macroexpand(pic_state *pic, pic_value expr)
puts("");
#endif
v = macroexpand(pic, expr, pic->lib->env);
/* change library for macro-expansion time processing */
prev = pic->lib;
pic->lib = lib;
v = macroexpand(pic, expr, lib->env);
pic->lib = prev;
#if DEBUG
puts("after expand:");
@ -560,7 +567,7 @@ pic_macro_macroexpand(pic_state *pic)
pic_get_args(pic, "o", &expr);
return pic_macroexpand(pic, expr);
return pic_macroexpand(pic, expr, pic->lib);
}
static pic_value

View File

@ -1063,11 +1063,11 @@ pic_apply_trampoline(pic_state *pic, struct pic_proc *proc, pic_value args)
}
pic_value
pic_eval(pic_state *pic, pic_value program)
pic_eval(pic_state *pic, pic_value program, struct pic_lib *lib)
{
struct pic_proc *proc;
proc = pic_compile(pic, program);
proc = pic_compile(pic, program, lib);
return pic_apply(pic, proc, pic_nil_value());
}

View File

@ -134,7 +134,7 @@ repl(pic_state *pic)
pic_for_each (v, exprs) {
/* eval */
v = pic_eval(pic, v);
v = pic_eval(pic, v, pic->lib);
/* print */
pic_printf(pic, "=> ~s\n", v);
@ -185,7 +185,7 @@ exec_file(pic_state *pic, const char *fname)
pic_for_each (v, exprs) {
proc = pic_compile(pic, v);
proc = pic_compile(pic, v, pic->lib);
if (proc == NULL) {
fputs(pic_errmsg(pic), stderr);
fprintf(stderr, "fatal error: %s compilation failure\n", fname);
@ -223,7 +223,7 @@ exec_string(pic_state *pic, const char *str)
ai = pic_gc_arena_preserve(pic);
pic_for_each (v, exprs) {
proc = pic_compile(pic, v);
proc = pic_compile(pic, v, pic->lib);
if (proc == NULL) {
goto abort;
}