aboutsummaryrefslogtreecommitdiff
path: root/src/primitives.c
diff options
context:
space:
mode:
authorMistivia <i@mistivia.com>2025-06-28 15:49:31 +0800
committerMistivia <i@mistivia.com>2025-06-28 15:51:04 +0800
commit0633c6c2797bc9182b2c1888385eac6cb6caed10 (patch)
treee920255dda5b6fea67f3eef91b27c4dae069c63e /src/primitives.c
parent9efc0e78ad1609217752b5aa02fbb389d726e9c7 (diff)
add unwind-protect
Diffstat (limited to 'src/primitives.c')
-rw-r--r--src/primitives.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/primitives.c b/src/primitives.c
index a8bb62a..9f3e670 100644
--- a/src/primitives.c
+++ b/src/primitives.c
@@ -79,6 +79,17 @@ SExpRef primitive_eval(Interp *interp, SExpRef args, bool istail) {
return lisp_eval(interp, args, istail);
}
+SExpRef primitive_unwind_protect(Interp *interp, SExpRef args, bool istail) {
+ if (LENGTH(args) < 2) {
+ return new_error(interp, "unwind-protect: syntax error.\n");
+ }
+ SExpRef ret = EVAL(CAR(args));
+ for (SExpRef i = CDR(args); !NILP(i); i = CDR(i)) {
+ EVAL(CAR(i));
+ }
+ return ret;
+}
+
SExpRef primitive_if(Interp *interp, SExpRef args, bool istail) {
SExpRef cond, tb, fb;