commit 63abc6886bb286a081afdde03219ff3502cbe85c
parent b4b80374ad6c5875f11f158df8e063d23ca773a7
Author: Andres Navarro <canavarro82@gmail.com>
Date: Mon, 7 Mar 2011 10:57:45 -0300
Moved the loop code out of klisp.c and into a function in kstate.
Diffstat:
4 files changed, 55 insertions(+), 57 deletions(-)
diff --git a/src/Makefile b/src/Makefile
@@ -48,7 +48,8 @@ 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 \
- kground.h
+ kground.h kenvironment.h kpair.h keval.h koperative.h kground.h \
+ krepl.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 kmem.h kstring.h
kauxlib.o: kauxlib.c kauxlib.h klisp.h kstate.h klisp.h
diff --git a/src/klisp.c b/src/klisp.c
@@ -15,55 +15,18 @@
#include "klimits.h"
#include "klisp.h"
-#include "kobject.h"
-#include "kauxlib.h"
#include "kstate.h"
-#include "kread.h"
-#include "kwrite.h"
-#include "keval.h"
-#include "krepl.h"
-
-#include "kcontinuation.h"
-#include "kenvironment.h"
-#include "koperative.h"
-#include "kapplicative.h"
-#include "kpair.h"
-#include "ksymbol.h"
-#include "kerror.h"
+#include "kauxlib.h"
int main(int argc, char *argv[])
{
- printf("Read/Write Test\n");
+ printf("REPL Test\n");
klisp_State *K = klispL_newstate();
- kinit_repl(K);
-
- int ret_value = 0;
- bool done = false;
-
- while(!done) {
- if (setjmp(K->error_jb)) {
- /* continuation called */
- /* TEMP: do nothing, the loop will call the continuation */
- } else {
- /* all ok, continue with next func */
- while (K->next_func) {
- if (ttisnil(K->next_env)) {
- /* continuation application */
- klisp_Cfunc fn = (klisp_Cfunc) K->next_func;
- (*fn)(K, K->next_xparams, K->next_value);
- } else {
- /* operative calling */
- klisp_Ofunc fn = (klisp_Ofunc) K->next_func;
- (*fn)(K, K->next_xparams, K->next_value, K->next_env);
- }
- }
- printf("Done!\n");
- ret_value = 0;
- done = true;
- }
- }
-
+ klispS_init_repl(K);
+ klispS_run(K);
klisp_close(K);
- return ret_value;
+
+ printf("Done!\n");
+ return 0;
}
diff --git a/src/kstate.c b/src/kstate.c
@@ -20,7 +20,7 @@
#include "keval.h"
#include "koperative.h"
#include "kground.h"
-
+#include "krepl.h"
/*
** State creation and destruction
@@ -112,16 +112,6 @@ klisp_State *klisp_newstate (klisp_Alloc f, void *ud) {
return K;
}
-void klisp_close (klisp_State *K)
-{
- /* TODO: free memory for all objects */
- klispM_freemem(K, ks_sbuf(K), ks_ssize(K));
- klispM_freemem(K, ks_tbuf(K), ks_tbsize(K));
- /* NOTE: this needs to be done "by hand" */
- (*(K->frealloc))(K->ud, K, state_size(), 0);
-}
-
-
void kcall_cont(klisp_State *K, TValue dst_cont, TValue obj)
{
/* TODO: interceptions */
@@ -135,3 +125,44 @@ void kcall_cont(klisp_State *K, TValue dst_cont, TValue obj)
longjmp(K->error_jb, 1);
}
+
+void klispS_init_repl(klisp_State *K)
+{
+ /* this is in repl.c */
+ kinit_repl(K);
+}
+
+void klispS_run(klisp_State *K)
+{
+ while(true) {
+ if (setjmp(K->error_jb)) {
+ /* continuation called */
+ /* TEMP: do nothing, the loop will call the continuation */
+ } else {
+ /* all ok, continue with next func */
+ while (K->next_func) {
+ if (ttisnil(K->next_env)) {
+ /* continuation application */
+ klisp_Cfunc fn = (klisp_Cfunc) K->next_func;
+ (*fn)(K, K->next_xparams, K->next_value);
+ } else {
+ /* operative calling */
+ klisp_Ofunc fn = (klisp_Ofunc) K->next_func;
+ (*fn)(K, K->next_xparams, K->next_value, K->next_env);
+ }
+ }
+ break;
+ }
+ }
+}
+
+void klisp_close (klisp_State *K)
+{
+ /* TODO: free memory for all objects */
+ klispM_freemem(K, ks_sbuf(K), ks_ssize(K));
+ klispM_freemem(K, ks_tbuf(K), ks_tbsize(K));
+ /* NOTE: this needs to be done "by hand" */
+ (*(K->frealloc))(K->ud, K, state_size(), 0);
+}
+
+
diff --git a/src/kstate.h b/src/kstate.h
@@ -270,7 +270,10 @@ inline void klispS_tail_call(klisp_State *K, TValue top, TValue ptree,
#define ktail_call(K_, op_, p_, e_) \
klispS_tail_call((K_), (op_), (p_), (e_)); return
-void kcall_cont(klisp_State *K, TValue cont, TValue obj);
+void kcall_cont(klisp_State *K, TValue dst_cont, TValue obj);
+void klispS_init_repl(klisp_State *K);
+void klispS_run(klisp_State *K);
+void klisp_close (klisp_State *K);
#endif