klisp

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

commit 969555a1086485e060a869b2c63fa7adb3f19c0c
parent 09cd15b1beb43e75813e584c2d2c934bd055f6e4
Author: Andres Navarro <canavarro82@gmail.com>
Date:   Wed, 30 Mar 2011 11:53:08 -0300

Moved do_return_value to kghelpers to allow its use from elsewhere.

Diffstat:
Msrc/Makefile | 3++-
Msrc/kghelpers.c | 15+++++++++++++++
Msrc/kghelpers.h | 13+++++++++++++
Msrc/kgports.c | 20--------------------
4 files changed, 30 insertions(+), 21 deletions(-)

diff --git a/src/Makefile b/src/Makefile @@ -85,7 +85,8 @@ kground.o: kground.c kground.h kstate.h kobject.h klisp.h kenvironment.h \ kgcontinuations.h kgencapsulations.h kgpromises.h kgkd_vars.h \ kgks_vars.h kgports.h kgchars.h kgnumbers.h kgstrings.o kghelpers.o: kghelpers.c kghelpers.h kstate.h kstate.h klisp.h kpair.h \ - kapplicative.h koperative.h kerror.h kobject.h ksymbol.h + kapplicative.h koperative.h kerror.h kobject.h ksymbol.h \ + kcontinuation.h kgbooleans.o: kgbooleans.c kgbooleans.c kghelpers.h kstate.h klisp.h \ kobject.h kerror.h kpair.h kcontinuation.h kgeqp.o: kgeqp.c kgeqp.c kghelpers.h kstate.h klisp.h \ diff --git a/src/kghelpers.c b/src/kghelpers.c @@ -235,3 +235,18 @@ int32_t check_list(klisp_State *K, char *name, bool allow_infp, return pairs; } } + + +/* +** Continuation that ignores the value received and instead returns +** a previously computed value. +*/ +void do_return_value(klisp_State *K, TValue *xparams, TValue obj) +{ + /* + ** xparams[0]: saved_obj + */ + UNUSED(obj); + TValue ret_obj = xparams[0]; + kapply_cc(K, ret_obj); +} diff --git a/src/kghelpers.h b/src/kghelpers.h @@ -20,6 +20,7 @@ #include "kpair.h" #include "kapplicative.h" #include "koperative.h" +#include "kcontinuation.h" /* to use in type checking binds when no check is needed */ #define anytype(obj_) (true) @@ -349,4 +350,16 @@ void ftyped_predp(klisp_State *K, TValue *xparams, TValue ptree, TValue denv); */ void ftyped_bpredp(klisp_State *K, TValue *xparams, TValue ptree, TValue denv); + +/* +** Continuation that ignores the value received and instead returns +** a previously computed value. +*/ +void do_return_value(klisp_State *K, TValue *xparams, TValue obj); + +inline TValue make_return_value_cont(klisp_State *K, TValue parent, TValue obj) +{ + return kmake_continuation(K, parent, KNIL, KNIL, do_return_value, 1, obj); +} + #endif diff --git a/src/kgports.c b/src/kgports.c @@ -285,26 +285,6 @@ void do_int_close_file(klisp_State *K, TValue *xparams, TValue ptree, kapply_cc(K, error_obj); } -/* -** helpers for load and get-module it discards the passed obj -** and instead returns a previously saved object -** this feature is used by load to return #inert and by -** get-module to return the created environment -*/ -void do_return_value(klisp_State *K, TValue *xparams, TValue obj) -{ - /* - ** xparams[0]: port - */ - UNUSED(obj); - TValue ret_obj = xparams[0]; - kapply_cc(K, ret_obj); -} - -inline TValue make_return_value_cont(klisp_State *K, TValue parent, TValue obj) -{ - return kmake_continuation(K, parent, KNIL, KNIL, do_return_value, 1, obj); -} /* ** guarded continuation making for read seq