commit 9eedfc4afa2c930bab72a94e132e86e3ce649e46
parent b6fac0032914a8870a81e9eaead3ea424a294c5d
Author: Andres Navarro <canavarro82@gmail.com>
Date: Wed, 23 Mar 2011 17:18:31 -0300
Added key for the dynamic variables for current-input-port and current-output-port.
Diffstat:
5 files changed, 28 insertions(+), 1 deletion(-)
diff --git a/src/Makefile b/src/Makefile
@@ -56,7 +56,8 @@ kwrite.o: kwrite.c kwrite.h kobject.h kpair.h kstring.h kstate.h kerror.h \
klisp.h kport.h
kstate.o: kstate.c kstate.h klisp.h kobject.h kmem.h kstring.h klisp.h \
kground.h kenvironment.h kpair.h keval.h koperative.h kground.h \
- krepl.h kcontinuation.h kapplicative.h kport.h ksymbol.h kport.h
+ krepl.h kcontinuation.h kapplicative.h kport.h ksymbol.h kport.h \
+ kstring.h
kmem.o: kmem.c kmem.h klisp.h kerror.h klisp.h kstate.h
kerror.o: kerror.c kerror.h klisp.h kstate.h klisp.h kmem.h kstring.h
kauxlib.o: kauxlib.c kauxlib.h klisp.h kstate.h klisp.h
diff --git a/src/kstate.c b/src/kstate.c
@@ -30,6 +30,7 @@
#include "kground.h"
#include "krepl.h"
#include "ksymbol.h"
+#include "kstring.h"
#include "kport.h"
/*
@@ -78,6 +79,11 @@ klisp_State *klisp_newstate (klisp_Alloc f, void *ud) {
K->filename_in = "*STDIN*";
K->filename_out = "*STDOUT*";
+ /* input / output for dynamic keys */
+ /* these are init later */
+ K->kd_in_port_key = KINERT;
+ K->kd_out_port_key = KINERT;
+
/* TODO: more gc info */
K->totalbytes = state_size() + KS_ISSIZE * sizeof(TValue) +
KS_ITBSIZE;
@@ -121,6 +127,14 @@ klisp_State *klisp_newstate (klisp_Alloc f, void *ud) {
K->stop = 0; /* stack is empty */
K->sbuf = (TValue *)s;
+ /* the dynamic ports and the keys for the dynamic ports */
+ TValue in_port = kmake_std_port(K, kstring_new_ns(K, "*STDIN*"),
+ false, KNIL, KNIL, stdin);
+ TValue out_port = kmake_std_port(K, kstring_new_ns(K, "*STDOUT*"),
+ true, KNIL, KNIL, stdout);
+ K->kd_in_port_key = kcons(K, KTRUE, in_port);
+ K->kd_out_port_key = kcons(K, KTRUE, out_port);
+
/* create the ground environment and the eval operative */
K->eval_op = kmake_operative(K, KNIL, KNIL, keval_ofn, 0);
K->ground_env = kmake_empty_environment(K);
diff --git a/src/kstate.h b/src/kstate.h
@@ -77,6 +77,10 @@ struct klisp_State {
char *filename_in;
char *filename_out;
+ /* for current-input-port, current-output-port */
+ TValue kd_in_port_key;
+ TValue kd_out_port_key;
+
/* Strings */
TValue empty_string;
diff --git a/src/kstring.c b/src/kstring.c
@@ -72,6 +72,12 @@ TValue kstring_new(klisp_State *K, const char *buf, uint32_t size)
return new_str;
}
+/* with no size, no embedded '\0's */
+TValue kstring_new_ns(klisp_State *K, const char *buf)
+{
+ return (kstring_new(K, buf, strlen(buf)));
+}
+
TValue kstring_new_sc(klisp_State *K, uint32_t size, char fill)
{
TValue new_str = kstring_new_g(K, size);
diff --git a/src/kstring.h b/src/kstring.h
@@ -16,6 +16,8 @@
TValue kstring_new_empty(klisp_State *K);
TValue kstring_new(klisp_State *K, const char *buf, uint32_t size);
+/* with no size, no embedded '\0's */
+TValue kstring_new_ns(klisp_State *K, const char *buf);
TValue kstring_new_g(klisp_State *K, uint32_t size);
TValue kstring_new_sc(klisp_State *K, uint32_t size, char fill);