1{-# OPTIONS_GHC -Wall #-}
3{-| The Abstract Syntax Tree (AST) for expressions comes in a couple formats.
4The first is the fully general version and is labeled with a prime (Expr').
5The others are specialized versions of the AST that represent specific phases
6of the compilation process. I expect there to be more phases as we begin to
7enrich the AST with more information.
9module AST.Expression.General where
11import qualified AST.Literal as Literal
12import qualified AST.Pattern as Pattern
13import qualified AST.Type as Type
14import qualified AST.Variable as Var
15import qualified Reporting.Annotation as A
20{-| This is a fully general Abstract Syntax Tree (AST) for expressions. It has
21"type holes" that allow us to enrich the AST with additional information as we
22move through the compilation process. The type holes are used to represent:
24 ann: Annotations for arbitrary expressions. Allows you to add information
25 to the AST like position in source code or inferred types.
27 def: Definition style. The source syntax separates type annotations and
28 definitions, but after parsing we check that they are well formed and
31 var: Representation of variables. Starts as strings, but is later enriched
32 with information about what module a variable came from.
35type Expr annotation definition variable tipe =
36 A.Annotated annotation (Expr' annotation definition variable tipe)
39data Expr' ann def var typ
40 = Literal Literal.Literal
42 | Range (Expr ann def var typ) (Expr ann def var typ)
43 | ExplicitList [Expr ann def var typ]
44 | Binop var (Expr ann def var typ) (Expr ann def var typ)
45 | Lambda (Pattern.Pattern ann var) (Expr ann def var typ)
46 | App (Expr ann def var typ) (Expr ann def var typ)
47 | If [(Expr ann def var typ, Expr ann def var typ)] (Expr ann def var typ)
48 | Let [def] (Expr ann def var typ)
49 | Case (Expr ann def var typ) [(Pattern.Pattern ann var, Expr ann def var typ)]
50 | Data String [Expr ann def var typ]
51 | Access (Expr ann def var typ) String
52 | Update (Expr ann def var typ) [(String, Expr ann def var typ)]
53 | Record [(String, Expr ann def var typ)]
54 -- for type checking and code gen only
55 | Port (PortImpl (Expr ann def var typ) typ)
56 | GLShader String String Literal.GLShaderTipe
61data PortImpl expr tipe
62 = In String (Type.Port tipe)
63 | Out String expr (Type.Port tipe)
64 | Task String expr (Type.Port tipe)
68portName :: PortImpl expr tipe -> String
78rawVar :: String -> Expr' ann def Var.Raw typ
83localVar :: String -> Expr' ann def Var.Canonical typ
85 Var (Var.Canonical Var.Local x)
88tuple :: [Expr ann def var typ] -> Expr' ann def var typ
90 Data ("_Tuple" ++ show (length expressions)) expressions
95 "_save_the_environment!!!"
98dummyLet :: [def] -> Expr ann def Var.Canonical typ
101 A.A undefined (Var (Var.builtin saveEnvName))
103 A.A undefined (Let defs body)
106collectApps :: Expr ann def var typ -> [Expr ann def var typ]
107collectApps annExpr@(A.A _ expr) =
109 App a b -> collectApps a ++ [b]
114 :: Expr ann def var typ
115 -> ([Pattern.Pattern ann var], Expr ann def var typ)
116collectLambdas lexpr@(A.A _ expr) =
118 Lambda pattern body ->
120 (ps, body') = collectLambdas body
122 (pattern : ps, body')
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list