diff options
Diffstat (limited to 'new-luxc/source/luxc/lang/translation/js/loop.jvm.lux')
-rw-r--r-- | new-luxc/source/luxc/lang/translation/js/loop.jvm.lux | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/new-luxc/source/luxc/lang/translation/js/loop.jvm.lux b/new-luxc/source/luxc/lang/translation/js/loop.jvm.lux index 64b2e5b39..9315508e8 100644 --- a/new-luxc/source/luxc/lang/translation/js/loop.jvm.lux +++ b/new-luxc/source/luxc/lang/translation/js/loop.jvm.lux @@ -5,27 +5,30 @@ text/format (coll [list "list/" Functor<List>])) [macro]) - (luxc (lang ["ls" synthesis])) + (luxc [lang] + (lang ["ls" synthesis])) [//] (// [".T" reference])) -(def: #export loop-name Text "_loop") - (def: #export (translate-loop translate offset initsS+ bodyS) (-> (-> ls.Synthesis (Meta //.Expression)) Nat (List ls.Synthesis) ls.Synthesis (Meta //.Expression)) (do macro.Monad<Meta> - [initsJS+ (monad.map @ translate initsS+) - bodyJS (translate bodyS) + [loop-name (:: @ map (|>> %code lang.normalize-name) + (macro.gensym "loop")) + initsJS+ (monad.map @ translate initsS+) + bodyJS (//.with-anchor [loop-name offset] + (translate bodyS)) #let [registersJS+ (|> (list.n/range +0 (n/dec (list.size initsS+))) (list/map (|>> (n/+ offset) referenceT.variable)))]] (wrap (format "(function " loop-name "(" (text.join-with "," registersJS+) ") {" "return " bodyJS ";" "})(" (text.join-with "," initsJS+) ")")))) -(def: #export (translate-iter translate offset argsS+) - (-> (-> ls.Synthesis (Meta //.Expression)) Nat (List ls.Synthesis) +(def: #export (translate-recur translate argsS+) + (-> (-> ls.Synthesis (Meta //.Expression)) (List ls.Synthesis) (Meta //.Expression)) (do macro.Monad<Meta> - [argsJS+ (monad.map @ translate argsS+)] + [[loop-name offset] //.anchor + argsJS+ (monad.map @ translate argsS+)] (wrap (format loop-name "(" (text.join-with "," argsJS+) ")")))) |