@@ -54,18 +54,18 @@ include alias moduleName =
55internalImports name =
55internalImports name =
56 VarDeclStmt ()
56 VarDeclStmt ()
57− [ varDecl "N" (obj "Elm.Native")
57+ [ varDecl "_N" (obj "Elm.Native")
58− , include "_N" "N.Utils"
58+ , include "_U" "_N.Utils"
59− , include "_L" "N.List"
59+ , include "_L" "_N.List"
60− , include "_E" "N.Error"
60+ , include "_E" "_N.Error"
61− , include "_J" "N.JavaScript"
61+ , include "_J" "_N.JavaScript"
62 , varDecl "$moduleName" (string name)
62 , varDecl "$moduleName" (string name)
65literal :: Literal -> Expression ()
65literal :: Literal -> Expression ()
66literal lit =
66literal lit =
67 case lit of
67 case lit of
68− Chr c -> obj "_N.chr" <| string [c]
68+ Chr c -> obj "_U.chr" <| string [c]
69 Str s -> string s
69 Str s -> string s
70 IntNum n -> IntLit () n
70 IntNum n -> IntLit () n
71 FloatNum n -> NumLit () n
71 FloatNum n -> NumLit () n
@@ -88,19 +88,19 @@ expression (L span expr) =
89 Remove e x ->
89 Remove e x ->
90 do e' <- expression e
90 do e' <- expression e
91− return $ obj "_N.remove" `call` [string x, e']
91+ return $ obj "_U.remove" `call` [string x, e']
93 Insert e x v ->
93 Insert e x v ->
94 do v' <- expression v
94 do v' <- expression v
95 e' <- expression e
95 e' <- expression e
96− return $ obj "_N.insert" `call` [string x, v', e']
96+ return $ obj "_U.insert" `call` [string x, v', e']
98 Modify e fs ->
98 Modify e fs ->
99 do e' <- expression e
99 do e' <- expression e
100 fs' <- forM fs $ \(f,v) -> do
100 fs' <- forM fs $ \(f,v) -> do
101 v' <- expression v
101 v' <- expression v
102 return $ ArrayLit () [string f, v']
102 return $ ArrayLit () [string f, v']
103− return $ obj "_N.replace" `call` [ArrayLit () fs', e']
103+ return $ obj "_U.replace" `call` [ArrayLit () fs', e']
105 Record fields ->
105 Record fields ->
106 do fields' <- forM fields $ \(f,e) -> do
106 do fields' <- forM fields $ \(f,e) -> do
@@ -198,11 +198,11 @@ expression (L span expr) =
199 PortIn name _ _ handler ->
199 PortIn name _ _ handler ->
200 do handler' <- expression handler
200 do handler' <- expression handler
201− return $ obj "_N.portIn" `call` [ string name, handler' ]
201+ return $ obj "Native.Ports.portIn" `call` [ string name, handler' ]
203 PortOut name _ signal ->
203 PortOut name _ signal ->
204 do signal' <- expression signal
204 do signal' <- expression signal
205− return $ obj "_N.portOut" `call` [ string name, signal' ]
205+ return $ obj "Native.Ports.portOut" `call` [ string name, signal' ]
207definition :: Def -> State Int [Statement ()]
207definition :: Def -> State Int [Statement ()]
208definition (Definition pattern expr@(L span _) _) = do
208definition (Definition pattern expr@(L span _) _) = do
@@ -309,8 +309,7 @@ generate unsafeModule =
309 concat [ setup (Just "_elm") (names modul ++ ["values"])
309 concat [ setup (Just "_elm") (names modul ++ ["values"])
310 , [ IfSingleStmt () thisModule (ReturnStmt () (Just thisModule)) ]
310 , [ IfSingleStmt () thisModule (ReturnStmt () (Just thisModule)) ]
311 , [ internalImports (List.intercalate "." (names modul)) ]
311 , [ internalImports (List.intercalate "." (names modul)) ]
312− , concatMap jsImport (imports modul)
312+ , concatMap jsImport . Set.toList . Set.fromList . map fst $ imports modul
313− , checkInPorts (recvPorts modul)
314 , [ assign ["_op"] (ObjectLit () []) ]
313 , [ assign ["_op"] (ObjectLit () []) ]
315 , concat $ evalState (mapM definition . fst . flattenLets [] $ program modul) 0
314 , concat $ evalState (mapM definition . fst . flattenLets [] $ program modul) 0
316 , [ jsExports ]
315 , [ jsExports ]
@@ -328,7 +327,7 @@ generate unsafeModule =
328 _ -> ExprStmt () $
327 _ -> ExprStmt () $
329 AssignExpr () OpAssign (LDot () (dotSep (init path)) (last path)) expr
328 AssignExpr () OpAssign (LDot () (dotSep (init path)) (last path)) expr
331− jsImport (modul,_) = setup Nothing path ++ [ include ]
330+ jsImport modul = setup Nothing path ++ [ include ]
333 path = split modul
332 path = split modul
334 include = assign path $ dotSep ("Elm" : path ++ ["make"]) <| ref "_elm"
333 include = assign path $ dotSep ("Elm" : path ++ ["make"]) <| ref "_elm"
@@ -340,11 +339,6 @@ generate unsafeModule =
340 Nothing -> tail . init $ List.inits path
339 Nothing -> tail . init $ List.inits path
341 Just nmspc -> drop 2 . init . List.inits $ nmspc : path
340 Just nmspc -> drop 2 . init . List.inits $ nmspc : path
343− checkInPorts ports =
344− [ ExprStmt () $ obj "_N.portCheck" `call` [ref "$moduleName", names] ]
346− names = ArrayLit () [ string name | (name, _, _) <- ports ]
348binop span op e1 e2 =
342binop span op e1 e2 =
349 case op of
343 case op of
350 "Basics.." ->
344 "Basics.." ->
@@ -394,8 +388,8 @@ binop span op e1 e2 =
394 specialOps = concat
388 specialOps = concat
395 [ specialOp "^" $ \a b -> obj "Math.pow" `call` [a,b]
389 [ specialOp "^" $ \a b -> obj "Math.pow" `call` [a,b]
396 , specialOp "|>" $ flip (<|)
390 , specialOp "|>" $ flip (<|)
397− , specialOp "==" $ \a b -> obj "_N.eq" `call` [a,b]
391+ , specialOp "==" $ \a b -> obj "_U.eq" `call` [a,b]
398− , specialOp "/=" $ \a b -> PrefixExpr () PrefixLNot (obj "_N.eq" `call` [a,b])
392+ , specialOp "/=" $ \a b -> PrefixExpr () PrefixLNot (obj "_U.eq" `call` [a,b])
399 , specialOp "<" $ cmp OpLT 0
393 , specialOp "<" $ cmp OpLT 0
400 , specialOp ">" $ cmp OpGT 0
394 , specialOp ">" $ cmp OpGT 0
401 , specialOp "<=" $ cmp OpLT 1
395 , specialOp "<=" $ cmp OpLT 1
@@ -403,4 +397,4 @@ binop span op e1 e2 =
403 , specialOp "div" $ \a b -> InfixExpr () OpBOr (InfixExpr () OpDiv a b) (IntLit () 0)
397 , specialOp "div" $ \a b -> InfixExpr () OpBOr (InfixExpr () OpDiv a b) (IntLit () 0)
406− cmp op n a b = InfixExpr () op (obj "_N.cmp" `call` [a,b]) (IntLit () n)
400+ cmp op n a b = InfixExpr () op (obj "_U.cmp" `call` [a,b]) (IntLit () n)