@@ -1,9 +1,15 @@
11{-# OPTIONS_GHC -Wall #-}
22{-# LANGUAGE OverloadedStrings #-}
33module AST.Expression.Canonical
4− ( Expr
5− , Expr_(..)
4+ ( Expr, Expr_(..)
65 , Def(..)
6+ -- patterns
7+ , Args(..), Arg(..)
8+ , Match(..)
9+ , Pattern, Pattern_(..)
10+ , Destructors
11+ , Destructor(..)
12+ -- decls
713 , Decl(..)
814 , Module(..)
915 , Alias(..)
@@ -25,7 +31,6 @@ import Data.Text (Text)
2531import qualified AST.Binop as Binop
2632import qualified AST.Literal as Literal
2733import qualified AST.Module.Name as ModuleName
28−import qualified AST.Pattern as Ptrn
2934import qualified AST.Type as Type
3035import qualified AST.Variable as Var
3136import qualified Elm.Name as N
@@ -39,7 +44,7 @@ import qualified Reporting.Region as R
3944
4045
4146type Expr =
42− A.Annotated R.Region Expr_
47+ A.Located Expr_
4348
4449
4550data Expr_
@@ -47,22 +52,25 @@ data Expr_
4752 | VarTopLevel ModuleName.Canonical Name
4853 | VarKernel Name Name
4954 | VarForeign ModuleName.Canonical Name
50− | VarOperator ModuleName.Canonical Name Name
55+ | VarOperator Name ModuleName.Canonical Name
5156 | Literal Literal.Literal
5257 | List [Expr]
58+ | Negate Expr
5359 | Binop Name ModuleName.Canonical Name Expr Expr
54− | Lambda [Ptrn.Canonical] Expr
60+ | Lambda Args Expr
5561 | Call Expr [Expr]
5662 | If [(Expr, Expr)] Expr
57− | Let [Graph.SCC Def] Expr
58− | Case Expr [(Ptrn.Canonical, Expr)]
63+ | Let Def Expr
64+ | LetRec [Def] Expr
65+ | LetDestruct Match Expr Expr
66+ | Case Expr [(Match, Expr)]
5967 | CtorAccess Expr Int
6068 | Accessor Name
6169 | Access Expr Name
62− | Update Expr [(Name, Expr)]
63− | Record [(Name, Expr)]
70+ | Update Expr (Map.Map Name Expr)
71+ | Record (Map.Map Name Expr)
6472 | Unit
65− | Tuple Expr Expr [Expr]
73+ | Tuple Expr Expr (Maybe Expr)
6674 | GLShader Name Name Literal.Shader
6775
6876
@@ -72,21 +80,54 @@ data Expr_
7280
7381data Def =
7482 Def
75− { _let_name :: Text
76− , _let_args :: [A.Located Ptrn.Canonical]
77− , _let_body :: Expr
78− , _let_type :: Maybe (A.Located Type.Canonical)
83+ { _def_name :: A.Located N.Name
84+ , _def_args :: Args
85+ , _def_body :: Expr
86+ , _def_type :: Maybe (A.Located Type.Canonical)
7987 }
8088
8189
8290
91+-- PATTERNS
92+
93+
94+data Args = Args [Arg] Destructors
95+data Arg = Arg Int Pattern
96+
97+data Match = Match Pattern Destructors
98+
99+
100+type Pattern = A.Located Pattern_
101+
102+data Pattern_
103+ = PAnything
104+ | PVar N.Name
105+ | PRecord [N.Name]
106+ | PAlias Pattern N.Name
107+ | PUnit
108+ | PTuple Pattern Pattern (Maybe Pattern)
109+ | PCtor ModuleName.Canonical N.Name [Pattern]
110+ | PList [Pattern]
111+ | PCons Pattern Pattern
112+ | PLiteral Literal.Literal
113+
114+
115+type Destructors = Map.Map N.Name (A.Located Destructor)
116+
117+data Destructor
118+ = DIndex Int Destructor
119+ | DField N.Name Destructor
120+ | DRoot Int
121+
122+
123+
83124-- DECLARATIONS
84125
85126
86127data Decl =
87128 Decl
88− { _top_name :: Text
89− , _top_args :: [A.Located Ptrn.Canonical]
129+ { _top_name :: N.Name
130+ , _top_args :: Args
90131 , _top_body :: Expr
91132 , _top_type :: Maybe (A.Located Type.Canonical)
92133 , _top_deps :: [Var.Global]