add another argument to eval
This commit is contained in:
parent
c0fd54d3fc
commit
09efa4715c
|
@ -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_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_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_apply_trampoline(pic_state *, struct pic_proc *, pic_value);
|
||||||
pic_value pic_eval(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_proc *pic_compile(pic_state *, pic_value, struct pic_lib *);
|
||||||
pic_value pic_macroexpand(pic_state *, pic_value);
|
pic_value pic_macroexpand(pic_state *, pic_value, struct pic_lib *);
|
||||||
|
|
||||||
void pic_in_library(pic_state *, pic_value);
|
void pic_in_library(pic_state *, pic_value);
|
||||||
struct pic_lib *pic_make_library(pic_state *, pic_value);
|
struct pic_lib *pic_make_library(pic_state *, pic_value);
|
||||||
|
|
|
@ -1442,7 +1442,7 @@ pic_codegen(pic_state *pic, pic_value obj)
|
||||||
}
|
}
|
||||||
|
|
||||||
struct pic_proc *
|
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;
|
struct pic_irep *irep;
|
||||||
size_t ai = pic_gc_arena_preserve(pic);
|
size_t ai = pic_gc_arena_preserve(pic);
|
||||||
|
@ -1458,7 +1458,7 @@ pic_compile(pic_state *pic, pic_value obj)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* macroexpand */
|
/* macroexpand */
|
||||||
obj = pic_macroexpand(pic, obj);
|
obj = pic_macroexpand(pic, obj, lib);
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
fprintf(stdout, "## macroexpand completed\n");
|
fprintf(stdout, "## macroexpand completed\n");
|
||||||
pic_debug(pic, obj);
|
pic_debug(pic, obj);
|
||||||
|
|
|
@ -20,7 +20,7 @@ pic_load_cstr(pic_state *pic, const char *src)
|
||||||
pic_for_each (v, exprs) {
|
pic_for_each (v, exprs) {
|
||||||
ai = pic_gc_arena_preserve(pic);
|
ai = pic_gc_arena_preserve(pic);
|
||||||
|
|
||||||
proc = pic_compile(pic, v);
|
proc = pic_compile(pic, v, pic->lib);
|
||||||
if (proc == NULL) {
|
if (proc == NULL) {
|
||||||
pic_error(pic, "load: compilation failure");
|
pic_error(pic, "load: compilation failure");
|
||||||
}
|
}
|
||||||
|
@ -54,7 +54,7 @@ pic_load(pic_state *pic, const char *fn)
|
||||||
pic_for_each (v, exprs) {
|
pic_for_each (v, exprs) {
|
||||||
ai = pic_gc_arena_preserve(pic);
|
ai = pic_gc_arena_preserve(pic);
|
||||||
|
|
||||||
proc = pic_compile(pic, v);
|
proc = pic_compile(pic, v, pic->lib);
|
||||||
if (proc == NULL) {
|
if (proc == NULL) {
|
||||||
pic_error(pic, "load: compilation failure");
|
pic_error(pic, "load: compilation failure");
|
||||||
}
|
}
|
||||||
|
|
17
src/macro.c
17
src/macro.c
|
@ -168,7 +168,7 @@ macroexpand_deflibrary(pic_state *pic, pic_value expr)
|
||||||
pic_in_library(pic, pic_cadr(pic, expr));
|
pic_in_library(pic, pic_cadr(pic, expr));
|
||||||
|
|
||||||
pic_for_each (v, pic_cddr(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);
|
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));
|
val = pic_cadr(pic, pic_cdr(pic, expr));
|
||||||
|
|
||||||
pic_try {
|
pic_try {
|
||||||
val = pic_eval(pic, val);
|
val = pic_eval(pic, val, pic->lib);
|
||||||
} pic_catch {
|
} pic_catch {
|
||||||
pic_errorf(pic, "macroexpand error while definition: %s", pic_errmsg(pic));
|
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_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;
|
pic_value v;
|
||||||
|
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
|
@ -423,7 +424,13 @@ pic_macroexpand(pic_state *pic, pic_value expr)
|
||||||
puts("");
|
puts("");
|
||||||
#endif
|
#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
|
#if DEBUG
|
||||||
puts("after expand:");
|
puts("after expand:");
|
||||||
|
@ -560,7 +567,7 @@ pic_macro_macroexpand(pic_state *pic)
|
||||||
|
|
||||||
pic_get_args(pic, "o", &expr);
|
pic_get_args(pic, "o", &expr);
|
||||||
|
|
||||||
return pic_macroexpand(pic, expr);
|
return pic_macroexpand(pic, expr, pic->lib);
|
||||||
}
|
}
|
||||||
|
|
||||||
static pic_value
|
static pic_value
|
||||||
|
|
4
src/vm.c
4
src/vm.c
|
@ -1063,11 +1063,11 @@ pic_apply_trampoline(pic_state *pic, struct pic_proc *proc, pic_value args)
|
||||||
}
|
}
|
||||||
|
|
||||||
pic_value
|
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;
|
struct pic_proc *proc;
|
||||||
|
|
||||||
proc = pic_compile(pic, program);
|
proc = pic_compile(pic, program, lib);
|
||||||
|
|
||||||
return pic_apply(pic, proc, pic_nil_value());
|
return pic_apply(pic, proc, pic_nil_value());
|
||||||
}
|
}
|
||||||
|
|
|
@ -134,7 +134,7 @@ repl(pic_state *pic)
|
||||||
pic_for_each (v, exprs) {
|
pic_for_each (v, exprs) {
|
||||||
|
|
||||||
/* eval */
|
/* eval */
|
||||||
v = pic_eval(pic, v);
|
v = pic_eval(pic, v, pic->lib);
|
||||||
|
|
||||||
/* print */
|
/* print */
|
||||||
pic_printf(pic, "=> ~s\n", v);
|
pic_printf(pic, "=> ~s\n", v);
|
||||||
|
@ -185,7 +185,7 @@ exec_file(pic_state *pic, const char *fname)
|
||||||
|
|
||||||
pic_for_each (v, exprs) {
|
pic_for_each (v, exprs) {
|
||||||
|
|
||||||
proc = pic_compile(pic, v);
|
proc = pic_compile(pic, v, pic->lib);
|
||||||
if (proc == NULL) {
|
if (proc == NULL) {
|
||||||
fputs(pic_errmsg(pic), stderr);
|
fputs(pic_errmsg(pic), stderr);
|
||||||
fprintf(stderr, "fatal error: %s compilation failure\n", fname);
|
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);
|
ai = pic_gc_arena_preserve(pic);
|
||||||
pic_for_each (v, exprs) {
|
pic_for_each (v, exprs) {
|
||||||
|
|
||||||
proc = pic_compile(pic, v);
|
proc = pic_compile(pic, v, pic->lib);
|
||||||
if (proc == NULL) {
|
if (proc == NULL) {
|
||||||
goto abort;
|
goto abort;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue