aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEduardo Julian2016-05-21 18:42:17 -0400
committerEduardo Julian2016-05-21 18:42:17 -0400
commit55442e41b5889692e2bbacc0f943bd3382e6e11e (patch)
tree30a8d3540871aef1f37a7f9218d47080bf1db78f
parent31c2f62988372e2a17aa0d2a955b56d28b90170e (diff)
- Now it's possible to pattern-match against variants using numeric indices.
-rw-r--r--src/lux/analyser/case.clj19
-rw-r--r--src/lux/analyser/lux.clj2
-rw-r--r--src/lux/type.clj14
3 files changed, 15 insertions, 20 deletions
diff --git a/src/lux/analyser/case.clj b/src/lux/analyser/case.clj
index 5d6bc9965..1c315e405 100644
--- a/src/lux/analyser/case.clj
+++ b/src/lux/analyser/case.clj
@@ -37,7 +37,7 @@
("VariantTestAC" 1))
;; [Utils]
-(def ^:private unit
+(def ^:private unit-tuple
(&/T [(&/T ["" -1 -1]) (&/$TupleS &/$Nil)]))
(defn ^:private resolve-type [type]
@@ -237,11 +237,20 @@
idx (&module/tag-index =module =name)
group (&module/tag-group =module =name)
case-type (&type/sum-at idx value-type*)
- [=test =kont] (analyse-pattern &/$None case-type unit kont)]
+ [=test =kont] (analyse-pattern &/$None case-type unit-tuple kont)]
(return (&/T [($VariantTestAC (&/T [idx (&/|length group) =test])) =kont])))
- (&/$FormS (&/$Cons [_ (&/$TagS ?ident)]
- ?values))
+ (&/$FormS (&/$Cons [_ (&/$IntS idx)] ?values))
+ (|do [value-type* (adjust-type value-type)
+ case-type (&type/sum-at idx value-type*)
+ [=test =kont] (case (int (&/|length ?values))
+ 0 (analyse-pattern &/$None case-type unit-tuple kont)
+ 1 (analyse-pattern &/$None case-type (&/|head ?values) kont)
+ ;; 1+
+ (analyse-pattern &/$None case-type (&/T [(&/T ["" -1 -1]) (&/$TupleS ?values)]) kont))]
+ (return (&/T [($VariantTestAC (&/T [idx (&/|length (&type/flatten-sum value-type*)) =test])) =kont])))
+
+ (&/$FormS (&/$Cons [_ (&/$TagS ?ident)] ?values))
(|do [[=module =name] (&&/resolved-ident ?ident)
must-infer? (&type/unknown? value-type)
variant-type (if must-infer?
@@ -255,7 +264,7 @@
group (&module/tag-group =module =name)
case-type (&type/sum-at idx value-type*)
[=test =kont] (case (int (&/|length ?values))
- 0 (analyse-pattern &/$None case-type unit kont)
+ 0 (analyse-pattern &/$None case-type unit-tuple kont)
1 (analyse-pattern &/$None case-type (&/|head ?values) kont)
;; 1+
(analyse-pattern &/$None case-type (&/T [(&/T ["" -1 -1]) (&/$TupleS ?values)]) kont))]
diff --git a/src/lux/analyser/lux.clj b/src/lux/analyser/lux.clj
index 8492d5766..a0891371b 100644
--- a/src/lux/analyser/lux.clj
+++ b/src/lux/analyser/lux.clj
@@ -472,7 +472,7 @@
_ (&type/delete-var _inf-var)]
(return _func*)))
=func
- (&/|reverse (&type/unfold-prod =input)))
+ (&/|reverse (&type/flatten-prod =input)))
_
(|do [=func* (&type/clean $input =func)
diff --git a/src/lux/type.clj b/src/lux/type.clj
index 614d51eb3..70a2f69fa 100644
--- a/src/lux/type.clj
+++ b/src/lux/type.clj
@@ -902,20 +902,6 @@
fold-sum &/$VoidT &/$SumT
)
-
-(do-template [<name> <ctor>]
- (defn <name> [type]
- (|case type
- (<ctor> l r)
- (&/$Cons l (<name> r))
-
- _
- (&/|list type)))
-
- unfold-prod &/$ProdT
- unfold-sum &/$SumT
- )
-
(def create-var+
(|do [id create-var]
(return (&/$VarT id))))