1
0
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:
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) (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

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); 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}
}; };

View File

@ -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)