From fa37f5d17184db1ed95949352e71542af8fb4ce1 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Tue, 24 Dec 2019 23:05:30 -0400 Subject: Ported program generation, host environment and packaging machinery to stdlib. --- stdlib/source/lux/target/jvm/attribute.lux | 20 +- .../source/lux/target/jvm/attribute/constant.lux | 8 +- stdlib/source/lux/target/jvm/bytecode.lux | 22 +- .../compiler/phase/extension/directive/jvm.lux | 303 +++++++++++++++++++++ .../tool/compiler/phase/generation/jvm/host.lux | 159 +++++++++++ .../compiler/phase/generation/jvm/packager.lux | 111 ++++++++ .../tool/compiler/phase/generation/jvm/program.lux | 143 ++++++++++ .../tool/compiler/phase/generation/jvm/runtime.lux | 17 +- 8 files changed, 750 insertions(+), 33 deletions(-) create mode 100644 stdlib/source/lux/tool/compiler/phase/extension/directive/jvm.lux create mode 100644 stdlib/source/lux/tool/compiler/phase/generation/jvm/host.lux create mode 100644 stdlib/source/lux/tool/compiler/phase/generation/jvm/packager.lux create mode 100644 stdlib/source/lux/tool/compiler/phase/generation/jvm/program.lux (limited to 'stdlib/source') diff --git a/stdlib/source/lux/target/jvm/attribute.lux b/stdlib/source/lux/target/jvm/attribute.lux index 5f8892631..083ebaa15 100644 --- a/stdlib/source/lux/target/jvm/attribute.lux +++ b/stdlib/source/lux/target/jvm/attribute.lux @@ -49,7 +49,7 @@ (with-expansions [ (as-is (/code.Code Attribute))] (type: #export #rec Attribute - (#Constant (Info Constant)) + (#Constant (Info (Constant Any))) (#Code (Info ))) (type: #export Code @@ -64,7 +64,7 @@ (info-equivalence /constant.equivalence) (info-equivalence (/code.equivalence equivalence)))))) -(def: fixed-attribute-length +(def: common-attribute-length ($_ n.+ ## u2 attribute_name_index; //unsigned.bytes/2 @@ -77,25 +77,23 @@ (case attribute (^template [] ( [name length info]) - (|> length //unsigned.value (n.+ fixed-attribute-length))) + (|> length //unsigned.value (n.+ ..common-attribute-length))) ([#Constant] [#Code]))) -(def: constant-name "ConstantValue") - +## TODO: Inline ASAP (def: (constant' @name index) - (-> (Index UTF8) Constant Attribute) + (-> (Index UTF8) (Constant Any) Attribute) (#Constant {#name @name #length (|> /constant.length //unsigned.u4 try.assume) #info index})) (def: #export (constant index) - (-> Constant (Resource Attribute)) + (-> (Constant Any) (Resource Attribute)) (do //constant/pool.monad - [@name (//constant/pool.utf8 ..constant-name)] + [@name (//constant/pool.utf8 "ConstantValue")] (wrap (constant' @name index)))) -(def: code-name "Code") - +## TODO: Inline ASAP (def: (code' @name specification) (-> (Index UTF8) Code Attribute) (#Code {#name @name @@ -109,7 +107,7 @@ (def: #export (code specification) (-> Code (Resource Attribute)) (do //constant/pool.monad - [@name (//constant/pool.utf8 ..code-name)] + [@name (//constant/pool.utf8 "Code")] (wrap (code' @name specification)))) (def: #export (writer value) diff --git a/stdlib/source/lux/target/jvm/attribute/constant.lux b/stdlib/source/lux/target/jvm/attribute/constant.lux index 0206ed26e..c5605bcc3 100644 --- a/stdlib/source/lux/target/jvm/attribute/constant.lux +++ b/stdlib/source/lux/target/jvm/attribute/constant.lux @@ -11,16 +11,16 @@ [encoding ["#." unsigned (#+ U2 U4)]]]) -(type: #export Constant - (Index Value)) +(type: #export (Constant a) + (Index (Value a))) (def: #export equivalence - (Equivalence Constant) + (All [a] (Equivalence (Constant a))) ///index.equivalence) (def: #export length ///index.length) (def: #export writer - (Writer Constant) + (All [a] (Writer (Constant a))) ///index.writer) diff --git a/stdlib/source/lux/target/jvm/bytecode.lux b/stdlib/source/lux/target/jvm/bytecode.lux index 5ad3d2204..a31b90195 100644 --- a/stdlib/source/lux/target/jvm/bytecode.lux +++ b/stdlib/source/lux/target/jvm/bytecode.lux @@ -219,17 +219,6 @@ [@4 5] ) -(def: discontinuity! - (Bytecode Any) - (function (_ [pool environment tracker]) - (do try.monad - [_ (/environment.stack environment)] - (#try.Success [[pool - (/environment.discontinue environment) - tracker] - [..relative-identity - []]])))) - (template [ ] [(def: #export (Bytecode Any) @@ -414,6 +403,17 @@ [monitorexit $1 $0 @_ _.monitorexit] ) +(def: discontinuity! + (Bytecode Any) + (function (_ [pool environment tracker]) + (do try.monad + [_ (/environment.stack environment)] + (#try.Success [[pool + (/environment.discontinue environment) + tracker] + [..relative-identity + []]])))) + (template [ ] [(def: #export (Bytecode Any) diff --git a/stdlib/source/lux/tool/compiler/phase/extension/directive/jvm.lux b/stdlib/source/lux/tool/compiler/phase/extension/directive/jvm.lux new file mode 100644 index 000000000..4db15e8e6 --- /dev/null +++ b/stdlib/source/lux/tool/compiler/phase/extension/directive/jvm.lux @@ -0,0 +1,303 @@ +(.module: + [lux (#- Type Definition) + ["." host] + [abstract + ["." monad (#+ do)]] + [control + [pipe (#+ case>)] + ["<>" parser ("#@." monad) + ["" code (#+ Parser)] + ["" text]]] + [data + ["." product] + [number + ["." i32]] + [text + ["%" format (#+ format)]] + [collection + ["." list ("#@." functor fold)] + ["." dictionary] + ["." row]]] + [type + ["." check (#+ Check)]] + [macro + ["." template]] + [target + [jvm + ["_" bytecode (#+ Bytecode)] + ["." modifier (#+ Modifier) ("#@." monoid)] + ["." attribute] + ["." field] + ["." version] + ["." class] + ["." constant + ["." pool (#+ Resource)]] + [encoding + ["." name]] + ["." type (#+ Type Constraint Argument Typed) + [category (#+ Void Value Return Method Primitive Object Class Array Var Parameter)] + [".T" lux (#+ Mapping)] + ["." signature] + ["." descriptor (#+ Descriptor)] + ["." parser]]]] + [tool + [compiler + ["." analysis] + ["." synthesis] + ["." directive (#+ Handler Bundle)] + ["." phase + [analysis + [".A" type]] + ["." generation + [jvm + [runtime (#+ Anchor Definition)]]] + ["." extension + ["." bundle] + [analysis + ["." jvm]] + [directive + ["/" lux]]]]]]]) + +(type: Operation + (directive.Operation Anchor (Bytecode Any) Definition)) + +(def: signature (|>> type.signature signature.signature)) + +(type: Declaration + [Text (List (Type Var))]) + +(def: declaration + (Parser Declaration) + (.form (<>.and .text (<>.some jvm.var)))) + +(def: visibility + (Parser (Modifier field.Field)) + (`` ($_ <>.either + (~~ (template [