commit bdb7962ed4c5e1eba7e7b872b7fe9a823f36f54a
parent bccaf30021071d01e62147ed79a62db7de1d95cc
Author: Andres Navarro <canavarro82@gmail.com>
Date: Mon, 14 Mar 2011 23:32:48 -0300
Added exit to the ground environment.
Diffstat:
4 files changed, 23 insertions(+), 3 deletions(-)
diff --git a/src/kgcontinuations.c b/src/kgcontinuations.c
@@ -133,4 +133,15 @@ void apply_continuation(klisp_State *K, TValue *xparams, TValue ptree,
/* TODO */
/* 7.3.4 exit */
-/* TODO */
+void kgexit(klisp_State *K, TValue *xparams, TValue ptree,
+ TValue denv)
+{
+ UNUSED(denv);
+ UNUSED(xparams);
+
+ check_0p(K, "exit", ptree);
+
+ /* TODO: look out for guards and dynamic variables */
+ /* should be probably handled in kcall_cont() */
+ kcall_cont(K, K->root_cont, KINERT);
+}
diff --git a/src/kgcontinuations.h b/src/kgcontinuations.h
@@ -52,6 +52,7 @@ void apply_continuation(klisp_State *K, TValue *xparams, TValue ptree,
/* TODO */
/* 7.3.4 exit */
-/* TODO */
+void kgexit(klisp_State *K, TValue *xparams, TValue ptree,
+ TValue denv);
#endif
diff --git a/src/kghelpers.h b/src/kghelpers.h
@@ -31,6 +31,13 @@
*/
/* XXX: add parens around macro vars!! */
+#define check_0p(K_, n_, ptree_) \
+ if (!ttisnil(ptree_)) { \
+ klispE_throw_extra((K_), (n_) , \
+ ": Bad ptree (expected no arguments)"); \
+ return; \
+ }
+
#define bind_1p(K_, n_, ptree_, v_) \
bind_1tp((K_), (n_), (ptree_), "any", anytype, (v_))
diff --git a/src/kground.c b/src/kground.c
@@ -390,7 +390,8 @@ void kinit_ground_env(klisp_State *K)
/* TODO */
/* 7.3.4 exit */
- /* TODO */
+ add_applicative(K, ground_env, "exit", kgexit,
+ 0);
return;
}