klisp

an open source interpreter for the Kernel Programming Language.
git clone http://git.hanabi.in/repos/klisp.git
Log | Files | Refs | README

commit 70ee93008be662eac3194822241d60e9bebd4c18
parent 5fed3daf3f2f77ee14577ea8ec6d05a2900dda16
Author: Andres Navarro <canavarro82@gmail.com>
Date:   Mon, 28 Nov 2011 14:07:40 -0300

Added back the continuation names, now organized a lot more like ground initialization.

Diffstat:
Msrc/Makefile | 67+++++++++++++++++++++++++++++++++++--------------------------------
Msrc/keval.c | 15+++++++++++++++
Msrc/keval.h | 6++----
Msrc/kgbooleans.c | 10++++++++++
Msrc/kgbooleans.h | 2++
Msrc/kgcombiners.c | 12++++++++++++
Msrc/kgcombiners.h | 2++
Msrc/kgcontinuations.c | 11+++++++++++
Msrc/kgcontinuations.h | 2++
Msrc/kgcontrol.c | 18+++++++++++++++---
Msrc/kgcontrol.h | 2++
Msrc/kgenv_mut.c | 14+++++++++++++-
Msrc/kgenv_mut.h | 3+++
Msrc/kgenvironments.c | 18+++++++++++++++++-
Msrc/kgenvironments.h | 2++
Msrc/kgffi.c | 15+++++++++++++++
Msrc/kgffi.h | 2++
Msrc/kghelpers.c | 13+++++++++++++
Msrc/kghelpers.h | 23++++++++++++++++++++++-
Msrc/kgpairs_lists.c | 34+++++++++++++++++++++++++++++++---
Msrc/kgpairs_lists.h | 2++
Msrc/kgports.c | 11+++++++++++
Msrc/kgports.h | 2++
Msrc/kgpromises.c | 10+++++++++-
Msrc/kgpromises.h | 2++
Msrc/kground.c | 77+++++++++++++++++++++--------------------------------------------------------
Msrc/kground.h | 1+
Msrc/krepl.c | 26++++++++++++++++++++------
Msrc/krepl.h | 9++-------
Msrc/kstate.c | 2+-
30 files changed, 297 insertions(+), 116 deletions(-)

