From fece4fc3d4decb70c94b49ab854fa9ae93b4d887 Mon Sep 17 00:00:00 2001 From: LLLL Colonq Date: Fri, 14 Aug 2026 14:51:01 -0400 Subject: pit: More VM-style evaluation --- pit/src/native.c | 43 ++++++++++++++++++++----------------------- 1 file changed, 20 insertions(+), 23 deletions(-) (limited to 'pit/src/native.c') diff --git a/pit/src/native.c b/pit/src/native.c index e4e0bf1..b5b13e1 100644 --- a/pit/src/native.c +++ b/pit/src/native.c @@ -95,27 +95,25 @@ static void check_invariants(pit_runtime *rt) { } } pit_value pit_load_file(pit_runtime *rt, char *path) { - // TODO - return PIT_NIL; - // pit_lexer lex; - // pit_parser parse; - // bool eof = false; - // pit_value p = PIT_NIL; - // pit_value ret = PIT_NIL; - // if (pit_lex_file(&lex, path) < 0) { - // pit_error(rt, "failed to lex file: %s", path); - // return PIT_NIL; - // } - // pit_parser_from_lexer(&parse, &lex); - // while (p = pit_parse(rt, &parse, &eof), !eof) { - // check_invariants(rt); if (pit_runtime_print_error(rt)) return PIT_NIL; - // ret = pit_eval(rt, p); - // check_invariants(rt); if (pit_runtime_print_error(rt)) return PIT_NIL; - // pit_gc(rt); - // check_invariants(rt); if (pit_runtime_print_error(rt)) return PIT_NIL; - // } - // check_invariants(rt); if (pit_runtime_print_error(rt)) return PIT_NIL; - // return ret; + pit_lexer lex; + pit_parser parse; + bool eof = false; + pit_value p = PIT_NIL; + pit_value ret = PIT_NIL; + if (pit_lex_file(&lex, path) < 0) { + pit_error(rt, "failed to lex file: %s", path); + return PIT_NIL; + } + pit_parser_from_lexer(&parse, &lex); + while (p = pit_parse(rt, &parse, &eof), !eof) { + check_invariants(rt); if (pit_runtime_print_error(rt)) return PIT_NIL; + ret = pit_vm_eval(rt, pit_compile(rt, pit_macroexpand(rt, p))); + check_invariants(rt); if (pit_runtime_print_error(rt)) return PIT_NIL; + pit_gc(rt); + check_invariants(rt); if (pit_runtime_print_error(rt)) return PIT_NIL; + } + check_invariants(rt); if (pit_runtime_print_error(rt)) return PIT_NIL; + return ret; } void pit_repl(pit_runtime *rt) { @@ -155,8 +153,7 @@ void pit_repl(pit_runtime *rt) { pit_parser_from_lexer(&parse, &lex); while (p = pit_parse(rt, &parse, &eof), !eof) { check_invariants(rt); - // res = pit_eval(rt, p); - res = pit_vm_eval(rt, pit_vm_compile(rt, p)); + res = pit_vm_eval(rt, pit_compile(rt, pit_macroexpand(rt, p))); check_invariants(rt); } if (pit_runtime_print_error(rt)) { -- cgit v1.3.1