mirror of
https://github.com/janet-lang/janet
synced 2024-11-25 09:47:17 +00:00
Fix macroexpand function in core.
This commit is contained in:
parent
aa8384488c
commit
d186aae1f8
@ -288,8 +288,7 @@
|
|||||||
(+ i 2) object
|
(+ i 2) object
|
||||||
} head)
|
} head)
|
||||||
(if (keyword? bindings)
|
(if (keyword? bindings)
|
||||||
(case
|
(case bindings
|
||||||
bindings
|
|
||||||
:while (do
|
:while (do
|
||||||
(array.push preds verb)
|
(array.push preds verb)
|
||||||
(doone (+ i 2) preds))
|
(doone (+ i 2) preds))
|
||||||
@ -928,11 +927,11 @@ value, one key will be ignored."
|
|||||||
"Expand macros in a form, but do not recursively expand macros."
|
"Expand macros in a form, but do not recursively expand macros."
|
||||||
[x]
|
[x]
|
||||||
|
|
||||||
(defn dotable [t recur-value]
|
(defn dotable [t on-value]
|
||||||
(def newt @{})
|
(def newt @{})
|
||||||
(var key (next t nil))
|
(var key (next t nil))
|
||||||
(while (not= nil key)
|
(while (not= nil key)
|
||||||
(put newt (macroexpand-1 key) (recur-value (get t key)))
|
(put newt (macroexpand-1 key) (on-value (get t key)))
|
||||||
(:= key (next t key)))
|
(:= key (next t key)))
|
||||||
newt)
|
newt)
|
||||||
|
|
||||||
@ -945,19 +944,27 @@ value, one key will be ignored."
|
|||||||
(macroexpand-1 x)))
|
(macroexpand-1 x)))
|
||||||
|
|
||||||
(defn expanddef [t]
|
(defn expanddef [t]
|
||||||
(def len (length t))
|
(def last (get t (- (length t) 1)))
|
||||||
(def last (get t (- len 1)))
|
(def bound (get t 1))
|
||||||
(def last2 (get t (- len 2)))
|
(tuple.slice
|
||||||
(tuple.slice (array.concat (array.slice t 0 -3)
|
(array.concat
|
||||||
@[(expand-bindings last2) (macroexpand-1 last)]) 0))
|
@[(get t 0) (expand-bindings bound)]
|
||||||
|
(tuple.slice t 2 -2)
|
||||||
|
@[(macroexpand-1 last)])
|
||||||
|
0))
|
||||||
|
|
||||||
(defn expandall [t]
|
(defn expandall [t]
|
||||||
(def args (mapa macroexpand-1 (tuple.slice t 1)))
|
(def args (mapa macroexpand-1 (tuple.slice t 1)))
|
||||||
(apply tuple (get t 0) args))
|
(apply tuple (get t 0) args))
|
||||||
|
|
||||||
(defn expandfn [t]
|
(defn expandfn [t]
|
||||||
(def args (mapa macroexpand-1 (tuple.slice t 2)))
|
(if (symbol? (get t 1))
|
||||||
(apply tuple 'fn (get t 1) args))
|
(do
|
||||||
|
(def args (mapa macroexpand-1 (tuple.slice t 3)))
|
||||||
|
(apply tuple 'fn (get t 1) (get t 2) args))
|
||||||
|
(do
|
||||||
|
(def args (mapa macroexpand-1 (tuple.slice t 2)))
|
||||||
|
(apply tuple 'fn (get t 1) args))))
|
||||||
|
|
||||||
(def specs
|
(def specs
|
||||||
{':= expanddef
|
{':= expanddef
|
||||||
@ -978,7 +985,7 @@ value, one key will be ignored."
|
|||||||
(cond
|
(cond
|
||||||
s (s t)
|
s (s t)
|
||||||
m? (apply m (tuple.slice t 1))
|
m? (apply m (tuple.slice t 1))
|
||||||
(map macroexpand-1 t) 0))
|
(map macroexpand-1 t)))
|
||||||
|
|
||||||
(def ret
|
(def ret
|
||||||
(case (type x)
|
(case (type x)
|
||||||
|
Loading…
Reference in New Issue
Block a user