From b14f95ca68887d9e6cea211b47e04e5ec00c05fa Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Tue, 13 Mar 2018 23:28:19 -0400 Subject: - Initial Ruby back-end implementation. --- .../source/luxc/lang/translation/ruby/loop.jvm.lux | 35 ++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 new-luxc/source/luxc/lang/translation/ruby/loop.jvm.lux (limited to 'new-luxc/source/luxc/lang/translation/ruby/loop.jvm.lux') diff --git a/new-luxc/source/luxc/lang/translation/ruby/loop.jvm.lux b/new-luxc/source/luxc/lang/translation/ruby/loop.jvm.lux new file mode 100644 index 000000000..e4da02c2a --- /dev/null +++ b/new-luxc/source/luxc/lang/translation/ruby/loop.jvm.lux @@ -0,0 +1,35 @@ +(.module: + lux + (lux (control [monad #+ do]) + (data [text] + text/format + (coll [list "list/" Functor])) + [macro]) + (luxc [lang] + (lang ["ls" synthesis] + (host [ruby #+ Ruby 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 + [loop-name (:: @ map (|>> %code lang.normalize-name) + (macro.gensym "loop")) + initsO+ (monad.map @ translate initsS+) + bodyO (//.with-anchor [loop-name offset] + (translate bodyS)) + #let [registersO+ (|> (list.n/range +0 (n/dec (list.size initsS+))) + (list/map (|>> (n/+ offset) referenceT.variable)))] + _ (//.save (ruby.function! loop-name registersO+ + (ruby.return! bodyO)))] + (wrap (ruby.apply loop-name initsO+)))) + +(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 (ruby.apply loop-name argsO+)))) -- cgit v1.2.3