From 7d539a83fd55f7ced7657302054e099955b55ae2 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Wed, 18 Apr 2018 01:28:24 -0400 Subject: - Initial Scheme back-end implementation. --- .../luxc/lang/translation/scheme/loop.jvm.lux | 37 ++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 new-luxc/source/luxc/lang/translation/scheme/loop.jvm.lux (limited to 'new-luxc/source/luxc/lang/translation/scheme/loop.jvm.lux') diff --git a/new-luxc/source/luxc/lang/translation/scheme/loop.jvm.lux b/new-luxc/source/luxc/lang/translation/scheme/loop.jvm.lux new file mode 100644 index 000000000..ecaf12c7c --- /dev/null +++ b/new-luxc/source/luxc/lang/translation/scheme/loop.jvm.lux @@ -0,0 +1,37 @@ +(.module: + lux + (lux (control [monad #+ do]) + (data [text] + text/format + (coll [list "list/" Functor])) + [macro]) + (luxc [lang] + (lang ["ls" synthesis] + (host [r #+ Expression @@]))) + [//] + (// [".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 + [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 (r.var loop-name) + @loop-name (@@ $loop-name)] + _ (//.save (r.set! $loop-name + (r.function (|> (list.n/range +0 (n/dec (list.size initsS+))) + (list/map (|>> (n/+ offset) referenceT.variable))) + bodyO)))] + (wrap (r.apply initsO+ @loop-name)))) + +(def: #export (translate-recur translate argsS+) + (-> (-> ls.Synthesis (Meta Expression)) (List ls.Synthesis) + (Meta Expression)) + (do macro.Monad + [[loop-name offset] //.anchor + argsO+ (monad.map @ translate argsS+)] + (wrap (r.apply argsO+ (r.global loop-name))))) -- cgit v1.2.3