diff options
| author | LLLL Colonq <llll@colonq> | 2026-09-24 16:40:51 -0400 |
|---|---|---|
| committer | LLLL Colonq <llll@colonq> | 2026-09-24 16:41:00 -0400 |
| commit | 394757c770ec871bdaf9d532940a575606ae3318 (patch) | |
| tree | 4064f3f0653bb66e0509c519d8f8c2082b73435f /pit/src/runtime/eval.c | |
| parent | d7f85e314f40548c6840d987a3f4b556f2b7b7ff (diff) | |
pit: Add comments
Diffstat (limited to 'pit/src/runtime/eval.c')
| -rw-r--r-- | pit/src/runtime/eval.c | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/pit/src/runtime/eval.c b/pit/src/runtime/eval.c index f62f4e8..eba9715 100644 --- a/pit/src/runtime/eval.c +++ b/pit/src/runtime/eval.c @@ -1,6 +1,7 @@ #include <lcq/pit/runtime/eval.h> -/* add a new stack frame to the vm (with a tag and callsite annotation) */ +/* add a new code frame to the vm (with a tag and callsite annotation) */ +/* bound is a list of symbols to be unbound when this frame ends */ static void vm_push_code_func(pit_runtime *rt, pit_value code, pit_value tag, pit_annotation ann, pit_value bound) { pit_callstack_entry ent; ent.tag = tag; @@ -12,7 +13,7 @@ static void vm_push_code_func(pit_runtime *rt, pit_value code, pit_value tag, pi } } -/* add a new stack frame to the vm (with no annotation) */ +/* add a new code frame to the vm (with no annotation) */ static void vm_push_code(pit_runtime *rt, pit_value code, pit_value bound) { pit_annotation ann; ann.line = -1; @@ -20,12 +21,14 @@ static void vm_push_code(pit_runtime *rt, pit_value code, pit_value bound) { vm_push_code_func(rt, code, PIT_NIL, ann, bound); } +/* push a value to the result stack */ static void vm_push(pit_runtime *rt, pit_value v) { if (pit_vec_push(pit_value)(rt->result_stack, v) < 0) { pit_error(rt, "vm stack overflow"); } } +/* pop a value from the result stack */ static pit_value vm_pop(pit_runtime *rt) { pit_value ret = PIT_NIL; if (pit_vec_pop(pit_value)(rt->result_stack, &ret) < 0) { @@ -46,6 +49,7 @@ static pit_value vm_bind_or_replace(pit_runtime *rt, pit_value nm, pit_value cel return bound; } +/* bind variables and push code for a call to the given lisp closure */ static void vm_call_lisp(pit_runtime *rt, pit_value tag, pit_value closure, pit_value args, pit_value bound) { pit_value env = pit_value_array_get(rt, closure, 0); pit_value anames = pit_value_array_get(rt, closure, 1); @@ -78,6 +82,7 @@ static void vm_call_lisp(pit_runtime *rt, pit_value tag, pit_value closure, pit_ vm_push_code_func(rt, body, tag, ann, bound); } +/* call the function f - this could be a native function or a lisp closure */ static bool vm_call(pit_runtime *rt, pit_value f, pit_value args, pit_value bound) { char buf[256] = {0}; if (pit_value_is_symbol(rt, f)) f = pit_symtab_fget(rt, f); @@ -147,7 +152,7 @@ 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) return false; + if (rt->callstack->next < 1 || rt->error != PIT_NIL) return false; 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; } pit_value ins = pit_value_cons_car(rt, ent->code); |
