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.Effects as Effects
12import qualified AST.Literal as Literal
13import qualified AST.Module.Name as ModuleName
14import qualified AST.Pattern as Pattern
15import qualified AST.Variable as Var
16import qualified Reporting.Annotation as A
23{-| This is a fully general Abstract Syntax Tree (AST) for expressions. It has
24"type holes" that allow us to enrich the AST with additional information as we
25move through the compilation process. The type holes are used to represent:
27 ann: Annotations for arbitrary expressions. Allows you to add information
28 to the AST like position in source code or inferred types.
30 def: Definition style. The source syntax separates type annotations and
31 definitions, but after parsing we check that they are well formed and
34 var: Representation of variables. Starts as strings, but is later enriched
35 with information about what module a variable came from.
38type Expr annotation definition variable tipe =
39 A.Annotated annotation (Expr' annotation definition variable tipe)
42data Expr' ann def var typ
43 = Literal Literal.Literal
45 | ExplicitList [Expr ann def var typ]
46 | Binop var (Expr ann def var typ) (Expr ann def var typ)
47 | Lambda (Pattern.Pattern ann var) (Expr ann def var typ)
48 | App (Expr ann def var typ) (Expr ann def var typ)
49 | If [(Expr ann def var typ, Expr ann def var typ)] (Expr ann def var typ)
50 | Let [def] (Expr ann def var typ)
51 | Case (Expr ann def var typ) [(Pattern.Pattern ann var, Expr ann def var typ)]
52 | Data String [Expr ann def var typ]
53 | Access (Expr ann def var typ) String
54 | Update (Expr ann def var typ) [(String, Expr ann def var typ)]
55 | Record [(String, Expr ann def var typ)]
56 -- for type checking and code gen only
57 | Cmd ModuleName.Canonical
58 | Sub ModuleName.Canonical
59 | OutgoingPort String typ
60 | IncomingPort String typ
61 | Program (Main typ) (Expr ann def var typ)
62 | SaveEnv ModuleName.Canonical Effects.Canonical
63 | GLShader String String Literal.GLShaderTipe
76rawVar :: String -> Expr' ann def Var.Raw typ
81localVar :: String -> Expr' ann def Var.Canonical typ
83 Var (Var.Canonical Var.Local x)
86tuple :: [Expr ann def var typ] -> Expr' ann def var typ
88 Data ("_Tuple" ++ show (length expressions)) expressions
91collectApps :: Expr ann def var typ -> [Expr ann def var typ]
92collectApps annExpr@(A.A _ expr) =
101collectLambdas :: Expr ann def var typ -> ([Pattern.Pattern ann var], Expr ann def var typ)
102collectLambdas lexpr@(A.A _ expr) =
104 Lambda pattern body ->
106 (ps, body') = collectLambdas body
108 (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