mirror of
https://github.com/janet-lang/janet
synced 2025-02-02 18:29:10 +00:00
Allow adding name to short-fns.
When short-fn is used in a macro, it can be useful to give the function a nicer name then a raw pointer.
This commit is contained in:
parent
fe5ccb163e
commit
ac2082e9b3
@ -2177,7 +2177,7 @@
|
||||
|(+ $ $) # use pipe reader macro for terse function literals.
|
||||
|(+ $&) # variadic functions
|
||||
```
|
||||
[arg]
|
||||
[arg &opt name]
|
||||
(var max-param-seen -1)
|
||||
(var vararg false)
|
||||
(defn saw-special-arg
|
||||
@ -2203,8 +2203,9 @@
|
||||
x))
|
||||
x))
|
||||
(def expanded (macex arg on-binding))
|
||||
(def name-splice (if name [name] []))
|
||||
(def fn-args (seq [i :range [0 (+ 1 max-param-seen)]] (symbol '$ i)))
|
||||
~(fn [,;fn-args ,;(if vararg ['& '$&] [])] ,expanded))
|
||||
~(fn ,;name-splice [,;fn-args ,;(if vararg ['& '$&] [])] ,expanded))
|
||||
|
||||
###
|
||||
###
|
||||
@ -3886,7 +3887,7 @@
|
||||
"E" (fn E-switch [i &]
|
||||
(set no-file false)
|
||||
(def subargs (array/slice args (+ i 2)))
|
||||
(def src ~|,(parse (in args (+ i 1))))
|
||||
(def src ~(short-fn ,(parse (in args (+ i 1))) E-expression))
|
||||
(def thunk (compile src))
|
||||
(if (function? thunk)
|
||||
((thunk) ;subargs)
|
||||
|
@ -996,7 +996,7 @@ JanetCompileResult janet_compile(Janet source, JanetTable *env, const uint8_t *w
|
||||
}
|
||||
|
||||
/* C Function for compiling */
|
||||
JANET_CORE_FN(cfun,
|
||||
JANET_CORE_FN(cfun_compile,
|
||||
"(compile ast &opt env source lints)",
|
||||
"Compiles an Abstract Syntax Tree (ast) into a function. "
|
||||
"Pair the compile function with parsing functionality to implement "
|
||||
@ -1043,7 +1043,7 @@ JANET_CORE_FN(cfun,
|
||||
|
||||
void janet_lib_compile(JanetTable *env) {
|
||||
JanetRegExt cfuns[] = {
|
||||
JANET_CORE_REG("compile", cfun),
|
||||
JANET_CORE_REG("compile", cfun_compile),
|
||||
JANET_REG_END
|
||||
};
|
||||
janet_core_cfuns_ext(env, NULL, cfuns);
|
||||
|
Loading…
Reference in New Issue
Block a user