summaryrefslogtreecommitdiffstats
path: root/eval.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2012-03-14 14:38:51 -0700
committerKaz Kylheku <kaz@kylheku.com>2012-03-14 14:38:51 -0700
commit4e1170250c22dbc1938e60538aef9f800cf8af92 (patch)
tree7b2ebf16559c4cddcfb87860f538f9b5250e08dd /eval.c
parent0592949de3e274b7d9700ec74466b541055c3bca (diff)
downloadtxr-4e1170250c22dbc1938e60538aef9f800cf8af92.tar.gz
txr-4e1170250c22dbc1938e60538aef9f800cf8af92.tar.bz2
txr-4e1170250c22dbc1938e60538aef9f800cf8af92.zip
Support quasiquoting over vectors also, and a bugfix for hash
quasiquoting. We cannot use the same symbol for the literal form from the parser, and for the expanded form, because this creates a confusion when there are multiple nestings of quasiquote expansion. * eval.c (vector_lit_s, vector_list_s, hash_lit_s): New symbol variables. (hash_construct_s): Relocated here from hash.c. (expand_qquote): Part of bugfix: look for hash_lit_s instead of has_construct_s. Translate to a hash_construct_s form which is no longer recognizes as a hash literal. Implementing recognition of a quasiquote vector literal, handled similarly. (eval_init): Initialize vector_lit_s, vector_list_s, hash_list_s and hash_lit_s. Use vector_list_s when registering vector_list function. * eval.h (vector_lit_s, vector_list_s, hash_lit_s, hash_constuct_s): Declared. * hash.c (hash_construct_s): Variable removed and relocated into eval.c. (hash_init): Initialization of hash_construct_s removed. * hash.h (hash_construct_s): Declaration removed. * parser.y: (vector): Action updated to generate a (vec-lit ...) form if the object contains unquotes, otherwise generate a vector object. (hash): Generate hash-lit form, not a hash-construct form.
Diffstat (limited to 'eval.c')
-rw-r--r--eval.c16
1 files changed, 13 insertions, 3 deletions
diff --git a/eval.c b/eval.c
index b87f23c5..483a412a 100644
--- a/eval.c
+++ b/eval.c
@@ -66,6 +66,8 @@ val dohash_s;
val uw_protect_s, return_s, return_from_s;
val list_s, append_s, apply_s, gen_s, generate_s, rest_s;
val delay_s, promise_s, op_s;
+val hash_lit_s, hash_construct_s;
+val vector_lit_s, vector_list_s;
val make_env(val vbindings, val fbindings, val up_env)
{
@@ -1383,10 +1385,13 @@ static val expand_qquote(val qquoted_form)
} else if (sym == qquote_s) {
return rlcp(expand_qquote(expand_qquote(second(qquoted_form))),
qquoted_form);
- } else if (sym == hash_construct_s) {
+ } else if (sym == hash_lit_s) {
val args = expand_qquote(second(qquoted_form));
val pairs = expand_qquote(rest(rest(qquoted_form)));
- return rlcp(list(sym, args, pairs, nao), qquoted_form);
+ return rlcp(list(hash_construct_s, args, pairs, nao), qquoted_form);
+ } else if (sym == vector_lit_s) {
+ val args = expand_qquote(second(qquoted_form));
+ return rlcp(list(vector_list_s, args, nao), qquoted_form);
} else {
val f = car(qquoted_form);
val r = cdr(qquoted_form);
@@ -2073,6 +2078,11 @@ void eval_init(void)
promise_s = intern(lit("promise"), system_package);
op_s = intern(lit("op"), user_package);
rest_s = intern(lit("rest"), user_package);
+ hash_lit_s = intern(lit("hash-construct"), system_package);
+ hash_construct_s = intern(lit("hash-construct"), user_package);
+ vector_lit_s = intern(lit("vector-lit"), system_package);
+ vector_list_s = intern(lit("vector-list"), user_package);
+
sethash(op_table, quote_s, cptr((mem_t *) op_quote));
sethash(op_table, qquote_s, cptr((mem_t *) op_qquote_error));
sethash(op_table, unquote_s, cptr((mem_t *) op_unquote_error));
@@ -2307,7 +2317,7 @@ void eval_init(void)
reg_fun(intern(lit("vec-push"), user_package), func_n2(vec_push));
reg_fun(intern(lit("length-vec"), user_package), func_n1(length_vec));
reg_fun(intern(lit("size-vec"), user_package), func_n1(size_vec));
- reg_fun(intern(lit("vector-list"), user_package), func_n1(vector_list));
+ reg_fun(vector_list_s, func_n1(vector_list));
reg_fun(intern(lit("list-vector"), user_package), func_n1(list_vector));
reg_fun(intern(lit("copy-vec"), user_package), func_n1(copy_vec));
reg_fun(intern(lit("sub-vec"), user_package), func_n3o(sub_vec, 1));