use pic_load to load built-in.scm

This commit is contained in:
Yuichi Nishiwaki 2014-01-13 14:52:19 +09:00
parent 9ecbd9e7bb
commit 34d52e1a51
1 changed files with 13 additions and 34 deletions

View File

@ -29,48 +29,27 @@ void pic_init_load(pic_state *);
void void
pic_load_stdlib(pic_state *pic) pic_load_stdlib(pic_state *pic)
{ {
static const char *fn = "piclib/built-in.scm"; static const char *filename = "piclib/built-in.scm";
FILE *file; jmp_buf jmp, *prev_jmp = pic->jmp;
int n, i, ai;
pic_value v, vs;
struct pic_proc *proc;
file = fopen(fn, "r"); if (setjmp(jmp) == 0) {
if (file == NULL) { pic->jmp = &jmp;
fputs("fatal error: could not read built-in.scm", stderr); }
else {
/* error! */
fputs("fatal error: failure in loading built-in.scm\n", stderr);
fputs(pic->errmsg, stderr);
abort(); abort();
} }
n = pic_parse_file(pic, file, &vs); /* load 'built-in.scm' */
if (n < 0) { pic_load(pic, filename);
fputs("fatal error: built-in.scm broken", stderr);
abort();
}
ai = pic_gc_arena_preserve(pic);
for (i = 0; i < n; ++i, vs = pic_cdr(pic, vs)) {
v = pic_car(pic, vs);
proc = pic_codegen(pic, v);
if (proc == NULL) {
fprintf(stderr, "in codegen: %s\n", pic->errmsg);
fputs("fatal error: built-in.scm compilation failure", stderr);
abort();
}
v = pic_apply(pic, proc, pic_nil_value());
if (pic_undef_p(v)) {
fprintf(stderr, "in execute: %s\n", pic->errmsg);
fputs("fatal error: built-in.scm evaluation failure", stderr);
abort();
}
pic_gc_arena_restore(pic, ai);
}
#if DEBUG #if DEBUG
puts("successfully loaded stdlib"); puts("successfully loaded stdlib");
#endif #endif
pic->jmp = prev_jmp;
} }
#define PUSH_SYM(pic, lst, name) \ #define PUSH_SYM(pic, lst, name) \