Fix some parsing bugs and allow running files

This commit is contained in:
2025-07-01 01:31:44 +09:00
parent 40f717277d
commit e557e58168
4 changed files with 142 additions and 36 deletions

View File

@ -56,12 +56,26 @@ LispVal *Ftoplevel_error_handler(LispVal *except) {
return Qnil;
}
DEF_STATIC_SYMBOL(toplevel_read, "toplevel-read");
int main(int argc, const char **argv) {
if (argc < 2) {
fprintf(stderr, "No input file!\n");
return 1;
}
FILE *in = fopen(argv[1], "r");
if (!in) {
perror("fopen");
return 1;
}
fseek(in, 0, SEEK_END);
off_t file_len = ftello(in);
rewind(in);
char buffer[file_len];
fread(buffer, 1, file_len, in);
fclose(in);
lisp_init();
char buffer[] = "(t)";
LispVal *tv;
read_from_buffer(buffer, sizeof(buffer) - 1, &tv);
lisp_ref(tv);
size_t pos = 0;
WITH_PUSH_FRAME(Qtoplevel, Qnil, false, {
the_stack->hidden = true;
LispVal *err_var = INTERN_STATIC("err-var");
@ -73,12 +87,19 @@ int main(int argc, const char **argv) {
the_stack->handlers, Qshutdown_signal,
// simply call the above function
make_list(3, err_var, Ftoplevel_exit_handler_function, err_var));
LispVal *out = Feval(tv);
lisp_ref(out);
debug_dump(stdout, out, 1);
lisp_unref(out);
})
UNREF_INPLACE(tv);
Fputhash(the_stack->handlers, Qeof_error,
// ignore
Fpair(Qnil, Qnil));
while (pos < file_len) {
LispVal *tv;
WITH_PUSH_FRAME(Qtoplevel_read, Qnil, false, {
pos += read_from_buffer(buffer + pos, file_len - pos, &tv);
});
WITH_CLEANUP(tv, {
IGNORE_REF(Feval(tv)); //
})
}
});
lisp_shutdown();
return exit_status;
}