diff options
| author | LLLL Colonq <llll@colonq> | 2026-10-21 02:43:23 -0400 |
|---|---|---|
| committer | LLLL Colonq <llll@colonq> | 2026-10-21 02:43:23 -0400 |
| commit | 62ab8e0b42a57bd794941f030b4c3140d6f7c744 (patch) | |
| tree | d4d26aca670f67a290399e83ca5e7253a5b9c395 /pit/src/runtime/eval.c | |
| parent | fe4c9bd487cb9ae59d86dc7680855c5797ae04e3 (diff) | |
Bake Lisp into builds, fix bug in error propagation
Diffstat (limited to 'pit/src/runtime/eval.c')
| -rw-r--r-- | pit/src/runtime/eval.c | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/pit/src/runtime/eval.c b/pit/src/runtime/eval.c index a2ed166..3cd1c1f 100644 --- a/pit/src/runtime/eval.c +++ b/pit/src/runtime/eval.c @@ -152,13 +152,14 @@ static pit_value vm_erase_empty(pit_runtime *rt, bool unbind) { /* run one instruction of the VM */ bool pit_vm_run_one(pit_runtime *rt) { vm_erase_empty(rt, true); - if (rt->callstack->next < 1 || rt->error != PIT_NIL) return false; + if (rt->callstack->next < 1) return false; + if (rt->error != PIT_NIL) goto err; pit_callstack_entry *ent = pit_vec_get(pit_callstack_entry)(rt->callstack, rt->callstack->next - 1); - if (ent == NULL) { pit_error(rt, "malformed call stack"); return false; } - if (rt->fuel == 0) { pit_error(rt, "out of fuel"); return false; } + if (ent == NULL) { pit_error(rt, "malformed call stack"); goto err; } + if (rt->fuel == 0) { pit_error(rt, "out of fuel"); goto err; } rt->fuel -= 1; pit_value ins = pit_value_cons_car(rt, ent->code); - if (ins == PIT_NIL) { pit_error(rt, "malformed vm instruction: %v %v", ins); return false; } + if (ins == PIT_NIL) { pit_error(rt, "malformed vm instruction: %v %v", ins); goto err; } ent->code = pit_value_cons_cdr(rt, ent->code); pit_value op = pit_value_cons_car(rt, ins); if (pit_symtab_symbol_name_match_cstr(rt, op, "literal")) { @@ -196,13 +197,17 @@ bool pit_vm_run_one(pit_runtime *rt) { pit_value args = PIT_NIL; while (arity-- > 0) args = pit_value_cons(rt, vm_pop(rt), args); pit_value bindings = vm_erase_empty(rt, false); - if (!vm_call(rt, f, args, bindings)) return false; + if (!vm_call(rt, f, args, bindings)) goto err; } else { pit_error(rt, "unrecognized vm instruction: %v", ins); return false; } vm_erase_empty(rt, true); return true; +err: + rt->result_stack->next = 0; + rt->callstack->next = 0; + return false; } /* run the VM until evaluation of this code finishes, returning the result */ |
