diff options
author | Eduardo Julian | 2018-04-04 00:56:16 -0400 |
---|---|---|
committer | Eduardo Julian | 2018-04-04 00:56:16 -0400 |
commit | 787fc34a8f7c66746046a8ce0c16403cf6c2bf6c (patch) | |
tree | 31c054f4a61e784875b7d66642558e9357d91493 /new-luxc/source/luxc/lang/translation/python/loop.jvm.lux | |
parent | b14f95ca68887d9e6cea211b47e04e5ec00c05fa (diff) |
- Initial Python back-end implementation.
Diffstat (limited to 'new-luxc/source/luxc/lang/translation/python/loop.jvm.lux')
-rw-r--r-- | new-luxc/source/luxc/lang/translation/python/loop.jvm.lux | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/new-luxc/source/luxc/lang/translation/python/loop.jvm.lux b/new-luxc/source/luxc/lang/translation/python/loop.jvm.lux new file mode 100644 index 000000000..e490033bf --- /dev/null +++ b/new-luxc/source/luxc/lang/translation/python/loop.jvm.lux @@ -0,0 +1,36 @@ +(.module: + lux + (lux (control [monad #+ do]) + (data [text] + text/format + (coll [list "list/" Functor<List>])) + [macro]) + (luxc [lang] + (lang ["ls" synthesis] + (host [python #+ Expression Statement @@]))) + [//] + (// [".T" reference])) + +(def: #export (translate-loop translate offset initsS+ bodyS) + (-> (-> ls.Synthesis (Meta Expression)) Nat (List ls.Synthesis) ls.Synthesis + (Meta Expression)) + (do macro.Monad<Meta> + [loop-name (|> (macro.gensym "loop") + (:: @ map (|>> %code lang.normalize-name))) + initsO+ (monad.map @ translate initsS+) + bodyO (//.with-anchor [loop-name offset] + (translate bodyS)) + #let [$loop-name (python.var loop-name) + @loop-name (@@ $loop-name)] + _ (//.save (python.def! $loop-name (|> (list.n/range +0 (n/dec (list.size initsS+))) + (list/map (|>> (n/+ offset) referenceT.variable))) + (python.return! bodyO)))] + (wrap (python.apply initsO+ @loop-name)))) + +(def: #export (translate-recur translate argsS+) + (-> (-> ls.Synthesis (Meta Expression)) (List ls.Synthesis) + (Meta Expression)) + (do macro.Monad<Meta> + [[loop-name offset] //.anchor + argsO+ (monad.map @ translate argsS+)] + (wrap (python.apply argsO+ (python.global loop-name))))) |