mirror of
https://github.com/janet-lang/janet
synced 2024-11-10 10:49:54 +00:00
Fix #919 - strange quasiquote behavior.
Nested expression in the quasiquote were being compiled with the "hint" flag passed to the expression compilation, essentially telling the compiler to put intermediates into the final slot, possibly overwriting other intermediate values. This fix removes that flags on any recursive calls to quasiquote.
This commit is contained in:
parent
66e0b53cf6
commit
a097537a03
@ -62,6 +62,8 @@ static JanetSlot quasiquote(JanetFopts opts, Janet x, int depth, int level) {
|
|||||||
return janetc_cslot(janet_wrap_nil());
|
return janetc_cslot(janet_wrap_nil());
|
||||||
}
|
}
|
||||||
JanetSlot *slots = NULL;
|
JanetSlot *slots = NULL;
|
||||||
|
JanetFopts subopts = opts;
|
||||||
|
subopts.flags &= ~JANET_FOPTS_HINT;
|
||||||
switch (janet_type(x)) {
|
switch (janet_type(x)) {
|
||||||
default:
|
default:
|
||||||
return janetc_cslot(x);
|
return janetc_cslot(x);
|
||||||
@ -82,7 +84,7 @@ static JanetSlot quasiquote(JanetFopts opts, Janet x, int depth, int level) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (i = 0; i < len; i++)
|
for (i = 0; i < len; i++)
|
||||||
janet_v_push(slots, quasiquote(opts, tup[i], depth - 1, level));
|
janet_v_push(slots, quasiquote(subopts, tup[i], depth - 1, level));
|
||||||
return qq_slots(opts, slots, (janet_tuple_flag(tup) & JANET_TUPLE_FLAG_BRACKETCTOR)
|
return qq_slots(opts, slots, (janet_tuple_flag(tup) & JANET_TUPLE_FLAG_BRACKETCTOR)
|
||||||
? JOP_MAKE_BRACKET_TUPLE
|
? JOP_MAKE_BRACKET_TUPLE
|
||||||
: JOP_MAKE_TUPLE);
|
: JOP_MAKE_TUPLE);
|
||||||
@ -91,7 +93,7 @@ static JanetSlot quasiquote(JanetFopts opts, Janet x, int depth, int level) {
|
|||||||
int32_t i;
|
int32_t i;
|
||||||
JanetArray *array = janet_unwrap_array(x);
|
JanetArray *array = janet_unwrap_array(x);
|
||||||
for (i = 0; i < array->count; i++)
|
for (i = 0; i < array->count; i++)
|
||||||
janet_v_push(slots, quasiquote(opts, array->data[i], depth - 1, level));
|
janet_v_push(slots, quasiquote(subopts, array->data[i], depth - 1, level));
|
||||||
return qq_slots(opts, slots, JOP_MAKE_ARRAY);
|
return qq_slots(opts, slots, JOP_MAKE_ARRAY);
|
||||||
}
|
}
|
||||||
case JANET_TABLE:
|
case JANET_TABLE:
|
||||||
@ -100,8 +102,8 @@ static JanetSlot quasiquote(JanetFopts opts, Janet x, int depth, int level) {
|
|||||||
int32_t len, cap = 0;
|
int32_t len, cap = 0;
|
||||||
janet_dictionary_view(x, &kvs, &len, &cap);
|
janet_dictionary_view(x, &kvs, &len, &cap);
|
||||||
while ((kv = janet_dictionary_next(kvs, cap, kv))) {
|
while ((kv = janet_dictionary_next(kvs, cap, kv))) {
|
||||||
JanetSlot key = quasiquote(opts, kv->key, depth - 1, level);
|
JanetSlot key = quasiquote(subopts, kv->key, depth - 1, level);
|
||||||
JanetSlot value = quasiquote(opts, kv->value, depth - 1, level);
|
JanetSlot value = quasiquote(subopts, kv->value, depth - 1, level);
|
||||||
key.flags &= ~JANET_SLOT_SPLICED;
|
key.flags &= ~JANET_SLOT_SPLICED;
|
||||||
value.flags &= ~JANET_SLOT_SPLICED;
|
value.flags &= ~JANET_SLOT_SPLICED;
|
||||||
janet_v_push(slots, key);
|
janet_v_push(slots, key);
|
||||||
|
@ -39,5 +39,14 @@
|
|||||||
|
|
||||||
(assert-error "compile error" (eval-string "(+ a 5)"))
|
(assert-error "compile error" (eval-string "(+ a 5)"))
|
||||||
|
|
||||||
|
# 919
|
||||||
|
(defn test
|
||||||
|
[]
|
||||||
|
(var x 1)
|
||||||
|
(set x ~(,x ()))
|
||||||
|
x)
|
||||||
|
|
||||||
|
(assert (= (test) '(1 ())) "issue #919")
|
||||||
|
|
||||||
(end-suite)
|
(end-suite)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user