@@ -11,13 +11,13 @@ module Optimize.Port
1111import Prelude hiding (maybe, null)
1212import Control.Monad (foldM)
1313import qualified Data.Map as Map
14+import qualified Data.Name as Name
1415
1516import qualified AST.Canonical as Can
1617import qualified AST.Optimized as Opt
1718import qualified AST.Module.Name as ModuleName
1819import qualified AST.Utils.Type as Type
1920import qualified Data.Index as Index
20−import qualified Elm.Name as N
2121import qualified Optimize.Names as Names
2222
2323
@@ -38,7 +38,7 @@ toEncoder tipe =
3838 error "toEncoder: type variable"
3939
4040 Can.TUnit ->
41− Opt.Function [N.dollar] <$> encode "null"
41+ Opt.Function [Name.dollar] <$> encode "null"
4242
4343 Can.TTuple a b c ->
4444 encodeTuple a b c
@@ -46,16 +46,16 @@ toEncoder tipe =
4646 Can.TType _ name args ->
4747 case args of
4848 []
49− | name == N.float -> encode "float"
50− | name == N.int -> encode "int"
51− | name == N.bool -> encode "bool"
52− | name == N.string -> encode "string"
53− | name == N.value -> Names.registerGlobal ModuleName.basics N.identity
49+ | name == Name.float -> encode "float"
50+ | name == Name.int -> encode "int"
51+ | name == Name.bool -> encode "bool"
52+ | name == Name.string -> encode "string"
53+ | name == Name.value -> Names.registerGlobal ModuleName.basics Name.identity
5454
5555 [arg]
56− | name == N.maybe -> encodeMaybe arg
57− | name == N.list -> encodeList arg
58− | name == N.array -> encodeArray arg
56+ | name == Name.maybe -> encodeMaybe arg
57+ | name == Name.list -> encodeList arg
58+ | name == Name.array -> encodeArray arg
5959
6060 _ ->
6161 error "toEncoder: bad union type"
@@ -67,13 +67,13 @@ toEncoder tipe =
6767 let
6868 encodeField (name, Can.FieldType _ fieldType) =
6969 do encoder <- toEncoder fieldType
70− let value = Opt.Call encoder [Opt.Access (Opt.VarLocal N.dollar) name]
71− return $ Opt.Tuple (Opt.Str (N.toText name)) value Nothing
70+ let value = Opt.Call encoder [Opt.Access (Opt.VarLocal Name.dollar) name]
71+ return $ Opt.Tuple (Opt.Str (Name.toUtf8 name)) value Nothing
7272 in
7373 do object <- encode "object"
7474 keyValuePairs <- traverse encodeField (Map.toList fields)
7575 Names.registerFieldDict fields $
76− Opt.Function [N.dollar] (Opt.Call object [Opt.List keyValuePairs])
76+ Opt.Function [Name.dollar] (Opt.Call object [Opt.List keyValuePairs])
7777
7878
7979
@@ -85,8 +85,8 @@ encodeMaybe tipe =
8585 do null <- encode "null"
8686 encoder <- toEncoder tipe
8787 destruct <- Names.registerGlobal ModuleName.maybe "destruct"
88− return $ Opt.Function [N.dollar] $
89− Opt.Call destruct [ null, encoder, Opt.VarLocal N.dollar ]
88+ return $ Opt.Function [Name.dollar] $
89+ Opt.Call destruct [ null, encoder, Opt.VarLocal Name.dollar ]
9090
9191
9292encodeList :: Can.Type -> Names.Tracker Opt.Expr
@@ -107,27 +107,27 @@ encodeTuple :: Can.Type -> Can.Type -> Maybe Can.Type -> Names.Tracker Opt.Expr
107107encodeTuple a b maybeC =
108108 let
109109 let_ arg index body =
110− Opt.Destruct (Opt.Destructor arg (Opt.Index index (Opt.Root N.dollar))) body
110+ Opt.Destruct (Opt.Destructor arg (Opt.Index index (Opt.Root Name.dollar))) body
111111
112112 encodeArg arg tipe =
113113 do encoder <- toEncoder tipe
114114 return $ Opt.Call encoder [ Opt.VarLocal arg ]
115115 in
116116 do list <- encode "list"
117− identity <- Names.registerGlobal ModuleName.basics N.identity
117+ identity <- Names.registerGlobal ModuleName.basics Name.identity
118118 arg1 <- encodeArg "a" a
119119 arg2 <- encodeArg "b" b
120120
121121 case maybeC of
122122 Nothing ->
123− return $ Opt.Function [N.dollar] $
123+ return $ Opt.Function [Name.dollar] $
124124 let_ "a" Index.first $
125125 let_ "b" Index.second $
126126 Opt.Call list [ identity, Opt.List [ arg1, arg2 ] ]
127127
128128 Just c ->
129129 do arg3 <- encodeArg "c" c
130− return $ Opt.Function [N.dollar] $
130+ return $ Opt.Function [Name.dollar] $
131131 let_ "a" Index.first $
132132 let_ "b" Index.second $
133133 let_ "c" Index.third $
@@ -174,16 +174,16 @@ toDecoder tipe =
174174 Can.TType _ name args ->
175175 case args of
176176 []
177− | name == N.float -> decode "float"
178− | name == N.int -> decode "int"
179− | name == N.bool -> decode "bool"
180− | name == N.string -> decode "string"
181− | name == N.value -> decode "value"
177+ | name == Name.float -> decode "float"
178+ | name == Name.int -> decode "int"
179+ | name == Name.bool -> decode "bool"
180+ | name == Name.string -> decode "string"
181+ | name == Name.value -> decode "value"
182182
183183 [arg]
184− | name == N.maybe -> decodeMaybe arg
185− | name == N.list -> decodeList arg
186− | name == N.array -> decodeArray arg
184+ | name == Name.maybe -> decodeMaybe arg
185+ | name == Name.list -> decodeList arg
186+ | name == Name.array -> decodeArray arg
187187
188188 _ ->
189189 error "toDecoder: bad type"
@@ -268,7 +268,7 @@ decodeTuple a b maybeC =
268268
269269toLocal :: Int -> Opt.Expr
270270toLocal index =
271− Opt.VarLocal (N.addIndex "x" index)
271+ Opt.VarLocal (Name.fromVarIndex index)
272272
273273
274274indexAndThen :: Int -> Can.Type -> Opt.Expr -> Names.Tracker Opt.Expr
@@ -278,7 +278,7 @@ indexAndThen i tipe decoder =
278278 typeDecoder <- toDecoder tipe
279279 return $
280280 Opt.Call andThen
281− [ Opt.Function [N.addIndex "x" i] decoder
281+ [ Opt.Function [Name.fromVarIndex i] decoder
282282 , Opt.Call index [ Opt.Int i, typeDecoder ]
283283 ]
284284
@@ -287,7 +287,7 @@ indexAndThen i tipe decoder =
287287-- DECODE RECORDS
288288
289289
290−decodeRecord :: Map.Map N.Name Can.FieldType -> Names.Tracker Opt.Expr
290+decodeRecord :: Map.Map Name.Name Can.FieldType -> Names.Tracker Opt.Expr
291291decodeRecord fields =
292292 let
293293 toFieldExpr name _ =
@@ -301,7 +301,7 @@ decodeRecord fields =
301301 Names.registerFieldDict fields (Map.toList fields)
302302
303303
304−fieldAndThen :: Opt.Expr -> (N.Name, Can.FieldType) -> Names.Tracker Opt.Expr
304+fieldAndThen :: Opt.Expr -> (Name.Name, Can.FieldType) -> Names.Tracker Opt.Expr
305305fieldAndThen decoder (key, Can.FieldType _ tipe) =
306306 do andThen <- decode "andThen"
307307 field <- decode "field"
@@ -309,7 +309,7 @@ fieldAndThen decoder (key, Can.FieldType _ tipe) =
309309 return $
310310 Opt.Call andThen
311311 [ Opt.Function [key] decoder
312− , Opt.Call field [ Opt.Str (N.toText key), typeDecoder ]
312+ , Opt.Call field [ Opt.Str (Name.toUtf8 key), typeDecoder ]
313313 ]
314314
315315
@@ -317,11 +317,11 @@ fieldAndThen decoder (key, Can.FieldType _ tipe) =
317317-- GLOBALS HELPERS
318318
319319
320−encode :: N.Name -> Names.Tracker Opt.Expr
320+encode :: Name.Name -> Names.Tracker Opt.Expr
321321encode name =
322322 Names.registerGlobal ModuleName.jsonEncode name
323323
324324
325−decode :: N.Name -> Names.Tracker Opt.Expr
325+decode :: Name.Name -> Names.Tracker Opt.Expr
326326decode name =
327327 Names.registerGlobal ModuleName.jsonDecode name