summaryrefslogtreecommitdiff
path: root/pit/src/runtime/eval.c
diff options
context:
space:
mode:
Diffstat (limited to 'pit/src/runtime/eval.c')
-rw-r--r--pit/src/runtime/eval.c15
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 */