on master help sign in
cosmetic: more vertical whitespace
f25ef0cEvan Czaplicki
src/AST/Expression/General.hs+22−13
@@ -15,8 +15,10 @@ import qualified AST.Variable as Var
15import qualified Reporting.Annotation as A
15import qualified Reporting.Annotation as A
16
16
17
17
18+
18---- GENERAL AST ----
19---- GENERAL AST ----
19
20
21+
20{-| This is a fully general Abstract Syntax Tree (AST) for expressions. It has
22{-| 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
23"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:
24move through the compilation process. The type holes are used to represent:
@@ -56,8 +58,10 @@ data Expr' ann def var typ
56 | GLShader String String Literal.GLShaderTipe
58 | GLShader String String Literal.GLShaderTipe
57
59
58
60
61+
59-- PORTS
62-- PORTS
60
63
64+
61data PortImpl expr tipe
65data PortImpl expr tipe
62 = In String (Type.Port tipe)
66 = In String (Type.Port tipe)
63 | Out String expr (Type.Port tipe)
67 | Out String expr (Type.Port tipe)
@@ -73,8 +77,10 @@ portName impl =
73 Task name _ _ -> name
77 Task name _ _ -> name
74
78
75
79
80+
76---- UTILITIES ----
81---- UTILITIES ----
77
82
83+
78rawVar :: String -> Expr' ann def Var.Raw typ
84rawVar :: String -> Expr' ann def Var.Raw typ
79rawVar x =
85rawVar x =
80 Var (Var.Raw x)
86 Var (Var.Raw x)
@@ -97,28 +103,31 @@ saveEnvName =
97
103
98dummyLet :: [def] -> Expr ann def Var.Canonical typ
104dummyLet :: [def] -> Expr ann def Var.Canonical typ
99dummyLet defs =
105dummyLet defs =
106+ let
100− let body =
107+ body =
101− A.A undefined (Var (Var.builtin saveEnvName))
108+ A.A undefined (Var (Var.builtin saveEnvName))
102 in
109 in
103− A.A undefined (Let defs body)
110+ A.A undefined (Let defs body)
104
111
105
112
106collectApps :: Expr ann def var typ -> [Expr ann def var typ]
113collectApps :: Expr ann def var typ -> [Expr ann def var typ]
107collectApps annExpr@(A.A _ expr) =
114collectApps annExpr@(A.A _ expr) =
108 case expr of
115 case expr of
116+ App a b ->
109− App a b -> collectApps a ++ [b]
117+ collectApps a ++ [b]
118+
119+ _ ->
110− _ -> [annExpr]
120+ [annExpr]
111
121
112
122
113−collectLambdas
114− :: Expr ann def var typ
115− -> ([Pattern.Pattern ann var], Expr ann def var typ)
123+collectLambdas :: Expr ann def var typ -> ([Pattern.Pattern ann var], Expr ann def var typ)
116collectLambdas lexpr@(A.A _ expr) =
124collectLambdas lexpr@(A.A _ expr) =
117 case expr of
125 case expr of
118 Lambda pattern body ->
126 Lambda pattern body ->
119− let
127+ let
120− (ps, body') = collectLambdas body
128+ (ps, body') = collectLambdas body
121− in
129+ in
122− (pattern : ps, body')
130+ (pattern : ps, body')
123
131
132+ _ ->
124− _ -> ([], lexpr)
133+ ([], lexpr)