From d0c938888b3dd00cfdb27bb9444401b9e5913490 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Wed, 31 Jul 2019 21:54:53 -0400 Subject: Ported JVM reference generation to the new JVM bytecode machinery. --- .../phase/generation/common-lisp/function.lux | 3 +- .../tool/compiler/phase/generation/js/function.lux | 3 +- .../compiler/phase/generation/jvm/primitive.lux | 6 +-- .../compiler/phase/generation/jvm/reference.lux | 61 ++++++++++++++++++++++ .../compiler/phase/generation/jvm/structure.lux | 4 +- .../tool/compiler/phase/generation/jvm/value.lux | 9 ++++ .../compiler/phase/generation/lua/function.lux | 3 +- .../compiler/phase/generation/php/function.lux | 3 +- .../compiler/phase/generation/python/function.lux | 3 +- .../compiler/phase/generation/ruby/function.lux | 3 +- .../compiler/phase/generation/scheme/function.lux | 3 +- 11 files changed, 89 insertions(+), 12 deletions(-) create mode 100644 stdlib/source/lux/tool/compiler/phase/generation/jvm/reference.lux create mode 100644 stdlib/source/lux/tool/compiler/phase/generation/jvm/value.lux (limited to 'stdlib/source/lux/tool/compiler/phase/generation') 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 ))))] (_.invokestatic "valueOf" - (list ) - (|.object ))))] + [(list ) + (|.object )])))] [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 [ ] + [(def: #export + (-> Register Text) + (|>> %.nat (format )))] + + [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+]) -- cgit v1.2.3