diff options
Diffstat (limited to 'stdlib/source/lux/tool/compiler/phase')
4 files changed, 83 insertions, 7 deletions
diff --git a/stdlib/source/lux/tool/compiler/phase/generation/js/structure.lux b/stdlib/source/lux/tool/compiler/phase/generation/js/structure.lux index 5bdbfd1a6..c721c991c 100644 --- a/stdlib/source/lux/tool/compiler/phase/generation/js/structure.lux +++ b/stdlib/source/lux/tool/compiler/phase/generation/js/structure.lux @@ -12,11 +12,13 @@ [analysis (#+ Variant Tuple)] ["#." synthesis (#+ Synthesis)]]]]) +(def: unit Expression (//primitive.text /////synthesis.unit)) + (def: #export (tuple generate elemsS+) (-> Phase (Tuple Synthesis) (Operation Expression)) (case elemsS+ #.Nil - (:: ////.monad wrap (//primitive.text /////synthesis.unit)) + (:: ////.monad wrap ..unit) (#.Cons singletonS #.Nil) (generate singletonS) diff --git a/stdlib/source/lux/tool/compiler/phase/generation/jvm.lux b/stdlib/source/lux/tool/compiler/phase/generation/jvm.lux index e9ece420f..9a4847165 100644 --- a/stdlib/source/lux/tool/compiler/phase/generation/jvm.lux +++ b/stdlib/source/lux/tool/compiler/phase/generation/jvm.lux @@ -5,7 +5,7 @@ ["." / #_ [runtime (#+ Phase)] ["#." primitive] - ## ["." structure] + ["#." structure] ## ["." reference ("#@." system)] ## ["." function] ## ["." case] @@ -27,11 +27,11 @@ [synthesis.f64 /primitive.f64] [synthesis.text /primitive.text]) - ## (^ (synthesis.variant variantS)) - ## (/structure.variant generate variantS) + (^ (synthesis.variant variantS)) + (/structure.variant generate variantS) - ## (^ (synthesis.tuple members)) - ## (/structure.tuple generate members) + (^ (synthesis.tuple members)) + (/structure.tuple generate members) ## (#synthesis.Reference value) ## (/reference@reference value) diff --git a/stdlib/source/lux/tool/compiler/phase/generation/jvm/runtime.lux b/stdlib/source/lux/tool/compiler/phase/generation/jvm/runtime.lux index 5a84c4990..f43fc907a 100644 --- a/stdlib/source/lux/tool/compiler/phase/generation/jvm/runtime.lux +++ b/stdlib/source/lux/tool/compiler/phase/generation/jvm/runtime.lux @@ -27,4 +27,6 @@ ) (type: #export (Generator i) - (-> i Phase (Operation (Program Any)))) + (-> Phase i (Operation (Program Any)))) + +(def: #export class "LuxRuntime") diff --git a/stdlib/source/lux/tool/compiler/phase/generation/jvm/structure.lux b/stdlib/source/lux/tool/compiler/phase/generation/jvm/structure.lux new file mode 100644 index 000000000..6c2dfc277 --- /dev/null +++ b/stdlib/source/lux/tool/compiler/phase/generation/jvm/structure.lux @@ -0,0 +1,72 @@ +(.module: + [lux #* + [abstract + ["." monad (#+ do)]] + [data + [collection + ["." list]]] + [target + [jvm + ["|" descriptor] + ["_." constant] + ["_" program (#+ Program)]]]] + ["." // #_ + ["#." runtime (#+ Operation Phase Generator)] + ["#." primitive] + ["#//" /// + ["#/" // #_ + [analysis (#+ Variant Tuple)] + ["#." synthesis (#+ Synthesis)]]]]) + +(def: unitG (Program Any) (//primitive.text /////synthesis.unit)) + +(template: (!integer <value>) + (|> <value> .int _constant.i32 _constant.integer)) + +(def: #export (tuple generate membersS) + (Generator (Tuple Synthesis)) + (case membersS + #.Nil + (:: ////.monad wrap ..unitG) + + (#.Cons singletonS #.Nil) + (generate singletonS) + + _ + (do ////.monad + [membersI (|> membersS + list.enumerate + (monad.map @ (function (_ [idx member]) + (do @ + [memberI (generate member)] + (wrap (do _.monad + [_ _.dup + _ (_.ldc/integer (!integer idx)) + _ memberI] + _.aastore))))))] + (wrap (do _.monad + [_ (_.ldc/integer (!integer (list.size membersS))) + _ (_.anewarray "java.lang.Object")] + (monad.seq @ membersI)))))) + +(def: (flagG right?) + (-> Bit (Program Any)) + (if right? + ..unitG + _.aconst-null)) + +(def: $Object (|.object "java.lang.Object")) + +(def: #export (variant generate [lefts right? valueS]) + (Generator (Variant Synthesis)) + (do ////.monad + [valueI (generate valueS)] + (wrap (do _.monad + [_ (_.ldc/integer (!integer (if right? + (.inc lefts) + lefts))) + _ (flagG right?) + _ valueI] + (_.invokestatic //runtime.class "variant" + (list |.int $Object $Object) + (|.array $Object)))))) |