diff --git a/src/Makefile b/src/Makefile @@ -130,124 +130,127 @@ kenvironment.o: kenvironment.c kenvironment.h kobject.h klimits.h klisp.h \ kerror.o: kerror.c klisp.h kobject.h klimits.h klispconf.h kpair.h \ kstate.h ktoken.h kmem.h kgc.h kstring.h kerror.h keval.o: keval.c klisp.h kobject.h klimits.h klispconf.h kstate.h \ - ktoken.h kmem.h kpair.h kgc.h kenvironment.h kcontinuation.h kerror.h + ktoken.h kmem.h kpair.h kgc.h kenvironment.h kcontinuation.h kerror.h \ + kghelpers.h kapplicative.h koperative.h ksymbol.h kstring.h ktable.h kgbooleans.o: kgbooleans.c kobject.h klimits.h klisp.h klispconf.h \ kstate.h ktoken.h kmem.h kpair.h kgc.h ksymbol.h kstring.h \ kcontinuation.h kerror.h kghelpers.h kapplicative.h koperative.h \ - kenvironment.h kgbooleans.h + kenvironment.h ktable.h kgbooleans.h kgbytevectors.o: kgbytevectors.c kstate.h klimits.h klisp.h kobject.h \ klispconf.h ktoken.h kmem.h kapplicative.h koperative.h kcontinuation.h \ kerror.h kpair.h kgc.h kbytevector.h kghelpers.h kenvironment.h \ - ksymbol.h kstring.h kgbytevectors.h + ksymbol.h kstring.h ktable.h kgbytevectors.h kgc.o: kgc.c kgc.h kobject.h klimits.h klisp.h klispconf.h kstate.h \ ktoken.h kmem.h kport.h imath.h imrat.h ktable.h kstring.h kbytevector.h \ kvector.h kerror.h kpair.h kgchars.o: kgchars.c kstate.h klimits.h klisp.h kobject.h klispconf.h \ ktoken.h kmem.h kapplicative.h koperative.h kcontinuation.h kerror.h \ kpair.h kgc.h kchar.h kghelpers.h kenvironment.h ksymbol.h kstring.h \ - kgchars.h + ktable.h kgchars.h kgcombiners.o: kgcombiners.c kstate.h klimits.h klisp.h kobject.h \ klispconf.h ktoken.h kmem.h kpair.h kgc.h kenvironment.h kcontinuation.h \ ksymbol.h kstring.h koperative.h kapplicative.h kerror.h kghelpers.h \ - kgcombiners.h + ktable.h kgcombiners.h kgcontinuations.o: kgcontinuations.c kstate.h klimits.h klisp.h kobject.h \ klispconf.h ktoken.h kmem.h kpair.h kgc.h kenvironment.h kcontinuation.h \ kapplicative.h koperative.h ksymbol.h kstring.h kerror.h kghelpers.h \ - kgcontinuations.h + ktable.h kgcontinuations.h kgcontrol.o: kgcontrol.c kstate.h klimits.h klisp.h kobject.h klispconf.h \ ktoken.h kmem.h kpair.h kgc.h kcontinuation.h kerror.h kghelpers.h \ - kapplicative.h koperative.h kenvironment.h ksymbol.h kstring.h \ + kapplicative.h koperative.h kenvironment.h ksymbol.h kstring.h ktable.h \ kgcontrol.h kgencapsulations.o: kgencapsulations.c kstate.h klimits.h klisp.h \ kobject.h klispconf.h ktoken.h kmem.h kencapsulation.h kapplicative.h \ koperative.h kerror.h kpair.h kgc.h kghelpers.h kcontinuation.h \ - kenvironment.h ksymbol.h kstring.h kgencapsulations.h + kenvironment.h ksymbol.h kstring.h ktable.h kgencapsulations.h kgenv_mut.o: kgenv_mut.c kstate.h klimits.h klisp.h kobject.h klispconf.h \ ktoken.h kmem.h kpair.h kgc.h kenvironment.h kcontinuation.h ksymbol.h \ - kstring.h kerror.h kghelpers.h kapplicative.h koperative.h kgenv_mut.h + kstring.h kerror.h kghelpers.h kapplicative.h koperative.h ktable.h \ + kgenv_mut.h kgenvironments.o: kgenvironments.c kstate.h klimits.h klisp.h kobject.h \ klispconf.h ktoken.h kmem.h kpair.h kgc.h kenvironment.h kcontinuation.h \ ksymbol.h kstring.h kerror.h kghelpers.h kapplicative.h koperative.h \ - kgenvironments.h + ktable.h kgenvironments.h kgeqp.o: kgeqp.c kstate.h klimits.h klisp.h kobject.h klispconf.h \ ktoken.h kmem.h kpair.h kgc.h kcontinuation.h kerror.h kghelpers.h \ - kapplicative.h koperative.h kenvironment.h ksymbol.h kstring.h kgeqp.h + kapplicative.h koperative.h kenvironment.h ksymbol.h kstring.h ktable.h \ + kgeqp.h kgequalp.o: kgequalp.c kstate.h klimits.h klisp.h kobject.h klispconf.h \ ktoken.h kmem.h kpair.h kgc.h kvector.h kstring.h kbytevector.h \ kcontinuation.h kerror.h kghelpers.h kapplicative.h koperative.h \ - kenvironment.h ksymbol.h kgequalp.h + kenvironment.h ksymbol.h ktable.h kgequalp.h kgerrors.o: kgerrors.c kstate.h klimits.h klisp.h kobject.h klispconf.h \ ktoken.h kmem.h kstring.h kpair.h kgc.h kerror.h kghelpers.h \ kapplicative.h koperative.h kcontinuation.h kenvironment.h ksymbol.h \ - kgerrors.h + ktable.h kgerrors.h kgffi.o: kgffi.c imath.h kobject.h klimits.h klisp.h klispconf.h kstate.h \ ktoken.h kmem.h kinteger.h kpair.h kgc.h kerror.h kbytevector.h \ kencapsulation.h ktable.h kghelpers.h kapplicative.h koperative.h \ kcontinuation.h kenvironment.h ksymbol.h kstring.h kgffi.h kghelpers.o: kghelpers.c kghelpers.h kstate.h klimits.h klisp.h kobject.h \ klispconf.h ktoken.h kmem.h kerror.h kpair.h kgc.h kapplicative.h \ - koperative.h kcontinuation.h kenvironment.h ksymbol.h kstring.h \ + koperative.h kcontinuation.h kenvironment.h ksymbol.h kstring.h ktable.h \ kinteger.h imath.h krational.h imrat.h kbytevector.h kvector.h \ kencapsulation.h kgkd_vars.o: kgkd_vars.c kstate.h klimits.h klisp.h kobject.h klispconf.h \ ktoken.h kmem.h kpair.h kgc.h kcontinuation.h koperative.h \ kapplicative.h kenvironment.h kerror.h kghelpers.h ksymbol.h kstring.h \ - kgkd_vars.h + ktable.h kgkd_vars.h kgks_vars.o: kgks_vars.c kstate.h klimits.h klisp.h kobject.h klispconf.h \ ktoken.h kmem.h kpair.h kgc.h kcontinuation.h koperative.h \ kapplicative.h kenvironment.h kerror.h kghelpers.h ksymbol.h kstring.h \ - kgks_vars.h + ktable.h kgks_vars.h kgnumbers.o: kgnumbers.c kstate.h klimits.h klisp.h kobject.h klispconf.h \ ktoken.h kmem.h kapplicative.h koperative.h kcontinuation.h kerror.h \ kpair.h kgc.h ksymbol.h kstring.h kinteger.h imath.h krational.h imrat.h \ - kreal.h kghelpers.h kenvironment.h kgnumbers.h + kreal.h kghelpers.h kenvironment.h ktable.h kgnumbers.h kgpair_mut.o: kgpair_mut.c kstate.h klimits.h klisp.h kobject.h \ klispconf.h ktoken.h kmem.h kpair.h kgc.h kcontinuation.h ksymbol.h \ kstring.h kerror.h kghelpers.h kapplicative.h koperative.h \ - kenvironment.h kgpair_mut.h + kenvironment.h ktable.h kgpair_mut.h kgpairs_lists.o: kgpairs_lists.c kstate.h klimits.h klisp.h kobject.h \ klispconf.h ktoken.h kmem.h kpair.h kgc.h kstring.h kcontinuation.h \ kenvironment.h ksymbol.h kerror.h kghelpers.h kapplicative.h \ - koperative.h kgpairs_lists.h + koperative.h ktable.h kgpairs_lists.h kgports.o: kgports.c kstate.h klimits.h klisp.h kobject.h klispconf.h \ ktoken.h kmem.h kport.h kstring.h kbytevector.h kenvironment.h \ kapplicative.h koperative.h kcontinuation.h kpair.h kgc.h kerror.h \ - ksymbol.h kread.h kwrite.h kghelpers.h kgports.h + ksymbol.h kread.h kwrite.h kghelpers.h ktable.h kgports.h kgpromises.o: kgpromises.c kstate.h klimits.h klisp.h kobject.h \ klispconf.h ktoken.h kmem.h kpromise.h kpair.h kgc.h kapplicative.h \ koperative.h kcontinuation.h kerror.h kghelpers.h kenvironment.h \ - ksymbol.h kstring.h kgpromises.h + ksymbol.h kstring.h ktable.h kgpromises.h kground.o: kground.c kstate.h klimits.h klisp.h kobject.h klispconf.h \ ktoken.h kmem.h kground.h kghelpers.h kerror.h kpair.h kgc.h \ kapplicative.h koperative.h kcontinuation.h kenvironment.h ksymbol.h \ - kstring.h kgbooleans.h kgeqp.h kgequalp.h kgsymbols.h kgcontrol.h \ - kgpairs_lists.h kgpair_mut.h kgenvironments.h kgenv_mut.h kgcombiners.h \ - kgcontinuations.h kgencapsulations.h kgpromises.h kgkd_vars.h \ - kgks_vars.h kgnumbers.h kgstrings.h kgchars.h kgports.h kgbytevectors.h \ - kgvectors.h kgsystem.h kgerrors.h $(if $(USE_LIBFFI),kgffi.h) ktable.h \ - keval.h krepl.h + kstring.h ktable.h kgbooleans.h kgeqp.h kgequalp.h kgsymbols.h \ + kgcontrol.h kgpairs_lists.h kgpair_mut.h kgenvironments.h kgenv_mut.h \ + kgcombiners.h kgcontinuations.h kgencapsulations.h kgpromises.h \ + kgkd_vars.h kgks_vars.h kgnumbers.h kgstrings.h kgchars.h kgports.h \ + kgbytevectors.h kgvectors.h kgsystem.h kgerrors.h \ + kgffi.h keval.h krepl.h kgstrings.o: kgstrings.c kstate.h klimits.h klisp.h kobject.h klispconf.h \ ktoken.h kmem.h kapplicative.h koperative.h kcontinuation.h kerror.h \ kpair.h kgc.h ksymbol.h kstring.h kchar.h kvector.h kbytevector.h \ - kghelpers.h kenvironment.h kgstrings.h + kghelpers.h kenvironment.h ktable.h kgstrings.h kgsymbols.o: kgsymbols.c kstate.h klimits.h klisp.h kobject.h klispconf.h \ ktoken.h kmem.h kcontinuation.h kpair.h kgc.h kstring.h ksymbol.h \ - kerror.h kghelpers.h kapplicative.h koperative.h kenvironment.h \ + kerror.h kghelpers.h kapplicative.h koperative.h kenvironment.h ktable.h \ kgsymbols.h kgsystem.o: kgsystem.c kstate.h klimits.h klisp.h kobject.h klispconf.h \ ktoken.h kmem.h kpair.h kgc.h kerror.h ksystem.h kghelpers.h \ kapplicative.h koperative.h kcontinuation.h kenvironment.h ksymbol.h \ - kstring.h kgsystem.h + kstring.h ktable.h kgsystem.h kgvectors.o: kgvectors.c kstate.h klimits.h klisp.h kobject.h klispconf.h \ ktoken.h kmem.h kapplicative.h koperative.h kcontinuation.h kerror.h \ kpair.h kgc.h kvector.h kbytevector.h kghelpers.h kenvironment.h \ - ksymbol.h kstring.h kgvectors.h + ksymbol.h kstring.h ktable.h kgvectors.h kinteger.o: kinteger.c kinteger.h kobject.h klimits.h klisp.h klispconf.h \ kstate.h ktoken.h kmem.h imath.h kgc.h klisp.o: klisp.c klimits.h klisp.h kobject.h klispconf.h kstate.h \ ktoken.h kmem.h kauxlib.h kstring.h kcontinuation.h koperative.h \ kapplicative.h ksymbol.h kenvironment.h kport.h kread.h kwrite.h \ - kerror.h kpair.h kgc.h krepl.h kghelpers.h + kerror.h kpair.h kgc.h krepl.h kghelpers.h ktable.h kmem.o: kmem.c klisp.h kobject.h klimits.h klispconf.h kstate.h ktoken.h \ kmem.h kerror.h kpair.h kgc.h kobject.o: kobject.c kobject.h klimits.h klisp.h klispconf.h diff --git a/src/keval.c b/src/keval.c @@ -12,6 +12,14 @@ #include "kcontinuation.h" #include "kerror.h" +/* for continuation name setting */ +#include "kghelpers.h" + +/* Continuations */ +void do_eval_ls(klisp_State *K); +void do_combine(klisp_State *K); + + /* ** Eval helpers */ @@ -173,4 +181,11 @@ void keval_ofn(klisp_State *K) } } +/* init continuation names */ +void kinit_eval_cont_names(klisp_State *K) +{ + Table *t = tv2table(K->cont_name_table); + add_cont_name(K, t, do_eval_ls, "eval-list"); + add_cont_name(K, t, do_combine, "eval-combine"); +} diff --git a/src/keval.h b/src/keval.h @@ -7,12 +7,10 @@ #ifndef keval_h #define keval_h -#include "klisp.h" #include "kstate.h" -#include "kobject.h" void keval_ofn(klisp_State *K); -void do_eval_ls(klisp_State *K); -void do_combine(klisp_State *K); +/* init continuation names */ +void kinit_eval_cont_names(klisp_State *K); #endif diff --git a/src/kgbooleans.c b/src/kgbooleans.c @@ -21,6 +21,9 @@ #include "kghelpers.h" #include "kgbooleans.h" +/* Continuations */ +void do_Sandp_Sorp(klisp_State *K); + /* 4.1.1 boolean? */ /* uses typep */ @@ -207,3 +210,10 @@ void kinit_booleans_ground_env(klisp_State *K) /* 6.1.5 $or? */ add_operative(K, ground_env, "$or?", Sandp_Sorp, 2, symbol, KTRUE); } + +/* init continuation names */ +void kinit_booleans_cont_names(klisp_State *K) +{ + Table *t = tv2table(K->cont_name_table); + add_cont_name(K, t, do_Sandp_Sorp, "eval-booleans"); +} diff --git a/src/kgbooleans.h b/src/kgbooleans.h @@ -11,5 +11,7 @@ /* init ground */ void kinit_booleans_ground_env(klisp_State *K); +/* init continuation names */ +void kinit_booleans_cont_names(klisp_State *K); #endif diff --git a/src/kgcombiners.c b/src/kgcombiners.c @@ -556,3 +556,15 @@ void kinit_combiners_ground_env(klisp_State *K) add_applicative(K, ground_env, "combiner?", ftypep, 2, symbol, p2tv(kcombinerp)); } + +/* init continuation names */ +void kinit_combiners_cont_names(klisp_State *K) +{ + Table *t = tv2table(K->cont_name_table); + + add_cont_name(K, t, do_map, "map-acyclic-part"); + add_cont_name(K, t, do_map_encycle, "map-encycle!"); + add_cont_name(K, t, do_map_ret, "map-ret"); + add_cont_name(K, t, do_map_cycle, "map-cyclic-part"); + add_cont_name(K, t, do_vau, "$vau-bind!-eval"); +} diff --git a/src/kgcombiners.h b/src/kgcombiners.h @@ -11,5 +11,7 @@ /* init ground */ void kinit_combiners_ground_env(klisp_State *K); +/* init continuation names */ +void kinit_combiners_cont_names(klisp_State *K); #endif diff --git a/src/kgcontinuations.c b/src/kgcontinuations.c @@ -23,6 +23,9 @@ #include "kghelpers.h" #include "kgcontinuations.h" +/* Continuations */ +void do_extended_cont(klisp_State *K); + /* 7.1.1 continuation? */ /* uses typep */ @@ -277,3 +280,11 @@ void kinit_continuations_ground_env(klisp_State *K) add_applicative(K, ground_env, "exit", kgexit, 0); } + +/* init continuation names */ +void kinit_continuations_cont_names(klisp_State *K) +{ + Table *t = tv2table(K->cont_name_table); + + add_cont_name(K, t, do_extended_cont, "extended-cont"); +} diff --git a/src/kgcontinuations.h b/src/kgcontinuations.h @@ -11,5 +11,7 @@ /* init ground */ void kinit_continuations_ground_env(klisp_State *K); +/* init continuation names */ +void kinit_continuations_cont_names(klisp_State *K); #endif diff --git a/src/kgcontrol.c b/src/kgcontrol.c @@ -19,14 +19,16 @@ #include "kghelpers.h" #include "kgcontrol.h" +/* Continuations */ +void do_select_clause(klisp_State *K); +void do_cond(klisp_State *K); +void do_for_each(klisp_State *K); + /* 4.5.1 inert? */ /* uses typep */ /* 4.5.2 $if */ -/* helpers */ -void do_select_clause(klisp_State *K); - /* ASK JOHN: both clauses should probably be copied (copy-es-immutable) */ void Sif(klisp_State *K) { @@ -384,3 +386,13 @@ void kinit_control_ground_env(klisp_State *K) /* 6.9.1 for-each */ add_applicative(K, ground_env, "for-each", for_each, 0); } + +/* init continuation names */ +void kinit_control_cont_names(klisp_State *K) +{ + Table *t = tv2table(K->cont_name_table); + + add_cont_name(K, t, do_select_clause, "select-clause"); + add_cont_name(K, t, do_cond, "eval-cond-list"); + add_cont_name(K, t, do_for_each, "for-each"); +} diff --git a/src/kgcontrol.h b/src/kgcontrol.h @@ -11,5 +11,7 @@ /* init ground */ void kinit_control_ground_env(klisp_State *K); +/* init continuation names */ +void kinit_control_cont_names(klisp_State *K); #endif diff --git a/src/kgenv_mut.c b/src/kgenv_mut.c @@ -21,9 +21,10 @@ #include "kghelpers.h" #include "kgenv_mut.h" -/* continuations */ +/* Continuations */ void do_match(klisp_State *K); void do_set_eval_obj(klisp_State *K); +void do_import(klisp_State *K); /* 4.9.1 $define! */ void SdefineB(klisp_State *K) @@ -327,3 +328,14 @@ void kinit_env_mut_ground_env(klisp_State *K) /* 6.8.3 $import! */ add_operative(K, ground_env, "$import!", SimportB, 1, symbol); } + +/* init continuation names */ +void kinit_env_mut_cont_names(klisp_State *K) +{ + Table *t = tv2table(K->cont_name_table); + + add_cont_name(K, t, do_match, "match-ptree"); + add_cont_name(K, t, do_set_eval_obj, "set-eval-obj"); + add_cont_name(K, t, do_import, "import-bindings"); +} + diff --git a/src/kgenv_mut.h b/src/kgenv_mut.h @@ -11,5 +11,8 @@ /* init ground */ void kinit_env_mut_ground_env(klisp_State *K); +/* init continuation names */ +void kinit_env_mut_cont_names(klisp_State *K); + #endif diff --git a/src/kgenvironments.c b/src/kgenvironments.c @@ -21,8 +21,12 @@ #include "kghelpers.h" #include "kgenvironments.h" -/* continuations */ +/* Continuations */ +void do_let(klisp_State *K); +void do_let_redirect(klisp_State *K); +void do_bindsp(klisp_State *K); void do_remote_eval(klisp_State *K); +void do_b_to_env(klisp_State *K); /* 4.8.1 environment? */ /* uses typep */ @@ -723,3 +727,15 @@ void kinit_environments_ground_env(klisp_State *K) add_operative(K, ground_env, "$bindings->environment", Sbindings_to_environment, 1, symbol); } + +/* init continuation names */ +void kinit_environments_cont_names(klisp_State *K) +{ + Table *t = tv2table(K->cont_name_table); + + add_cont_name(K, t, do_let, "eval-let"); + add_cont_name(K, t, do_let_redirect, "eval-let-redirect"); + add_cont_name(K, t, do_bindsp, "eval-$binds?-env"); + add_cont_name(K, t, do_remote_eval, "eval-remote-eval-env"); + add_cont_name(K, t, do_b_to_env, "bindings-to-env"); +} diff --git a/src/kgenvironments.h b/src/kgenvironments.h @@ -11,5 +11,7 @@ /* init ground */ void kinit_environments_ground_env(klisp_State *K); +/* init continuation names */ +void kinit_environments_cont_names(klisp_State *K); #endif diff --git a/src/kgffi.c b/src/kgffi.c @@ -76,6 +76,10 @@ typedef struct { #define CB_INDEX_STACK 1 #define CB_INDEX_FIRST_CALLBACK 2 +/* Continuations */ +void do_ffi_callback_encode_result(klisp_State *K); +void do_ffi_callback_return(klisp_State *K); + static TValue ffi_decode_void(ffi_codec_t *self, klisp_State *K, const void *buf) { UNUSED(self); @@ -1178,3 +1182,14 @@ void kinit_ffi_ground_env(klisp_State *K) add_applicative(K, ground_env, "ffi-library?", enc_typep, 1, dll_key); add_applicative(K, ground_env, "ffi-call-interface?", enc_typep, 1, cif_key); } + +/* init continuation names */ +void kinit_ffi_cont_names(klisp_State *K) +{ + Table *t = tv2table(K->cont_name_table); + + add_cont_name(K, t, do_ffi_callback_encode_result, + "ffi-callback-encode-result"); + add_cont_name(K, t, do_ffi_callback_return, + "ffi-callback-ret"); +} diff --git a/src/kgffi.h b/src/kgffi.h @@ -15,5 +15,7 @@ /* init ground */ void kinit_ffi_ground_env(klisp_State *K); +/* init continuation names */ +void kinit_ffi_cont_names(klisp_State *K); #endif diff --git a/src/kghelpers.c b/src/kghelpers.c @@ -26,6 +26,19 @@ #include "kcontinuation.h" #include "kencapsulation.h" +/* Initialization of continuation names */ +void kinit_kghelpers_cont_names(klisp_State *K) +{ + Table *t = tv2table(K->cont_name_table); + add_cont_name(K, t, do_seq, "eval-sequence"); + add_cont_name(K, t, do_pass_value, "pass-value"); + add_cont_name(K, t, do_return_value, "return-value"); + add_cont_name(K, t, do_bind, "dynamic-bind"); + add_cont_name(K, t, do_bind, "dynamic-access"); + add_cont_name(K, t, do_bind, "dynamic-unbind"); + add_cont_name(K, t, do_bind, "dynamic-set!-pass"); +} + /* Type predicates */ /* TODO these should be moved to either kobject.h or the corresponding files (e.g. kbooleanp to kboolean.h */ diff --git a/src/kghelpers.h b/src/kghelpers.h @@ -23,6 +23,18 @@ #include "kcontinuation.h" #include "kenvironment.h" #include "ksymbol.h" +#include "kstring.h" +#include "ktable.h" + +/* +** REFACTOR split this file into several. +** Some should have their own files (like knumber, kbool, etc) +** Others are simply helpers that should be split into modules +** (like continuation helpers, list helpers, environment helpers) +*/ + +/* Initialization of continuation names */ +void kinit_kghelpers_cont_names(klisp_State *K); /* to use in type checking binds when no check is needed */ #define anytype(obj_) (true) @@ -481,6 +493,7 @@ TValue map_for_each_transpose(klisp_State *K, TValue lss, int32_t app_apairs, int32_t app_cpairs, int32_t res_apairs, int32_t res_cpairs); + /* ** Macros for ground environment initialization */ @@ -489,7 +502,7 @@ TValue map_for_each_transpose(klisp_State *K, TValue lss, ** BEWARE: this is highly unhygienic, it assumes variables "symbol" and ** "value", both of type TValue. symbol will be bound to a symbol named by ** "n_" and can be referrenced in the var_args -** GC: All of these should be called when GC is deactivated on startup +** GC: All of these should be called when GC is deactivated */ /* TODO add si to the symbols */ @@ -530,3 +543,11 @@ TValue map_for_each_transpose(klisp_State *K, TValue lss, kadd_binding(K_, env_, symbol, v_); } #endif + +/* for initiliazing continuation names */ +#define add_cont_name(K_, t_, c_, n_) \ + { TValue str = kstring_new_b_imm(K_, n_); \ + TValue *node = klispH_set(K_, t_, p2tv(c_)); \ + *node = str; \ + } + diff --git a/src/kgpairs_lists.c b/src/kgpairs_lists.c @@ -22,6 +22,19 @@ #include "kghelpers.h" #include "kgpairs_lists.h" +/* Continuations */ +void do_ret_cdr(klisp_State *K); + +void do_filter_encycle(klisp_State *K); +void do_filter(klisp_State *K); +void do_filter_cycle(klisp_State *K); + +void do_reduce(klisp_State *K); +void do_reduce_prec(klisp_State *K); +void do_reduce_postc(klisp_State *K); +void do_reduce_combine(klisp_State *K); +void do_reduce_cycle(klisp_State *K); + /* 4.6.1 pair? */ /* uses typep */ @@ -819,9 +832,6 @@ void countable_listp(klisp_State *K) /* Helpers for reduce */ -/* NOTE: This is used from both do_reduce_cycle and reduce */ -void do_reduce(klisp_State *K); - void do_reduce_prec(klisp_State *K) { TValue *xparams = K->next_xparams; @@ -1202,3 +1212,21 @@ void kinit_pairs_lists_ground_env(klisp_State *K) /* TODO add make-list, list-copy and reverse (from r7rs) */ } + +/* init continuation names */ +void kinit_pairs_lists_cont_names(klisp_State *K) +{ + Table *t = tv2table(K->cont_name_table); + + add_cont_name(K, t, do_ret_cdr, "return-cdr"); + + add_cont_name(K, t, do_filter, "filter-acyclic-part"); + add_cont_name(K, t, do_filter_encycle, "filter-encycle!"); + add_cont_name(K, t, do_filter_cycle, "filter-cyclic-part"); + + add_cont_name(K, t, do_reduce, "reduce-acyclic-part"); + add_cont_name(K, t, do_reduce_prec, "reduce-precycle"); + add_cont_name(K, t, do_reduce_combine, "reduce-combine"); + add_cont_name(K, t, do_reduce_postc, "reduce-postcycle"); + add_cont_name(K, t, do_reduce_cycle, "reduce-cyclic-part"); +} diff --git a/src/kgpairs_lists.h b/src/kgpairs_lists.h @@ -11,5 +11,7 @@ /* init ground */ void kinit_pairs_lists_ground_env(klisp_State *K); +/* init continuation names */ +void kinit_pairs_lists_cont_names(klisp_State *K); #endif diff --git a/src/kgports.c b/src/kgports.c @@ -30,6 +30,9 @@ #include "kghelpers.h" #include "kgports.h" +/* Continuations */ +void do_close_file_ret(klisp_State *K); + /* 15.1.1 port? */ /* uses typep */ @@ -1015,3 +1018,11 @@ void kinit_ports_ground_env(klisp_State *K) * would be nice */ } + +/* init continuation names */ +void kinit_ports_cont_names(klisp_State *K) +{ + Table *t = tv2table(K->cont_name_table); + + add_cont_name(K, t, do_close_file_ret, "close-file-and-ret"); +} diff --git a/src/kgports.h b/src/kgports.h @@ -11,5 +11,7 @@ /* init ground */ void kinit_ports_ground_env(klisp_State *K); +/* init continuation names */ +void kinit_ports_cont_names(klisp_State *K); #endif diff --git a/src/kgpromises.c b/src/kgpromises.c @@ -21,7 +21,7 @@ #include "kghelpers.h" #include "kgpromises.h" -/* continuations */ +/* Continuations */ void do_handle_result(klisp_State *K); @@ -141,3 +141,11 @@ void kinit_promises_ground_env(klisp_State *K) /* 9.1.4 memoize */ add_applicative(K, ground_env, "memoize", memoize, 0); } + +/* init continuation names */ +void kinit_promises_cont_names(klisp_State *K) +{ + Table *t = tv2table(K->cont_name_table); + + add_cont_name(K, t, do_handle_result, "promise-handle-result"); +} diff --git a/src/kgpromises.h b/src/kgpromises.h @@ -11,5 +11,7 @@ /* init ground */ void kinit_promises_ground_env(klisp_State *K); +/* init continuation names */ +void kinit_promises_cont_names(klisp_State *K); #endif diff --git a/src/kground.c b/src/kground.c @@ -50,13 +50,6 @@ #include "keval.h" #include "krepl.h" -/* for init_cont_names */ -#define add_cont_name(K_, t_, c_, n_) \ - { TValue str = kstring_new_b_imm(K_, n_); \ - TValue *node = klispH_set(K_, t_, p2tv(c_)); \ - *node = str; \ - } - /* ** This is called once to save the names of the types of continuations ** used in the ground environment & repl @@ -64,52 +57,31 @@ */ void kinit_cont_names(klisp_State *K) { + /* TEMP root and error continuations are set here (they are in kstate) */ Table *t = tv2table(K->cont_name_table); -/* XXX this should be handled like the init_ground_env */ -#if 0 - /* REPL, root-continuation & error-continuation */ add_cont_name(K, t, do_root_exit, "exit"); add_cont_name(K, t, do_error_exit, "error"); - add_cont_name(K, t, do_repl_read, "repl-read"); - add_cont_name(K, t, do_repl_eval, "repl-eval"); - add_cont_name(K, t, do_repl_loop, "repl-loop"); - - /* GROUND ENV */ - add_cont_name(K, t, do_eval_ls, "eval-list"); - add_cont_name(K, t, do_combine, "eval-combine"); - add_cont_name(K, t, do_Sandp_Sorp, "eval-booleans"); - add_cont_name(K, t, do_seq, "eval-sequence"); - add_cont_name(K, t, do_map, "map-acyclic-part"); - add_cont_name(K, t, do_map_encycle, "map-encycle!"); - add_cont_name(K, t, do_map_ret, "map-ret"); - add_cont_name(K, t, do_map_cycle, "map-cyclic-part"); - add_cont_name(K, t, do_extended_cont, "extended-cont"); - add_cont_name(K, t, do_pass_value, "pass-value"); - add_cont_name(K, t, do_select_clause, "select-clause"); - add_cont_name(K, t, do_cond, "eval-cond-list"); - add_cont_name(K, t, do_for_each, "for-each"); - add_cont_name(K, t, do_let, "eval-let"); - add_cont_name(K, t, do_bindsp, "eval-$binds?-env"); - add_cont_name(K, t, do_let_redirect, "eval-let-redirect"); - add_cont_name(K, t, do_remote_eval, "eval-remote-eval-env"); - add_cont_name(K, t, do_b_to_env, "bindings-to-env"); - add_cont_name(K, t, do_match, "match-ptree"); - add_cont_name(K, t, do_set_eval_obj, "set-eval-obj"); - add_cont_name(K, t, do_import, "import-bindings"); - add_cont_name(K, t, do_return_value, "return-value"); - add_cont_name(K, t, do_unbind, "unbind-dynamic-var"); - add_cont_name(K, t, do_filter, "filter-acyclic-part"); - add_cont_name(K, t, do_filter_encycle, "filter-encycle!"); - add_cont_name(K, t, do_ret_cdr, "return-cdr"); - add_cont_name(K, t, do_filter_cycle, "filter-cyclic-part"); - add_cont_name(K, t, do_reduce_prec, "reduce-precycle"); - add_cont_name(K, t, do_reduce_combine, "reduce-combine"); - add_cont_name(K, t, do_reduce_postc, "reduce-postcycle"); - add_cont_name(K, t, do_reduce, "reduce-acyclic-part"); - add_cont_name(K, t, do_reduce_cycle, "reduce-cyclic-part"); - add_cont_name(K, t, do_close_file_ret, "close-file-and-ret"); - add_cont_name(K, t, do_handle_result, "handle-result"); + /* TEMP this is also in kstate */ add_cont_name(K, t, do_interception, "do-interception"); + + /* TEMP repl ones should be done in the interpreter, and not in + the init state */ + kinit_repl_cont_names(K); + + kinit_eval_cont_names(K); + kinit_kghelpers_cont_names(K); + + kinit_booleans_cont_names(K); + kinit_combiners_cont_names(K); + kinit_environments_cont_names(K); + kinit_env_mut_cont_names(K); + kinit_pairs_lists_cont_names(K); + kinit_continuations_cont_names(K); + kinit_control_cont_names(K); + kinit_promises_cont_names(K); + kinit_ports_cont_names(K); +#if KUSE_LIBFFI + kinit_ffi_cont_names(K); #endif } @@ -147,11 +119,4 @@ void kinit_ground_env(klisp_State *K) #if KUSE_LIBFFI kinit_ffi_ground_env(K); #endif - - /* - ** Initialize the names of the continuation used in - ** the supported modules to aid in debugging/error msgs - */ - /* MAYBE some/most/all of these could be done in each module */ - kinit_cont_names(K); } diff --git a/src/kground.h b/src/kground.h @@ -10,5 +10,6 @@ #include "kstate.h" void kinit_ground_env(klisp_State *K); +void kinit_cont_names(klisp_State *K); #endif diff --git a/src/krepl.c b/src/krepl.c @@ -22,6 +22,13 @@ #include "ktable.h" /* for names */ #include "kghelpers.h" /* for do_pass_value */ +/* Continuations */ +void do_repl_read(klisp_State *K); +void do_repl_eval(klisp_State *K); +void do_repl_loop(klisp_State *K); +void do_repl_int_error(klisp_State *K); + + /* TODO add names & source info to the repl continuations */ /* the underlying function of the read cont */ @@ -79,17 +86,14 @@ void do_repl_eval(klisp_State *K) } } -void do_repl_loop(klisp_State *K); -void do_int_repl_error(klisp_State *K); - -/* this is called from both do_repl_loop and do_repl_error */ +/* this is called from both do_repl_loop and do_repl_int_error */ /* GC: assumes denv is NOT rooted */ void create_loop(klisp_State *K, TValue denv) { krooted_tvs_push(K, denv); /* TODO this should be factored out, it is quite common */ - TValue error_int = kmake_operative(K, do_int_repl_error, 1, denv); + TValue error_int = kmake_operative(K, do_repl_int_error, 1, denv); krooted_tvs_pop(K); /* already in cont */ krooted_tvs_push(K, error_int); TValue exit_guard = kcons(K, K->error_cont, error_int); @@ -151,7 +155,7 @@ void do_repl_loop(klisp_State *K) } /* the underlying function of the error cont */ -void do_int_repl_error(klisp_State *K) +void do_repl_int_error(klisp_State *K) { TValue *xparams = K->next_xparams; TValue ptree = K->next_value; @@ -259,3 +263,13 @@ void kinit_repl(klisp_State *K) /* GC: create_loop will root std_env */ create_loop(K, std_env); } + +/* init continuation names */ +void kinit_repl_cont_names(klisp_State *K) +{ + Table *t = tv2table(K->cont_name_table); + add_cont_name(K, t, do_repl_read, "repl-read"); + add_cont_name(K, t, do_repl_eval, "repl-eval"); + add_cont_name(K, t, do_repl_loop, "repl-print-loop"); + add_cont_name(K, t, do_repl_int_error, "repl-int-error"); +} diff --git a/src/krepl.h b/src/krepl.h @@ -12,12 +12,7 @@ #include "kobject.h" void kinit_repl(klisp_State *K); - -/* continuation functions */ -void do_repl_exit(klisp_State *K); -void do_repl_read(klisp_State *K); -void do_repl_eval(klisp_State *K); -void do_repl_loop(klisp_State *K); -void do_repl_error(klisp_State *K); +/* init continuation names */ +void kinit_repl_cont_names(klisp_State *K); #endif diff --git a/src/kstate.c b/src/kstate.c @@ -263,8 +263,8 @@ klisp_State *klisp_newstate (klisp_Alloc f, void *ud) { /* this must be done before calling kinit_ground_env */ kinit_error_hierarchy(K); - kinit_ground_env(K); + kinit_cont_names(K); /* create a std environment and leave it in K->next_env */ K->next_env = kmake_table_environment(K, K->ground_env);