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 | Range (Expr ann def var typ) (Expr ann def var typ)
46 | ExplicitList [Expr ann def var typ]
47 | Binop var (Expr ann def var typ) (Expr ann def var typ)
48 | Lambda (Pattern.Pattern ann var) (Expr ann def var typ)
49 | App (Expr ann def var typ) (Expr ann def var typ)
50 | If [(Expr ann def var typ, Expr ann def var typ)] (Expr ann def var typ)
51 | Let [def] (Expr ann def var typ)
52 | Case (Expr ann def var typ) [(Pattern.Pattern ann var, Expr ann def var typ)]
53 | Data String [Expr ann def var typ]
54 | Access (Expr ann def var typ) String
55 | Update (Expr ann def var typ) [(String, Expr ann def var typ)]
56 | Record [(String, Expr ann def var typ)]
57 -- for type checking and code gen only
58 | Cmd ModuleName.Canonical
59 | Sub ModuleName.Canonical
60 | OutgoingPort String typ
61 | IncomingPort String typ
62 | Program (Main typ) (Expr ann def var typ)
63 | SaveEnv ModuleName.Canonical Effects.Canonical
64 | GLShader String String Literal.GLShaderTipe
77rawVar :: String -> Expr' ann def Var.Raw typ
82localVar :: String -> Expr' ann def Var.Canonical typ
84 Var (Var.Canonical Var.Local x)
87tuple :: [Expr ann def var typ] -> Expr' ann def var typ
89 Data ("_Tuple" ++ show (length expressions)) expressions
92collectApps :: Expr ann def var typ -> [Expr ann def var typ]
93collectApps annExpr@(A.A _ expr) =
102collectLambdas :: Expr ann def var typ -> ([Pattern.Pattern ann var], Expr ann def var typ)
103collectLambdas lexpr@(A.A _ expr) =
105 Lambda pattern body ->
107 (ps, body') = collectLambdas body
109 (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