aboutsummaryrefslogtreecommitdiff
path: root/new-luxc/source/luxc/lang/translation/js/loop.jvm.lux
diff options
context:
space:
mode:
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.lux31
1 files changed, 31 insertions, 0 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
new file mode 100644
index 000000000..64b2e5b39
--- /dev/null
+++ b/new-luxc/source/luxc/lang/translation/js/loop.jvm.lux
@@ -0,0 +1,31 @@
+(.module:
+ lux
+ (lux (control [monad #+ do])
+ (data [text]
+ text/format
+ (coll [list "list/" Functor<List>]))
+ [macro])
+ (luxc (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)
+ #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)
+ (Meta //.Expression))
+ (do macro.Monad<Meta>
+ [argsJS+ (monad.map @ translate argsS+)]
+ (wrap (format loop-name "(" (text.join-with "," argsJS+) ")"))))