klisp

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

commit 7f2a6e59d8bec64b7fbdff8901eff9c258189851
parent b65f6cb7e2f5d9057506a943373af15afed5323c
Author: Andres Navarro <canavarro82@gmail.com>
Date:   Sun, 13 Mar 2011 02:14:36 -0300

Extracted out the environment features from kground.c to a new file kgenvironments.c (and .h).

Diffstat:
Msrc/Makefile | 6+++++-
Asrc/kgenvironments.c | 74++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/kgenvironments.h | 38++++++++++++++++++++++++++++++++++++++
3 files changed, 117 insertions(+), 1 deletion(-)

diff --git a/src/Makefile b/src/Makefile @@ -68,7 +68,8 @@ krepl.o: krepl.c krepl.h kcontinuation.h kstate.h kobject.h keval.h klisp.h \ kread.h kwrite.h kenvironment.h kground.o: kground.c kground.h kstate.h kobject.h klisp.h kenvironment.h \ kpair.h kapplicative.h koperative.h ksymbol.h kerror.h kghelpers.h \ - kgbooleans.h kgeqp.h kgequalp.h kgsymbols.h kgpairs_lists.h + kgbooleans.h kgeqp.h kgequalp.h kgsymbols.h kgpairs_lists.h \ + kgpair_mut.h kgenvironments.h kghelpers.o: kghelpers.c kghelpers.h kstate.h kstate.h klisp.h kpair.h \ kapplicative.h koperative.h kerror.h kobject.h ksymbol.h kgbooleans.o: kgbooleans.c kgbooleans.c kghelpers.h kstate.h klisp.h \ @@ -85,3 +86,6 @@ kgpairs_lists.o: kgpairs_lists.c kgpairs_lists.h kghelpers.h kstate.h klisp.h \ kobject.h kerror.h kpair.h ksymbol.h kcontinuation.h kgpair_mut.o: kgpair_mut.c kgpair_mut.h kghelpers.h kstate.h klisp.h \ kobject.h kerror.h kpair.h ksymbol.h kcontinuation.h +kgenvironments.o: kgenvironments.c kgenvironments.h kghelpers.h kstate.h \ + klisp.h kobject.h kerror.h kpair.h ksymbol.h kcontinuation.h \ + kenvironment.h diff --git a/src/kgenvironments.c b/src/kgenvironments.c @@ -0,0 +1,74 @@ +/* +** kgenvironments.h +** Environments features for the ground environment +** See Copyright Notice in klisp.h +*/ + +#include <assert.h> +#include <stdio.h> +#include <stdlib.h> +#include <stdbool.h> +#include <stdint.h> + +#include "kstate.h" +#include "kobject.h" +#include "kground.h" +#include "kpair.h" +#include "kstring.h" +#include "kenvironment.h" +#include "kcontinuation.h" +#include "ksymbol.h" +#include "kerror.h" + +#include "kghelpers.h" +#include "kgenvironments.h" + +/* 4.8.1 environment? */ +/* uses typep */ + +/* 4.8.2 ignore? */ +/* uses typep */ + +/* 4.8.3 eval */ +void eval(klisp_State *K, TValue *xparams, TValue ptree, + TValue denv) +{ + (void) denv; + bind_2tp(K, "eval", ptree, "any", anytype, expr, + "environment", ttisenvironment, env); + + ktail_eval(K, expr, env); +} + +/* 4.8.4 make-environment */ +void make_environment(klisp_State *K, TValue *xparams, TValue ptree, + TValue denv) +{ + (void) denv; + (void) xparams; + TValue new_env; + if (ttisnil(ptree)) { + new_env = kmake_empty_environment(K); + kapply_cc(K, new_env); + } else if (ttispair(ptree) && ttisnil(kcdr(ptree))) { + /* special common case of one parent, don't keep a list */ + TValue parent = kcar(ptree); + if (ttisenvironment(parent)) { + new_env = kmake_environment(K, parent); + kapply_cc(K, new_env); + } else { + klispE_throw(K, "make-environment: not an environment in " + "parent list"); + return; + } + } else { + /* this is the general case, copy the list but without the + cycle if there is any */ + TValue parents = check_copy_env_list(K, "make-environment", ptree); + new_env = kmake_environment(K, parents); + kapply_cc(K, new_env); + } +} + +/* 5.10.1 $let */ +/* TODO */ diff --git a/src/kgenvironments.h b/src/kgenvironments.h @@ -0,0 +1,38 @@ +/* +** kgenvironments.h +** Environments features for the ground environment +** See Copyright Notice in klisp.h +*/ + +#ifndef kgpairs_lists_h +#define kgpairs_lists_h + +#include <assert.h> +#include <stdio.h> +#include <stdlib.h> +#include <stdbool.h> +#include <stdint.h> + +#include "kobject.h" +#include "klisp.h" +#include "kstate.h" +#include "kghelpers.h" + +/* 4.8.1 environment? */ +/* uses typep */ + +/* 4.8.2 ignore? */ +/* uses typep */ + +/* 4.8.3 eval */ +void eval(klisp_State *K, TValue *xparams, TValue ptree, + TValue denv); + +/* 4.8.4 make-environment */ +void make_environment(klisp_State *K, TValue *xparams, TValue ptree, + TValue denv); + +/* 5.10.1 $let */ +/* TODO */ + +#endif