From 498af2e0123c1ce65e46bf15fe3854266ad58f53 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Sun, 21 Jan 2018 12:58:48 -0400 Subject: - WIP: Host procedures for JS. --- .../source/luxc/lang/translation/js/loop.jvm.lux | 31 ++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 new-luxc/source/luxc/lang/translation/js/loop.jvm.lux (limited to 'new-luxc/source/luxc/lang/translation/js/loop.jvm.lux') 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])) + [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 + [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 + [argsJS+ (monad.map @ translate argsS+)] + (wrap (format loop-name "(" (text.join-with "," argsJS+) ")")))) -- cgit v1.2.3