aboutsummaryrefslogtreecommitdiff
path: root/new-luxc/source/luxc
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--new-luxc/source/luxc/analyser/case.lux44
-rw-r--r--new-luxc/source/luxc/analyser/primitive.lux2
-rw-r--r--new-luxc/source/luxc/analyser/struct.lux5
-rw-r--r--new-luxc/source/luxc/lang/analysis.lux3
-rw-r--r--new-luxc/source/luxc/lang/pattern.lux3
-rw-r--r--new-luxc/source/luxc/lang/synthesis.lux3
-rw-r--r--new-luxc/source/luxc/synthesizer.lux3
7 files changed, 36 insertions, 27 deletions
diff --git a/new-luxc/source/luxc/analyser/case.lux b/new-luxc/source/luxc/analyser/case.lux
index fc151f771..391261ac8 100644
--- a/new-luxc/source/luxc/analyser/case.lux
+++ b/new-luxc/source/luxc/analyser/case.lux
@@ -98,7 +98,7 @@
[_ (&;within-type-env
(TC;check inputT Unit))
outputA next]
- (wrap [#lp;Unit outputA])))
+ (wrap [(#lp;Tuple (list)) outputA])))
(^ [cursor (#;Tuple (list singleton))])
(analyse-pattern #;None inputT singleton next)
@@ -162,18 +162,28 @@
[inputT' (simplify-case-type inputT)]
(case inputT'
(#;Sum _)
- (let [flat-sum (type;flatten-variant inputT)]
+ (let [flat-sum (type;flatten-variant inputT)
+ size-sum (list;size flat-sum)
+ num-cases (default size-sum num-tags)]
(case (list;nth idx flat-sum)
- #;None
- (&;fail (format "Cannot match index " (%n idx) " against type: " (%type inputT)))
-
- (#;Some case-type)
- (do Monad<Lux>
- [[testP nextA] (analyse-pattern #;None case-type (' [(~@ values)]) next)]
- (wrap [(#lp;Variant [idx (default (list;size flat-sum)
- num-tags)]
- testP)
- nextA]))))
+ (^=> (#;Some case-type)
+ (n.< num-cases idx))
+ (if (and (n.> num-cases size-sum)
+ (n.= (n.dec num-cases) idx))
+ (do Monad<Lux>
+ [[testP nextA] (analyse-pattern #;None
+ (type;variant (list;drop (n.dec num-cases) flat-sum))
+ (' [(~@ values)])
+ next)]
+ (wrap [(#lp;Variant idx num-cases testP)
+ nextA]))
+ (do Monad<Lux>
+ [[testP nextA] (analyse-pattern #;None case-type (' [(~@ values)]) next)]
+ (wrap [(#lp;Variant idx num-cases testP)
+ nextA])))
+
+ _
+ (&;fail (format "Cannot match index " (%n idx) " against type: " (%type inputT)))))
_
(&;fail (pattern-error inputT pattern)))))
@@ -206,13 +216,17 @@
false))]
[total? #TotalC]
- [alt? #AltC])
+ [alt? #AltC]
+ )
(def: (determine-coverage pattern)
(-> Pattern Coverage)
(case pattern
- (^or (#lp;Bind _) #lp;Unit)
+ (^or (#lp;Bind _) (^ (#lp;Tuple (list))))
#TotalC
+
+ (^ (#lp;Tuple (list singleton)))
+ (determine-coverage singleton)
(#lp;Bool value)
(#BoolC value)
@@ -234,7 +248,7 @@
(#SeqC (determine-coverage sub)
post)))))
- (#lp;Variant [tag-id num-tags] sub)
+ (#lp;Variant tag-id num-tags sub)
(#VariantC num-tags
(|> (D;new number;Hash<Nat>)
(D;put tag-id (determine-coverage sub))))))
diff --git a/new-luxc/source/luxc/analyser/primitive.lux b/new-luxc/source/luxc/analyser/primitive.lux
index 26580a503..48be75c3c 100644
--- a/new-luxc/source/luxc/analyser/primitive.lux
+++ b/new-luxc/source/luxc/analyser/primitive.lux
@@ -31,4 +31,4 @@
[expected macro;expected-type
_ (&;within-type-env
(TC;check expected Unit))]
- (wrap #la;Unit)))
+ (wrap (#la;Tuple (list)))))
diff --git a/new-luxc/source/luxc/analyser/struct.lux b/new-luxc/source/luxc/analyser/struct.lux
index 1fbca886f..c1b332155 100644
--- a/new-luxc/source/luxc/analyser/struct.lux
+++ b/new-luxc/source/luxc/analyser/struct.lux
@@ -130,12 +130,11 @@
type-size (list;size flat)]
(if (n.< type-size tag)
(do @
- [#let [last? (n.= tag (n.dec type-size))
- variant-type (default (undefined)
+ [#let [variant-type (default (undefined)
(list;nth tag flat))]
=value (&;with-expected-type variant-type
(analyse value))]
- (wrap (#la;Variant tag last? =value)))
+ (wrap (#la;Variant tag type-size =value)))
(&;fail (format "Trying to create variant with tag beyond type's limitations." "\n"
" Tag: " (%n tag) "\n"
"Type size: " (%n type-size) "\n"
diff --git a/new-luxc/source/luxc/lang/analysis.lux b/new-luxc/source/luxc/lang/analysis.lux
index d9064604a..8cfc9b108 100644
--- a/new-luxc/source/luxc/lang/analysis.lux
+++ b/new-luxc/source/luxc/lang/analysis.lux
@@ -4,7 +4,6 @@
(.. ["lp" pattern]))
(type: #export #rec Analysis
- #Unit
(#Bool Bool)
(#Nat Nat)
(#Int Int)
@@ -12,7 +11,7 @@
(#Real Real)
(#Char Char)
(#Text Text)
- (#Variant Nat Bool Analysis)
+ (#Variant Nat Nat Analysis)
(#Tuple (List Analysis))
(#Case Analysis (List [lp;Pattern Analysis]))
(#Function Scope Analysis)
diff --git a/new-luxc/source/luxc/lang/pattern.lux b/new-luxc/source/luxc/lang/pattern.lux
index c422ea419..0b51e6284 100644
--- a/new-luxc/source/luxc/lang/pattern.lux
+++ b/new-luxc/source/luxc/lang/pattern.lux
@@ -3,7 +3,6 @@
(type: #export #rec Pattern
(#Bind Nat)
- #Unit
(#Bool Bool)
(#Nat Nat)
(#Int Int)
@@ -12,4 +11,4 @@
(#Char Char)
(#Text Text)
(#Tuple (List Pattern))
- (#Variant [Nat Nat] Pattern))
+ (#Variant Nat Nat Pattern))
diff --git a/new-luxc/source/luxc/lang/synthesis.lux b/new-luxc/source/luxc/lang/synthesis.lux
index 3eabd1d62..1edf0f1a0 100644
--- a/new-luxc/source/luxc/lang/synthesis.lux
+++ b/new-luxc/source/luxc/lang/synthesis.lux
@@ -3,7 +3,6 @@
(.. ["lp" pattern]))
(type: #export #rec Synthesis
- #Unit
(#Bool Bool)
(#Nat Nat)
(#Int Int)
@@ -11,7 +10,7 @@
(#Real Real)
(#Char Char)
(#Text Text)
- (#Variant Nat Bool Synthesis)
+ (#Variant Nat Nat Synthesis)
(#Tuple (List Synthesis))
(#Case (List [lp;Pattern Synthesis]))
(#Function Scope Synthesis)
diff --git a/new-luxc/source/luxc/synthesizer.lux b/new-luxc/source/luxc/synthesizer.lux
index fae6d8c5f..6acd2a0a2 100644
--- a/new-luxc/source/luxc/synthesizer.lux
+++ b/new-luxc/source/luxc/synthesizer.lux
@@ -15,8 +15,7 @@
(^template [<from> <to>]
(<from> value)
(<to> value))
- ([#la;Unit #ls;Unit]
- [#la;Bool #ls;Bool]
+ ([#la;Bool #ls;Bool]
[#la;Nat #ls;Nat]
[#la;Int #ls;Int]
[#la;Deg #ls;Deg]