summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLLLL Colonq <llll@colonq>2025-09-27 19:39:13 -0400
committerLLLL Colonq <llll@colonq>2025-09-27 19:39:13 -0400
commitf712d031f0406c84d2ee8addfa53e6522d146104 (patch)
tree2114d9d69a3c8e593a740e95a14b34849f98536a /src
parentab57bc2a6d6ea9c24aa119df6efbd8a38b54c312 (diff)
Fix bug related to nested evaluation
Diffstat (limited to 'src')
-rw-r--r--src/library.c10
-rw-r--r--src/runtime.c8
2 files changed, 13 insertions, 5 deletions
diff --git a/src/library.c b/src/library.c
index be38292..9aaadc3 100644
--- a/src/library.c
+++ b/src/library.c
@@ -130,7 +130,15 @@ static pit_value impl_symbol_is_macro(pit_runtime *rt, pit_value args) {
static pit_value impl_funcall(pit_runtime *rt, pit_value args) {
pit_value fsym = pit_car(rt, args);
- pit_value f = pit_fget(rt, fsym);
+ pit_value f;
+ if (pit_is_symbol(rt, fsym)) {
+ f = pit_fget(rt, fsym);
+ } else {
+ // if f is not a symbol, assume it is a func or nativefunc
+ // most commonly, this happens when you funcall a variable
+ // with a function in the value cell, e.g. passing a lambda to a function
+ f = fsym;
+ }
pit_value as = pit_cdr(rt, args);
return pit_apply(rt, f, as);
}
diff --git a/src/runtime.c b/src/runtime.c
index 6825bbe..633ad32 100644
--- a/src/runtime.c
+++ b/src/runtime.c
@@ -567,7 +567,7 @@ pit_value pit_cell_new(pit_runtime *rt, pit_value v) {
}
pit_value pit_cell_get(pit_runtime *rt, pit_value cell) {
if (pit_value_sort(cell) != PIT_VALUE_SORT_REF) {
- pit_error(rt, "cell value is not ref");
+ pit_error(rt, "attempted to get cell value that is not ref");
return PIT_NIL;
}
pit_value_heavy *h = pit_deref(rt, pit_as_ref(rt, cell));
@@ -580,7 +580,7 @@ pit_value pit_cell_get(pit_runtime *rt, pit_value cell) {
}
void pit_cell_set(pit_runtime *rt, pit_value cell, pit_value v) {
if (pit_value_sort(cell) != PIT_VALUE_SORT_REF) {
- pit_error(rt, "cell value is not ref");
+ pit_error(rt, "attempted to set cell value that is not ref");
return;
}
pit_ref idx = pit_as_ref(rt, cell);
@@ -823,7 +823,7 @@ pit_value pit_expand_macros(pit_runtime *rt, pit_value top) {
i64 result_stack_reset = rt->result_stack->top;
i64 program_reset = rt->program->top;
pit_values_push(rt, rt->expr_stack, top);
- while (rt->expr_stack->top > 0) {
+ while (rt->expr_stack->top > expr_stack_reset) {
if (rt->error != PIT_NIL) goto end;
pit_value cur = pit_values_pop(rt, rt->expr_stack);
if (pit_is_cons(rt, cur)) {
@@ -929,7 +929,7 @@ pit_value pit_eval(pit_runtime *rt, pit_value top) {
i64 program_reset = rt->program->top;
pit_values_push(rt, rt->expr_stack, top);
// first, convert the expression tree into "polish notation" in program
- while (rt->expr_stack->top > 0) {
+ while (rt->expr_stack->top > expr_stack_reset) {
if (rt->error != PIT_NIL) goto end;
pit_value cur = pit_values_pop(rt, rt->expr_stack);
if (pit_is_cons(rt, cur)) { // compound expressions: function/macro application special forms