summaryrefslogtreecommitdiff
path: root/src/runtime.c
diff options
context:
space:
mode:
authorLLLL Colonq <llll@colonq>2025-09-28 18:56:19 -0400
committerLLLL Colonq <llll@colonq>2025-09-28 18:56:19 -0400
commit8e4c0380da7e120476f060b4fa00f181add6dc87 (patch)
tree85efca0f10859ad8a9c5da197d836b3bf497e3a3 /src/runtime.c
parentf712d031f0406c84d2ee8addfa53e6522d146104 (diff)
Add README
Diffstat (limited to 'src/runtime.c')
-rw-r--r--src/runtime.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/runtime.c b/src/runtime.c
index 633ad32..2d30420 100644
--- a/src/runtime.c
+++ b/src/runtime.c
@@ -750,9 +750,10 @@ pit_value pit_apply(pit_runtime *rt, pit_value f, pit_value args) {
pit_value_heavy *h = pit_deref(rt, pit_as_ref(rt, f));
if (!h) { pit_error(rt, "bad ref"); return PIT_NIL; }
if (h->hsort == PIT_VALUE_HEAVY_SORT_FUNC) {
+ // calling a Lisp function is simple!
pit_value bound = PIT_NIL;
pit_value env = h->func.env;
- while (env != PIT_NIL) {
+ while (env != PIT_NIL) { // first, bind all entries in the closure
pit_value b = pit_car(rt, env);
pit_value nm = pit_car(rt, b);
pit_bind(rt, nm, pit_cdr(rt, b));
@@ -760,7 +761,7 @@ pit_value pit_apply(pit_runtime *rt, pit_value f, pit_value args) {
env = pit_cdr(rt, env);
}
pit_value anames = h->func.args;
- while (anames != PIT_NIL) {
+ while (anames != PIT_NIL) { // bind all argument names to their values
pit_value aform = pit_car(rt, anames);
pit_value nm = pit_car(rt, aform);
pit_value cell = pit_cdr(rt, aform);
@@ -770,13 +771,14 @@ pit_value pit_apply(pit_runtime *rt, pit_value f, pit_value args) {
args = pit_cdr(rt, args);
anames = pit_cdr(rt, anames);
}
- pit_value ret = pit_eval(rt, h->func.body);
- while (bound != PIT_NIL) {
+ pit_value ret = pit_eval(rt, h->func.body); // evaluate the body
+ while (bound != PIT_NIL) { // unbind everything we bound earlier, in reverse
pit_unbind(rt, pit_car(rt, bound));
bound = pit_cdr(rt, bound);
}
return ret;
} else if (h->hsort == PIT_VALUE_HEAVY_SORT_NATIVEFUNC) {
+ // calling native functions is even simpler
return h->nativefunc(rt, args);
} else {
pit_error(rt, "attempt to apply non-nativefunc ref");