mirror of
https://github.com/janet-lang/janet
synced 2024-12-26 08:20:27 +00:00
Remove top-level unquote for comptime macro
True top level unquote currently requires basically double compilation as it currently stands. Also, implementing such double compilation looses all source mapping information. This is a compromise implementation that makes it clear that this works differently than a true top-level unquote.
This commit is contained in:
parent
11a7a7069a
commit
49954c7a30
@ -1850,9 +1850,9 @@
|
|||||||
(res)
|
(res)
|
||||||
(error (res :error))))
|
(error (res :error))))
|
||||||
|
|
||||||
(def unquote
|
(def comptime
|
||||||
"(unquote x)\n\nEscapes one level inside of a quasiquote. When used outside of a quasiquote, evaluates
|
"(comptime x)\n\n
|
||||||
its argument at compile-time."
|
Evals x at compile time and returns the result. Similar to a top level unquote."
|
||||||
:macro eval)
|
:macro eval)
|
||||||
|
|
||||||
(defn make-image
|
(defn make-image
|
||||||
|
@ -120,6 +120,13 @@ static JanetSlot janetc_quasiquote(JanetFopts opts, int32_t argn, const Janet *a
|
|||||||
return quasiquote(opts, argv[0], JANET_RECURSION_GUARD, 0);
|
return quasiquote(opts, argv[0], JANET_RECURSION_GUARD, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static JanetSlot janetc_unquote(JanetFopts opts, int32_t argn, const Janet *argv) {
|
||||||
|
(void) argn;
|
||||||
|
(void) argv;
|
||||||
|
janetc_cerror(opts.compiler, "cannot use unquote here");
|
||||||
|
return janetc_cslot(janet_wrap_nil());
|
||||||
|
}
|
||||||
|
|
||||||
/* Perform destructuring. Be careful to
|
/* Perform destructuring. Be careful to
|
||||||
* keep the order registers are freed.
|
* keep the order registers are freed.
|
||||||
* Returns if the slot 'right' can be freed. */
|
* Returns if the slot 'right' can be freed. */
|
||||||
@ -812,6 +819,7 @@ static const JanetSpecial janetc_specials[] = {
|
|||||||
{"quote", janetc_quote},
|
{"quote", janetc_quote},
|
||||||
{"set", janetc_varset},
|
{"set", janetc_varset},
|
||||||
{"splice", janetc_splice},
|
{"splice", janetc_splice},
|
||||||
|
{"unquote", janetc_unquote},
|
||||||
{"var", janetc_var},
|
{"var", janetc_var},
|
||||||
{"while", janetc_while}
|
{"while", janetc_while}
|
||||||
};
|
};
|
||||||
|
@ -273,8 +273,8 @@
|
|||||||
# Top level unquote
|
# Top level unquote
|
||||||
(defn constantly
|
(defn constantly
|
||||||
[]
|
[]
|
||||||
,(math/random))
|
(comptime (math/random)))
|
||||||
|
|
||||||
(assert (= (constantly) (constantly)) "top level unquote")
|
(assert (= (constantly) (constantly)) "comptime 1")
|
||||||
|
|
||||||
(end-suite)
|
(end-suite)
|
||||||
|
Loading…
Reference in New Issue
Block a user