aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEduardo Julian2021-09-10 03:53:29 -0400
committerEduardo Julian2021-09-10 03:53:29 -0400
commitd48270f43c404ba19ca04da2553455ecaaf2caba (patch)
tree850f3a240267fd8b944fbd221ace130c8f7b8606
parent343fda007c09deb70917a4afda19891cacf54504 (diff)
Adjusted new compilers to work with the new variant syntax.
-rw-r--r--lux-jvm/source/luxc/lang/translation/jvm/extension/host.lux2
-rw-r--r--lux-jvm/source/program.lux10
-rw-r--r--stdlib/source/library/lux/data/format/json.lux39
-rw-r--r--stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis.lux24
-rw-r--r--stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis/case.lux15
-rw-r--r--stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis/structure.lux14
-rw-r--r--stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/directive/lux.lux2
-rw-r--r--stdlib/source/poly/lux/abstract/equivalence.lux8
-rw-r--r--stdlib/source/poly/lux/abstract/functor.lux8
-rw-r--r--stdlib/source/poly/lux/data/format/json.lux16
10 files changed, 83 insertions, 55 deletions
diff --git a/lux-jvm/source/luxc/lang/translation/jvm/extension/host.lux b/lux-jvm/source/luxc/lang/translation/jvm/extension/host.lux
index 8535c3b35..5eda6443d 100644
--- a/lux-jvm/source/luxc/lang/translation/jvm/extension/host.lux
+++ b/lux-jvm/source/luxc/lang/translation/jvm/extension/host.lux
@@ -906,7 +906,7 @@
(^ {#synthesis.Primitive value})
body
- (^ {synthesis.constant value})
+ (^ (synthesis.constant value))
body
(^ (synthesis.variant [lefts right? sub]))
diff --git a/lux-jvm/source/program.lux b/lux-jvm/source/program.lux
index 7ae009ad4..ea4503d63 100644
--- a/lux-jvm/source/program.lux
+++ b/lux-jvm/source/program.lux
@@ -152,11 +152,11 @@
(|>> .i64 $.i64 unwrap_long long_to_int))
write! (: (-> Text Nat Synthesis Synthesis Synthesis)
(function (_ element_class index value array)
- ({#$.Extension "jvm array write object"
- (list (jvm_type (jvm/type.array (jvm/type.class element_class (list))))
- (literal_nat index)
- value
- array)})))
+ {#$.Extension "jvm array write object"
+ (list (jvm_type (jvm/type.array (jvm/type.class element_class (list))))
+ (literal_nat index)
+ value
+ array)}))
object_array (: (-> Text Nat Synthesis)
(function (_ class_name size)
{#$.Extension "jvm array new object"
diff --git a/stdlib/source/library/lux/data/format/json.lux b/stdlib/source/library/lux/data/format/json.lux
index aa6ef2279..f29042a83 100644
--- a/stdlib/source/library/lux/data/format/json.lux
+++ b/stdlib/source/library/lux/data/format/json.lux
@@ -67,8 +67,19 @@
(-> (List [String JSON]) JSON)
(|>> (dictionary.of_list text.hash) #..Object))
+(type: JSON'
+ (Rec JSON'
+ (Variant
+ {#Null' Null}
+ {#Boolean' Boolean}
+ {#Number' Number}
+ {#String' String}
+ {#Array' (Row JSON')}
+ {#Object' (Dictionary String JSON')}
+ {#Code' Code})))
+
(def: jsonP
- (<code>.Parser JSON)
+ (<code>.Parser JSON')
(<>.rec
(function (_ jsonP)
($_ <>.or
@@ -80,31 +91,35 @@
(<code>.tuple (<>.some jsonP)))
(<>\each (dictionary.of_list text.hash)
(<code>.variant (<>.some (<>.and <code>.text jsonP))))
+ <code>.any
))))
(def: (jsonF token)
- (-> JSON Code)
+ (-> JSON' Code)
(case token
- {#Null _}
+ {#Null' _}
(` #..Null)
- (^template [<ctor> <json_tag>]
- [{<json_tag> value}
- (` {<json_tag> (~ (<ctor> value))})])
- ([code.bit #..Boolean]
- [code.frac #..Number]
- [code.text #..String])
+ (^template [<ctor> <input_tag> <output_tag>]
+ [{<input_tag> value}
+ (` {<output_tag> (~ (<ctor> value))})])
+ ([code.bit #..Boolean' #..Boolean]
+ [code.frac #..Number' #..Number]
+ [code.text #..String' #..String])
- {#Array members}
+ {#Array' members}
(` {#..Array ((~! row.row) (~+ (row.list (row\each jsonF members))))})
- {#Object pairs}
+ {#Object' pairs}
(` {#..Object ((~! dictionary.of_list)
(~! text.hash)
(list (~+ (|> pairs
dictionary.entries
(list\each (function (_ [key_name value])
- (` [(~ (code.text key_name)) (~ (jsonF value))])))))))})))
+ (` [(~ (code.text key_name)) (~ (jsonF value))])))))))})
+
+ {#Code' code}
+ code))
(syntax: .public (json [token ..jsonP])
(in (list (` (: JSON (~ (jsonF token)))))))
diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis.lux
index 53968905c..5bebbcde9 100644
--- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis.lux
+++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis.lux
@@ -7,7 +7,12 @@
["[0]" exception {"+" [exception:]}]]
[data
[text
- ["%" format {"+" [format]}]]]
+ ["%" format {"+" [format]}]]
+ [collection
+ ["[0]" list]]]
+ [math
+ [number
+ ["n" nat]]]
["[0]" meta
["[0]" location]]]]
["[0]" / "_"
@@ -29,7 +34,8 @@
[archive {"+" [Archive]}]]]]]])
(exception: .public (unrecognized_syntax [code Code])
- (exception.report ["Code" (%.code code)]))
+ (exception.report
+ ["Code" (%.code code)]))
... TODO: Had to split the 'compile' function due to compilation issues
... with old-luxc. Must re-combine all the code ASAP
@@ -50,8 +56,8 @@
[#.Frac /primitive.frac]
[#.Text /primitive.text])
- (^ {#.Form (list& [_ {#.Tag tag}]
- values)})
+ (^ {#.Variant (list& [_ {#.Tag tag}]
+ values)})
(case values
{#.Item value #.End}
(/structure.tagged_sum compile tag archive value)
@@ -59,8 +65,8 @@
_
(/structure.tagged_sum compile tag archive (` [(~+ values)])))
- (^ {#.Form (list& [_ {#.Nat lefts}] [_ {#.Bit right?}]
- values)})
+ (^ {#.Variant (list& [_ {#.Nat lefts}] [_ {#.Bit right?}]
+ values)})
(case values
{#.Item value #.End}
(/structure.sum compile lefts right? archive value)
@@ -83,8 +89,10 @@
{#.Identifier reference}
(/reference.reference reference)
- (^ {#.Form (list [_ {#.Record branches}] input)})
- (/case.case compile branches archive input)
+ (^ {#.Form (list [_ {#.Variant branches}] input)})
+ (if (n.even? (list.size branches))
+ (/case.case compile (list.pairs branches) archive input)
+ (//.except ..unrecognized_syntax [location.dummy code']))
(^ {#.Form (list& [_ {#.Text extension_name}] extension_args)})
(//extension.apply archive compile [extension_name extension_args])
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 d7a7bf6ab..69307c2ac 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
@@ -13,7 +13,7 @@
[text
["%" format {"+" [format]}]]
[collection
- ["[0]" list ("[1]\[0]" mix monoid functor)]]]
+ ["[0]" list ("[1]\[0]" mix monoid monad)]]]
[math
[number
["n" nat]]]
@@ -57,7 +57,10 @@
coverage Coverage])
(exception.report
["Input" (%.code input)]
- ["Branches" (%.code (code.record branches))]
+ ["Branches" (%.code (code.tuple (|> branches
+ (list\each (function (_ [slot value])
+ (list slot value)))
+ list\conjoint)))]
["Coverage" (/coverage.%coverage coverage)]))
(exception: .public (cannot_have_empty_branches [message Text])
@@ -263,9 +266,9 @@
[location {#.Tag tag}]
(/.with_location location
- (analyse_pattern #.None inputT (` ((~ pattern))) next))
+ (analyse_pattern #.None inputT (` {(~ pattern)}) next))
- (^ [location {#.Form (list& [_ {#.Nat lefts}] [_ {#.Bit right?}] values)}])
+ (^ [location {#.Variant (list& [_ {#.Nat lefts}] [_ {#.Bit right?}] values)}])
(/.with_location location
(do ///.monad
[inputT' (simplify_case inputT)]
@@ -304,7 +307,7 @@
_
(/.except ..cannot_match_with_pattern [inputT' pattern]))))
- (^ [location {#.Form (list& [_ {#.Tag tag}] values)}])
+ (^ [location {#.Variant (list& [_ {#.Tag tag}] values)}])
(/.with_location location
(do ///.monad
[tag (///extension.lifted (meta.normal tag))
@@ -312,7 +315,7 @@
_ (//type.with_env
(check.check inputT variantT))
.let [[lefts right?] (/.choice (list.size group) idx)]]
- (analyse_pattern {#.Some (list.size group)} inputT (` ((~ (code.nat lefts)) (~ (code.bit right?)) (~+ values))) next)))
+ (analyse_pattern {#.Some (list.size group)} inputT (` {(~ (code.nat lefts)) (~ (code.bit right?)) (~+ values)}) next)))
_
(/.except ..not_a_pattern pattern)
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 417fe9709..0ccb8f1e0 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
@@ -15,7 +15,7 @@
[text
["%" format {"+" [format]}]]
[collection
- ["[0]" list ("[1]\[0]" functor)]
+ ["[0]" list ("[1]\[0]" monad)]
["[0]" dictionary {"+" [Dictionary]}]]]
[macro
["[0]" code]]
@@ -77,9 +77,10 @@
record (List [Name Code])])
(exception.report
["Tag" (%.code (code.tag key))]
- ["Record" (%.code (code.record (list\each (function (_ [keyI valC])
- [(code.tag keyI) valC])
- record)))]))]
+ ["Record" (%.code (code.tuple (|> record
+ (list\each (function (_ [keyI valC])
+ (list (code.tag keyI) valC)))
+ list\conjoint)))]))]
[cannot_repeat_tag]
)
@@ -100,8 +101,9 @@
["Type" (%.type type)]
["Expression" (%.code (|> record
(list\each (function (_ [keyI valueC])
- [(code.tag keyI) valueC]))
- code.record))]))
+ (list (code.tag keyI) valueC)))
+ list\conjoint
+ code.tuple))]))
(def: .public (sum analyse lefts right? archive)
(-> Phase Nat Bit Phase)
diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/directive/lux.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/directive/lux.lux
index 4ea0c4e7a..95775c22a 100644
--- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/directive/lux.lux
+++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/directive/lux.lux
@@ -248,7 +248,7 @@
(-> Expander /////analysis.Bundle Handler)
(..custom
[($_ <>.and <code>.local_identifier <code>.any
- (<>.or (<code>.form (<>.some <code>.text))
+ (<>.or (<code>.variant (<>.some <code>.text))
(<code>.tuple (<>.some <code>.text)))
<code>.any)
(function (_ extension_name phase archive [short_name valueC labels exported?C])
diff --git a/stdlib/source/poly/lux/abstract/equivalence.lux b/stdlib/source/poly/lux/abstract/equivalence.lux
index c6bdaf517..37bb54d79 100644
--- a/stdlib/source/poly/lux/abstract/equivalence.lux
+++ b/stdlib/source/poly/lux/abstract/equivalence.lux
@@ -117,11 +117,11 @@
(case [(~ g!left) (~ g!right)]
(~+ (list\conjoint (list\each (function (_ [tag g!eq])
(if (nat.= last tag)
- (list (` [((~ (code.nat (-- tag))) #1 (~ g!left))
- ((~ (code.nat (-- tag))) #1 (~ g!right))])
+ (list (` [{(~ (code.nat (-- tag))) #1 (~ g!left)}
+ {(~ (code.nat (-- tag))) #1 (~ g!right)}])
(` ((~ g!eq) (~ g!left) (~ g!right))))
- (list (` [((~ (code.nat tag)) #0 (~ g!left))
- ((~ (code.nat tag)) #0 (~ g!right))])
+ (list (` [{(~ (code.nat tag)) #0 (~ g!left)}
+ {(~ (code.nat tag)) #0 (~ g!right)}])
(` ((~ g!eq) (~ g!left) (~ g!right))))))
(list.enumeration members))))
(~ g!_)
diff --git a/stdlib/source/poly/lux/abstract/functor.lux b/stdlib/source/poly/lux/abstract/functor.lux
index 9537f3d38..d4637711f 100644
--- a/stdlib/source/poly/lux/abstract/functor.lux
+++ b/stdlib/source/poly/lux/abstract/functor.lux
@@ -58,10 +58,10 @@
(in (` (case (~ valueC)
(~+ (list\conjoint (list\each (function (_ [tag memberC])
(if (n.= last tag)
- (list (` ((~ (code.nat (-- tag))) #1 (~ valueC)))
- (` ((~ (code.nat (-- tag))) #1 (~ memberC))))
- (list (` ((~ (code.nat tag)) #0 (~ valueC)))
- (` ((~ (code.nat tag)) #0 (~ memberC))))))
+ (list (` {(~ (code.nat (-- tag))) #1 (~ valueC)})
+ (` {(~ (code.nat (-- tag))) #1 (~ memberC)}))
+ (list (` {(~ (code.nat tag)) #0 (~ valueC)})
+ (` {(~ (code.nat tag)) #0 (~ memberC)}))))
(list.enumeration membersC))))))))
... Tuples
(do p.monad
diff --git a/stdlib/source/poly/lux/data/format/json.lux b/stdlib/source/poly/lux/data/format/json.lux
index e556c2ac6..80d8e37e7 100644
--- a/stdlib/source/poly/lux/data/format/json.lux
+++ b/stdlib/source/poly/lux/data/format/json.lux
@@ -106,16 +106,16 @@
<encoder>))))]
[(<type>.exactly Any) (function ((~ g!_) (~ (code.identifier ["" "0"]))) #/.Null)]
- [(<type>.sub Bit) (|>> #/.Boolean)]
+ [(<type>.sub Bit) (|>> {#/.Boolean})]
[(<type>.sub Nat) (\ (~! ..nat_codec) (~' encoded))]
[(<type>.sub Int) (\ (~! ..int_codec) (~' encoded))]
- [(<type>.sub Frac) (|>> #/.Number)]
- [(<type>.sub Text) (|>> #/.String)])
+ [(<type>.sub Frac) (|>> {#/.Number})]
+ [(<type>.sub Text) (|>> {#/.String})])
<time> (template [<type> <codec>]
[(do !
[_ (<type>.exactly <type>)]
(in (` (: (~ (@JSON\encoded inputT))
- (|>> (\ (~! <codec>) (~' encoded)) #/.String)))))]
+ (|>> (\ (~! <codec>) (~' encoded)) {#/.String})))))]
... [duration.Duration duration.codec]
... [instant.Instant instant.codec]
@@ -150,7 +150,7 @@
((~! list\each) (function ((~ g!_) [(~ g!key) (~ g!val)])
[(~ g!key) ((~ =val=) (~ g!val))]))
((~! dictionary.of_list) (~! text.hash))
- #/.Object)))))
+ {#/.Object})))))
(do !
[[_ =sub=] (<type>.applied ($_ <>.and
(<type>.exactly .Maybe)
@@ -162,7 +162,7 @@
(<type>.exactly .List)
encoded))]
(in (` (: (~ (@JSON\encoded inputT))
- (|>> ((~! list\each) (~ =sub=)) ((~! row.of_list)) #/.Array)))))
+ (|>> ((~! list\each) (~ =sub=)) ((~! row.of_list)) {#/.Array})))))
(do !
[.let [g!_ (code.local_identifier "_______")
g!input (code.local_identifier "_______input")]
@@ -173,11 +173,11 @@
(case (~ g!input)
(~+ (list\conjoint (list\each (function (_ [tag g!encoded])
(if (n.= last tag)
- (.list (` ((~ (code.nat (-- tag))) #1 (~ g!input)))
+ (.list (` {(~ (code.nat (-- tag))) #1 (~ g!input)})
(` ((~! /.json) [(~ (code.frac (..tag (-- tag))))
#1
((~ g!encoded) (~ g!input))])))
- (.list (` ((~ (code.nat tag)) #0 (~ g!input)))
+ (.list (` {(~ (code.nat tag)) #0 (~ g!input)})
(` ((~! /.json) [(~ (code.frac (..tag tag)))
#0
((~ g!encoded) (~ g!input))])))))