on master help sign in
Get generated code pointing to Native.Utils properly
3df5323Evan Czaplicki
src/Generate/JavaScript.hs+5−7
@@ -97,13 +97,11 @@ assign path expr =
97
97
98imports :: [ModuleName.Raw] -> [Statement ()]
98imports :: [ModuleName.Raw] -> [Statement ()]
99imports rawImports =
99imports rawImports =
100− case rawImports of
100+ let
101− [] ->
101+ utils =
102− []
102+ varDecl "_U" (call (obj ["Elm", "Native", "Utils", "make"]) [ref localRuntime])
103−
103+ in
104− _ ->
105− [ VarDeclStmt () (map jsImport rawImports)
104+ [ VarDeclStmt () (utils : map jsImport rawImports) ]
106− ]
107
105
108
106
109jsImport :: ModuleName.Raw -> VarDecl ()
107jsImport :: ModuleName.Raw -> VarDecl ()
src/Generate/JavaScript/BuiltIn.hs+9−10
@@ -1,5 +1,6 @@
1module Generate.JavaScript.BuiltIn where
1module Generate.JavaScript.BuiltIn where
2
2
3+import Control.Arrow (first)
3import qualified Language.ECMAScript3.Syntax as JS
4import qualified Language.ECMAScript3.Syntax as JS
4
5
5import Generate.JavaScript.Helpers
6import Generate.JavaScript.Helpers
@@ -8,7 +9,7 @@ import qualified Reporting.Region as R
8
9
9utils :: String -> [JS.Expression ()] -> JS.Expression ()
10utils :: String -> [JS.Expression ()] -> JS.Expression ()
10utils func args =
11utils func args =
11− obj ["_utils", func] `call` args
12+ obj ["_U", func] `call` args
12
13
13
14
14-- LITERALS
15-- LITERALS
@@ -39,12 +40,10 @@ range low high =
39
40
40recordUpdate :: JS.Expression () -> [(String, JS.Expression ())] -> JS.Expression ()
41recordUpdate :: JS.Expression () -> [(String, JS.Expression ())] -> JS.Expression ()
41recordUpdate record fields =
42recordUpdate record fields =
42− utils "update" [ record, JS.ArrayLit () (map toKeyValue fields) ]
43+ utils "update"
43−
44+ [ record
44−
45+ , JS.ObjectLit () (map (first prop) fields)
45−toKeyValue :: (String, JS.Expression ()) -> JS.Expression ()
46+ ]
46−toKeyValue (key, value) =
47− JS.ArrayLit () [ JS.StringLit () key, value ]
48
47
49
48
50-- COMPARISIONS
49-- COMPARISIONS
@@ -54,9 +53,9 @@ eq left right =
54 utils "eq" [ left, right ]
53 utils "eq" [ left, right ]
55
54
56
55
57−compare :: JS.Expression () -> JS.Expression () -> JS.Expression ()
56+cmp :: JS.Expression () -> JS.Expression () -> JS.Expression ()
58−compare left right =
57+cmp left right =
59− utils "compare" [ left, right ]
58+ utils "cmp" [ left, right ]
60
59
61
60
62-- CRASH
61-- CRASH
src/Generate/JavaScript/Expression.hs+3−3
@@ -1,7 +1,7 @@
1module Generate.JavaScript.Expression (generateDef) where
1module Generate.JavaScript.Expression (generateDef) where
2
2
3−import Control.Arrow (first, second, (***))
3+import Control.Arrow (second)
4−import Control.Monad.State (State, forM, foldM)
4+import Control.Monad.State (State, foldM)
5import qualified Data.List as List
5import qualified Data.List as List
6import qualified Data.Map as Map
6import qualified Data.Map as Map
7import Language.ECMAScript3.Syntax
7import Language.ECMAScript3.Syntax
@@ -517,4 +517,4 @@ specialOps =
517
517
518cmp :: InfixOp -> Int -> Expression () -> Expression () -> Expression ()
518cmp :: InfixOp -> Int -> Expression () -> Expression () -> Expression ()
519cmp op n a b =
519cmp op n a b =
520− InfixExpr () op (BuiltIn.compare a b) (IntLit () n)
520+ InfixExpr () op (BuiltIn.cmp a b) (IntLit () n)