aboutsummaryrefslogtreecommitdiff
path: root/src/interp.c
diff options
context:
space:
mode:
authorMistivia <i@mistivia.com>2025-06-24 19:50:12 +0800
committerMistivia <i@mistivia.com>2025-06-24 19:50:12 +0800
commita19d0c8bc99948af39b43cc8291abfa89e5a57f8 (patch)
tree3c29d474b6e93c85190c5758af88b470eca5e9af /src/interp.c
parentec5910bea4db98b40db374a2484380fe1892c563 (diff)
add list funcs
Diffstat (limited to 'src/interp.c')
-rw-r--r--src/interp.c20
1 files changed, 13 insertions, 7 deletions
diff --git a/src/interp.c b/src/interp.c
index 65eeaff..3d7b318 100644
--- a/src/interp.c
+++ b/src/interp.c
@@ -88,6 +88,11 @@ void Interp_init(Interp *self) {
Interp_add_primitive(self, "assert-error", primitive_assert_error);
Interp_add_primitive(self, "load", primitive_load);
+ Interp_add_userfunc(self, "map", builtin_map);
+ Interp_add_userfunc(self, "filter", builtin_filter);
+ Interp_add_userfunc(self, "remove", builtin_remove);
+ Interp_add_userfunc(self, "count", builtin_count);
+ Interp_add_userfunc(self, "foreach", builtin_foreach);
Interp_add_userfunc(self, "symbol->string", builtin_symbol2string);
Interp_add_userfunc(self, "intern", builtin_intern);
Interp_add_userfunc(self, "gensym", builtin_gensym);
@@ -478,13 +483,6 @@ SExpRef lisp_macroexpand1(Interp *interp, SExpRef macro, SExpRef args) {
PUSH_REG(fn);
SExpRef ret = lisp_apply(interp, fn, args, false);
POP_REG();
- while (VALTYPE(ret) == kTailcallSExp) {
- fn = REF(ret)->tailcall.fn;
- args = REF(ret)->tailcall.args;
- PUSH_REG(ret);
- ret = lisp_apply(interp, fn, args, false);
- POP_REG();
- }
return ret;
error:
return new_error(interp, "macroexpand: syntax error.\n");
@@ -736,6 +734,14 @@ end:
if (VALTYPE(ret) == kReturnSignal) {
ret = REF(ret)->ret;
}
+ if (VALTYPE(ret) == kTailcallSExp && !istail) {
+ fn = REF(ret)->tailcall.fn;
+ args = REF(ret)->tailcall.args;
+ PUSH_REG(ret);
+ ret = lisp_apply(interp, fn, args, false);
+ POP_REG();
+ goto end;
+ }
interp->stack = CDR(interp->stack);
interp->recursion_depth--;
return ret;