diff options
Diffstat (limited to '')
35 files changed, 1071 insertions, 384 deletions
diff --git a/stdlib/source/documentation/lux/tool/compiler/language/lux/analysis.lux b/stdlib/source/documentation/lux/tool/compiler/language/lux/analysis.lux index 92f6991ab..153ed2a11 100644 --- a/stdlib/source/documentation/lux/tool/compiler/language/lux/analysis.lux +++ b/stdlib/source/documentation/lux/tool/compiler/language/lux/analysis.lux @@ -31,7 +31,7 @@ ($.default /.composite_equivalence) ($.default /.composite_hash) ($.default /.equivalence) - ($.default /.control/case) + ($.default /.case) ($.default /.unit) ($.default /.bit) ($.default /.nat) @@ -60,7 +60,7 @@ ($.default /.pattern/frac) ($.default /.pattern/text) ($.default /.pattern/bind) - ($.default /.%analysis) + ($.default /.format) ($.default /.State+) ($.default /.Operation) ($.default /.Phase) diff --git a/stdlib/source/library/lux.lux b/stdlib/source/library/lux.lux index 9655f0afa..4ae552aba 100644 --- a/stdlib/source/library/lux.lux +++ b/stdlib/source/library/lux.lux @@ -2079,42 +2079,98 @@ (in_meta (list token))} token)) -(def:''' .private (full_expansion syntax) - (-> Code ($' Meta ($' List Code))) - ({[_ {#Form {#Item [_ {#Symbol name}] args}}] - (do meta_monad - [name' (normal name) - ?macro (macro' name')] - ({{#Some macro} - (do meta_monad - [expansion (("lux type as" Macro' macro) args) - expansion' (monad#each meta_monad full_expansion expansion)] - (in (list#conjoint expansion'))) - - {#None} - (do meta_monad - [args' (monad#each meta_monad full_expansion args)] - (in (list (form$ {#Item (symbol$ name) (list#conjoint args')}))))} - ?macro)) +(def:''' .private (full_expansion' full_expansion name args) + (-> (-> Code ($' Meta ($' List Code))) Symbol ($' List Code) ($' Meta ($' List Code))) + (do meta_monad + [name' (normal name) + ?macro (macro' name')] + ({{#Some macro} + (do meta_monad + [expansion (("lux type as" Macro' macro) args) + expansion' (monad#each meta_monad full_expansion expansion)] + (in (list#conjoint expansion'))) + + {#None} + (do meta_monad + [args' (monad#each meta_monad full_expansion args)] + (in (list (form$ {#Item (symbol$ name) (list#conjoint args')}))))} + ?macro))) - [_ {#Form members}] - (do meta_monad - [members' (monad#each meta_monad full_expansion members)] - (in (list (form$ (list#conjoint members'))))) +(def:''' .private (in_module module meta) + (All (_ a) + (-> Text ($' Meta a) ($' Meta a))) + (function' [lux] + ({[..#info info ..#source source + ..#current_module current_module ..#modules modules + ..#scopes scopes ..#type_context type_context + ..#host host ..#seed seed + ..#expected expected ..#location location + ..#extensions extensions ..#scope_type_vars scope_type_vars + ..#eval eval] + ({{#Left error} + {#Left error} + + {#Right [[..#info info' ..#source source' + ..#current_module _ ..#modules modules' + ..#scopes scopes' ..#type_context type_context' + ..#host host' ..#seed seed' + ..#expected expected' ..#location location' + ..#extensions extensions' ..#scope_type_vars scope_type_vars' + ..#eval eval'] + output]} + {#Right [[..#info info' ..#source source' + ..#current_module current_module ..#modules modules' + ..#scopes scopes' ..#type_context type_context' + ..#host host' ..#seed seed' + ..#expected expected' ..#location location' + ..#extensions extensions' ..#scope_type_vars scope_type_vars' + ..#eval eval'] + output]}} + (meta [..#info info ..#source source + ..#current_module {.#Some module} ..#modules modules + ..#scopes scopes ..#type_context type_context + ..#host host ..#seed seed + ..#expected expected ..#location location + ..#extensions extensions ..#scope_type_vars scope_type_vars + ..#eval eval]))} + lux))) + +(def:''' .private (full_expansion expand_in_module?) + (-> Bit Code ($' Meta ($' List Code))) + (function' again [syntax] + ({[_ {#Form {#Item head tail}}] + ({[_ {#Form {#Item [_ {#Text "lux in-module"}] + {#Item [_ {#Text module}] + {#Item [_ {#Symbol name}] + {#End}}}}}] + (if expand_in_module? + (..in_module module (..full_expansion' again name tail)) + (do meta_monad + [members' (monad#each meta_monad again {#Item head tail})] + (in (list (form$ (list#conjoint members')))))) + + [_ {#Symbol name}] + (..full_expansion' again name tail) - [_ {#Variant members}] - (do meta_monad - [members' (monad#each meta_monad full_expansion members)] - (in (list (variant$ (list#conjoint members'))))) + _ + (do meta_monad + [members' (monad#each meta_monad again {#Item head tail})] + (in (list (form$ (list#conjoint members')))))} + head) - [_ {#Tuple members}] - (do meta_monad - [members' (monad#each meta_monad full_expansion members)] - (in (list (tuple$ (list#conjoint members'))))) + [_ {#Variant members}] + (do meta_monad + [members' (monad#each meta_monad again members)] + (in (list (variant$ (list#conjoint members'))))) - _ - (in_meta (list syntax))} - syntax)) + [_ {#Tuple members}] + (do meta_monad + [members' (monad#each meta_monad again members)] + (in (list (tuple$ (list#conjoint members'))))) + + _ + (in_meta (list syntax))} + syntax))) (def:''' .private (text#encoded original) (-> Text Text) @@ -2218,7 +2274,7 @@ [initialized_quantification? (function' [lux] {#Right [lux (initialized_quantification? lux)]})] (if initialized_quantification? (do meta_monad - [type+ (full_expansion type)] + [type+ (full_expansion #0 type)] ({{#Item type' {#End}} (in (list (normal_type type'))) @@ -2381,7 +2437,7 @@ (case tokens {#Item [_ {#Form {#Item pattern {#End}}}] {#Item body branches}} (do meta_monad - [pattern+ (full_expansion pattern)] + [pattern+ (full_expansion #1 pattern)] (case pattern+ {#Item pattern' {#End}} (in (list& pattern' body branches)) diff --git a/stdlib/source/library/lux/control/parser/analysis.lux b/stdlib/source/library/lux/control/parser/analysis.lux index 73889de68..fbe5f943c 100644 --- a/stdlib/source/library/lux/control/parser/analysis.lux +++ b/stdlib/source/library/lux/control/parser/analysis.lux @@ -30,24 +30,23 @@ [variable {"+" }]] [language [lux - ["/" analysis {"+" Environment Analysis} - ["[1][0]" composite]]]]]]]] + ["/" analysis {"+" Environment Analysis}]]]]]]] ["[0]" //]) (def: (remaining_inputs asts) (-> (List Analysis) Text) (format text.new_line "Remaining input: " (|> asts - (list#each /.%analysis) + (list#each /.format) (text.interposed " ")))) (exception: .public (cannot_parse [input (List Analysis)]) (exception.report - ["Input" (exception.listing /.%analysis input)])) + ["Input" (exception.listing /.format input)])) (exception: .public (unconsumed_input [input (List Analysis)]) (exception.report - ["Input" (exception.listing /.%analysis input)])) + ["Input" (exception.listing /.format input)])) (type: .public Parser (//.Parser (List Analysis))) diff --git a/stdlib/source/library/lux/data/text/escape.lux b/stdlib/source/library/lux/data/text/escape.lux index d3bfa17b0..c30343aac 100644 --- a/stdlib/source/library/lux/data/text/escape.lux +++ b/stdlib/source/library/lux/data/text/escape.lux @@ -1,23 +1,23 @@ (.using - [library - [lux "*" - ["[0]" meta] - [abstract - [monad {"+" do}]] - [control - ["[0]" maybe] - ["[0]" try {"+" Try}] - ["[0]" exception {"+" exception:}] - ["<>" parser - ["<[0]>" code]]] - [math - [number {"+" hex} - ["n" nat]]] - [macro - [syntax {"+" syntax:}] - ["[0]" code]]]] - ["[0]" // {"+" Char} - ["%" format {"+" format}]]) + [library + [lux "*" + ["[0]" meta] + [abstract + [monad {"+" do}]] + [control + ["[0]" maybe] + ["[0]" try {"+" Try}] + ["[0]" exception {"+" exception:}] + ["<>" parser + ["<[0]>" code]]] + [math + [number {"+" hex} + ["n" nat]]] + [macro + [syntax {"+" syntax:}] + ["[0]" code]]]] + ["[0]" // {"+" Char} + ["%" format {"+" format}]]) (def: sigil "\") diff --git a/stdlib/source/library/lux/target/ruby.lux b/stdlib/source/library/lux/target/ruby.lux index eb3c30c2f..1d96e72ff 100644 --- a/stdlib/source/library/lux/target/ruby.lux +++ b/stdlib/source/library/lux/target/ruby.lux @@ -77,6 +77,7 @@ [Literal [Computation' Expression' Code]] [Access [Location' Computation' Expression' Code]] + [CVar [Var' Location' Computation' Expression' Code]] [GVar [Var' Location' Computation' Expression' Code]] [IVar [Var' Location' Computation' Expression' Code]] [SVar [Var' Location' Computation' Expression' Code]] @@ -89,15 +90,13 @@ (-> Text <var>) (|>> (format <prefix>) :abstraction))] + [LVar "l_" local] + [CVar "C_" constant] [GVar "$" global] [IVar "@" instance] [SVar "@@" static] ) - (def: .public local - (-> Text LVar) - (|>> :abstraction)) - (template [<var> <prefix> <modifier> <unpacker>] [(template [<name> <input> <output>] [(def: .public <name> @@ -133,7 +132,8 @@ (template [<ruby_name> <lux_name>] [(def: .public <lux_name> - (..local <ruby_name>))] + CVar + (..manual <ruby_name>))] ["ARGV" command_line_arguments] ) @@ -367,6 +367,10 @@ [break "break"] ) + (def: .public initialize + LVar + (..manual "initialize")) + (def: .public (function name args body!) (-> LVar (List LVar) Statement Statement) (<| :abstraction @@ -433,27 +437,34 @@ (:abstraction (format "# " (..safe commentary) \n+ (:representation on)))) - (def: .public (class name definition) - (-> LVar Statement Statement) - (:abstraction - (format "class " (:representation name) - (control_structure - (nested - (:representation definition)))))) - - (def: .public (attribute_readers attributes) - (-> (List Text) Statement) - (..statement - (..apply/* (list#each ..string attributes) {.#None} (..local "attr_reader")))) + (template [<name>] + [(`` (def: .public ((~~ (template.symbol [<name> "/*"])) attributes) + (-> (List Text) Statement) + (..statement + (..apply/* (list#each ..string attributes) {.#None} (..manual <name>)))))] + + ["attr_reader"] + ["attr_writer"] + ["attr_accessor"]) ) (def: .public (do method arguments block object) (-> Text (List Expression) (Maybe Block) Expression Computation) (|> object (..the method) (..apply/* arguments block))) +(def: .public new + (-> (List Expression) (Maybe Block) Expression Computation) + (..do "new")) + +(def: .public (class definition) + (-> Block Computation) + (|> (..manual "Class") + (..new (list) {.#Some definition}))) + (def: .public (apply_lambda/* args lambda) (-> (List Expression) Expression Computation) - (..do "call" args {.#None} lambda)) + (|> lambda + (..do "call" args {.#None}))) (syntax: (arity_inputs [arity <code>.nat]) (in (case arity @@ -473,7 +484,7 @@ (template [<function>] [(`` (def: .public ((~~ (template.symbol [<function> "/" <arity>])) <inputs>) (-> <types> Computation) - (..apply/* (.list <inputs>) {.#None} (..local <function>))))] + (..apply/* (.list <inputs>) {.#None} (..manual <function>))))] <definitions>))] @@ -490,8 +501,8 @@ (def: .public (throw/1 error) (-> Expression Statement) - (..statement (..apply/* (list error) {.#None} (..local "throw")))) + (..statement (..apply/* (list error) {.#None} (..manual "throw")))) (def: .public (throw/2 tag value) (-> Expression Expression Statement) - (..statement (..apply/* (list tag value) {.#None} (..local "throw")))) + (..statement (..apply/* (list tag value) {.#None} (..manual "throw")))) 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)) diff --git a/stdlib/source/test/lux/data.lux b/stdlib/source/test/lux/data.lux index 40112aeb9..631a72b76 100644 --- a/stdlib/source/test/lux/data.lux +++ b/stdlib/source/test/lux/data.lux @@ -1,26 +1,26 @@ (.using - [library - [lux "*" - ["_" test {"+" Test}] - [abstract - [monad {"+" do}]] - [math - ["[0]" random]]]] - ["[0]" / "_" - ["[1][0]" binary] - ["[1][0]" bit] - ["[1][0]" color - ["[1]/[0]" named]] - ["[1][0]" identity] - ["[1][0]" product] - ["[1][0]" sum] - ["[1][0]" text] - ["[1][0]" format "_" - ["[1]/[0]" binary] - ["[1]/[0]" json] - ["[1]/[0]" tar] - ["[1]/[0]" xml]] - ["[1][0]" collection]]) + [library + [lux "*" + ["_" test {"+" Test}] + [abstract + [monad {"+" do}]] + [math + ["[0]" random]]]] + ["[0]" / "_" + ["[1][0]" binary] + ["[1][0]" bit] + ["[1][0]" color + ["[1]/[0]" named]] + ["[1][0]" identity] + ["[1][0]" product] + ["[1][0]" sum] + ["[1][0]" text] + ["[1][0]" format "_" + ["[1]/[0]" binary] + ["[1]/[0]" json] + ["[1]/[0]" tar] + ["[1]/[0]" xml]] + ["[1][0]" collection]]) ... TODO: Get rid of this ASAP (template: (!bundle body) diff --git a/stdlib/source/test/lux/data/text/escape.lux b/stdlib/source/test/lux/data/text/escape.lux index 7a55f2594..6abb32e94 100644 --- a/stdlib/source/test/lux/data/text/escape.lux +++ b/stdlib/source/test/lux/data/text/escape.lux @@ -1,35 +1,35 @@ (.using - [library - [lux "*" - ["_" test {"+" Test}] - ["[0]" debug] - ["[0]" meta] - [abstract - [monad {"+" do}]] - [control - ["[0]" try] - ["[0]" exception] - [parser - ["<[0]>" code]]] - [data - ["[0]" bit ("[1]#[0]" equivalence)] - ["[0]" text {"+" Char} ("[1]#[0]" equivalence) - ["%" format {"+" format}]] - [collection - ["[0]" set {"+" Set}]]] - [macro - [syntax {"+" syntax:}] - ["[0]" code] - ["[0]" template]] - [math - ["[0]" random {"+" Random}] - [number {"+" hex} - ["n" nat]]]]] - [\\library - ["[0]" / - [// - ["[0]" unicode "_" - ["[1]" set]]]]]) + [library + [lux "*" + ["_" test {"+" Test}] + ["[0]" debug] + ["[0]" meta] + [abstract + [monad {"+" do}]] + [control + ["[0]" try] + ["[0]" exception] + [parser + ["<[0]>" code]]] + [data + ["[0]" bit ("[1]#[0]" equivalence)] + ["[0]" text {"+" Char} ("[1]#[0]" equivalence) + ["%" format {"+" format}]] + [collection + ["[0]" set {"+" Set}]]] + [macro + [syntax {"+" syntax:}] + ["[0]" code] + ["[0]" template]] + [math + ["[0]" random {"+" Random}] + [number {"+" hex} + ["n" nat]]]]] + [\\library + ["[0]" / + [// + ["[0]" unicode "_" + ["[1]" set]]]]]) (def: (range max min) (-> Char Char (Random Char)) diff --git a/stdlib/source/test/lux/target/ruby.lux b/stdlib/source/test/lux/target/ruby.lux index 5e2cecbde..2a2f9667d 100644 --- a/stdlib/source/test/lux/target/ruby.lux +++ b/stdlib/source/test/lux/target/ruby.lux @@ -230,7 +230,21 @@ (do [! random.monad] [size (# ! each (|>> (n.% 10) ++) random.nat) index (# ! each (n.% size) random.nat) - items (random.list size random.safe_frac)] + items (random.list size random.safe_frac) + $class (# ! each (|>> %.nat (format "class_") /.local) + random.nat) + $method/0 (# ! each (|>> %.nat (format "method_") /.local) + random.nat) + $method/1 (|> random.nat + (# ! each (|>> %.nat (format "method_") /.local)) + (random.only (|>> (# /.equivalence = $method/0) not))) + $arg/0 (# ! each (|>> %.nat (format "arg_") /.local) + random.nat) + $state (# ! each (|>> %.nat (format "instance_") /.instance) + random.nat) + single random.safe_frac + .let [double (/.function $method/0 (list $arg/0) + (/.return (/.+ $arg/0 $arg/0)))]] ($_ _.and (_.cover [/.the] (expression (|>> (:as Int) (i.= (.int size))) @@ -243,6 +257,44 @@ (|>> (:as Frac) (f.= expected))) (|> (/.array (list#each /.float items)) (/.do "at" (list (/.int (.int index))) {.#None})))) + (_.cover [/.class] + (expression (|>> (:as Frac) (f.= (f.+ single single))) + (|> ($_ /.then + (/.set (list $class) (/.class [/.#parameters (list) + /.#body double])) + (/.return (|> $class + (/.new (list) {.#None}) + (/.do (/.code $method/0) (list (/.float single)) {.#None})))) + [(list)] (/.lambda {.#None}) + (/.apply_lambda/* (list))))) + (_.cover [/.new /.initialize] + (expression (|>> (:as Frac) (f.= single)) + (|> ($_ /.then + (/.set (list $class) (/.class [/.#parameters (list) + /.#body ($_ /.then + (/.function /.initialize (list $arg/0) + (/.set (list $state) $arg/0)) + (/.function $method/0 (list) + (/.return $state)) + )])) + (/.return (|> $class + (/.new (list (/.float single)) {.#None}) + (/.do (/.code $method/0) (list) {.#None})))) + [(list)] (/.lambda {.#None}) + (/.apply_lambda/* (list))))) + (_.cover [/.alias_method/2] + (expression (|>> (:as Frac) (f.= (f.+ single single))) + (|> ($_ /.then + (/.set (list $class) (/.class [/.#parameters (list) + /.#body ($_ /.then + double + (/.statement (/.alias_method/2 (/.string (/.code $method/1)) + (/.string (/.code $method/0)))))])) + (/.return (|> $class + (/.new (list) {.#None}) + (/.do (/.code $method/1) (list (/.float single)) {.#None})))) + [(list)] (/.lambda {.#None}) + (/.apply_lambda/* (list))))) ))) (def: test|computation @@ -306,6 +358,16 @@ ($_ _.and (<| (_.for [/.Var]) ($_ _.and + (_.cover [/.defined?/1] + (and (expression (|>> (:as Bit)) + (|> (/.defined?/1 $foreign) + (/.= /.nil))) + (expression (|>> (:as Text) (text#= "local-variable")) + (|> ($_ /.then + (/.set (list $foreign) (/.float float/0)) + (/.return (/.defined?/1 $foreign))) + [(list)] (/.lambda {.#None}) + (/.apply_lambda/* (list)))))) (_.cover [/.LVar /.local /.set] (expression (|>> (:as Frac) (f.= (f.+ float/0 float/0))) (|> ($_ /.then @@ -534,7 +596,7 @@ (/.statement (/.raise (/.string error))) (/.return (/.float dummy))) (list [(list) $ex (/.return ($_ /.and - (/.do "kind_of?" (list (/.local "Array")) {.#None} /.latest_error_location) + (/.do "kind_of?" (list (: /.CVar (/.manual "Array"))) {.#None} /.latest_error_location) (/.> (/.int +0) (/.the "length" /.latest_error_location))))])) [(list)] (/.lambda {.#None}) (/.apply_lambda/* (list)))))) @@ -652,7 +714,7 @@ [(list $arg/0 $arg/1)] (/.lambda {.#None}) (/.apply_lambda/* (list (/.float float/0) (/.float float/1)))))) (_.cover [/.require/1] - (let [$JSON (/.local "JSON")] + (let [$JSON (: /.CVar (/.manual "JSON"))] (expression (|>> (:as Text) (text#= expected)) (|> ($_ /.then (/.statement (/.require/1 (/.string "json"))) diff --git a/stdlib/source/test/lux/tool.lux b/stdlib/source/test/lux/tool.lux index 6dc3eabd9..635322a92 100644 --- a/stdlib/source/test/lux/tool.lux +++ b/stdlib/source/test/lux/tool.lux @@ -11,10 +11,7 @@ [language [lux ... ["[1][0]" syntax] - ["[1][0]" analysis "_" - ["[1]/[0]" simple] - ["[1]/[0]" composite] - ["[1]/[0]" pattern]] + ["[1][0]" analysis] ["[1][0]" phase "_" ["[1]/[0]" extension] ... ["[1]/[0]" analysis] @@ -35,9 +32,7 @@ /version.test /reference.test /phase.test - /analysis/simple.test - /analysis/composite.test - /analysis/pattern.test + /analysis.test /meta/archive/artifact.test /meta/archive/signature.test /meta/archive/key.test diff --git a/stdlib/source/test/lux/tool/compiler/language/lux/analysis.lux b/stdlib/source/test/lux/tool/compiler/language/lux/analysis.lux new file mode 100644 index 000000000..210d6d29a --- /dev/null +++ b/stdlib/source/test/lux/tool/compiler/language/lux/analysis.lux @@ -0,0 +1,439 @@ +(.using + [library + [lux "*" + ["_" test {"+" Test}] + ["[0]" static] + [abstract + [monad {"+" do}] + [\\specification + ["$[0]" equivalence]]] + [control + [pipe {"+" case>}] + ["[0]" maybe] + ["[0]" try] + ["[0]" exception {"+" exception:}]] + [data + ["[0]" bit ("[1]#[0]" equivalence)] + ["[0]" text ("[1]#[0]" equivalence)] + [collection + ["[0]" list]]] + [macro + ["[0]" template]] + [math + ["[0]" random {"+" Random} ("[1]#[0]" monad)] + [number + ["f" frac]]]]] + ["[0]" / "_" + ["[1][0]" simple] + ["[1][0]" complex] + ["[1][0]" pattern] + [//// + ["[1][0]" reference + ["[2][0]" variable]] + [/// + [meta + ["[1][0]" symbol] + ["[0]" location "_" + ["[2][1]" /] + ["[1]" \\library ("[1]#[0]" equivalence)]]]]]] + [\\library + ["[0]" / + [// + [phase + ["[0]" extension]] + [/// + ["[0]" phase] + ["[0]" version]]]]]) + +(def: (random_branch random) + (All (_ a) (-> (Random a) (Random (/.Branch' a)))) + ($_ random.and + /pattern.random + random + )) + +(def: (random_match multiplicity random) + (All (_ a) (-> Nat (Random a) (Random (/.Match' a)))) + ($_ random.and + (..random_branch random) + (random.list multiplicity (..random_branch random)) + )) + +(def: .public (random multiplicity) + (-> Nat (Random /.Analysis)) + (<| random.rec + (function (_ random)) + (let [random|case ($_ random.and + random + (..random_match multiplicity random) + ) + random|function ($_ random.and + (random.list multiplicity random) + random + ) + random|apply ($_ random.and + random + random + ) + random|extension ($_ random.and + (random.ascii/lower 1) + (random.list multiplicity random) + )]) + ($_ random.or + /simple.random + (/complex.random multiplicity random) + /reference.random + random|case + random|function + random|apply + random|extension + ))) + +(def: test|simple + Test + (do random.monad + [bit random.bit + nat random.nat + int random.int + rev random.rev + frac random.frac + text (random.ascii/lower 1)] + (`` ($_ _.and + (_.cover [/.unit] + (case (/.unit) + (^ (/.unit)) + true + + _ + false)) + (~~ (template [<tag> <expected>] + [(_.cover [<tag>] + (case (<tag> <expected>) + (^ (<tag> actual)) + (same? <expected> actual) + + _ + false))] + + [/.bit bit] + [/.nat nat] + [/.int int] + [/.rev rev] + [/.frac frac] + [/.text text])) + )))) + +(def: test|complex + Test + (do random.monad + [expected_left (..random 2) + expected_right (..random 2) + expected_lefts random.nat + expected_right? random.bit] + ($_ _.and + (_.cover [/.variant] + (let [expected (if expected_right? + expected_right + expected_left)] + (case (/.variant [expected_lefts expected_right? expected]) + (^ (/.variant [actual_lefts actual_right? actual])) + (and (same? expected_lefts actual_lefts) + (same? expected_right? actual_right?) + (same? expected actual)) + + _ + false))) + (_.cover [/.tuple] + (case (/.tuple (list expected_left expected_right)) + (^ (/.tuple (list actual_left actual_right))) + (and (same? expected_left actual_left) + (same? expected_right actual_right)) + + _ + false)) + ))) + +(def: test|reference + Test + (do random.monad + [expected_register random.nat + expected_constant (/symbol.random 1 1) + expected_variable /variable.random] + (`` ($_ _.and + (~~ (template [<tag> <expected>] + [(_.cover [<tag>] + (case (<tag> <expected>) + (^ (<tag> actual)) + (same? <expected> actual) + + _ + false))] + + [/.variable/local expected_register] + [/.variable/foreign expected_register] + [/.constant expected_constant] + [/.variable expected_variable] + )) + )))) + +(template: (tagged? <tag> <it>) + [(case <it> + {<tag> _} + true + + _ + false)]) + +(def: test|application + Test + (do random.monad + [expected_abstraction (random.only (|>> (..tagged? /.#Apply) not) + (..random 2)) + expected_parameter/0 (..random 2) + expected_parameter/1 (..random 2)] + ($_ _.and + (_.cover [/.apply /.application] + (case (|> [expected_abstraction (list expected_parameter/0 expected_parameter/1)] + /.apply + /.application) + (^ [actual_abstraction (list actual_parameter/0 actual_parameter/1)]) + (and (same? expected_abstraction actual_abstraction) + (same? expected_parameter/0 actual_parameter/0) + (same? expected_parameter/1 actual_parameter/1)) + + _ + false)) + (_.cover [/.no_op] + (case (/.no_op expected_parameter/0) + (^ (/.no_op actual)) + (same? expected_parameter/0 actual) + + _ + false)) + ))) + +(def: test|case + Test + (do random.monad + [expected_input (..random 2) + expected_match (random_match 2 (..random 2))] + ($_ _.and + (_.cover [/.case] + (case (/.case [expected_input expected_match]) + (^ (/.case [actual_input actual_match])) + (and (same? expected_input actual_input) + (same? expected_match actual_match)) + + _ + false)) + ))) + +(with_expansions [<id> (static.random_nat) + <exception> (template.symbol ["exception_" <id>])] + (exception: <exception>) + + (def: test|phase + Test + (do random.monad + [version random.nat + host (random.ascii/lower 5) + expected_error (random.ascii/lower 10) + location /location.random + .let [state (with@ .#location location + (/.state (/.info version host)))]] + ($_ _.and + (_.cover [/.failure] + (|> (/.failure expected_error) + (phase.result [extension.#bundle extension.empty + extension.#state state]) + (case> {try.#Failure actual_error} + (and (text.contains? expected_error actual_error) + (text.contains? (location.format location) actual_error)) + + _ + false))) + (_.cover [/.except] + (|> (/.except <exception> []) + (phase.result [extension.#bundle extension.empty + extension.#state state]) + (case> {try.#Failure actual_error} + (and (text.contains? (exception.error <exception> []) actual_error) + (text.contains? (location.format location) actual_error)) + + _ + false))) + (_.cover [/.assertion] + (and (|> (/.assertion <exception> [] false) + (phase.result [extension.#bundle extension.empty + extension.#state state]) + (case> {try.#Failure actual_error} + (and (text.contains? (exception.error <exception> []) actual_error) + (text.contains? (location.format location) actual_error)) + + _ + false)) + (|> (/.assertion <exception> [] true) + (phase.result [extension.#bundle extension.empty + extension.#state state]) + (case> {try.#Success _} + true + + _ + false)))) + )))) + +(def: test|state + Test + (do random.monad + [version random.nat + host (random.ascii/lower 5) + + expected_module (random.ascii/lower 10) + dummy_module (random.ascii/lower 11) + + location /location.random + + expected_file (random.ascii/lower 12) + expected_code (random.ascii/lower 13) + + .let [state (with@ .#location location + (/.state (/.info version host)))]] + ($_ _.and + (_.cover [/.info] + (let [it (/.info version host)] + (and (text#= (version.format version) + (value@ .#version it)) + (same? host + (value@ .#target it)) + (..tagged? .#Build (value@ .#mode it))))) + (_.cover [/.state] + (let [info (/.info version host) + it (/.state info)] + (and (same? info + (value@ .#info it)) + (same? location.dummy + (value@ .#location it)) + (..tagged? .#None (value@ .#current_module it)) + (..tagged? .#None (value@ .#expected it)) + (list.empty? (value@ .#modules it)) + (list.empty? (value@ .#scopes it)) + (list.empty? (value@ [.#type_context .#var_bindings] it)) + (case (value@ .#source it) + [location 0 ""] + (same? location.dummy location) + + _ + false)))) + (_.cover [/.set_current_module] + (|> (do phase.monad + [_ (/.set_current_module expected_module)] + (extension.read (|>> (value@ .#current_module) (maybe.else "")))) + (phase.result [extension.#bundle extension.empty + extension.#state state]) + (case> {try.#Success actual} + (same? expected_module actual) + + _ + false))) + (_.cover [/.with_current_module] + (let [current_module (extension.read (|>> (value@ .#current_module) (maybe.else "")))] + (|> (do phase.monad + [_ (/.set_current_module expected_module) + pre current_module + mid (/.with_current_module dummy_module + current_module) + post current_module] + (in (and (same? expected_module pre) + (same? dummy_module mid) + (same? expected_module post)))) + (phase.result [extension.#bundle extension.empty + extension.#state state]) + (try.else false)))) + (_.cover [/.location /.set_location] + (let [expected (/.location expected_file)] + (|> (do phase.monad + [_ (/.set_location expected)] + (extension.read (value@ .#location))) + (phase.result [extension.#bundle extension.empty + extension.#state state]) + (case> {try.#Success actual} + (same? expected actual) + + _ + false)))) + (_.cover [/.with_location] + (let [expected (/.location expected_file) + dummy (/.location expected_code) + location (extension.read (value@ .#location))] + (|> (do phase.monad + [_ (/.set_location expected) + pre location + mid (/.with_location dummy + location) + post location] + (in (and (same? expected pre) + (same? dummy mid) + (same? expected post)))) + (phase.result [extension.#bundle extension.empty + extension.#state state]) + (try.else false)))) + (_.cover [/.source /.set_source_code] + (let [expected (/.source expected_file expected_code)] + (|> (do phase.monad + [_ (/.set_source_code expected)] + (extension.read (value@ .#source))) + (phase.result [extension.#bundle extension.empty + extension.#state state]) + (case> {try.#Success actual} + (same? expected actual) + + _ + false)))) + (_.cover [/.with_source_code] + (let [expected (/.source expected_file expected_code) + dummy (/.source expected_code expected_file) + source (extension.read (value@ .#source))] + (|> (do phase.monad + [_ (/.set_source_code expected) + pre source + mid (/.with_source_code dummy + source) + post source] + (in (and (same? expected pre) + (same? dummy mid) + (same? expected post)))) + (phase.result [extension.#bundle extension.empty + extension.#state state]) + (try.else false)))) + ))) + +(def: .public test + Test + (<| (_.covering /._) + (_.for [/.Analysis]) + (do random.monad + [left (..random 2) + right (..random 2)] + ($_ _.and + (_.for [/.equivalence] + ($equivalence.spec /.equivalence (..random 2))) + + ..test|simple + ..test|complex + ..test|reference + (_.for [/.Application] + ..test|application) + (_.for [/.Branch /.Branch' /.Match /.Match'] + ..test|case) + (_.for [/.Operation /.Phase /.Handler /.Bundle] + ..test|phase) + (_.for [/.State+] + ..test|state) + (_.cover [/.format] + (bit#= (# /.equivalence = left right) + (text#= (/.format left) (/.format right)))) + + /simple.test + /complex.test + /pattern.test + )))) diff --git a/stdlib/source/test/lux/tool/compiler/language/lux/analysis/composite.lux b/stdlib/source/test/lux/tool/compiler/language/lux/analysis/complex.lux index 8c74718b8..c6454b07f 100644 --- a/stdlib/source/test/lux/tool/compiler/language/lux/analysis/composite.lux +++ b/stdlib/source/test/lux/tool/compiler/language/lux/analysis/complex.lux @@ -44,7 +44,7 @@ (def: .public (random multiplicity it) (All (_ a) - (-> Nat (Random a) (Random (/.Composite a)))) + (-> Nat (Random a) (Random (/.Complex a)))) ($_ random.or ($_ random.and (random#each (n.% (-- multiplicity)) random.nat) @@ -57,7 +57,7 @@ Test (let [random (..random 3 random.nat)] (<| (_.covering /._) - (_.for [/.Composite /.Variant /.Tuple]) + (_.for [/.Complex /.Variant /.Tuple]) ($_ _.and (_.for [/.equivalence] ($equivalence.spec (/.equivalence n.equivalence) random)) diff --git a/stdlib/source/test/lux/tool/compiler/language/lux/analysis/pattern.lux b/stdlib/source/test/lux/tool/compiler/language/lux/analysis/pattern.lux index 7a1d4c66d..85a701185 100644 --- a/stdlib/source/test/lux/tool/compiler/language/lux/analysis/pattern.lux +++ b/stdlib/source/test/lux/tool/compiler/language/lux/analysis/pattern.lux @@ -17,7 +17,7 @@ ["[0]" /]] ["[0]" // "_" ["[1][0]" simple] - ["[1][0]" composite]]) + ["[1][0]" complex]]) (def: .public random (Random /.Pattern) @@ -25,7 +25,7 @@ (function (_ random) ($_ random.or //simple.random - (//composite.random 4 random) + (//complex.random 4 random) random.nat )))) diff --git a/stdlib/source/test/lux/tool/compiler/language/lux/phase/synthesis/case.lux b/stdlib/source/test/lux/tool/compiler/language/lux/phase/synthesis/case.lux index 97cfd277b..beb9c4a34 100644 --- a/stdlib/source/test/lux/tool/compiler/language/lux/phase/synthesis/case.lux +++ b/stdlib/source/test/lux/tool/compiler/language/lux/phase/synthesis/case.lux @@ -1,54 +1,54 @@ (.using - [lux "*" - ["_" test {"+" Test}] - [abstract - [hash {"+" Hash}] - ["[0]" monad {"+" do}]] - [control - [pipe {"+" case>}] - ["[0]" try ("[1]#[0]" functor)]] - [data - ["[0]" sum] - ["[0]" text - ["%" format {"+" format}]] - [number - ["n" nat] - ["[0]" int] - ["[0]" rev] - ["[0]" frac]] - [collection - ["[0]" list ("[1]#[0]" functor mix monoid)] - ["[0]" set]]] - [math - ["[0]" random {"+" Random}]]] - ["[0]" // "_" - ["[1][0]" primitive]] - [\\ - ["[0]" / - ["/[1]" // - ["/[1]" // "_" - [extension - ["[1][0]" bundle]] - ["/[1]" // - ["[0]" analysis {"+" Branch Match Analysis}] - ["[0]" synthesis {"+" Path Synthesis}] - [/// - ["[1][0]" reference - [variable {"+" Register}]] - ["[0]" phase] - [meta - ["[0]" archive]]]]]]]]) + [lux "*" + ["_" test {"+" Test}] + [abstract + [hash {"+" Hash}] + ["[0]" monad {"+" do}]] + [control + [pipe {"+" case>}] + ["[0]" try ("[1]#[0]" functor)]] + [data + ["[0]" sum] + ["[0]" text + ["%" format {"+" format}]] + [number + ["n" nat] + ["[0]" int] + ["[0]" rev] + ["[0]" frac]] + [collection + ["[0]" list ("[1]#[0]" functor mix monoid)] + ["[0]" set]]] + [math + ["[0]" random {"+" Random}]]] + ["[0]" // "_" + ["[1][0]" primitive]] + [\\ + ["[0]" / + ["/[1]" // + ["/[1]" // "_" + [extension + ["[1][0]" bundle]] + ["/[1]" // + ["[0]" analysis {"+" Branch Match Analysis}] + ["[0]" synthesis {"+" Path Synthesis}] + [/// + ["[1][0]" reference + [variable {"+" Register}]] + ["[0]" phase] + [meta + ["[0]" archive]]]]]]]]) (def: masking_test Test (do [! random.monad] [maskedA //primitive.primitive temp (|> random.nat (# ! each (n.% 100))) - .let [maskA (analysis.control/case - [maskedA - [[{analysis.#Bind temp} - {analysis.#Reference (////reference.local temp)}] - (list)]])]] + .let [maskA (analysis.case + [maskedA + [[{analysis.#Bind temp} + {analysis.#Reference (////reference.local temp)}] + (list)]])]] (_.cover [/.synthesize_masking] (|> maskA (//.phase archive.empty) @@ -62,11 +62,11 @@ [registerA random.nat inputA //primitive.primitive outputA //primitive.primitive - .let [letA (analysis.control/case - [inputA - [[{analysis.#Bind registerA} - outputA] - (list)]])]] + .let [letA (analysis.case + [inputA + [[{analysis.#Bind registerA} + outputA] + (list)]])]] (_.cover [/.synthesize_let] (|> letA (//.phase archive.empty) @@ -93,8 +93,8 @@ [{analysis.#Simple {analysis.#Bit false}} elseA]) ifA (if then|else - (analysis.control/case [inputA [thenB (list elseB)]]) - (analysis.control/case [inputA [elseB (list thenB)]]))]] + (analysis.case [inputA [thenB (list elseB)]]) + (analysis.case [inputA [elseB (list thenB)]]))]] (_.cover [/.synthesize_if] (|> ifA (//.phase archive.empty) @@ -151,9 +151,9 @@ (# ! each (|>> analysis.tuple))) pathA ..random_path [pattern @member] (get_pattern pathA) - .let [getA (analysis.control/case [recordA [[pattern - {analysis.#Reference (////reference.local @member)}] - (list)]])]] + .let [getA (analysis.case [recordA [[pattern + {analysis.#Reference (////reference.local @member)}] + (list)]])]] (_.cover [/.synthesize_get] (|> getA (//.phase archive.empty) |