summaryrefslogtreecommitdiff
path: root/pit/src/native.c
diff options
context:
space:
mode:
authorLLLL Colonq <llll@colonq>2026-08-14 14:51:01 -0400
committerLLLL Colonq <llll@colonq>2026-08-14 14:51:01 -0400
commitfece4fc3d4decb70c94b49ab854fa9ae93b4d887 (patch)
tree71e355aaae2381078d0a403f89abfc6e6d7343f6 /pit/src/native.c
parent7b9c4a3ac265026d98624ac614eead866a190042 (diff)
pit: More VM-style evaluation
Diffstat (limited to 'pit/src/native.c')
-rw-r--r--pit/src/native.c43
1 files changed, 20 insertions, 23 deletions
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)) {