diff options
author | Eduardo Julian | 2019-07-31 21:54:53 -0400 |
---|---|---|
committer | Eduardo Julian | 2019-07-31 21:54:53 -0400 |
commit | d0c938888b3dd00cfdb27bb9444401b9e5913490 (patch) | |
tree | 925c81616a87b0998d66fa0664923be491cfacba /stdlib/source/lux/tool | |
parent | a0889b2ee76c1ae7a9a5bbe2eec9f051b4f341e4 (diff) |
Ported JVM reference generation to the new JVM bytecode machinery.
Diffstat (limited to '')
15 files changed, 108 insertions, 16 deletions
diff --git a/stdlib/source/lux/tool/compiler/analysis.lux b/stdlib/source/lux/tool/compiler/analysis.lux index 33973f979..ffefb48f7 100644 --- a/stdlib/source/lux/tool/compiler/analysis.lux +++ b/stdlib/source/lux/tool/compiler/analysis.lux @@ -16,6 +16,7 @@ [collection ["." list ("#@." functor fold)]]]] [// + [arity (#+ Arity)] ["." reference (#+ Register Variable Reference)] ["." phase ["." extension (#+ Extension)]]]) @@ -91,8 +92,6 @@ [text Text #..Text] ) -(type: #export Arity Nat) - (type: #export (Abstraction c) [Environment Arity c]) (type: #export (Application c) [c (List c)]) diff --git a/stdlib/source/lux/tool/compiler/arity.lux b/stdlib/source/lux/tool/compiler/arity.lux new file mode 100644 index 000000000..2e6b07490 --- /dev/null +++ b/stdlib/source/lux/tool/compiler/arity.lux @@ -0,0 +1,14 @@ +(.module: + [lux #* + [data + [number + ["n" nat]]]]) + +(type: #export Arity Nat) + +(template [<name> <comparison>] + [(def: #export <name> (-> Arity Bit) (<comparison> 1))] + + [mono? n.=] + [poly? n.>] + ) diff --git a/stdlib/source/lux/tool/compiler/phase/generation/common-lisp/function.lux b/stdlib/source/lux/tool/compiler/phase/generation/common-lisp/function.lux index c8edd4e46..3dcc24448 100644 --- a/stdlib/source/lux/tool/compiler/phase/generation/common-lisp/function.lux +++ b/stdlib/source/lux/tool/compiler/phase/generation/common-lisp/function.lux @@ -19,7 +19,8 @@ ["#/" // ["." // #_ [reference (#+ Register Variable)] - [analysis (#+ Variant Tuple Environment Arity Abstraction Application Analysis)] + [arity (#+ Arity)] + [analysis (#+ Variant Tuple Environment Abstraction Application Analysis)] [synthesis (#+ Synthesis)]]]]]) (def: #export (apply generate [functionS argsS+]) diff --git a/stdlib/source/lux/tool/compiler/phase/generation/js/function.lux b/stdlib/source/lux/tool/compiler/phase/generation/js/function.lux index a0418b839..ec48162c5 100644 --- a/stdlib/source/lux/tool/compiler/phase/generation/js/function.lux +++ b/stdlib/source/lux/tool/compiler/phase/generation/js/function.lux @@ -19,7 +19,8 @@ ["#/" // ("#@." monad) ["." // #_ [reference (#+ Register Variable)] - [analysis (#+ Variant Tuple Environment Arity Abstraction Application Analysis)] + [arity (#+ Arity)] + [analysis (#+ Variant Tuple Environment Abstraction Application Analysis)] [synthesis (#+ Synthesis)]]]]]) (def: #export (apply generate [functionS argsS+]) diff --git a/stdlib/source/lux/tool/compiler/phase/generation/jvm/primitive.lux b/stdlib/source/lux/tool/compiler/phase/generation/jvm/primitive.lux index 2807487ae..27a02d7b4 100644 --- a/stdlib/source/lux/tool/compiler/phase/generation/jvm/primitive.lux +++ b/stdlib/source/lux/tool/compiler/phase/generation/jvm/primitive.lux @@ -24,11 +24,11 @@ (do _.monad [_ (`` (|> value (~~ (template.splice <ldc>))))] (_.invokestatic <class> "valueOf" - (list <inputD>) - (|.object <class>))))] + [(list <inputD>) + (|.object <class>)])))] [i64 (I64 Any) [.int constant.long _.ldc/long] "java.lang.Long" |.long] - [f64 Frac [constant.double _.ldc/double] "java.lang.Double" |.double] + [f64 Frac [constant.double _.ldc/double] "java.lang.Double" |.double] ) (def: #export text _.ldc/string) diff --git a/stdlib/source/lux/tool/compiler/phase/generation/jvm/reference.lux b/stdlib/source/lux/tool/compiler/phase/generation/jvm/reference.lux new file mode 100644 index 000000000..3e6738df0 --- /dev/null +++ b/stdlib/source/lux/tool/compiler/phase/generation/jvm/reference.lux @@ -0,0 +1,61 @@ +(.module: + [lux #* + [abstract + [monad (#+ do)]] + [data + [text + ["%" format (#+ format)]]] + [tool + [compiler + ["." reference (#+ Register Variable)] + ["." phase ("operation@." monad) + ["." generation]]]] + [target + [jvm + ["_" instruction (#+ Instruction)] + [encoding + ["." unsigned]]]]] + ["." // #_ + [runtime (#+ Operation)] + ["#." value]]) + +(def: #export this + (Instruction Any) + (_.aload (unsigned.u1 0))) + +(template [<name> <prefix>] + [(def: #export <name> + (-> Register Text) + (|>> %.nat (format <prefix>)))] + + [foreign-name "f"] + [partial-name "p"] + ) + +(def: (foreign variable) + (-> Register (Operation (Instruction Any))) + (do phase.monad + [function-class generation.context] + (wrap ($_ _.compose + ..this + (_.getfield function-class (..foreign-name variable) + //value.type))))) + +(def: local + (-> Register (Instruction Any)) + (|>> unsigned.u1 _.aload)) + +(def: #export (variable variable) + (-> Variable (Operation (Instruction Any))) + (case variable + (#reference.Local variable) + (operation@wrap (..local variable)) + + (#reference.Foreign variable) + (..foreign variable))) + +(def: #export (constant name) + (-> Name (Operation (Instruction Any))) + (do phase.monad + [bytecode-name (generation.remember name)] + (wrap (_.getstatic bytecode-name //value.field //value.type)))) diff --git a/stdlib/source/lux/tool/compiler/phase/generation/jvm/structure.lux b/stdlib/source/lux/tool/compiler/phase/generation/jvm/structure.lux index 1282ac245..8b2c6c270 100644 --- a/stdlib/source/lux/tool/compiler/phase/generation/jvm/structure.lux +++ b/stdlib/source/lux/tool/compiler/phase/generation/jvm/structure.lux @@ -70,5 +70,5 @@ _ (flagG right?) _ valueI] (_.invokestatic //runtime.class "variant" - (list |.int $Object $Object) - (|.array $Object)))))) + [(list |.int $Object $Object) + (|.array $Object)]))))) diff --git a/stdlib/source/lux/tool/compiler/phase/generation/jvm/value.lux b/stdlib/source/lux/tool/compiler/phase/generation/jvm/value.lux new file mode 100644 index 000000000..a598b9997 --- /dev/null +++ b/stdlib/source/lux/tool/compiler/phase/generation/jvm/value.lux @@ -0,0 +1,9 @@ +(.module: + [lux (#- type) + [target + [jvm + ["." descriptor (#+ Descriptor Value)]]]]) + +(def: #export field "_value") + +(def: #export type (Descriptor (Value Any)) (descriptor.object "java.lang.Object")) diff --git a/stdlib/source/lux/tool/compiler/phase/generation/lua/function.lux b/stdlib/source/lux/tool/compiler/phase/generation/lua/function.lux index eb0a5e71b..7bac2e107 100644 --- a/stdlib/source/lux/tool/compiler/phase/generation/lua/function.lux +++ b/stdlib/source/lux/tool/compiler/phase/generation/lua/function.lux @@ -19,7 +19,8 @@ ["#/" // ["." // #_ [reference (#+ Register Variable)] - [analysis (#+ Variant Tuple Environment Arity Abstraction Application Analysis)] + [arity (#+ Arity)] + [analysis (#+ Variant Tuple Environment Abstraction Application Analysis)] [synthesis (#+ Synthesis)]]]]]) (def: #export (apply generate [functionS argsS+]) diff --git a/stdlib/source/lux/tool/compiler/phase/generation/php/function.lux b/stdlib/source/lux/tool/compiler/phase/generation/php/function.lux index 8dfb9668e..6e75f37bc 100644 --- a/stdlib/source/lux/tool/compiler/phase/generation/php/function.lux +++ b/stdlib/source/lux/tool/compiler/phase/generation/php/function.lux @@ -20,7 +20,8 @@ ["#/" // ["." // #_ [reference (#+ Register Variable)] - [analysis (#+ Variant Tuple Environment Arity Abstraction Application Analysis)] + [arity (#+ Arity)] + [analysis (#+ Variant Tuple Environment Abstraction Application Analysis)] [synthesis (#+ Synthesis)]]]]]) (def: #export (apply generate [functionS argsS+]) diff --git a/stdlib/source/lux/tool/compiler/phase/generation/python/function.lux b/stdlib/source/lux/tool/compiler/phase/generation/python/function.lux index c70ca9c37..ed6e53274 100644 --- a/stdlib/source/lux/tool/compiler/phase/generation/python/function.lux +++ b/stdlib/source/lux/tool/compiler/phase/generation/python/function.lux @@ -19,7 +19,8 @@ ["#/" // ["." // #_ [reference (#+ Register Variable)] - [analysis (#+ Variant Tuple Environment Arity Abstraction Application Analysis)] + [arity (#+ Arity)] + [analysis (#+ Variant Tuple Environment Abstraction Application Analysis)] [synthesis (#+ Synthesis)]]]]]) (def: #export (apply generate [functionS argsS+]) diff --git a/stdlib/source/lux/tool/compiler/phase/generation/ruby/function.lux b/stdlib/source/lux/tool/compiler/phase/generation/ruby/function.lux index ef3920d23..02e221894 100644 --- a/stdlib/source/lux/tool/compiler/phase/generation/ruby/function.lux +++ b/stdlib/source/lux/tool/compiler/phase/generation/ruby/function.lux @@ -19,7 +19,8 @@ ["#/" // ["." // #_ [reference (#+ Register Variable)] - [analysis (#+ Variant Tuple Environment Arity Abstraction Application Analysis)] + [arity (#+ Arity)] + [analysis (#+ Variant Tuple Environment Abstraction Application Analysis)] [synthesis (#+ Synthesis)]]]]]) (def: #export (apply generate [functionS argsS+]) diff --git a/stdlib/source/lux/tool/compiler/phase/generation/scheme/function.lux b/stdlib/source/lux/tool/compiler/phase/generation/scheme/function.lux index 41a2e6b17..797e31e1d 100644 --- a/stdlib/source/lux/tool/compiler/phase/generation/scheme/function.lux +++ b/stdlib/source/lux/tool/compiler/phase/generation/scheme/function.lux @@ -21,7 +21,8 @@ ["#/" // ("#;." monad) ["#/" // #_ [reference (#+ Register Variable)] - [analysis (#+ Variant Tuple Environment Arity Abstraction Application Analysis)] + [arity (#+ Arity)] + [analysis (#+ Variant Tuple Environment Abstraction Application Analysis)] [synthesis (#+ Synthesis)]]]]]) (def: #export (apply generate [functionS argsS+]) diff --git a/stdlib/source/lux/tool/compiler/phase/synthesis/function.lux b/stdlib/source/lux/tool/compiler/phase/synthesis/function.lux index dbcc56e38..4e09f08e9 100644 --- a/stdlib/source/lux/tool/compiler/phase/synthesis/function.lux +++ b/stdlib/source/lux/tool/compiler/phase/synthesis/function.lux @@ -15,8 +15,9 @@ ["#." loop (#+ Transform)] ["#/" // ("#;." monad) ["#/" // #_ + [arity (#+ Arity)] ["#." reference (#+ Register Variable)] - ["#." analysis (#+ Environment Arity Analysis)] + ["#." analysis (#+ Environment Analysis)] ["/" synthesis (#+ Path Synthesis Operation Phase)]]]]) (exception: #export (cannot-find-foreign-variable-in-environment {foreign Register} {environment Environment}) diff --git a/stdlib/source/lux/tool/compiler/synthesis.lux b/stdlib/source/lux/tool/compiler/synthesis.lux index 4c8959b26..e44432bcb 100644 --- a/stdlib/source/lux/tool/compiler/synthesis.lux +++ b/stdlib/source/lux/tool/compiler/synthesis.lux @@ -17,8 +17,9 @@ ["." list ("#;." functor)] ["." dictionary (#+ Dictionary)]]]] ["." // #_ + [arity (#+ Arity)] ["#." reference (#+ Register Variable Reference)] - ["#." analysis (#+ Environment Arity Composite Analysis)] + ["#." analysis (#+ Environment Composite Analysis)] ["#." phase ["." extension (#+ Extension)]]]) |