commit 1290b026a13b93fb75706c0b46b7b3af619d071c
parent 99e47cdce86382c82389a61a5ee863ed20024fc4
Author: Andres Navarro <canavarro82@gmail.com>
Date: Thu, 24 Mar 2011 00:02:02 -0300
Bugfix: now load and get-module read the file with an immutable evaluation structure.
Diffstat:
5 files changed, 13 insertions(+), 5 deletions(-)
diff --git a/src/kgports.c b/src/kgports.c
@@ -154,6 +154,7 @@ void read(klisp_State *K, TValue *xparams, TValue ptree, TValue denv)
ktok_reset_source_info(K); /* this should be saved in the port
and restored before the call to
read and saved after it */
+ K->read_cons_flag = true; /* read mutable pairs */
TValue obj = kread(K); /* this may throw an error, that's ok */
kapply_cc(K, obj);
}
@@ -242,14 +243,16 @@ void call_with_file(klisp_State *K, TValue *xparams, TValue ptree,
/* helpers for load */
-/* read all expressions in a file */
+/* read all expressions in a file, as immutable pairs */
TValue read_all_expr(klisp_State *K, TValue port)
{
/* TEMP: for now set this by hand */
K->curr_in = kport_file(port);
ktok_reset_source_info(K);
+ K->read_cons_flag = false; /* read immutable pairs */
+
/* GC: root dummy and obj */
- TValue dummy = kcons(K, KNIL, KNIL);
+ TValue dummy = kimm_cons(K, KNIL, KNIL);
TValue tail = dummy;
TValue obj = KINERT;
@@ -258,7 +261,7 @@ TValue read_all_expr(klisp_State *K, TValue port)
if (ttiseof(obj)) {
return kcdr(dummy);
} else {
- TValue new_pair = kcons(K, obj, KNIL);
+ TValue new_pair = kimm_cons(K, obj, KNIL);
kset_cdr(tail, new_pair);
tail = new_pair;
}
diff --git a/src/kread.c b/src/kread.c
@@ -164,7 +164,8 @@ TValue kread_fsm(klisp_State *K)
/* avoid warning */
return KINERT;
}
- TValue np = kdummy_cons(K);
+ /* construct the list with the correct type of pair */
+ TValue np = kcons_g(K, K->read_cons_flag, KINERT, KNIL);
/*
** NOTE: the source info of the '(' is temporarily saved
** in np (later it will be replace by the source info
@@ -406,7 +407,8 @@ TValue kread_fsm(klisp_State *K)
case ST_MIDDLE_LIST: {
/* get the state out of the way */
pop_state(K);
- TValue np = kcons(K, obj, KNIL);
+ /* construct the list with the correct type of pair */
+ TValue np = kcons_g(K, K->read_cons_flag, obj, KNIL);
kset_source_info(np, obj_si);
kset_cdr(get_data(K), np);
/* replace last pair of the (still incomplete) read next obj */
diff --git a/src/krepl.c b/src/krepl.c
@@ -42,6 +42,7 @@ void read_fn(klisp_State *K, TValue *xparams, TValue obj)
/* TEMP: for now set this by hand */
K->curr_in = stdin;
ktok_reset_source_info(K);
+ K->read_cons_flag = true; /* read mutable pairs */
obj = kread(K);
kapply_cc(K, obj);
diff --git a/src/kstate.c b/src/kstate.c
@@ -119,6 +119,7 @@ klisp_State *klisp_newstate (klisp_Alloc f, void *ud) {
/* initialize reader */
K->shared_dict = KNIL;
+ K->read_cons_flag = false; /* should be set before calling read */
/* initialize writer */
diff --git a/src/kstate.h b/src/kstate.h
@@ -101,6 +101,7 @@ struct klisp_State {
/* reader */
/* TODO: replace the list with a hashtable */
TValue shared_dict;
+ bool read_cons_flag;
/* auxiliary stack */
int32_t ssize; /* total size of array */