mirror of
https://github.com/janet-lang/janet
synced 2024-12-25 07:50: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)
|
||||
(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
|
||||
|
@ -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}
|
||||
};
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user