klisp

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

commit 06dba19305906c9aea47ec3432c2ff329c787827
parent 522c7efcbec5a3e3602620fe4d47f18194928276
Author: Andres Navarro <canavarro82@gmail.com>
Date:   Fri,  9 Dec 2011 19:38:00 -0300

Added eval-string to the ground environment. TODO use it in the interpreter for '-e' and KLISP_INIT (in do_string).

Diffstat:
MTODO | 128+++++++++++++++++++++++++++++++++++++++++++------------------------------------
Msrc/Makefile | 2+-
Msrc/kgenvironments.c | 56++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/kgkeywords.c | 1-
4 files changed, 127 insertions(+), 60 deletions(-)

diff --git a/TODO b/TODO @@ -1,58 +1,70 @@ -* refactor: -** double check combiner names to be verbs - (e.g. add get- where appropriate) -** split kghelpers in appropriate parts - (e.g. create knumber.h knumber.c and move there kfinitep, kintegerp, etc - from kgnumbers) -** use some convention for ground operative underlaying function names - maybe add "kgop_" -** use a better convention for continuation underlaying function names -** try to use krooted_vars_push more to save some lines and avoid - clutter (e.g. when creating continuations) -** Study differrent c interfaces (maybe a stack like in lua would be - better than dealing with gc push/pop) -** eliminate all remaining char * arguments where not needed -** remove most of inline declarations, we may then add some - back after proper profiling -** standarize either int32_t (now used in lists) or uint32_t (now used - in strings, vectors and bytevectors) for sizes (and maybe use a - typedef like lua) -* fix: -** fix char-ready? and u8-ready? (r7rs) -* documentation -** update the manual with the current features -** add a section to the manual with the interpreter usage -* reader/writer -** syntax support for complex numbers (Kernel report) -* library -** some simplified error guarding (r7rs) -** $case (r7rs) -** $case-lambda + $case-vau (r7rs) -** $named-let + $do (r7rs) -** $define-record-type (r7rs) -** eager comprehensions (at least for check.k) see SRFIs 42 and 78 - (srfi) -* other -** restarts (r7rs/common lisp) -** add restart support to the repl/interpreter (r7rs) -** simple modules (something inspired in r7rs) (r7rs) -** add modules support to the interpreter (r7rs) -** complex numbers (Kernel report) -** interval arithmetic (Kernel report) -* reduce binary size -** currently (2011/12/05) is 3megs... most of it from kg*.o -** 1st culprite klisp_assert: -** almost 1 meg comes from klisp_asserts, asserts also add - considerably to the compilation time -** add a flag to enable assertions (maybe debug) and disable - it by default -** fix warnings when assertions are turned off (probably unitialized - uses, unused variables, etc) -** 2nd culprite debugging symbols: -** 1 meg and a half comes from debugging symbols, they also add to - the compilation time -** add a flag (maybe the same as for asserts, maybe another one) to - include debug symbols and disable it by default -** After removing asserts & symbols the size is reduced to a more - manageable 500k, however it would be nice to bring that even - lower +* Release 0.3 +** modules: +*** simple modules (something inspired in r7rs) (r7rs) +*** add modules support to the interpreter (r7rs) +** documentation: +*** update the manual with the current features +*** add a section to the manual with the interpreter usage + + +* Release 0.4+ +** refactor: +*** clean stand alone interpreter +*** double check combiner names to be verbs + - add get- where appropriate +*** split kghelpers + - knumber.h knumber.c (kfinitep, kintegerp, etc) +*** naming convention for ground operative functions + - maybe add "kgop_" +*** naming convention for continuation functions + - intead of "do_" +*** use krooted_vars_push more to avoid clutter + - when creating continuations +*** Study differrent c interfaces + - maybe a stack like in lua would be better than dealing with gc guarding +*** eliminate all remaining char * arguments where not needed + - typep +*** remove most of inline declarations +*** standarize size type + - do a typedef + - currently + - int32_t (used in lists) + - uint32_t (used in strings, vectors and bytevectors) +** fix: +*** fix char-ready? and u8-ready? (r7rs) +** reader/writer +*** syntax support for complex numbers (Kernel report) +*** unicode support +*** add case sensitive option / compiler flag +** library +*** some simplified error guarding (r7rs) +*** $case (r7rs) +*** $case-lambda + $case-vau (r7rs) +*** $named-let + $do (r7rs) +*** $define-record-type (r7rs) +*** eager comprehensions (at least for check.k) see SRFIs 42 and 78 (srfi) +** other +*** restarts (r7rs/common lisp) +*** add restart support to the repl/interpreter (r7rs) +*** complex numbers (Kernel report) +*** interval arithmetic (Kernel report) +** reduce binary size +*** currently (2011/12/05) is 3megs + - most of it from kg*.o + - klisp_assert: + - almost 1 meg comes from klisp_asserts + - adds considerably to the compilation time + - add a flag to enable assertions + - and disable it by default + - fix warnings when assertions are turned off + - unitialized uses + - unused variables + - debugging symbols: + - 1 meg and a half comes from debugging symbols + - adds to the compilation time + - add a flag + - maybe the same as for asserts + - maybe another one + - disable it by default + - Even after disabling these two, the size is 500k + - Continue investigating and try to make it lower diff --git a/src/Makefile b/src/Makefile @@ -170,7 +170,7 @@ kgenv_mut.o: kgenv_mut.c kstate.h klimits.h klisp.h kobject.h klispconf.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 \ - ktable.h kgenvironments.h + ktable.h kport.h kread.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 ktable.h \ diff --git a/src/kgenvironments.c b/src/kgenvironments.c @@ -17,6 +17,8 @@ #include "kcontinuation.h" #include "ksymbol.h" #include "kerror.h" +#include "kport.h" /* for eval_string */ +#include "kread.h" /* for eval_string */ #include "kghelpers.h" #include "kgenvironments.h" @@ -27,6 +29,7 @@ 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); +void do_eval_string(klisp_State *K); /* 4.8.1 environment? */ /* uses typep */ @@ -690,6 +693,56 @@ void Sbindings_to_environment(klisp_State *K) ktail_eval(K, expr, denv); } +void do_eval_string(klisp_State *K) +{ + TValue *xparams = K->next_xparams; + TValue obj = K->next_value; + klisp_assert(ttisnil(K->next_env)); + /* + ** xparams[0]: environment + */ + TValue env = xparams[0]; + ktail_eval(K, obj, env); +} + +/* ?.? eval-string */ +void eval_string(klisp_State *K) +{ + TValue *xparams = K->next_xparams; + TValue ptree = K->next_value; + TValue denv = K->next_env; + klisp_assert(ttisenvironment(K->next_env)); + UNUSED(xparams); + UNUSED(denv); + + bind_2tp(K, ptree, "string", ttisstring, str, + "environment", ttisenvironment, env); + + /* create a continuation for better stack traces + in case of error */ + TValue port = kmake_mport(K, str, false, false); + krooted_tvs_push(K, port); + TValue cont = kmake_continuation(K, kget_cc(K), do_eval_string, 1, env); + kset_cc(K, cont); + krooted_tvs_pop(K); + + TValue obj = kread_from_port(K, port, true); /* read mutable pairs */ + if (ttiseof(obj)) { + klispE_throw_simple_with_irritants(K, "No object found in string", 1, + str); + return; + } + krooted_tvs_push(K, obj); + TValue second_obj = kread_from_port(K, port, true); + krooted_tvs_pop(K); + if (!ttiseof(second_obj)) { + klispE_throw_simple_with_irritants(K, "More than one object found " + "in string", 1, str); + return; + } + kapply_cc(K, obj); +} + /* init ground */ void kinit_environments_ground_env(klisp_State *K) { @@ -731,6 +784,8 @@ void kinit_environments_ground_env(klisp_State *K) /* 6.7.10 $bindings->environment */ add_operative(K, ground_env, "$bindings->environment", Sbindings_to_environment, 1, symbol); + /* ?.? eval-string */ + add_applicative(K, ground_env, "eval-string", eval_string, 0); } /* init continuation names */ @@ -742,5 +797,6 @@ void kinit_environments_cont_names(klisp_State *K) 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_eval_string, "eval-string"); add_cont_name(K, t, do_b_to_env, "bindings-to-env"); } diff --git a/src/kgkeywords.c b/src/kgkeywords.c @@ -76,7 +76,6 @@ void symbol_to_keyword(klisp_State *K) UNUSED(xparams); UNUSED(denv); bind_1tp(K, ptree, "symbol", ttissymbol, sym); - /* If the symbol is mutable it is copied */ TValue new_keyw = kkeyword_new_str(K, ksymbol_str(sym)); kapply_cc(K, new_keyw); }