on master help sign in
Get generated code pointing to Native.Utils properly
commit3df5323808c07315bc4b4eb02ea0b76b66146069 authorEvan Czaplicki <info@elm-lang.org> dateMon 5 Oct 2015, 19:13 (11 years ago) parent240bfb2
3 files changed+17−20
src/Generate/JavaScript.hs+5−7 src/Generate/JavaScript/BuiltIn.hs+9−10 src/Generate/JavaScript/Expression.hs+3−3
src/Generate/JavaScript.hs+5−7
@@ -97,13 +97,11 @@ assign path expr =
9797
9898imports :: [ModuleName.Raw] -> [Statement ()]
9999imports rawImports =
100− case rawImports of
101− [] ->
102− []
103−
104− _ ->
105− [ VarDeclStmt () (map jsImport rawImports)
106− ]
100+ let
101+ utils =
102+ varDecl "_U" (call (obj ["Elm", "Native", "Utils", "make"]) [ref localRuntime])
103+ in
104+ [ VarDeclStmt () (utils : map jsImport rawImports) ]
107105
108106
109107jsImport :: ModuleName.Raw -> VarDecl ()
src/Generate/JavaScript/BuiltIn.hs+9−10
@@ -1,5 +1,6 @@
11module Generate.JavaScript.BuiltIn where
22
3+import Control.Arrow (first)
34import qualified Language.ECMAScript3.Syntax as JS
45
56import Generate.JavaScript.Helpers
@@ -8,7 +9,7 @@ import qualified Reporting.Region as R
89
910utils :: String -> [JS.Expression ()] -> JS.Expression ()
1011utils func args =
11− obj ["_utils", func] `call` args
12+ obj ["_U", func] `call` args
1213
1314
1415-- LITERALS
@@ -39,12 +40,10 @@ range low high =
3940
4041recordUpdate :: JS.Expression () -> [(String, JS.Expression ())] -> JS.Expression ()
4142recordUpdate record fields =
42− utils "update" [ record, JS.ArrayLit () (map toKeyValue fields) ]
43−
44−
45−toKeyValue :: (String, JS.Expression ()) -> JS.Expression ()
46−toKeyValue (key, value) =
47− JS.ArrayLit () [ JS.StringLit () key, value ]
43+ utils "update"
44+ [ record
45+ , JS.ObjectLit () (map (first prop) fields)
46+ ]
4847
4948
5049-- COMPARISIONS
@@ -54,9 +53,9 @@ eq left right =
5453 utils "eq" [ left, right ]
5554
5655
57−compare :: JS.Expression () -> JS.Expression () -> JS.Expression ()
58−compare left right =
59− utils "compare" [ left, right ]
56+cmp :: JS.Expression () -> JS.Expression () -> JS.Expression ()
57+cmp left right =
58+ utils "cmp" [ left, right ]
6059
6160
6261-- CRASH
src/Generate/JavaScript/Expression.hs+3−3
@@ -1,7 +1,7 @@
11module Generate.JavaScript.Expression (generateDef) where
22
3−import Control.Arrow (first, second, (***))
4−import Control.Monad.State (State, forM, foldM)
3+import Control.Arrow (second)
4+import Control.Monad.State (State, foldM)
55import qualified Data.List as List
66import qualified Data.Map as Map
77import Language.ECMAScript3.Syntax
@@ -517,4 +517,4 @@ specialOps =
517517
518518cmp :: InfixOp -> Int -> Expression () -> Expression () -> Expression ()
519519cmp op n a b =
520− InfixExpr () op (BuiltIn.compare a b) (IntLit () n)
520+ InfixExpr () op (BuiltIn.cmp a b) (IntLit () n)