@@ -10,42 +10,77 @@ import qualified AST.Expression.Canonical as Canonical
10import qualified AST.Pattern as Pattern
10import qualified AST.Pattern as Pattern
11import qualified AST.Variable as V
11import qualified AST.Variable as V
13subst :: String -> Canonical.Expr' -> Canonical.Expr' -> Canonical.Expr'
14subst :: String -> Canonical.Expr' -> Canonical.Expr' -> Canonical.Expr'
14−subst old new expr =
15+subst old new expression =
15 let f (A a e) = A a (subst old new e) in
16 let f (A a e) = A a (subst old new e) in
16− case expr of
17+ case expression of
17− Range e1 e2 -> Range (f e1) (f e2)
19+ Range (f e1) (f e2)
21+ ExplicitList exprs ->
18− ExplicitList es -> ExplicitList (map f es)
22+ ExplicitList (map f exprs)
19− Binop op e1 e2 -> Binop op (f e1) (f e2)
25+ Binop op (f e1) (f e2)
20− Lambda p e
27+ Lambda pattern body
21− | Set.member old (Pattern.boundVars p) -> expr
28+ | Set.member old (Pattern.boundVars pattern) -> expression
22− | otherwise -> Lambda p (f e)
29+ | otherwise -> Lambda pattern (f body)
23− App e1 e2 -> App (f e1) (f e2)
32+ App (f e1) (f e2)
24− MultiIf ps -> MultiIf (map (f *** f) ps)
35+ MultiIf (map (f *** f) branches)
26 Let defs body
37 Let defs body
27− | anyShadow -> expr
38+ | anyShadow -> expression
28 | otherwise -> Let (map substDef defs) (f body)
39 | otherwise -> Let (map substDef defs) (f body)
30− substDef (Canonical.Definition p e t) = Canonical.Definition p (f e) t
41+ substDef (Canonical.Definition p e t) =
42+ Canonical.Definition p (f e) t
31 anyShadow =
44 anyShadow =
32− any (Set.member old . Pattern.boundVars) [ p | Canonical.Definition p _ _ <- defs ]
45+ any (Set.member old . Pattern.boundVars)
46+ [ pattern | Canonical.Definition pattern _ _ <- defs ]
34 Var (V.Canonical home x) ->
48 Var (V.Canonical home x) ->
35 case home of
49 case home of
36− V.Module _ -> expr
50+ V.Module _ -> expression
37− V.BuiltIn -> expr
51+ V.BuiltIn -> expression
38− V.Local -> if x == old then new else expr
52+ V.Local -> if x == old then new else expression
40− Case e cases -> Case (f e) $ map (second f) cases
55+ Case (f e) $ map (second f) cases
41− Data name es -> Data name (map f es)
56+
58+ Data tag (map f values)
60+ Access record field ->
42− Access e x -> Access (f e) x
61+ Access (f record) field
63+ Remove record field ->
43− Remove e x -> Remove (f e) x
64+ Remove (f record) field
44− Insert e x v -> Insert (f e) x (f v)
65+
66+ Insert record field value ->
67+ Insert (f record) field (f value)
69+ Modify record fields ->
45− Modify r fs -> Modify (f r) (map (second f) fs)
70+ Modify (f record) (map (second f) fields)
46− Record fs -> Record (map (second f) fs)
73+ Record (map (second f) fields)
47− Literal _ -> expr
75+ Literal _ -> expression
77+ Markdown uid md exprs ->
48− Markdown uid md es -> Markdown uid md (map f es)
78+ Markdown uid md (map f exprs)
49− GLShader _ _ _ -> expr
80+ GLShader _ _ _ -> expression
50− PortIn name st -> PortIn name st
82+ PortIn name st ->
85+ PortOut name st signal ->
51− PortOut name st signal -> PortOut name st (f signal)
86+ PortOut name st (f signal)