add pic_compile

This commit is contained in:
Yuichi Nishiwaki 2014-01-20 16:57:39 +09:00
parent 293fef5235
commit 655eb7a3bd
6 changed files with 421 additions and 884 deletions

View File

@ -152,7 +152,7 @@ pic_value pic_load(pic_state *, const char *);
pic_value pic_apply(pic_state *pic, struct pic_proc *, pic_value); pic_value pic_apply(pic_state *pic, struct pic_proc *, pic_value);
pic_value pic_apply_argv(pic_state *pic, struct pic_proc *, size_t, ...); pic_value pic_apply_argv(pic_state *pic, struct pic_proc *, size_t, ...);
struct pic_proc *pic_codegen(pic_state *, pic_value); struct pic_proc *pic_compile(pic_state *, pic_value);
pic_value pic_macroexpand(pic_state *, pic_value); pic_value pic_macroexpand(pic_state *, pic_value);
void pic_in_library(pic_state *, pic_value); void pic_in_library(pic_state *, pic_value);

View File

@ -69,6 +69,9 @@ struct pic_irep {
size_t clen, ilen, plen; size_t clen, ilen, plen;
}; };
pic_value pic_analyze(pic_state *, pic_value);
struct pic_irep *pic_codegen(pic_state *pic, pic_value obj);
void pic_dump_irep(pic_state *, struct pic_irep *); void pic_dump_irep(pic_state *, struct pic_irep *);
#if defined(__cplusplus) #if defined(__cplusplus)

File diff suppressed because it is too large Load Diff

View File

@ -27,7 +27,7 @@ pic_load(pic_state *pic, const char *fn)
for (i = 0; i < n; ++i, vs = pic_cdr(pic, vs)) { for (i = 0; i < n; ++i, vs = pic_cdr(pic, vs)) {
v = pic_car(pic, vs); v = pic_car(pic, vs);
proc = pic_codegen(pic, v); proc = pic_compile(pic, v);
if (proc == NULL) { if (proc == NULL) {
pic_error(pic, "load: compilation failure"); pic_error(pic, "load: compilation failure");
} }

View File

@ -317,7 +317,7 @@ macroexpand(pic_state *pic, pic_value expr, struct pic_senv *senv)
for (exprs = pic_cddr(pic, expr); ! pic_nil_p(exprs); exprs = pic_cdr(pic, exprs)) { for (exprs = pic_cddr(pic, expr); ! pic_nil_p(exprs); exprs = pic_cdr(pic, exprs)) {
v = pic_car(pic, exprs); v = pic_car(pic, exprs);
proc = pic_codegen(pic, v); proc = pic_compile(pic, v);
if (proc == NULL) { if (proc == NULL) {
abort(); abort();
} }
@ -364,7 +364,7 @@ macroexpand(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));
proc = pic_codegen(pic, val); proc = pic_compile(pic, val);
if (pic->errmsg) { if (pic->errmsg) {
printf("macroexpand error: %s\n", pic->errmsg); printf("macroexpand error: %s\n", pic->errmsg);
abort(); abort();
@ -406,7 +406,7 @@ macroexpand(pic_state *pic, pic_value expr, struct pic_senv *senv)
pic_error(pic, "syntax error"); pic_error(pic, "syntax error");
} }
proc = pic_codegen(pic, val); proc = pic_compile(pic, val);
if (pic->errmsg) { if (pic->errmsg) {
printf("macroexpand error: %s\n", pic->errmsg); printf("macroexpand error: %s\n", pic->errmsg);
abort(); abort();

View File

@ -122,7 +122,7 @@ repl(pic_state *pic)
#endif #endif
/* eval */ /* eval */
proc = pic_codegen(pic, v); proc = pic_compile(pic, v);
if (proc == NULL) { if (proc == NULL) {
printf("compilation error: %s\n", pic->errmsg); printf("compilation error: %s\n", pic->errmsg);
pic->errmsg = NULL; pic->errmsg = NULL;
@ -183,7 +183,7 @@ exec_file(pic_state *pic, const char *fname)
v = pic_car(pic, vs); v = pic_car(pic, vs);
proc = pic_codegen(pic, v); proc = pic_compile(pic, v);
if (proc == NULL) { if (proc == NULL) {
fputs(pic->errmsg, stderr); fputs(pic->errmsg, 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)
for (i = 0; i < n; ++i) { for (i = 0; i < n; ++i) {
v = pic_car(pic, vs); v = pic_car(pic, vs);
proc = pic_codegen(pic, v); proc = pic_compile(pic, v);
if (proc == NULL) { if (proc == NULL) {
goto abort; goto abort;
} }