commit 9ad171b1c2435c8b4609a3879183ebdc473d9e7c
parent 7469f9a2f14ee2a40c1d470bbd8c707b9f63897b
Author: Andres Navarro <canavarro82@gmail.com>
Date: Sun, 6 Mar 2011 22:02:12 -0300
Moved part of the repl to a new file.
Diffstat:
5 files changed, 111 insertions(+), 65 deletions(-)
diff --git a/src/Makefile b/src/Makefile
@@ -9,7 +9,7 @@ MYLIBS=
CORE_O= kobject.o ktoken.o kpair.o kstring.o ksymbol.o kread.o \
kwrite.o kstate.o kmem.o kerror.o kauxlib.o kenvironment.o \
- kcontinuation.o koperative.o kapplicative.o keval.o
+ kcontinuation.o koperative.o kapplicative.o keval.o krepl.o
KRN_T= klisp
KRN_O= klisp.o
@@ -35,24 +35,30 @@ clean:
klisp.o: klisp.c klisp.h kobject.h kread.h kwrite.h klimits.h kstate.h kmem.h \
kerror.h kauxlib.h koperative.h kenvironment.h kcontinuation.h \
- kapplicative.h koperative.h
-kobject.o: kobject.c kobject.h
+ kapplicative.h koperative.h keval.h krepl.h
+kobject.o: kobject.c kobject.h klisp.h
ktoken.o: ktoken.c ktoken.h kobject.h kstate.h kpair.h kstring.h ksymbol.h \
- kerror.h
-kpair.o: kpair.c kpair.h kobject.h kstate.h kmem.h
-kstring.o: kstring.c kstring.h kobject.h kstate.h kmem.h
+ kerror.h klisp.h
+kpair.o: kpair.c kpair.h kobject.h kstate.h kmem.h klisp.h
+kstring.o: kstring.c kstring.h kobject.h kstate.h kmem.h klisp.h
# XXX: kpair.h because of use of list as symbol table
-ksymbol.o: ksymbol.c ksymbol.h kobject.h kpair.h kstate.h kmem.h
-kread.o: kread.c kread.h kobject.h ktoken.h kpair.h kstate.h kerror.h
-kwrite.o: kwrite.c kwrite.h kobject.h kpair.h kstring.h kstate.h kerror.h
-kstate.o: kstate.c kstate.h klisp.h kobject.h kmem.h kstring.h
-kmem.o: kmem.c kmem.h klisp.h kerror.h
-kerror.o: kerror.c kerror.h klisp.h kstate.h
-kauxlib.o: kauxlib.c kauxlib.h klisp.h kstate.h
+ksymbol.o: ksymbol.c ksymbol.h kobject.h kpair.h kstate.h kmem.h klisp.h
+kread.o: kread.c kread.h kobject.h ktoken.h kpair.h kstate.h kerror.h klisp.h
+kwrite.o: kwrite.c kwrite.h kobject.h kpair.h kstring.h kstate.h kerror.h \
+ klisp.h
+kstate.o: kstate.c kstate.h klisp.h kobject.h kmem.h kstring.h klisp.h
+kmem.o: kmem.c kmem.h klisp.h kerror.h klisp.h
+kerror.o: kerror.c kerror.h klisp.h kstate.h klisp.h
+kauxlib.o: kauxlib.c kauxlib.h klisp.h kstate.h klisp.h
kenvironment.o: kenvironment.c kenvironment.h kpair.h kobject.h kerror.h \
- kmem.h kstate.h
-kcontinuation.o: kcontinuation.c kcontinuation.h kmem.h kstate.h kobject.h
-koperative.o: koperative.c koperative.h kmem.h kstate.h kobject.h
-kapplicative.o: kapplicative.c kapplicative.h kmem.h kstate.h kobject.h
+ kmem.h kstate.h klisp.h
+kcontinuation.o: kcontinuation.c kcontinuation.h kmem.h kstate.h kobject.h \
+ klisp.h
+koperative.o: koperative.c koperative.h kmem.h kstate.h kobject.h \
+ klisp.h
+kapplicative.o: kapplicative.c kapplicative.h kmem.h kstate.h kobject.h \
+ klisp.h
keval.o: keval.c keval.h kcontinuation.h kenvironment.h kstate.h kobject.h \
- kpair.h kerror.h
-\ No newline at end of file
+ kpair.h kerror.h klisp.h
+krepl.o: krepl.c krepl.h kcontinuation.h kstate.h kobject.h keval.h klisp.h \
+ kread.h kwrite.h
+\ No newline at end of file
diff --git a/src/keval.h b/src/keval.h
@@ -7,6 +7,10 @@
#ifndef keval_h
#define keval_h
+#include "klisp.h"
+#include "kstate.h"
+#include "kobject.h"
+
void keval_ofn(klisp_State *K, TValue *xparams, TValue obj, TValue env);
#endif
diff --git a/src/klisp.c b/src/klisp.c
@@ -21,6 +21,7 @@
#include "kread.h"
#include "kwrite.h"
#include "keval.h"
+#include "krepl.h"
#include "kcontinuation.h"
#include "kenvironment.h"
@@ -30,52 +31,6 @@
#include "ksymbol.h"
#include "kerror.h"
-/* the exit continuation, it exits the loop */
-void exit_fn(klisp_State *K, TValue *xparams, TValue obj)
-{
- /* avoid warnings */
- (void) xparams;
- (void) obj;
-
- /* force the loop to terminate */
- K->next_func = NULL;
- return;
-}
-
-/* the underlying function of the eval cont */
-void eval_cfn(klisp_State *K, TValue *xparams, TValue obj)
-{
- /*
- ** xparams[0]: dynamic environment
- */
- TValue denv = xparams[0];
-
- ktail_call(K, K->eval_op, obj, denv);
-}
-
-/* the underlying function of the write & loop cont */
-void loop_fn(klisp_State *K, TValue *xparams, TValue obj)
-{
- /*
- ** xparams[0]: dynamic environment
- */
- if (ttiseof(obj)) {
- /* this will in turn call main_cont */
- kapply_cc(K, obj);
- } else {
- kwrite(K, obj);
- knewline(K);
- TValue denv = xparams[0];
-
- TValue loop_cont = kmake_continuation(
- K, kget_cc(K), KNIL, KNIL, &loop_fn, 1, denv);
- TValue eval_cont = kmake_continuation(
- K, loop_cont, KNIL, KNIL, &eval_cfn, 1, denv);
- kset_cc(K, eval_cont);
- TValue robj = kread(K);
- kapply_cc(K, robj);
- }
-}
/* define helper */
void match_cfn(klisp_State *K, TValue *xparams, TValue obj)
diff --git a/src/krepl.c b/src/krepl.c
@@ -0,0 +1,63 @@
+/*
+** krepl.c
+** klisp repl
+** See Copyright Notice in klisp.h
+*/
+#include <stdio.h>
+#include <setjmp.h>
+
+#include "klisp.h"
+#include "kstate.h"
+#include "kobject.h"
+#include "kcontinuation.h"
+#include "kerror.h"
+#include "kwrite.h"
+#include "kread.h"
+#include "krepl.h"
+
+/* the exit continuation, it exits the loop */
+void exit_fn(klisp_State *K, TValue *xparams, TValue obj)
+{
+ /* avoid warnings */
+ (void) xparams;
+ (void) obj;
+
+ /* force the loop to terminate */
+ K->next_func = NULL;
+ return;
+}
+
+/* the underlying function of the eval cont */
+void eval_cfn(klisp_State *K, TValue *xparams, TValue obj)
+{
+ /*
+ ** xparams[0]: dynamic environment
+ */
+ TValue denv = xparams[0];
+
+ ktail_call(K, K->eval_op, obj, denv);
+}
+
+/* the underlying function of the write & loop cont */
+void loop_fn(klisp_State *K, TValue *xparams, TValue obj)
+{
+ /*
+ ** xparams[0]: dynamic environment
+ */
+ if (ttiseof(obj)) {
+ /* this will in turn call main_cont */
+ kapply_cc(K, obj);
+ } else {
+ kwrite(K, obj);
+ knewline(K);
+ TValue denv = xparams[0];
+
+ TValue loop_cont = kmake_continuation(
+ K, kget_cc(K), KNIL, KNIL, &loop_fn, 1, denv);
+ TValue eval_cont = kmake_continuation(
+ K, loop_cont, KNIL, KNIL, &eval_cfn, 1, denv);
+ kset_cc(K, eval_cont);
+ TValue robj = kread(K);
+ kapply_cc(K, robj);
+ }
+}
diff --git a/src/krepl.h b/src/krepl.h
@@ -0,0 +1,18 @@
+/*
+** krepl.h
+** klisp repl
+** See Copyright Notice in klisp.h
+*/
+
+#ifndef krepl_h
+#define krepl_h
+
+#include "klisp.h"
+#include "kstate.h"
+#include "kobject.h"
+
+void loop_fn(klisp_State *K, TValue *xparams, TValue obj);
+void eval_cfn(klisp_State *K, TValue *xparams, TValue obj);
+void exit_fn(klisp_State *K, TValue *xparams, TValue obj);
+
+#endif