diff options
author | Eduardo Julian | 2022-01-19 06:06:10 -0400 |
---|---|---|
committer | Eduardo Julian | 2022-01-19 06:06:10 -0400 |
commit | f47fb7404bcbd9fac5df8697e57e08f03ec468ac (patch) | |
tree | 0e744df7371ffbfed6fac03911e4a1982f32a0ec /stdlib/source/library/lux/tool/compiler | |
parent | 4fb3c45f9d0e91cbfe5714c7de2189cddb0abad7 (diff) |
Fixes for the pure-Lux JVM compiler machinery. [Part 8]
Diffstat (limited to 'stdlib/source/library/lux/tool/compiler')
22 files changed, 307 insertions, 182 deletions
diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/analysis.lux b/stdlib/source/library/lux/tool/compiler/language/lux/analysis.lux index 108c5670e..0f1d59581 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/analysis.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/analysis.lux @@ -1,6 +1,6 @@ (.using [library - [lux {"-" Tuple Variant nat int rev} + [lux {"-" Tuple Variant nat int rev case} [abstract [equivalence {"+" Equivalence}] [hash {"+" Hash}] @@ -9,14 +9,18 @@ ["[0]" function] ["[0]" maybe] ["[0]" try] - ["[0]" exception {"+" Exception}]] + ["[0]" exception {"+" Exception}] + [parser + ["<[0]>" code]]] [data ["[0]" product] ["[0]" bit ("[1]#[0]" equivalence)] ["[0]" text ("[1]#[0]" equivalence) - ["%" format {"+" Format format}]] + ["%" format {"+" Format}]] [collection ["[0]" list ("[1]#[0]" functor mix)]]] + [macro + [syntax {"+" syntax:}]] [math [number ["n" nat] @@ -27,14 +31,14 @@ ["[0]" location]]]] ["[0]" / "_" ["[1][0]" simple {"+" Simple}] - ["[1][0]" composite {"+" Tuple Variant Composite}] + ["[1][0]" complex {"+" Tuple Variant Complex}] ["[1][0]" pattern {"+" Pattern}] [// [phase ["[0]" extension {"+" Extension}]] [/// [arity {"+" Arity}] - [version {"+" Version}] + ["[0]" version {"+" Version}] ["[0]" phase] ["[0]" reference {"+" Reference} ["[0]" variable {"+" Register Variable}]]]]]) @@ -54,7 +58,7 @@ (Rec Analysis (.Variant {#Simple Simple} - {#Structure (Composite Analysis)} + {#Structure (Complex Analysis)} {#Reference Reference} {#Case Analysis (Match' Analysis)} {#Function (Environment Analysis) Analysis} @@ -78,12 +82,12 @@ (Equivalence Analysis) (def: (= reference sample) - (case [reference sample] + (.case [reference sample] [{#Simple reference} {#Simple sample}] (# /simple.equivalence = reference sample) [{#Structure reference} {#Structure sample}] - (# (/composite.equivalence =) = reference sample) + (# (/complex.equivalence =) = reference sample) [{#Reference reference} {#Reference sample}] (# reference.equivalence = reference sample) @@ -113,7 +117,7 @@ [(template: .public (<name> content) [{<tag> content}])] - [control/case ..#Case] + [case ..#Case] ) (template: .public (unit) @@ -156,7 +160,7 @@ (-> Analysis (Application Analysis)) (loop [abstraction analysis inputs (list)] - (case abstraction + (.case abstraction {#Apply input next} (again next {.#Item input inputs}) @@ -164,16 +168,16 @@ [abstraction inputs]))) (template [<name> <tag>] - [(template: .public (<name> content) - [(.<| {..#Reference} - <tag> - content)])] + [(syntax: .public (<name> [content <code>.any]) + (in (list (` (.<| {..#Reference} + <tag> + (~ content))))))] [variable {reference.#Variable}] [constant {reference.#Constant}] - [variable/local (reference.local)] - [variable/foreign (reference.foreign)] + [variable/local ((~! reference.local))] + [variable/foreign ((~! reference.foreign))] ) (template [<name> <tag>] @@ -182,47 +186,54 @@ {<tag>} content)])] - [variant /composite.#Variant] - [tuple /composite.#Tuple] + [variant /complex.#Variant] + [tuple /complex.#Tuple] ) -(def: .public (%analysis analysis) +(def: .public (format analysis) (Format Analysis) - (case analysis + (.case analysis {#Simple it} (/simple.format it) {#Structure it} - (/composite.format %analysis it) + (/complex.format format it) {#Reference reference} (reference.format reference) {#Case analysis match} - "{?}" + (%.format "({" + (|> {.#Item match} + (list#each (function (_ [when then]) + (%.format (/pattern.format when) " " (format then)))) + (text.interposed " ")) + "} " + (format analysis) + ")") {#Function environment body} - (|> (%analysis body) - (format " ") - (format (|> environment - (list#each %analysis) - (text.interposed " ") - (text.enclosed ["[" "]"]))) + (|> (format body) + (%.format " ") + (%.format (|> environment + (list#each format) + (text.interposed " ") + (text.enclosed ["[" "]"]))) (text.enclosed ["(" ")"])) {#Apply _} (|> analysis ..application {.#Item} - (list#each %analysis) + (list#each format) (text.interposed " ") (text.enclosed ["(" ")"])) {#Extension name parameters} (|> parameters - (list#each %analysis) + (list#each format) (text.interposed " ") - (format (%.text name) " ") + (%.format (%.text name) " ") (text.enclosed ["(" ")"])))) (template [<special> <general>] @@ -240,7 +251,7 @@ (All (_ a) (-> Source (Operation a) (Operation a))) (function (_ [bundle state]) (let [old_source (value@ .#source state)] - (case (action [bundle (with@ .#source source state)]) + (.case (action [bundle (with@ .#source source state)]) {try.#Success [[bundle' state'] output]} {try.#Success [[bundle' (with@ .#source old_source state')] output]} @@ -263,9 +274,9 @@ (def: .public (with_scope action) (All (_ a) (-> (Operation a) (Operation [Scope a]))) (function (_ [bundle state]) - (case (action [bundle (revised@ .#scopes (|>> {.#Item fresh_scope}) state)]) + (.case (action [bundle (revised@ .#scopes (|>> {.#Item fresh_scope}) state)]) {try.#Success [[bundle' state'] output]} - (case (value@ .#scopes state') + (.case (value@ .#scopes state') {.#Item head tail} {try.#Success [[bundle' (with@ .#scopes tail state')] [head output]]} @@ -283,7 +294,7 @@ (def: .public (without_scopes action) (All (_ a) (-> (Operation a) (Operation a))) (function (_ [bundle state]) - (case (action [bundle (with@ .#scopes ..scope_reset state)]) + (.case (action [bundle (with@ .#scopes ..scope_reset state)]) {try.#Success [[bundle' state'] output]} {try.#Success [[bundle' (with@ .#scopes (value@ .#scopes state) state')] output]} @@ -303,7 +314,7 @@ action (function (_ [bundle state]) (let [old_location (value@ .#location state)] - (case (action [bundle (with@ .#location location state)]) + (.case (action [bundle (with@ .#location location state)]) {try.#Success [[bundle' state'] output]} {try.#Success [[bundle' (with@ .#location old_location state')] output]} @@ -313,8 +324,8 @@ (def: (locate_error location error) (-> Location Text Text) - (format (%.location location) text.new_line - error)) + (%.format (%.location location) text.new_line + error)) (def: .public (failure error) (-> Text Operation) @@ -331,20 +342,11 @@ (# phase.monad in []) (..except exception parameters))) -(def: .public (failure' error) - (-> Text (phase.Operation Lux)) - (function (_ state) - {try.#Failure (locate_error (value@ .#location state) error)})) - -(def: .public (except' exception parameters) - (All (_ e) (-> (Exception e) e (phase.Operation Lux))) - (..failure' (exception.error exception parameters))) - (def: .public (with_stack exception message action) (All (_ e o) (-> (Exception e) e (Operation o) (Operation o))) (function (_ bundle,state) - (case (exception.with exception message - (action bundle,state)) + (.case (exception.with exception message + (action bundle,state)) {try.#Success output} {try.#Success output} @@ -389,7 +391,7 @@ (def: .public (info version host) (-> Version Text Info) [.#target host - .#version (%.nat version) + .#version (version.format version) .#mode {.#Build}]) (def: .public (state info) diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/analysis/composite.lux b/stdlib/source/library/lux/tool/compiler/language/lux/analysis/complex.lux index c85f332f9..b3a2f635f 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/analysis/composite.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/analysis/complex.lux @@ -23,7 +23,7 @@ (type: .public (Tuple a) (List a)) -(type: .public (Composite a) +(type: .public (Complex a) (.Variant {#Variant (Variant a)} {#Tuple (Tuple a)})) @@ -50,7 +50,7 @@ right?])) (implementation: .public (equivalence (^open "/#[0]")) - (All (_ a) (-> (Equivalence a) (Equivalence (Composite a)))) + (All (_ a) (-> (Equivalence a) (Equivalence (Complex a)))) (def: (= reference sample) (case [reference sample] @@ -67,7 +67,7 @@ false))) (implementation: .public (hash super) - (All (_ a) (-> (Hash a) (Hash (Composite a)))) + (All (_ a) (-> (Hash a) (Hash (Complex a)))) (def: &equivalence (..equivalence (# super &equivalence))) @@ -86,7 +86,7 @@ ))) (def: .public (format %it it) - (All (_ a) (-> (Format a) (Format (Composite a)))) + (All (_ a) (-> (Format a) (Format (Complex a)))) (case it {#Variant [lefts right? it]} (%.format "{" (%.nat lefts) " " (%.bit right?) " " (%it it) "}") diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/analysis/pattern.lux b/stdlib/source/library/lux/tool/compiler/language/lux/analysis/pattern.lux index 9aaf606ac..21b6218ba 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/analysis/pattern.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/analysis/pattern.lux @@ -3,21 +3,24 @@ [lux {"-" nat int rev} [abstract [equivalence {"+" Equivalence}]] + [data + [text + ["%" format {"+" Format}]]] [math [number ["n" nat]]]]] ["[0]" // "_" ["[1][0]" simple {"+" Simple}] - ["[1][0]" composite {"+" Composite}] + ["[1][0]" complex {"+" Complex}] [//// [reference - [variable {"+" Register}]]]]) + ["[1][0]" variable {"+" Register}]]]]) (type: .public Pattern (Rec Pattern (.Variant {#Simple Simple} - {#Complex (Composite Pattern)} + {#Complex (Complex Pattern)} {#Bind Register}))) (implementation: .public equivalence @@ -29,7 +32,7 @@ (# //simple.equivalence = reference sample) [{#Complex reference} {#Complex sample}] - (# (//composite.equivalence =) = reference sample) + (# (//complex.equivalence =) = reference sample) [{#Bind reference} {#Bind sample}] (n.= reference sample) @@ -37,14 +40,26 @@ _ false))) +(def: .public (format it) + (Format Pattern) + (case it + {#Simple it} + (//simple.format it) + + {#Complex it} + (//complex.format format it) + + {#Bind it} + (//variable.format {//variable.#Local it}))) + (template [<name> <tag>] [(template: .public (<name> content) [(.<| {..#Complex} <tag> content)])] - [variant {//composite.#Variant}] - [tuple {//composite.#Tuple}] + [variant {//complex.#Variant}] + [tuple {//complex.#Tuple}] ) (template: .public (unit) diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis/case.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis/case.lux index 03ff2ea6e..e2d411efe 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis/case.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis/case.lux @@ -32,7 +32,7 @@ [// ["/" analysis {"+" Analysis Operation Phase} ["[1][0]" simple] - ["[1][0]" composite] + ["[1][0]" complex] ["[1][0]" pattern {"+" Pattern}]] [/// ["[1]" phase]]]]]]) @@ -287,7 +287,7 @@ (let [flat_sum (type.flat_variant inputT') size_sum (list.size flat_sum) num_cases (maybe.else size_sum num_tags) - idx (/composite.tag right? lefts)] + idx (/complex.tag right? lefts)] (.case (list.item idx flat_sum) (^multi {.#Some caseT} (n.< num_cases idx)) @@ -324,7 +324,7 @@ [idx group variantT] (///extension.lifted (meta.tag tag)) _ (//type.with_env (check.check inputT variantT)) - .let [[lefts right?] (/composite.choice (list.size group) idx)]] + .let [[lefts right?] (/complex.choice (list.size group) idx)]] (analyse_pattern {.#Some (list.size group)} inputT (` {(~ (code.nat lefts)) (~ (code.bit right?)) (~+ values)}) next))) _ diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis/case/coverage.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis/case/coverage.lux index aa66b8c01..7ec92c76b 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis/case/coverage.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis/case/coverage.lux @@ -26,7 +26,7 @@ [// ["/" analysis {"+" Operation} ["[1][0]" simple] - ["[1][0]" composite] + ["[1][0]" complex] ["[1][0]" pattern {"+" Pattern}]] [/// ["[1]" phase ("[1]#[0]" monad)]]]]) @@ -140,7 +140,7 @@ ... Tuple patterns can be exhaustive if there is exhaustiveness for all of ... their sub-patterns. - {/pattern.#Complex {/composite.#Tuple membersP+}} + {/pattern.#Complex {/complex.#Tuple membersP+}} (case (list.reversed membersP+) (^or {.#End} {.#Item _ {.#End}}) (/.except ..invalid_tuple_pattern []) @@ -162,7 +162,7 @@ ... Variant patterns can be shown to be exhaustive if all the possible ... cases are handled exhaustively. - {/pattern.#Complex {/composite.#Variant [lefts right? value]}} + {/pattern.#Complex {/complex.#Variant [lefts right? value]}} (do ////.monad [value_coverage (determine value) .let [idx (if right? diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis/inference.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis/inference.lux index 6c94f14bd..6c0b9a429 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis/inference.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis/inference.lux @@ -23,7 +23,7 @@ ["[1][0]" extension] [// ["/" analysis {"+" Analysis Operation Phase} - [composite {"+" Tag}]] + [complex {"+" Tag}]] [/// ["[1]" phase ("[1]#[0]" monad)] [meta diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis/module.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis/module.lux index 76cf4f82a..3ca157f38 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis/module.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis/module.lux @@ -132,7 +132,8 @@ []]} {.#Some already_existing} - ((/.except' ..cannot_define_more_than_once [[self_name name] already_existing]) state)))))) + ((///extension.up (/.except ..cannot_define_more_than_once [[self_name name] already_existing])) + state)))))) (def: .public (create hash name) (-> Nat Text (Operation Any)) @@ -167,11 +168,12 @@ (plist.has module_name (with@ .#module_state {<tag>} module)) state) []]} - ((/.except' can_only_change_state_of_active_module [module_name {<tag>}]) + ((///extension.up (/.except can_only_change_state_of_active_module [module_name {<tag>}])) state))) {.#None} - ((/.except' unknown_module module_name) state))))) + ((///extension.up (/.except unknown_module module_name)) + state))))) (def: .public (<asker> module_name) (-> Text (Operation Bit)) @@ -185,7 +187,8 @@ _ #0)]} {.#None} - ((/.except' unknown_module module_name) state)))))] + ((///extension.up (/.except unknown_module module_name)) + state)))))] [set_active active? .#Active] [set_compiled compiled? .#Compiled] @@ -201,7 +204,8 @@ {try.#Success [state (value@ .#module_hash module)]} {.#None} - ((/.except' unknown_module module_name) state))))) + ((///extension.up (/.except unknown_module module_name)) + state))))) (def: .public (declare_tags record? tags exported? type) (-> Bit (List Tag) Bit Type (Operation Any)) diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis/reference.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis/reference.lux index abee40e63..87337d8b6 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis/reference.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis/reference.lux @@ -21,10 +21,12 @@ ["[1]" phase]]]]]) (exception: .public (foreign_module_has_not_been_imported [current Text - foreign Text]) + foreign Text + definition Symbol]) (exception.report ["Current" current] - ["Foreign" foreign])) + ["Foreign" foreign] + ["Definition" (%.symbol definition)])) (exception: .public (definition_has_not_been_exported [definition Symbol]) (exception.report @@ -55,7 +57,7 @@ [imported! (///extension.lifted (meta.imported_by? ::module current))] (if imported! <return> - (/.except foreign_module_has_not_been_imported [current ::module]))) + (/.except foreign_module_has_not_been_imported [current ::module def_name]))) (/.except definition_has_not_been_exported def_name)))) {.#Type [exported? value labels]} @@ -70,7 +72,7 @@ [imported! (///extension.lifted (meta.imported_by? ::module current))] (if imported! <return> - (/.except foreign_module_has_not_been_imported [current ::module]))) + (/.except foreign_module_has_not_been_imported [current ::module def_name]))) (/.except definition_has_not_been_exported def_name)))) {.#Tag _} diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis/structure.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis/structure.lux index 54eca8afb..bcc0a82fe 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis/structure.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis/structure.lux @@ -33,7 +33,7 @@ ["[1][0]" extension] [// ["/" analysis {"+" Analysis Operation Phase} - ["[1][0]" composite {"+" Tag}]] + ["[1][0]" complex {"+" Tag}]] [/// ["[1]" phase] [meta @@ -109,7 +109,7 @@ (def: .public (sum analyse lefts right? archive) (-> Phase Nat Bit Phase) - (let [tag (/composite.tag right? lefts)] + (let [tag (/complex.tag right? lefts)] (function (again valueC) (do [! ///.monad] [expectedT (///extension.lifted meta.expected_type) @@ -290,7 +290,7 @@ [tag (///extension.lifted (meta.normal tag)) [idx group variantT] (///extension.lifted (meta.tag tag)) .let [case_size (list.size group) - [lefts right?] (/composite.choice case_size idx)] + [lefts right?] (/complex.choice case_size idx)] expectedT (///extension.lifted meta.expected_type)] (case expectedT {.#Var _} diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension.lux index 568e061a6..0f1848eff 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension.lux @@ -1,25 +1,25 @@ (.using - [library - [lux "*" - [abstract - [equivalence {"+" Equivalence}] - [hash {"+" Hash}] - ["[0]" monad {"+" do}]] - [control - ["[0]" function] - ["[0]" try {"+" Try}] - ["[0]" exception {"+" exception:}]] - [data - ["[0]" product] - ["[0]" text ("[1]#[0]" order) - ["%" format {"+" Format format}]] - [collection - ["[0]" list] - ["[0]" dictionary {"+" Dictionary}]]]]] - [///// - ["//" phase] - [meta - [archive {"+" Archive}]]]) + [library + [lux "*" + [abstract + [equivalence {"+" Equivalence}] + [hash {"+" Hash}] + ["[0]" monad {"+" do}]] + [control + ["[0]" function] + ["[0]" try {"+" Try}] + ["[0]" exception {"+" exception:}]] + [data + ["[0]" product] + ["[0]" text ("[1]#[0]" order) + ["%" format {"+" Format format}]] + [collection + ["[0]" list] + ["[0]" dictionary {"+" Dictionary}]]]]] + [///// + ["//" phase] + [meta + [archive {"+" Archive}]]]) (type: .public Name Text) @@ -180,3 +180,14 @@ {try.#Failure error} {try.#Failure error}))) + +(def: .public (up it) + (All (_ s i o v) + (-> (Operation s i o v) (//.Operation s v))) + (function (_ state) + (case (it [..empty state]) + {try.#Success [[_ state'] output]} + {try.#Success [state' output]} + + {try.#Failure error} + {try.#Failure error}))) diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/analysis/jvm.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/analysis/jvm.lux index db5642a25..1e6c6af8e 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/analysis/jvm.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/analysis/jvm.lux @@ -51,7 +51,7 @@ ["[0]" scope]] ["/[1]" // "_" ["[1][0]" analysis {"+" Analysis Operation Phase Handler Bundle} - ["[1]/[0]" composite] + ["[1]/[0]" complex] ["[1]/[0]" pattern]] ["[1][0]" synthesis] [/// @@ -169,7 +169,9 @@ ... TODO: Get rid of this template block and use the definition in ... lux/ffi.jvm.lux ASAP (template [<name> <class>] - [(def: .public <name> .Type {.#Primitive <class> {.#End}})] + [(def: .public <name> + .Type + {.#Primitive <class> {.#End}})] ... Boxes [Boolean box.boolean] @@ -206,7 +208,7 @@ (Record [#method .Type #deprecated? Bit - #exceptions (List .Type)])) + #throws (List .Type)])) (template [<name>] [(exception: .public (<name> [type .Type]) @@ -1749,6 +1751,27 @@ (<code>.tuple (<>.some ..class)) <code>.any))) +(type: .public (Method_Declaration a) + (Record + [#name Text + #annotations (List (Annotation a)) + #type_variables (List (Type Var)) + #exceptions (List (Type Class)) + #arguments (List (Type Value)) + #return (Type Return)])) + +(def: .public method_declaration + (Parser (Method_Declaration Code)) + (<code>.form + ($_ <>.and + <code>.text + (<code>.tuple (<>.some ..annotation)) + (<code>.tuple (<>.some ..var)) + (<code>.tuple (<>.some ..class)) + (<code>.tuple (<>.some ..type)) + ..return + ))) + (def: .public (analyse_virtual_method analyse archive selfT mapping method) (-> Phase Archive .Type Mapping (Virtual_Method Code) (Operation Analysis)) (let [[method_name visibility @@ -1982,7 +2005,7 @@ {/////analysis.#Case (/////analysis.unit) [[/////analysis.#when {/////analysis/pattern.#Complex - {/////analysis/composite.#Tuple + {/////analysis/complex.#Tuple (|> arity list.indices (list#each (|>> (n.+ 2) {/////analysis/pattern.#Bind})))}} diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/directive/jvm.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/directive/jvm.lux index b7693e24b..5442fafdb 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/directive/jvm.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/directive/jvm.lux @@ -7,8 +7,8 @@ [control [pipe {"+" case>}] ["<>" parser ("[1]#[0]" monad) - ["<c>" code {"+" Parser}] - ["<t>" text]]] + ["<[0]>" code {"+" Parser}] + ["<[0]>" text]]] [data ["[0]" product] [text @@ -16,7 +16,9 @@ [collection ["[0]" list ("[1]#[0]" functor mix)] ["[0]" dictionary] - ["[0]" sequence]]] + ["[0]" sequence]] + ["[0]" format "_" + ["[1]" binary]]] [macro ["[0]" template]] [math @@ -29,13 +31,14 @@ ["[0]" attribute] ["[0]" field] ["[0]" version] + ["[0]" method {"+" Method}] ["[0]" class] ["[0]" constant ["[0]" pool {"+" Resource}]] [encoding - ["[0]" name]] + ["[0]" name {"+" External}]] ["[0]" type {"+" Type Constraint Argument Typed} - [category {"+" Void Value Return Method Primitive Object Class Array Var Parameter}] + [category {"+" Void Value Return Primitive Object Class Array Var Parameter}] ["[0]T" lux {"+" Mapping}] ["[0]" signature] ["[0]" descriptor {"+" Descriptor}] @@ -44,7 +47,8 @@ [compiler ["[0]" phase] [meta - [archive {"+" Archive}]] + [archive {"+" Archive} + ["[0]" artifact]]] [language [lux ["[0]" analysis] @@ -56,7 +60,7 @@ ["[0]A" type]] [generation [jvm - [runtime {"+" Anchor Definition Extender}]]] + ["[0]" runtime {"+" Anchor Definition Extender}]]] ["[0]" extension ["[0]" bundle] [analysis @@ -76,13 +80,13 @@ (def: declaration (Parser Declaration) - (<c>.form (<>.and <c>.text (<>.some jvm.var)))) + (<code>.form (<>.and <code>.text (<>.some jvm.var)))) (def: visibility (Parser (Modifier field.Field)) (`` ($_ <>.either (~~ (template [<label> <modifier>] - [(<>.after (<c>.text! <label>) (<>#in <modifier>))] + [(<>.after (<code>.text! <label>) (<>#in <modifier>))] ["public" field.public] ["private" field.private] @@ -93,7 +97,7 @@ (Parser (Modifier class.Class)) (`` ($_ <>.either (~~ (template [<label> <modifier>] - [(<>.after (<c>.text! <label>) (<>#in <modifier>))] + [(<>.after (<code>.text! <label>) (<>#in <modifier>))] ["final" class.final] ["abstract" class.abstract] @@ -103,7 +107,7 @@ (Parser (Modifier field.Field)) (`` ($_ <>.either (~~ (template [<label> <modifier>] - [(<>.after (<c>.text! <label>) (<>#in <modifier>))] + [(<>.after (<code>.text! <label>) (<>#in <modifier>))] ["volatile" field.volatile] ["final" field.final] @@ -113,24 +117,24 @@ (def: annotation (Parser Annotation) - <c>.any) + <code>.any) (def: field_type (Parser (Type Value)) - (<t>.then parser.value <c>.text)) + (<text>.then parser.value <code>.text)) (type: Constant [Text (List Annotation) (Type Value) Code]) (def: constant (Parser Constant) - (<| <c>.form - (<>.after (<c>.text! "constant")) + (<| <code>.form + (<>.after (<code>.text! "constant")) ($_ <>.and - <c>.text - (<c>.tuple (<>.some ..annotation)) + <code>.text + (<code>.tuple (<>.some ..annotation)) ..field_type - <c>.any + <code>.any ))) (type: Variable @@ -138,13 +142,13 @@ (def: variable (Parser Variable) - (<| <c>.form - (<>.after (<c>.text! "variable")) + (<| <code>.form + (<>.after (<code>.text! "variable")) ($_ <>.and - <c>.text + <code>.text ..visibility ..state - (<c>.tuple (<>.some ..annotation)) + (<code>.tuple (<>.some ..annotation)) ..field_type ))) @@ -254,11 +258,11 @@ [($_ <>.and ..declaration jvm.class - (<c>.tuple (<>.some jvm.class)) + (<code>.tuple (<>.some jvm.class)) ..inheritance - (<c>.tuple (<>.some ..annotation)) - (<c>.tuple (<>.some ..field)) - (<c>.tuple (<>.some ..method))) + (<code>.tuple (<>.some ..annotation)) + (<code>.tuple (<>.some ..field)) + (<code>.tuple (<>.some ..method))) (function (_ extension phase archive [[name parameters] super_class @@ -304,9 +308,66 @@ ... (list) ... TODO: Add methods ... (sequence.sequence))])) _ (directive.lifted_generation - (generation.log! (format "Class " name)))] + (generation.log! (format "JVM Class " name)))] (in directive.no_requirements)))])) +(def: (method_declaration (^open "it[0]")) + (-> (jvm.Method_Declaration Code) (Resource Method)) + (let [type (type.method [it#type_variables it#arguments it#return it#exceptions])] + (method.method ($_ modifier#composite + method.public + method.abstract) + it#name + type + (list) + {.#None}))) + +(template [<name> <type> <parser>] + [(def: <name> + (Parser <type>) + (do [! <>.monad] + [raw <code>.text] + (<>.lifted (<text>.result <parser> raw))))] + + [class_declaration [External (List (Type Var))] parser.declaration'] + ) + +(def: jvm::class::interface + (Handler Anchor (Bytecode Any) Definition) + (/.custom + [($_ <>.and + ..class_declaration + (<code>.tuple (<>.some jvm.class)) + (<code>.tuple (<>.some ..annotation)) + (<>.some jvm.method_declaration)) + (function (_ extension_name phase archive [[name parameters] supers annotations method_declarations]) + (directive.lifted_generation + (do [! phase.monad] + [bytecode (<| (# ! each (format.result class.writer)) + phase.lifted + (class.class version.v6_0 + ($_ modifier#composite + class.public + class.abstract + class.interface) + (name.internal name) + (name.internal "java.lang.Object") + (list#each (|>> parser.read_class product.left name.internal) + supers) + (list) + (list#each ..method_declaration method_declarations) + (sequence.sequence))) + ... module generation.module + ... module_id (generation.module_id module archive) + artifact_id (generation.learn_custom name artifact.no_dependencies) + .let [artifact [name + ... (runtime.class_name [module_id artifact_id]) + bytecode]] + _ (generation.execute! artifact) + _ (generation.save! artifact_id {.#Some name} artifact) + _ (generation.log! (format "JVM Interface " (%.text name)))] + (in directive.no_requirements))))])) + (import: java/lang/ClassLoader) (def: .public (bundle class_loader extender) @@ -315,4 +376,5 @@ (|> bundle.empty ... TODO: Finish handling methods and un-comment. ... (dictionary.has "class" jvm::class) + (dictionary.has "class interface" ..jvm::class::interface) ))) diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/jvm/case.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/jvm/case.lux index c166c3aed..ffd226015 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/jvm/case.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/jvm/case.lux @@ -324,4 +324,5 @@ value! //runtime.push path! - (_.set_label @end))))) + (<| (_.when_acknowledged @end) + (_.set_label @end)))))) diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/jvm/structure.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/jvm/structure.lux index e7cfad2c2..4b0b2c145 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/jvm/structure.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/jvm/structure.lux @@ -24,7 +24,7 @@ ["///[1]" //// "_" ["[1][0]" synthesis {"+" Synthesis}] [analysis - [composite {"+" Variant Tuple}]] + [complex {"+" Variant Tuple}]] [/// ["[0]" phase]]]]) diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/ruby/runtime.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/ruby/runtime.lux index d82d5e7ba..bccbf9fff 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/ruby/runtime.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/ruby/runtime.lux @@ -82,12 +82,17 @@ (def: module_id 0) +(def: $Numeric + !.CVar + (_.manual "Numeric")) + (def: mruby? _.Expression - (_.and (_.not (_.do "method_defined?" (list (_.string "remainder")) {.#None} - (_.local "Numeric"))) - (_.do "method_defined?" (list (_.string "remainder_of_divide")) {.#None} - (_.local "Numeric")))) + (_.and (|> $Numeric + (_.do "method_defined?" (list (_.string "remainder")) {.#None}) + _.not) + (|> $Numeric + (_.do "method_defined?" (list (_.string "remainder_of_divide")) {.#None})))) (def: normal_ruby? _.Expression @@ -107,8 +112,8 @@ (case declaration {.#Left name} (macro.with_symbols [g!_] - (let [runtime (code.local_symbol (format "C" (///reference.artifact [..module_id runtime_id]))) - runtime_name (` (_.local (~ (code.text (%.code runtime))))) + (let [runtime (code.local_symbol (///reference.artifact [..module_id runtime_id])) + runtime_name (` (_.constant (~ (code.text (%.code runtime))))) g!name (code.local_symbol name)] (in (list (` (def: .public (~ g!name) LVar (~ runtime_name))) (` (def: (~ (code.local_symbol (format "@" name))) @@ -602,7 +607,7 @@ (_.statement (_.alias_method/2 (_.string "remainder") (_.string "remainder_of_divide")))]} - (_.local "Numeric")))) + $Numeric))) runtime//adt runtime//lux runtime//i64 diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/synthesis.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/synthesis.lux index 7edfdb599..428e3438c 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/synthesis.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/synthesis.lux @@ -20,7 +20,7 @@ ["/" synthesis {"+" Synthesis Phase}] ["[1][0]" analysis {"+" Analysis} ["[2][0]" simple] - ["[2][0]" composite]] + ["[2][0]" complex]] [/// ["[0]" phase ("[1]#[0]" monad)] [reference {"+"} @@ -59,12 +59,12 @@ {///analysis.#Structure structure} (/.with_currying? false (case structure - {///composite.#Variant variant} + {///complex.#Variant variant} (do phase.monad - [valueS (optimization' (value@ ///composite.#value variant))] - (in (/.variant (with@ ///composite.#value valueS variant)))) + [valueS (optimization' (value@ ///complex.#value variant))] + (in (/.variant (with@ ///complex.#value valueS variant)))) - {///composite.#Tuple tuple} + {///complex.#Tuple tuple} (|> tuple (monad.each phase.monad optimization') (phase#each (|>> /.tuple))))) diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/synthesis/case.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/synthesis/case.lux index 89d432d68..c4e0c5fad 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/synthesis/case.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/synthesis/case.lux @@ -23,7 +23,7 @@ ["/" synthesis {"+" Path Synthesis Operation Phase}] ["[1][0]" analysis {"+" Match Analysis} ["[2][0]" simple] - ["[2][0]" composite] + ["[2][0]" complex] ["[2][0]" pattern {"+" Pattern}]] [/// ["[1]" phase ("[1]#[0]" monad)] @@ -65,7 +65,7 @@ /.with_new_local thenC) - {///pattern.#Complex {///composite.#Variant [lefts right? value_pattern]}} + {///pattern.#Complex {///complex.#Variant [lefts right? value_pattern]}} (<| (///#each (|>> {/.#Seq {/.#Access {/.#Side (if right? {.#Right lefts} {.#Left lefts})}}})) @@ -73,7 +73,7 @@ (when> [(new> (not end?) [])] [(///#each ..clean_up)]) thenC) - {///pattern.#Complex {///composite.#Tuple tuple}} + {///pattern.#Complex {///complex.#Tuple tuple}} (let [tuple::last (-- (list.size tuple))] (list#mix (function (_ [tuple::lefts tuple::member] nextC) (.case tuple::member @@ -194,7 +194,7 @@ <default>))) (def: (get patterns @selection) - (-> (///composite.Tuple Pattern) Register (List /.Member)) + (-> (///complex.Tuple Pattern) Register (List /.Member)) (loop [lefts 0 patterns patterns] (with_expansions [<failure> (as_is (list)) @@ -217,7 +217,7 @@ (list <member>) <continue>) - {///pattern.#Complex {///composite.#Tuple sub_patterns}} + {///pattern.#Complex {///complex.#Tuple sub_patterns}} (case (get sub_patterns @selection) {.#End} <continue> @@ -266,7 +266,7 @@ (.list)]]) (def: .public (synthesize_get synthesize archive input patterns @member) - (-> Phase Archive Synthesis (///composite.Tuple Pattern) Register (Operation Synthesis)) + (-> Phase Archive Synthesis (///complex.Tuple Pattern) Register (Operation Synthesis)) (case (..get patterns @member) {.#End} (..synthesize_case synthesize archive input (!get patterns @member)) diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/synthesis/function.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/synthesis/function.lux index 5e171165e..d7fa84bfd 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/synthesis/function.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/synthesis/function.lux @@ -20,7 +20,7 @@ ["[1][0]" loop {"+" Transform}] ["//[1]" /// "_" ["[1][0]" analysis {"+" Environment Analysis} - ["[1]/[0]" composite]] + ["[1]/[0]" complex]] ["/" synthesis {"+" Path Abstraction Synthesis Operation Phase}] [/// [arity {"+" Arity}] @@ -144,12 +144,12 @@ (case expression {/.#Structure structure} (case structure - {////analysis/composite.#Variant [lefts right? subS]} + {////analysis/complex.#Variant [lefts right? subS]} (|> subS (grow environment) (phase#each (|>> [lefts right?] /.variant))) - {////analysis/composite.#Tuple membersS+} + {////analysis/complex.#Tuple membersS+} (|> membersS+ (monad.each phase.monad (grow environment)) (phase#each (|>> /.tuple)))) diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/synthesis/loop.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/synthesis/loop.lux index eea8ea951..080bc436c 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/synthesis/loop.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/synthesis/loop.lux @@ -13,7 +13,7 @@ ["n" nat]]]]] [//// ["[0]" analysis {"+" Environment} - ["[1]/[0]" composite]] + ["[1]/[0]" complex]] ["/" synthesis {"+" Path Abstraction Synthesis}] [/// [arity {"+" Arity}] @@ -85,14 +85,14 @@ {/.#Structure structure} (case structure - {analysis/composite.#Variant variant} + {analysis/complex.#Variant variant} (do maybe.monad - [value' (|> variant (value@ analysis/composite.#value) (again false))] + [value' (|> variant (value@ analysis/complex.#value) (again false))] (in (|> variant - (with@ analysis/composite.#value value') + (with@ analysis/complex.#value value') /.variant))) - {analysis/composite.#Tuple tuple} + {analysis/complex.#Tuple tuple} (|> tuple (monad.each maybe.monad (again false)) (maybe#each (|>> /.tuple)))) @@ -191,11 +191,11 @@ matches (monad.each ! (function (_ match) (case match - (^ {/.#Structure {analysis/composite.#Tuple (list when then)}}) + (^ {/.#Structure {analysis/complex.#Tuple (list when then)}}) (do ! [when (again false when) then (again return? then)] - (in {/.#Structure {analysis/composite.#Tuple (list when then)}})) + (in {/.#Structure {analysis/complex.#Tuple (list when then)}})) _ (again false match))) diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/synthesis/variable.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/synthesis/variable.lux index 0389a03af..2d9e8ce5c 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/synthesis/variable.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/synthesis/variable.lux @@ -21,7 +21,7 @@ [//// ["/" synthesis {"+" Path Synthesis}] ["[0]" analysis - ["[1]/[0]" composite]] + ["[1]/[0]" complex]] [/// [arity {"+" Arity}] ["[0]" reference @@ -113,11 +113,11 @@ {/.#Structure structure} {/.#Structure (case structure - {analysis/composite.#Variant [lefts right value]} - {analysis/composite.#Variant [lefts right (again value)]} + {analysis/complex.#Variant [lefts right value]} + {analysis/complex.#Variant [lefts right (again value)]} - {analysis/composite.#Tuple tuple} - {analysis/composite.#Tuple (list#each again tuple)})} + {analysis/complex.#Tuple tuple} + {analysis/complex.#Tuple (list#each again tuple)})} {/.#Reference reference} (case reference @@ -336,17 +336,17 @@ {/.#Structure structure} (case structure - {analysis/composite.#Variant [lefts right value]} + {analysis/complex.#Variant [lefts right value]} (do try.monad [[redundancy value] (optimization' [redundancy value])] (in [redundancy - {/.#Structure {analysis/composite.#Variant [lefts right value]}}])) + {/.#Structure {analysis/complex.#Variant [lefts right value]}}])) - {analysis/composite.#Tuple tuple} + {analysis/complex.#Tuple tuple} (do try.monad [[redundancy tuple] (..list_optimization optimization' [redundancy tuple])] (in [redundancy - {/.#Structure {analysis/composite.#Tuple tuple}}]))) + {/.#Structure {analysis/complex.#Tuple tuple}}]))) {/.#Reference reference} (case reference diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/synthesis.lux b/stdlib/source/library/lux/tool/compiler/language/lux/synthesis.lux index 2bd2bd22e..f2b061315 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/synthesis.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/synthesis.lux @@ -26,7 +26,7 @@ ["f" frac]]]]] [// ["[0]" analysis {"+" Environment Analysis} - ["[1]/[0]" composite {"+" Composite}]] + ["[1]/[0]" complex {"+" Complex}]] [phase ["[0]" extension {"+" Extension}]] [/// @@ -132,7 +132,7 @@ (Rec Synthesis (Variant {#Primitive Primitive} - {#Structure (Composite Synthesis)} + {#Structure (Complex Synthesis)} {#Reference Reference} {#Control (Control Synthesis)} {#Extension (Extension Synthesis)}))) @@ -239,8 +239,8 @@ {<tag>} content)])] - [variant analysis/composite.#Variant] - [tuple analysis/composite.#Tuple] + [variant analysis/complex.#Variant] + [tuple analysis/complex.#Tuple] ) (template [<name> <tag>] @@ -351,12 +351,12 @@ {#Structure structure} (case structure - {analysis/composite.#Variant [lefts right? content]} + {analysis/complex.#Variant [lefts right? content]} (|> (%synthesis content) (format (%.nat lefts) " " (%.bit right?) " ") (text.enclosed ["{" "}"])) - {analysis/composite.#Tuple members} + {analysis/complex.#Tuple members} (|> members (list#each %synthesis) (text.interposed " ") @@ -776,7 +776,7 @@ [[{<tag> reference'} {<tag> sample'}] (# <equivalence> = reference' sample')]) ([#Primitive ..primitive_equivalence] - [#Structure (analysis/composite.equivalence =)] + [#Structure (analysis/complex.equivalence =)] [#Reference reference.equivalence] [#Control (control_equivalence =)] [#Extension (extension.equivalence =)]) @@ -800,7 +800,7 @@ [{<tag> value} (# <hash> hash value)]) ([#Primitive ..primitive_hash] - [#Structure (analysis/composite.hash again_hash)] + [#Structure (analysis/complex.hash again_hash)] [#Reference reference.hash] [#Control (..control_hash again_hash)] [#Extension (extension.hash again_hash)]))))) diff --git a/stdlib/source/library/lux/tool/compiler/meta/archive/dependency.lux b/stdlib/source/library/lux/tool/compiler/meta/archive/dependency.lux index 0962b5b61..1e6613015 100644 --- a/stdlib/source/library/lux/tool/compiler/meta/archive/dependency.lux +++ b/stdlib/source/library/lux/tool/compiler/meta/archive/dependency.lux @@ -24,7 +24,7 @@ [language [lux ["[0]" analysis - ["[1]/[0]" composite]] + ["[1]/[0]" complex]] ["[0]" synthesis {"+" Synthesis Path}] ["[0]" generation {"+" Context Operation}]]] [meta @@ -81,12 +81,12 @@ {synthesis.#Structure value} (case value - {analysis/composite.#Variant value} + {analysis/complex.#Variant value} (|> value - (value@ analysis/composite.#value) + (value@ analysis/complex.#value) references) - {analysis/composite.#Tuple value} + {analysis/complex.#Tuple value} (|> value (list#each references) list#conjoint)) |