[bugfix] picrin evaluates exprs in files in order.
This commit is contained in:
parent
808fe32ac0
commit
7ae15246fa
38
tools/main.c
38
tools/main.c
|
@ -159,8 +159,8 @@ int
|
||||||
exec_file(pic_state *pic, const char *fname)
|
exec_file(pic_state *pic, const char *fname)
|
||||||
{
|
{
|
||||||
FILE *file;
|
FILE *file;
|
||||||
bool r;
|
int n, i;
|
||||||
pic_value v;
|
pic_value vs;
|
||||||
struct pic_proc *proc;
|
struct pic_proc *proc;
|
||||||
|
|
||||||
file = fopen(fname, "r");
|
file = fopen(fname, "r");
|
||||||
|
@ -169,24 +169,32 @@ exec_file(pic_state *pic, const char *fname)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
r = pic_parse_file(pic, file, &v);
|
n = pic_parse_file(pic, file, &vs);
|
||||||
if (! r) {
|
if (n <= 0) {
|
||||||
fprintf(stderr, "fatal error: %s broken\n", fname);
|
fprintf(stderr, "fatal error: %s broken\n", fname);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
proc = pic_codegen(pic, v);
|
for (i = 0; i < n; ++i) {
|
||||||
if (proc == NULL) {
|
pic_value v;
|
||||||
fputs(pic->errmsg, stderr);
|
|
||||||
fprintf(stderr, "fatal error: %s compilation failure\n", fname);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
v = pic_apply(pic, proc, pic_nil_value());
|
v = pic_car(pic, vs);
|
||||||
if (pic_undef_p(v)) {
|
|
||||||
fputs(pic->errmsg, stderr);
|
proc = pic_codegen(pic, v);
|
||||||
fprintf(stderr, "fatal error: %s evaluation failure\n", fname);
|
if (proc == NULL) {
|
||||||
return 1;
|
fputs(pic->errmsg, stderr);
|
||||||
|
fprintf(stderr, "fatal error: %s compilation failure\n", fname);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
v = pic_apply(pic, proc, pic_nil_value());
|
||||||
|
if (pic_undef_p(v)) {
|
||||||
|
fputs(pic->errmsg, stderr);
|
||||||
|
fprintf(stderr, "fatal error: %s evaluation failure\n", fname);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
vs = pic_cdr(pic, vs);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Reference in New Issue