diff options
author | Eduardo Julian | 2017-11-01 00:51:45 -0400 |
---|---|---|
committer | Eduardo Julian | 2017-11-01 00:51:45 -0400 |
commit | 012f6bd41e527479dddbccbdab10daa78fd9a0fd (patch) | |
tree | 621f344a09acd52736f343d94582b3f1a2f0c5f9 /new-luxc/source/luxc/lang/translation/structure.jvm.lux | |
parent | 71d7a4c7206155e09f3e1e1d8699561ea6967382 (diff) |
- Re-organized code-generation, and re-named it "translation".
Diffstat (limited to 'new-luxc/source/luxc/lang/translation/structure.jvm.lux')
-rw-r--r-- | new-luxc/source/luxc/lang/translation/structure.jvm.lux | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/new-luxc/source/luxc/lang/translation/structure.jvm.lux b/new-luxc/source/luxc/lang/translation/structure.jvm.lux new file mode 100644 index 000000000..c3e07fd55 --- /dev/null +++ b/new-luxc/source/luxc/lang/translation/structure.jvm.lux @@ -0,0 +1,59 @@ +(;module: + lux + (lux (control [monad #+ do]) + (data text/format + (coll [list])) + [meta] + [host #+ do-to]) + (luxc ["&" base] + [";L" host] + (host ["$" jvm] + (jvm ["$t" type] + ["$d" def] + ["$i" inst])) + (lang ["la" analysis] + ["ls" synthesis] + (translation [";T" common]))) + [../runtime]) + +(def: $Object $;Type ($t;class "java.lang.Object" (list))) + +(def: #export (generate-tuple generate members) + (-> (-> ls;Synthesis (Meta $;Inst)) (List ls;Synthesis) (Meta $;Inst)) + (do meta;Monad<Meta> + [#let [size (list;size members)] + _ (&;assert "Cannot generate tuples with less than 2 elements." + (n.>= +2 size)) + membersI (|> members + list;enumerate + (monad;map @ (function [[idx member]] + (do @ + [memberI (generate member)] + (wrap (|>. $i;DUP + ($i;int (nat-to-int idx)) + memberI + $i;AASTORE))))) + (:: @ map $i;fuse))] + (wrap (|>. ($i;int (nat-to-int size)) + ($i;array $Object) + membersI)))) + +(def: (flagI tail?) + (-> Bool $;Inst) + (if tail? + ($i;string "") + $i;NULL)) + +(def: #export (generate-variant generate tag tail? member) + (-> (-> ls;Synthesis (Meta $;Inst)) Nat Bool ls;Synthesis (Meta $;Inst)) + (do meta;Monad<Meta> + [memberI (generate member)] + (wrap (|>. ($i;int (nat-to-int tag)) + (flagI tail?) + memberI + ($i;INVOKESTATIC hostL;runtime-class + "variant_make" + ($t;method (list $t;int $Object $Object) + (#;Some ($t;array +1 $Object)) + (list)) + false))))) |