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:
Calvin Rose 2019-12-04 19:53:13 -06:00
parent 11a7a7069a
commit 49954c7a30
3 changed files with 13 additions and 5 deletions

View File

@ -1850,9 +1850,9 @@
(res)
(error (res :error))))
(def unquote
"(unquote x)\n\nEscapes one level inside of a quasiquote. When used outside of a quasiquote, evaluates
its argument at compile-time."
(def comptime
"(comptime x)\n\n
Evals x at compile time and returns the result. Similar to a top level unquote."
:macro eval)
(defn make-image

View File

@ -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);
}
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
* keep the order registers are freed.
* Returns if the slot 'right' can be freed. */
@ -812,6 +819,7 @@ static const JanetSpecial janetc_specials[] = {
{"quote", janetc_quote},
{"set", janetc_varset},
{"splice", janetc_splice},
{"unquote", janetc_unquote},
{"var", janetc_var},
{"while", janetc_while}
};

View File

@ -273,8 +273,8 @@
# Top level unquote
(defn constantly
[]
,(math/random))
(comptime (math/random)))
(assert (= (constantly) (constantly)) "top level unquote")
(assert (= (constantly) (constantly)) "comptime 1")
(end-suite)