aboutsummaryrefslogtreecommitdiff
path: root/stdlib
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--stdlib/source/library/lux/data/format/json.lux8
-rw-r--r--stdlib/source/library/lux/math/number/frac.lux2
-rw-r--r--stdlib/source/library/lux/meta/location.lux14
-rw-r--r--stdlib/source/library/lux/target/jvm/bytecode.lux8
-rw-r--r--stdlib/source/library/lux/target/ruby.lux1
-rw-r--r--stdlib/source/library/lux/tool/compiler/language/lux/analysis.lux135
-rw-r--r--stdlib/source/library/lux/tool/compiler/language/lux/analysis/primitive.lux62
-rw-r--r--stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis/case.lux81
-rw-r--r--stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis/case/coverage.lux63
-rw-r--r--stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis/primitive.lux37
-rw-r--r--stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/jvm/common.lux10
-rw-r--r--stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/jvm/case.lux22
-rw-r--r--stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/jvm/runtime.lux2
-rw-r--r--stdlib/source/library/lux/tool/compiler/language/lux/phase/synthesis.lux63
-rw-r--r--stdlib/source/library/lux/tool/compiler/language/lux/phase/synthesis/case.lux77
-rw-r--r--stdlib/source/library/lux/tool/compiler/language/lux/synthesis.lux8
-rw-r--r--stdlib/source/library/lux/tool/compiler/meta/archive/signature.lux56
-rw-r--r--stdlib/source/test/lux/target/ruby.lux59
-rw-r--r--stdlib/source/test/lux/tool.lux32
-rw-r--r--stdlib/source/test/lux/tool/compiler/language/lux/analysis/primitive.lux44
20 files changed, 463 insertions, 321 deletions
diff --git a/stdlib/source/library/lux/data/format/json.lux b/stdlib/source/library/lux/data/format/json.lux
index 1ad804cdb..49686f9fa 100644
--- a/stdlib/source/library/lux/data/format/json.lux
+++ b/stdlib/source/library/lux/data/format/json.lux
@@ -232,9 +232,11 @@
(def: number_format
(-> Number Text)
- (|>> (case>
- (^or +0.0 -0.0) "0.0"
- value (let [raw (# f.decimal encoded value)]
+ (|>> (case> +0.0 ... OR -0.0
+ "0.0"
+
+ value
+ (let [raw (# f.decimal encoded value)]
(if (f.< +0.0 value)
raw
(|> raw (text.split_at 1) maybe.trusted product.right))))))
diff --git a/stdlib/source/library/lux/math/number/frac.lux b/stdlib/source/library/lux/math/number/frac.lux
index d830a6db7..bf73a6491 100644
--- a/stdlib/source/library/lux/math/number/frac.lux
+++ b/stdlib/source/library/lux/math/number/frac.lux
@@ -257,7 +257,7 @@
..negative_zero_bits))
... else
- (let [sign_bit (if (..< -0.0 it)
+ (let [sign_bit (if (..< +0.0 it)
1
0)
it (..abs it)
diff --git a/stdlib/source/library/lux/meta/location.lux b/stdlib/source/library/lux/meta/location.lux
index e83823a84..1c2908972 100644
--- a/stdlib/source/library/lux/meta/location.lux
+++ b/stdlib/source/library/lux/meta/location.lux
@@ -1,8 +1,8 @@
(.using
- [library
- [lux "*"
- [abstract
- [equivalence {"+" Equivalence}]]]])
+ [library
+ [lux "*"
+ [abstract
+ [equivalence {"+" Equivalence}]]]])
(implementation: .public equivalence
(Equivalence Location)
@@ -24,9 +24,9 @@
(let [location (value@ .#location compiler)]
{.#Right [compiler
(list (` (.: .Location
- [(~ [..dummy {.#Text (value@ .#module location)}])
- (~ [..dummy {.#Nat (value@ .#line location)}])
- (~ [..dummy {.#Nat (value@ .#column location)}])])))]})
+ [.#module (~ [..dummy {.#Text (value@ .#module location)}])
+ .#line (~ [..dummy {.#Nat (value@ .#line location)}])
+ .#column (~ [..dummy {.#Nat (value@ .#column location)}])])))]})
_
{.#Left (`` (("lux in-module" (~~ (static .prelude_module)) wrong_syntax_error) (symbol ..here)))}))
diff --git a/stdlib/source/library/lux/target/jvm/bytecode.lux b/stdlib/source/library/lux/target/jvm/bytecode.lux
index 97871977f..d7a29db73 100644
--- a/stdlib/source/library/lux/target/jvm/bytecode.lux
+++ b/stdlib/source/library/lux/target/jvm/bytecode.lux
@@ -207,6 +207,14 @@
{.#None} (in [])
{.#Some _} it)))
+(def: .public (when_acknowledged @ it)
+ (-> Label (Bytecode Any) (Bytecode Any))
+ (do ..monad
+ [?@ (..acknowledged? @)]
+ (.case ?@
+ {.#None} (in [])
+ {.#Some _} it)))
+
(def: .public failure
(-> Text Bytecode)
(|>> {try.#Failure} function.constant))
diff --git a/stdlib/source/library/lux/target/ruby.lux b/stdlib/source/library/lux/target/ruby.lux
index b2c9088dc..c2d0517c9 100644
--- a/stdlib/source/library/lux/target/ruby.lux
+++ b/stdlib/source/library/lux/target/ruby.lux
@@ -120,6 +120,7 @@
(template [<ruby_name> <lux_name>]
[(def: .public <lux_name>
+ GVar
(..global <ruby_name>))]
["@" latest_error]
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 c118e09b4..1b3f70f05 100644
--- a/stdlib/source/library/lux/tool/compiler/language/lux/analysis.lux
+++ b/stdlib/source/library/lux/tool/compiler/language/lux/analysis.lux
@@ -1,30 +1,32 @@
(.using
- [library
- [lux {"-" Primitive Tuple Variant nat int rev}
- [abstract
- [equivalence {"+" Equivalence}]
- [hash {"+" Hash}]
- [monad {"+" do}]]
- [control
- ["[0]" function]
- ["[0]" maybe]
- ["[0]" try]
- ["[0]" exception {"+" Exception}]]
- [data
- ["[0]" product]
- ["[0]" bit ("[1]#[0]" equivalence)]
- ["[0]" text ("[1]#[0]" equivalence)
- ["%" format {"+" Format format}]]
- [collection
- ["[0]" list ("[1]#[0]" functor mix)]]]
- [math
- [number
- ["n" nat]
- ["i" int]
- ["r" rev]
- ["f" frac]]]
- [meta
- ["[0]" location]]]]
+ [library
+ [lux {"-" Primitive Tuple Variant nat int rev}
+ [abstract
+ [equivalence {"+" Equivalence}]
+ [hash {"+" Hash}]
+ [monad {"+" do}]]
+ [control
+ ["[0]" function]
+ ["[0]" maybe]
+ ["[0]" try]
+ ["[0]" exception {"+" Exception}]]
+ [data
+ ["[0]" product]
+ ["[0]" bit ("[1]#[0]" equivalence)]
+ ["[0]" text ("[1]#[0]" equivalence)
+ ["%" format {"+" Format format}]]
+ [collection
+ ["[0]" list ("[1]#[0]" functor mix)]]]
+ [math
+ [number
+ ["n" nat]
+ ["i" int]
+ ["r" rev]
+ ["f" frac]]]
+ [meta
+ ["[0]" location]]]]
+ ["[0]" / "_"
+ ["[1][0]" primitive {"+" Primitive}]
[//
[phase
["[0]" extension {"+" Extension}]]
@@ -33,17 +35,7 @@
[version {"+" Version}]
["[0]" phase]
["[0]" reference {"+" Reference}
- ["[0]" variable {"+" Register Variable}]]]])
-
-(type: .public Primitive
- (.Variant
- {#Unit}
- {#Bit Bit}
- {#Nat Nat}
- {#Int Int}
- {#Rev Rev}
- {#Frac Frac}
- {#Text Text}))
+ ["[0]" variable {"+" Register Variable}]]]]])
(type: .public Tag
Nat)
@@ -115,27 +107,6 @@
(type: .public Match
(Match' Analysis))
-(implementation: primitive_equivalence
- (Equivalence Primitive)
-
- (def: (= reference sample)
- (case [reference sample]
- [{#Unit} {#Unit}]
- true
-
- (^template [<tag> <=>]
- [[{<tag> reference} {<tag> sample}]
- (<=> reference sample)])
- ([#Bit bit#=]
- [#Nat n.=]
- [#Int i.=]
- [#Rev r.=]
- [#Frac f.=]
- [#Text text#=])
-
- _
- false)))
-
(implementation: .public (composite_equivalence (^open "/#[0]"))
(All (_ a) (-> (Equivalence a) (Equivalence (Composite a))))
@@ -178,7 +149,7 @@
(def: (= reference sample)
(case [reference sample]
[{#Simple reference} {#Simple sample}]
- (# primitive_equivalence = reference sample)
+ (# /primitive.equivalence = reference sample)
[{#Complex reference} {#Complex sample}]
(# (composite_equivalence =) = reference sample)
@@ -202,7 +173,7 @@
(def: (= reference sample)
(case [reference sample]
[{#Primitive reference} {#Primitive sample}]
- (# primitive_equivalence = reference sample)
+ (# /primitive.equivalence = reference sample)
[{#Structure reference} {#Structure sample}]
(# (composite_equivalence =) = reference sample)
@@ -239,18 +210,18 @@
)
(template: .public (unit)
- [{..#Primitive {..#Unit}}])
+ [{..#Primitive {/primitive.#Unit}}])
(template [<name> <tag>]
[(template: .public (<name> value)
[{..#Primitive {<tag> value}}])]
- [bit ..#Bit]
- [nat ..#Nat]
- [int ..#Int]
- [rev ..#Rev]
- [frac ..#Frac]
- [text ..#Text]
+ [bit /primitive.#Bit]
+ [nat /primitive.#Nat]
+ [int /primitive.#Int]
+ [rev /primitive.#Rev]
+ [frac /primitive.#Frac]
+ [text /primitive.#Text]
)
(type: .public (Abstraction c)
@@ -323,18 +294,18 @@
)
(template: .public (pattern/unit)
- [{..#Simple {..#Unit}}])
+ [{..#Simple {/primitive.#Unit}}])
(template [<name> <tag>]
[(template: .public (<name> content)
[{..#Simple {<tag> content}}])]
- [pattern/bit ..#Bit]
- [pattern/nat ..#Nat]
- [pattern/int ..#Int]
- [pattern/rev ..#Rev]
- [pattern/frac ..#Frac]
- [pattern/text ..#Text]
+ [pattern/bit /primitive.#Bit]
+ [pattern/nat /primitive.#Nat]
+ [pattern/int /primitive.#Int]
+ [pattern/rev /primitive.#Rev]
+ [pattern/frac /primitive.#Frac]
+ [pattern/text /primitive.#Text]
)
(template: .public (pattern/bind register)
@@ -343,20 +314,8 @@
(def: .public (%analysis analysis)
(Format Analysis)
(case analysis
- {#Primitive primitive}
- (case primitive
- {#Unit}
- "[]"
-
- (^template [<tag> <format>]
- [{<tag> value}
- (<format> value)])
- ([#Bit %.bit]
- [#Nat %.nat]
- [#Int %.int]
- [#Rev %.rev]
- [#Frac %.frac]
- [#Text %.text]))
+ {#Primitive it}
+ (/primitive.format it)
{#Structure structure}
(case structure
diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/analysis/primitive.lux b/stdlib/source/library/lux/tool/compiler/language/lux/analysis/primitive.lux
new file mode 100644
index 000000000..b4eca6b5e
--- /dev/null
+++ b/stdlib/source/library/lux/tool/compiler/language/lux/analysis/primitive.lux
@@ -0,0 +1,62 @@
+(.using
+ [library
+ [lux {"-" Primitive}
+ [abstract
+ [equivalence {"+" Equivalence}]]
+ [data
+ ["[0]" bit ("[1]#[0]" equivalence)]
+ ["[0]" text ("[1]#[0]" equivalence)
+ ["%" format {"+" Format}]]]
+ [math
+ [number
+ ["n" nat]
+ ["i" int]
+ ["r" rev]
+ ["f" frac]]]]])
+
+(type: .public Primitive
+ (Variant
+ {#Unit}
+ {#Bit Bit}
+ {#Nat Nat}
+ {#Int Int}
+ {#Rev Rev}
+ {#Frac Frac}
+ {#Text Text}))
+
+(implementation: .public equivalence
+ (Equivalence Primitive)
+
+ (def: (= reference sample)
+ (case [reference sample]
+ [{#Unit} {#Unit}]
+ true
+
+ (^template [<tag> <=>]
+ [[{<tag> reference} {<tag> sample}]
+ (<=> reference sample)])
+ ([#Bit bit#=]
+ [#Nat n.=]
+ [#Int i.=]
+ [#Rev r.=]
+ [#Frac f.=]
+ [#Text text#=])
+
+ _
+ false)))
+
+(def: .public (format it)
+ (Format Primitive)
+ (case it
+ {#Unit}
+ "[]"
+
+ (^template [<tag> <format>]
+ [{<tag> value}
+ (<format> value)])
+ ([#Bit %.bit]
+ [#Nat %.nat]
+ [#Int %.int]
+ [#Rev %.rev]
+ [#Frac %.frac]
+ [#Text %.text])))
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 b71f0176b..c2ae6155d 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
@@ -1,38 +1,39 @@
(.using
- [library
- [lux {"-" case}
- ["[0]" meta]
- [abstract
- ["[0]" monad {"+" do}]]
- [control
- ["[0]" maybe]
- ["[0]" try]
- ["[0]" exception {"+" exception:}]]
- [data
- ["[0]" product]
- [text
- ["%" format {"+" format}]]
- [collection
- ["[0]" list ("[1]#[0]" mix monoid monad)]]]
- [math
- [number
- ["n" nat]]]
- [macro
- ["[0]" code]]
- ["[0]" type
- ["[0]" check]]]]
- ["[0]" / "_"
- ["[1][0]" coverage {"+" Coverage}]
+ [library
+ [lux {"-" case}
+ ["[0]" meta]
+ [abstract
+ ["[0]" monad {"+" do}]]
+ [control
+ ["[0]" maybe]
+ ["[0]" try]
+ ["[0]" exception {"+" exception:}]]
+ [data
+ ["[0]" product]
+ [text
+ ["%" format {"+" format}]]
+ [collection
+ ["[0]" list ("[1]#[0]" mix monoid monad)]]]
+ [math
+ [number
+ ["n" nat]]]
+ [macro
+ ["[0]" code]]
+ ["[0]" type
+ ["[0]" check]]]]
+ ["[0]" / "_"
+ ["[1][0]" coverage {"+" Coverage}]
+ ["/[1]" // "_"
+ ["[1][0]" scope]
+ ["[1][0]" type]
+ ["[1][0]" structure]
["/[1]" // "_"
- ["[1][0]" scope]
- ["[1][0]" type]
- ["[1][0]" structure]
- ["/[1]" // "_"
- ["[1][0]" extension]
- [//
- ["/" analysis {"+" Pattern Analysis Operation Phase}]
- [///
- ["[1]" phase]]]]]])
+ ["[1][0]" extension]
+ [//
+ ["/" analysis {"+" Pattern Analysis Operation Phase}
+ ["[1][0]" primitive]]
+ [///
+ ["[1]" phase]]]]]])
(exception: .public (cannot_match_with_pattern [type Type
pattern Code])
@@ -233,13 +234,13 @@
(^template [<type> <input> <output>]
[[location <input>]
(analyse_primitive <type> inputT location {/.#Simple <output>} next)])
- ([Bit {.#Bit pattern_value} {/.#Bit pattern_value}]
- [Nat {.#Nat pattern_value} {/.#Nat pattern_value}]
- [Int {.#Int pattern_value} {/.#Int pattern_value}]
- [Rev {.#Rev pattern_value} {/.#Rev pattern_value}]
- [Frac {.#Frac pattern_value} {/.#Frac pattern_value}]
- [Text {.#Text pattern_value} {/.#Text pattern_value}]
- [Any {.#Tuple {.#End}} {/.#Unit}])
+ ([Bit {.#Bit pattern_value} {/primitive.#Bit pattern_value}]
+ [Nat {.#Nat pattern_value} {/primitive.#Nat pattern_value}]
+ [Int {.#Int pattern_value} {/primitive.#Int pattern_value}]
+ [Rev {.#Rev pattern_value} {/primitive.#Rev pattern_value}]
+ [Frac {.#Frac pattern_value} {/primitive.#Frac pattern_value}]
+ [Text {.#Text pattern_value} {/primitive.#Text pattern_value}]
+ [Any {.#Tuple {.#End}} {/primitive.#Unit}])
(^ [location {.#Tuple (list singleton)}])
(analyse_pattern {.#None} inputT singleton 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 7e1b4fec2..c7b3a9849 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
@@ -1,28 +1,29 @@
(.using
- [library
- [lux {"-" Variant}
- [abstract
- equivalence
- ["[0]" monad {"+" do}]]
- [control
- ["[0]" maybe]
- ["[0]" try {"+" Try} ("[1]#[0]" monad)]
- ["[0]" exception {"+" exception:}]]
- [data
- ["[0]" bit ("[1]#[0]" equivalence)]
- ["[0]" text
- ["%" format {"+" Format format}]]
- [collection
- ["[0]" list ("[1]#[0]" functor mix)]
- ["[0]" dictionary {"+" Dictionary}]]]
- [math
- [number
- ["n" nat]]]]]
- ["[0]" //// "_"
- [//
- ["/" analysis {"+" Pattern Variant Operation}]
- [///
- ["[1]" phase ("[1]#[0]" monad)]]]])
+ [library
+ [lux {"-" Variant}
+ [abstract
+ equivalence
+ ["[0]" monad {"+" do}]]
+ [control
+ ["[0]" maybe]
+ ["[0]" try {"+" Try} ("[1]#[0]" monad)]
+ ["[0]" exception {"+" exception:}]]
+ [data
+ ["[0]" bit ("[1]#[0]" equivalence)]
+ ["[0]" text
+ ["%" format {"+" Format format}]]
+ [collection
+ ["[0]" list ("[1]#[0]" functor mix)]
+ ["[0]" dictionary {"+" Dictionary}]]]
+ [math
+ [number
+ ["n" nat]]]]]
+ ["[0]" //// "_"
+ [//
+ ["/" analysis {"+" Pattern Variant Operation}
+ ["[1][0]" primitive]]
+ [///
+ ["[1]" phase ("[1]#[0]" monad)]]]])
(exception: .public invalid_tuple_pattern
"Tuple size must be >= 2")
@@ -99,7 +100,7 @@
(def: .public (determine pattern)
(-> Pattern (Operation Coverage))
(case pattern
- (^or {/.#Simple {/.#Unit}}
+ (^or {/.#Simple {/primitive.#Unit}}
{/.#Bind _})
(////#in {#Exhaustive})
@@ -108,16 +109,16 @@
(^template [<tag>]
[{/.#Simple {<tag> _}}
(////#in {#Partial})])
- ([/.#Nat]
- [/.#Int]
- [/.#Rev]
- [/.#Frac]
- [/.#Text])
+ ([/primitive.#Nat]
+ [/primitive.#Int]
+ [/primitive.#Rev]
+ [/primitive.#Frac]
+ [/primitive.#Text])
... Bits are the exception, since there is only "#1" and
... "#0", which means it is possible for bit
... pattern-matching to become exhaustive if complementary parts meet.
- {/.#Simple {/.#Bit value}}
+ {/.#Simple {/primitive.#Bit value}}
(////#in {#Bit value})
... Tuple patterns can be exhaustive if there is exhaustiveness for all of
diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis/primitive.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis/primitive.lux
index de1cb6fd1..547d23a8e 100644
--- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis/primitive.lux
+++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis/primitive.lux
@@ -1,15 +1,16 @@
(.using
- [library
- [lux {"-" nat int rev}
- [abstract
- monad]]]
- ["[0]" // "_"
- ["[1][0]" type]
- ["/[1]" // "_"
- [//
- ["/" analysis {"+" Analysis Operation}]
- [///
- ["[1]" phase]]]]])
+ [library
+ [lux {"-" nat int rev}
+ [abstract
+ monad]]]
+ ["[0]" // "_"
+ ["[1][0]" type]
+ ["/[1]" // "_"
+ [//
+ ["/" analysis {"+" Analysis Operation}
+ ["[1][0]" primitive]]
+ [///
+ ["[1]" phase]]]]])
(template [<name> <type> <tag>]
[(def: .public (<name> value)
@@ -18,16 +19,16 @@
[_ (//type.infer <type>)]
(in {/.#Primitive {<tag> value}})))]
- [bit .Bit /.#Bit]
- [nat .Nat /.#Nat]
- [int .Int /.#Int]
- [rev .Rev /.#Rev]
- [frac .Frac /.#Frac]
- [text .Text /.#Text]
+ [bit .Bit /primitive.#Bit]
+ [nat .Nat /primitive.#Nat]
+ [int .Int /primitive.#Int]
+ [rev .Rev /primitive.#Rev]
+ [frac .Frac /primitive.#Frac]
+ [text .Text /primitive.#Text]
)
(def: .public unit
(Operation Analysis)
(do ///.monad
[_ (//type.infer .Any)]
- (in {/.#Primitive {/.#Unit}})))
+ (in {/.#Primitive {/primitive.#Unit}})))
diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/jvm/common.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/jvm/common.lux
index 9ed84603f..1538e19ae 100644
--- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/jvm/common.lux
+++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/jvm/common.lux
@@ -336,12 +336,14 @@
rightG ..ensure_string
(_.invokevirtual ..$String "concat" (type.method [(list) (list ..$String) ..$String (list)]))))
-(def: (text::clip [startG endG subjectG])
+(def: (text::clip [offset! length! subject!])
(Trinary (Bytecode Any))
($_ _.composite
- subjectG ..ensure_string
- startG ..jvm_int
- endG ..jvm_int
+ subject! ..ensure_string
+ offset! ..jvm_int
+ _.dup
+ length! ..jvm_int
+ _.iadd
(_.invokevirtual ..$String "substring" (type.method [(list) (list type.int type.int) ..$String (list)]))))
(def: index_method (type.method [(list) (list ..$String type.int) type.int (list)]))
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 a22654346..fd927cebd 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
@@ -7,14 +7,19 @@
["[0]" function]]
[data
[collection
- ["[0]" list ("[1]#[0]" mix)]]]
+ ["[0]" list ("[1]#[0]" mix)]]
+ ["[0]" text ("[1]#[0]" equivalence)
+ ["%" format {"+" format}]]]
[math
[number
["n" nat]
["[0]" i32]]]
[target
[jvm
- ["_" bytecode {"+" Label Bytecode} ("[1]#[0]" monad)]
+ ["_" bytecode {"+" Label Bytecode} ("[1]#[0]" monad)
+ [environment
+ [limit
+ ["[0]" stack]]]]
["[0]" type {"+" Type}
[category {"+" Method}]]]]]]
["[0]" // "_"
@@ -243,18 +248,12 @@
path! (..path' 1 @else @end phase archive path)]
(in ($_ _.composite
path!
- (do _.monad
- [?@else (_.acknowledged? @else)]
- (.case ?@else
- {.#None}
- (in [])
-
- {.#Some _}
+ (<| (_.when_acknowledged @else)
($_ _.composite
(_.set_label @else)
//runtime.pm_failure
(_.goto @end)
- )))
+ ))
))))
(def: .public (if phase archive [testS thenS elseS])
@@ -274,7 +273,8 @@
(_.when_continuous (_.goto @end))
(_.set_label @else)
else!
- (_.set_label @end))))))
+ (<| (_.when_acknowledged @end)
+ (_.set_label @end)))))))
(def: .public (let phase archive [inputS register bodyS])
(Generator [Synthesis Register Synthesis])
diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/jvm/runtime.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/jvm/runtime.lux
index fccfabf64..d71b1817a 100644
--- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/jvm/runtime.lux
+++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/jvm/runtime.lux
@@ -630,4 +630,4 @@
... This shift is done to avoid the possibility of forged labels
... to be in the range of the labels that are generated automatically
... during the evaluation of Bytecode expressions.
- (# ////.monad each (i64.left_shifted shift) generation.next)))
+ (# ////.monad each (|>> ++ (i64.left_shifted shift)) generation.next)))
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 a78ae83f8..68f3c22d4 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
@@ -1,48 +1,49 @@
(.using
- [library
- [lux "*"
- [abstract
- ["[0]" monad {"+" do}]]
- [control
- [pipe {"+" case>}]
- ["[0]" try]]
- [data
- [collection
- ["[0]" list ("[1]#[0]" functor)]
- ["[0]" dictionary {"+" Dictionary}]]]]]
- ["[0]" / "_"
- ["[1][0]" function]
- ["[1][0]" case]
- ["[1][0]" variable]
+ [library
+ [lux "*"
+ [abstract
+ ["[0]" monad {"+" do}]]
+ [control
+ [pipe {"+" case>}]
+ ["[0]" try]]
+ [data
+ [collection
+ ["[0]" list ("[1]#[0]" functor)]
+ ["[0]" dictionary {"+" Dictionary}]]]]]
+ ["[0]" / "_"
+ ["[1][0]" function]
+ ["[1][0]" case]
+ ["[1][0]" variable]
+ ["/[1]" // "_"
+ ["[1][0]" extension]
["/[1]" // "_"
- ["[1][0]" extension]
- ["/[1]" // "_"
- ["[1][0]" analysis {"+" Analysis}]
- ["/" synthesis {"+" Synthesis Phase}]
- [///
- ["[0]" phase ("[1]#[0]" monad)]
- [reference {"+"}
- [variable {"+"}]]]]]])
+ ["/" synthesis {"+" Synthesis Phase}]
+ ["[1][0]" analysis {"+" Analysis}
+ ["[2][0]" primitive]]
+ [///
+ ["[0]" phase ("[1]#[0]" monad)]
+ [reference {"+"}
+ [variable {"+"}]]]]]])
(def: (primitive analysis)
- (-> ///analysis.Primitive /.Primitive)
+ (-> ///primitive.Primitive /.Primitive)
(case analysis
- {///analysis.#Unit}
+ {///primitive.#Unit}
{/.#Text /.unit}
(^template [<analysis> <synthesis>]
[{<analysis> value}
{<synthesis> value}])
- ([///analysis.#Bit /.#Bit]
- [///analysis.#Frac /.#F64]
- [///analysis.#Text /.#Text])
+ ([///primitive.#Bit /.#Bit]
+ [///primitive.#Frac /.#F64]
+ [///primitive.#Text /.#Text])
(^template [<analysis> <synthesis>]
[{<analysis> value}
{<synthesis> (.i64 value)}])
- ([///analysis.#Nat /.#I64]
- [///analysis.#Int /.#I64]
- [///analysis.#Rev /.#I64])))
+ ([///primitive.#Nat /.#I64]
+ [///primitive.#Int /.#I64]
+ [///primitive.#Rev /.#I64])))
(def: (optimization archive)
Phase
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 548294999..874d4d4ef 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
@@ -1,33 +1,34 @@
(.using
- [library
- [lux "*"
- [abstract
- [equivalence {"+" Equivalence}]
- ["[0]" monad {"+" do}]]
- [control
- [pipe {"+" when> new> case>}]]
- [data
- ["[0]" product]
- ["[0]" bit ("[1]#[0]" equivalence)]
- ["[0]" text ("[1]#[0]" equivalence)]
- [collection
- ["[0]" list ("[1]#[0]" functor mix monoid)]
- ["[0]" set {"+" Set}]]]
- [math
- [number
- ["n" nat]
- ["[0]" i64]
- ["[0]" frac ("[1]#[0]" equivalence)]]]]]
- ["[0]" /// "_"
- [//
- ["[1][0]" analysis {"+" Pattern Match Analysis}]
- ["/" synthesis {"+" Path Synthesis Operation Phase}]
- [///
- ["[1]" phase ("[1]#[0]" monad)]
- ["[1][0]" reference
- ["[1]/[0]" variable {"+" Register Variable}]]
- [meta
- [archive {"+" Archive}]]]]])
+ [library
+ [lux "*"
+ [abstract
+ [equivalence {"+" Equivalence}]
+ ["[0]" monad {"+" do}]]
+ [control
+ [pipe {"+" when> new> case>}]]
+ [data
+ ["[0]" product]
+ ["[0]" bit ("[1]#[0]" equivalence)]
+ ["[0]" text ("[1]#[0]" equivalence)]
+ [collection
+ ["[0]" list ("[1]#[0]" functor mix monoid)]
+ ["[0]" set {"+" Set}]]]
+ [math
+ [number
+ ["n" nat]
+ ["[0]" i64]
+ ["[0]" frac ("[1]#[0]" equivalence)]]]]]
+ ["[0]" /// "_"
+ [//
+ ["/" synthesis {"+" Path Synthesis Operation Phase}]
+ ["[1][0]" analysis {"+" Pattern Match Analysis}
+ ["[2][0]" primitive]]
+ [///
+ ["[1]" phase ("[1]#[0]" monad)]
+ ["[1][0]" reference
+ ["[1]/[0]" variable {"+" Register Variable}]]
+ [meta
+ [archive {"+" Archive}]]]]])
(def: clean_up
(-> Path Path)
@@ -38,10 +39,10 @@
(case pattern
{///analysis.#Simple simple}
(case simple
- {///analysis.#Unit}
+ {///primitive.#Unit}
thenC
- {///analysis.#Bit when}
+ {///primitive.#Bit when}
(///#each (function (_ then)
{/.#Bit_Fork when then {.#None}})
thenC)
@@ -51,11 +52,11 @@
(///#each (function (_ then)
{<to> [(<conversion> test) then] (list)})
thenC)])
- ([///analysis.#Nat /.#I64_Fork .i64]
- [///analysis.#Int /.#I64_Fork .i64]
- [///analysis.#Rev /.#I64_Fork .i64]
- [///analysis.#Frac /.#F64_Fork |>]
- [///analysis.#Text /.#Text_Fork |>]))
+ ([///primitive.#Nat /.#I64_Fork .i64]
+ [///primitive.#Int /.#I64_Fork .i64]
+ [///primitive.#Rev /.#I64_Fork .i64]
+ [///primitive.#Frac /.#F64_Fork |>]
+ [///primitive.#Text /.#Text_Fork |>]))
{///analysis.#Bind register}
(<| (# ///.monad each (|>> {/.#Seq {/.#Bind register}}))
@@ -74,7 +75,7 @@
(let [tuple::last (-- (list.size tuple))]
(list#mix (function (_ [tuple::lefts tuple::member] nextC)
(.case tuple::member
- {///analysis.#Simple {///analysis.#Unit}}
+ {///analysis.#Simple {///primitive.#Unit}}
nextC
_
@@ -204,7 +205,7 @@
{.#Item head tail}
(case head
- {///analysis.#Simple {///analysis.#Unit}}
+ {///analysis.#Simple {///primitive.#Unit}}
<continue>
{///analysis.#Bind register}
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 13d773310..002eddaec 100644
--- a/stdlib/source/library/lux/tool/compiler/language/lux/synthesis.lux
+++ b/stdlib/source/library/lux/tool/compiler/language/lux/synthesis.lux
@@ -305,10 +305,10 @@
{#Side side}
(case side
{.#Left lefts}
- (format "(" (%.nat lefts) " #0" ")")
+ (format "{" (%.nat lefts) " #0" "}")
{.#Right lefts}
- (format "(" (%.nat lefts) " #1" ")"))
+ (format "{" (%.nat lefts) " #1" "}"))
{#Member member}
(case member
@@ -322,10 +322,10 @@
(format "(@ " (%.nat register) ")")
{#Alt left right}
- (format "(Variant " (%path' %then left) " " (%path' %then right) ")")
+ (format "(| " (%path' %then left) " " (%path' %then right) ")")
{#Seq left right}
- (format "(Tuple " (%path' %then left) " " (%path' %then right) ")")
+ (format "(& " (%path' %then left) " " (%path' %then right) ")")
{#Then then}
(|> (%then then)
diff --git a/stdlib/source/library/lux/tool/compiler/meta/archive/signature.lux b/stdlib/source/library/lux/tool/compiler/meta/archive/signature.lux
index fe078baa2..533ed6cb0 100644
--- a/stdlib/source/library/lux/tool/compiler/meta/archive/signature.lux
+++ b/stdlib/source/library/lux/tool/compiler/meta/archive/signature.lux
@@ -1,24 +1,24 @@
(.using
- [library
- [lux "*"
- [abstract
- [equivalence {"+" Equivalence}]]
- [control
- ["<>" parser
- ["<b>" binary {"+" Parser}]]]
- [data
- ["[0]" product]
- ["[0]" text
- ["%" format {"+" format}]]
- [format
- ["[0]" binary {"+" Writer}]]]
- [math
- [number
- ["[0]" nat]]]
- [meta
- ["[0]" symbol]]]]
- [////
- [version {"+" Version}]])
+ [library
+ [lux "*"
+ [abstract
+ [equivalence {"+" Equivalence}]]
+ [control
+ ["<>" parser
+ ["<[0]>" binary {"+" Parser}]]]
+ [data
+ ["[0]" product]
+ ["[0]" text
+ ["%" format {"+" format}]]
+ [format
+ ["[0]" binary {"+" Writer}]]]
+ [math
+ [number
+ ["[0]" nat]]]
+ [meta
+ ["[0]" symbol]]]]
+ [////
+ ["[0]" version {"+" Version}]])
(type: .public Signature
(Record
@@ -27,18 +27,22 @@
(def: .public equivalence
(Equivalence Signature)
- (product.equivalence symbol.equivalence nat.equivalence))
+ ($_ product.equivalence
+ symbol.equivalence
+ nat.equivalence))
(def: .public (description signature)
(-> Signature Text)
- (format (%.symbol (value@ #name signature)) " " (%.nat (value@ #version signature))))
+ (format (%.symbol (value@ #name signature)) " " (version.format (value@ #version signature))))
(def: .public writer
(Writer Signature)
- (binary.and (binary.and binary.text binary.text)
- binary.nat))
+ ($_ binary.and
+ (binary.and binary.text binary.text)
+ binary.nat))
(def: .public parser
(Parser Signature)
- (<>.and (<>.and <b>.text <b>.text)
- <b>.nat))
+ ($_ <>.and
+ (<>.and <binary>.text <binary>.text)
+ <binary>.nat))
diff --git a/stdlib/source/test/lux/target/ruby.lux b/stdlib/source/test/lux/target/ruby.lux
index 87e781ebc..86a817703 100644
--- a/stdlib/source/test/lux/target/ruby.lux
+++ b/stdlib/source/test/lux/target/ruby.lux
@@ -11,7 +11,8 @@
["[0]" try {"+" Try} ("[1]#[0]" functor)]]
[data
["[0]" bit ("[1]#[0]" equivalence)]
- ["[0]" text ("[1]#[0]" equivalence)]
+ ["[0]" text ("[1]#[0]" equivalence)
+ ["%" format {"+" format}]]
[collection
["[0]" list ("[1]#[0]" functor)]]]
["[0]" math
@@ -20,7 +21,14 @@
["n" nat]
["i" int]
["f" frac]
- ["[0]" i64]]]]]
+ ["[0]" i64]]]
+ [tool
+ [compiler
+ [meta
+ ["[0]" packager "_"
+ ["[1]" ruby]]]]]
+ [world
+ ["[0]" file]]]]
[\\library
["[0]" /]])
@@ -580,15 +588,58 @@
..test/location)
)))
+(def: test|global
+ Test
+ ($_ _.and
+ (_.cover [/.script_name]
+ (expression (let [file (format (# file.default separator) packager.main_file)]
+ (|>> (:as Text)
+ (predicate.or (text.ends_with? file)
+ (text#= "<script>"))))
+ /.script_name))
+ (_.cover [/.input_record_separator]
+ (expression (|>> (:as Text)
+ (text#= text.\n))
+ /.input_record_separator))
+ (_.cover [/.output_record_separator]
+ (|> /.output_record_separator
+ /.code
+ ..eval
+ (try#each (function (_ it)
+ (case it
+ {.#None} true
+ {.#Some _} false)))
+ (try.else false)))
+ ))
+
+(def: random_expression
+ (Random /.Expression)
+ (let [literal (: (Random /.Literal)
+ ($_ random.either
+ (random#each /.bool random.bit)
+ (random#each /.float random.frac)
+ (random#each /.int random.int)
+ (random#each /.string (random.ascii/lower 5))
+ ))]
+ ($_ random.either
+ literal
+ )))
+
(def: .public test
Test
(do [! random.monad]
- []
+ [expected ..random_expression]
(<| (_.covering /._)
- (_.for [/.Code /.code])
+ (_.for [/.Code])
($_ _.and
+ (_.cover [/.code /.manual]
+ (|> (/.manual (/.code expected))
+ (: /.Expression)
+ (# /.code_equivalence = expected)))
(_.for [/.Expression]
..test|expression)
(_.for [/.Statement]
..test|statement)
+ (_.for [/.GVar]
+ ..test|global)
))))
diff --git a/stdlib/source/test/lux/tool.lux b/stdlib/source/test/lux/tool.lux
index ef83286b4..f7734328b 100644
--- a/stdlib/source/test/lux/tool.lux
+++ b/stdlib/source/test/lux/tool.lux
@@ -1,24 +1,28 @@
(.using
- [library
- [lux "*"
- ["_" test {"+" Test}]]]
- ["[0]" / "_"
- [compiler
- ["[1][0]" arity]
- ["[1][0]" reference]
- ... [language
- ... [lux
- ... ["[1][0]" syntax]
- ... [phase
- ... ["[1][0]" analysis]
- ... ["[1][0]" synthesis]]]]
- ]])
+ [library
+ [lux "*"
+ ["_" test {"+" Test}]]]
+ ["[0]" / "_"
+ [compiler
+ ["[1][0]" arity]
+ ["[1][0]" reference]
+ [language
+ [lux
+ ... ["[1][0]" syntax]
+ ["[1][0]" analysis "_"
+ ["[1]/[0]" primitive]]
+ ... [phase
+ ... ["[1][0]" analysis]
+ ... ["[1][0]" synthesis]]
+ ]]
+ ]])
(def: .public test
Test
($_ _.and
/arity.test
/reference.test
+ /analysis/primitive.test
... /syntax.test
... /analysis.test
... /synthesis.test
diff --git a/stdlib/source/test/lux/tool/compiler/language/lux/analysis/primitive.lux b/stdlib/source/test/lux/tool/compiler/language/lux/analysis/primitive.lux
new file mode 100644
index 000000000..4d67a47f9
--- /dev/null
+++ b/stdlib/source/test/lux/tool/compiler/language/lux/analysis/primitive.lux
@@ -0,0 +1,44 @@
+(.using
+ [library
+ [lux "*"
+ ["_" test {"+" Test}]
+ [abstract
+ [monad {"+" do}]
+ [\\specification
+ ["$[0]" equivalence]]]
+ [data
+ ["[0]" bit ("[1]#[0]" equivalence)]
+ ["[0]" text ("[1]#[0]" equivalence)]]
+ [math
+ ["[0]" random {"+" Random} ("[1]#[0]" monad)]
+ [number
+ ["f" frac]]]]]
+ [\\library
+ ["[0]" /]])
+
+(def: .public random
+ (Random /.Primitive)
+ ($_ random.or
+ (random#in [])
+ random.bit
+ random.nat
+ random.int
+ random.rev
+ (random.only (|>> f.not_a_number? not) random.frac)
+ (random.ascii/lower 5)
+ ))
+
+(def: .public test
+ Test
+ (<| (_.covering /._)
+ (_.for [/.Primitive])
+ ($_ _.and
+ (_.for [/.equivalence]
+ ($equivalence.spec /.equivalence ..random))
+ (do random.monad
+ [left ..random
+ right ..random]
+ (_.cover [/.format]
+ (bit#= (# /.equivalence = left right)
+ (text#= (/.format left) (/.format right)))))
+ )))