From 55442e41b5889692e2bbacc0f943bd3382e6e11e Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Sat, 21 May 2016 18:42:17 -0400 Subject: - Now it's possible to pattern-match against variants using numeric indices. --- src/lux/analyser/case.clj | 19 ++++++++++++++----- src/lux/analyser/lux.clj | 2 +- src/lux/type.clj | 14 -------------- 3 files changed, 15 insertions(+), 20 deletions(-) (limited to 'src') 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 [ ] - (defn [type] - (|case type - ( l r) - (&/$Cons l ( r)) - - _ - (&/|list type))) - - unfold-prod &/$ProdT - unfold-sum &/$SumT - ) - (def create-var+ (|do [id create-var] (return (&/$VarT id)))) -- cgit v1.2.3