commit 1407b2adf81afc9a066f41da46a8ec330d6ce42f
parent b4f7355824d7fb78e36302fe13764edd592eda97
Author: Andres Navarro <canavarro82@gmail.com>
Date:   Wed, 16 Mar 2011 03:07:15 -0300
Added promise? and memoize to the ground environment.
Diffstat:
4 files changed, 112 insertions(+), 2 deletions(-)
diff --git a/src/Makefile b/src/Makefile
@@ -13,7 +13,8 @@ CORE_O=	kobject.o ktoken.o kpair.o kstring.o ksymbol.o kread.o \
 	kencapsulation.o kpromise.o \
 	kground.o kghelpers.o kgbooleans.o kgeqp.o kgequalp.o \
 	kgsymbols.o kgcontrol.o kgpairs_lists.o kgpair_mut.o kgenvironments.o \
-	kgenv_mut.o kgcombiners.o kgcontinuations.o kgencapsulations.o
+	kgenv_mut.o kgcombiners.o kgcontinuations.o kgencapsulations.o \
+	kgpromises.o
 
 KRN_T=	klisp
 KRN_O=	klisp.o
@@ -76,7 +77,7 @@ kground.o: kground.c kground.h kstate.h kobject.h klisp.h kenvironment.h \
 	kapplicative.h koperative.h ksymbol.h kerror.h kghelpers.h \
 	kgbooleans.h kgeqp.h kgequalp.h kgsymbols.h kgpairs_lists.h \
 	kgpair_mut.h kgenvironments.h kgenv_mut.h kgcombiners.h \
-	kgcontinuations.h kgencapsulations.h
+	kgcontinuations.h kgencapsulations.h kgpromises.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 \
@@ -105,3 +106,9 @@ kgcombiners.o: kgcombiners.c kgenvironments.h kghelpers.h kstate.h \
 kgcontinuations.o: kgcontinuations.c kgcontinuations.h kghelpers.h kstate.h \
 	klisp.h kobject.h kerror.h kpair.h ksymbol.h kcontinuation.h \
 	kenvironment.h kapplicative.h koperative.h
+kgencapsulations.o: kgencapsulations.c kgencapsulations.h kghelpers.h \
+	kstate.h klisp.h kobject.h kerror.h kapplicative.h koperative.h \
+	kencapsulation.h
+kgpromises.o: kgpromises.c kgpromises.h kghelpers.h kstate.h klisp.h \
+	kobject.h kerror.h kapplicative.h koperative.h kcontinuation.h \
+	kpair.h kpromise.h
diff --git a/src/kgpromises.c b/src/kgpromises.c
@@ -0,0 +1,42 @@
+/*
+** kgencapsulations.c
+** Encapsulations 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 "kpromise.h"
+#include "kapplicative.h"
+#include "koperative.h"
+#include "kcontinuation.h"
+#include "kerror.h"
+
+#include "kghelpers.h"
+#include "kgpromises.h"
+
+/* 9.1.1 promise? */
+/* uses typep */
+
+/* 9.1.2 force */
+/* TODO */
+
+/* 9.1.3 $lazy */
+/* TODO */
+
+/* 9.1.4 memoize */
+void memoize(klisp_State *K, TValue *xparams, TValue ptree, TValue denv)
+{
+    UNUSED(xparams);
+    UNUSED(denv);
+
+    bind_1p(K, "memoize", ptree, exp);
+    TValue new_prom = kmake_promise(K, KNIL, KNIL, exp, KNIL);
+    kapply_cc(K, new_prom);
+}
diff --git a/src/kgpromises.h b/src/kgpromises.h
@@ -0,0 +1,33 @@
+/*
+** kgpromises.h
+** Promises features for the ground environment
+** See Copyright Notice in klisp.h
+*/
+
+#ifndef kgpromises_h
+#define kgpromises_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"
+
+/* 9.1.1 promise? */
+/* uses typep */
+
+/* 9.1.2 force */
+/* TODO */
+
+/* 9.1.3 $lazy */
+/* TODO */
+
+/* 9.1.4 memoize */
+void memoize(klisp_State *K, TValue *xparams, TValue ptree, TValue denv);
+
+#endif
diff --git a/src/kground.c b/src/kground.c
@@ -32,6 +32,7 @@
 #include "kgcombiners.h"
 #include "kgcontinuations.h"
 #include "kgencapsulations.h"
+#include "kgpromises.h"
 
 /*
 ** BEWARE: this is highly unhygienic, it assumes variables "symbol" and
@@ -412,5 +413,32 @@ void kinit_ground_env(klisp_State *K)
     add_applicative(K, ground_env, "make-encapsulation-type", 
 		    make_encapsulation_type, 0); 
 
+
+
+    /*
+    **
+    ** 9 Promises
+    **
+    */
+
+    /* 
+    ** 9.1 Library features
+    */
+
+
+    /* 9.1.1 promise? */
+    add_applicative(K, ground_env, "promise?", typep, 2, symbol, 
+		    i2tv(K_TPROMISE));
+
+    /* 9.1.2 force */
+    /* TODO */
+
+    /* 9.1.3 $lazy */
+    /* TODO */
+
+    /* 9.1.4 memoize */
+    add_applicative(K, ground_env, "memoize", memoize, 0); 
+
     return;
+
 }