@@ -1,10 +1,13 @@
1+{-# LANGUAGE OverloadedStrings #-}
1module Generate.JavaScript.Expression (generateDef) where
2module Generate.JavaScript.Expression (generateDef) where
3import Control.Arrow (second)
4import Control.Arrow (second)
4import Control.Monad.State (State, foldM)
5import Control.Monad.State (State, foldM)
5import qualified Data.List as List
6import qualified Data.List as List
6import qualified Data.Map as Map
7import qualified Data.Map as Map
7−import Language.ECMAScript3.Syntax
8+import Data.Monoid ((<>))
9+import qualified Data.Text as Text
10+import Data.Text (Text)
9import qualified AST.Expression.Canonical as Can
12import qualified AST.Expression.Canonical as Can
10import AST.Expression.Optimized as Opt
13import AST.Expression.Optimized as Opt
@@ -12,6 +15,7 @@ import qualified AST.Literal as L
12import qualified AST.Module.Name as ModuleName
15import qualified AST.Module.Name as ModuleName
13import qualified AST.Variable as Var
16import qualified AST.Variable as Var
14import Generate.JavaScript.Helpers as Help
17import Generate.JavaScript.Helpers as Help
18+import qualified Generate.JavaScript.Builder as JS
15import qualified Generate.JavaScript.BuiltIn as BuiltIn
19import qualified Generate.JavaScript.BuiltIn as BuiltIn
16import qualified Generate.JavaScript.Foreign as Foreign
20import qualified Generate.JavaScript.Foreign as Foreign
17import qualified Generate.JavaScript.Literal as Literal
21import qualified Generate.JavaScript.Literal as Literal
@@ -24,16 +28,16 @@ import qualified Optimize.DecisionTree as DT
27− = JsExpr (Expression ())
31+ = JsExpr JS.Expr
28− | JsBlock [Statement ()]
32+ | JsBlock [JS.Stmt]
31−jsExpr :: Expression () -> State Int Code
35+jsExpr :: JS.Expr -> State Int Code
32jsExpr exp =
36jsExpr exp =
33 return (JsExpr exp)
37 return (JsExpr exp)
36−jsBlock :: [Statement ()] -> State Int Code
40+jsBlock :: [JS.Stmt] -> State Int Code
37jsBlock exp =
41jsBlock exp =
38 return (JsBlock exp)
42 return (JsBlock exp)
@@ -45,44 +49,44 @@ isBlock code =
45 JsExpr _ -> False
49 JsExpr _ -> False
48−toStatementList :: Code -> [Statement ()]
52+toStatementList :: Code -> [JS.Stmt]
49toStatementList code =
53toStatementList code =
50 case code of
54 case code of
51 JsExpr expr ->
55 JsExpr expr ->
52− [ ReturnStmt () (Just expr) ]
56+ [ JS.Return (Just expr) ]
54 JsBlock stmts ->
58 JsBlock stmts ->
58−toStatement :: Code -> Statement ()
62+toStatement :: Code -> JS.Stmt
59toStatement code =
63toStatement code =
60 case code of
64 case code of
61 JsExpr expr ->
65 JsExpr expr ->
62− ReturnStmt () (Just expr)
66+ JS.Return (Just expr)
64 JsBlock [stmt] ->
68 JsBlock [stmt] ->
67 JsBlock stmts ->
71 JsBlock stmts ->
68− BlockStmt () stmts
72+ JS.Block stmts
71−toExpr :: Code -> Expression ()
75+toExpr :: Code -> JS.Expr
72toExpr code =
76toExpr code =
73 case code of
77 case code of
74 JsExpr expr ->
78 JsExpr expr ->
77 JsBlock stmts ->
81 JsBlock stmts ->
78− function [] stmts `call` []
82+ JS.Call (function [] stmts) []
82-- DEFINITIONS
86-- DEFINITIONS
85−generateDef :: Opt.Def -> State Int [Statement ()]
89+generateDef :: Opt.Def -> State Int [JS.Stmt]
86generateDef def =
90generateDef def =
87 do (home, name, jsBody) <-
91 do (home, name, jsBody) <-
88 case def of
92 case def of
@@ -99,7 +103,7 @@ generateDef def =
99-- EXPRESSIONS
103-- EXPRESSIONS
102−generateJsExpr :: Opt.Expr -> State Int (Expression ())
106+generateJsExpr :: Opt.Expr -> State Int JS.Expr
103generateJsExpr optExpr =
107generateJsExpr optExpr =
104 toExpr <$> generateCode optExpr
108 toExpr <$> generateCode optExpr
@@ -114,8 +118,8 @@ generateCode expr =
114 jsExpr (Literal.literal lit)
118 jsExpr (Literal.literal lit)
116 Access record field ->
120 Access record field ->
117− do record' <- generateJsExpr record
121+ do jsRecord <- generateJsExpr record
118− jsExpr $ DotRef () record' (var (Var.safe field))
122+ jsExpr $ JS.DotRef jsRecord (JS.Id (Var.safe field))
120 Update record fields ->
124 Update record fields ->
@@ -134,7 +138,7 @@ generateCode expr =
134 return (Var.safe field ==> jsValue)
138 return (Var.safe field ==> jsValue)
136 do jsFields <- mapM toField fields
140 do jsFields <- mapM toField fields
137− jsExpr $ ObjectLit () jsFields
141+ jsExpr $ JS.Object jsFields
139 Binop op leftExpr rightExpr ->
143 Binop op leftExpr rightExpr ->
140 binop op leftExpr rightExpr
144 binop op leftExpr rightExpr
@@ -148,14 +152,15 @@ generateCode expr =
148 TailCall name argNames args ->
152 TailCall name argNames args ->
150 reassign name tempName =
154 reassign name tempName =
151− ExprStmt () (AssignExpr () OpAssign (LVar () (Var.safe name)) (ref tempName))
156+ JS.Assign JS.OpAssign (JS.LVar (Var.safe name)) (ref tempName)
153 do args' <- mapM generateJsExpr args
158 do args' <- mapM generateJsExpr args
154 tempNames <- mapM (\_ -> Var.fresh) args
159 tempNames <- mapM (\_ -> Var.fresh) args
155 jsBlock $
160 jsBlock $
156− VarDeclStmt () (zipWith varDecl tempNames args')
161+ JS.VarDeclStmt (zipWith varDecl tempNames args')
157 : zipWith reassign argNames tempNames
162 : zipWith reassign argNames tempNames
158− ++ [ContinueStmt () (Just (Id () (Var.safe name)))]
163+ ++ [JS.Continue (Just (JS.Id (Var.safe name)))]
160 Let defs body ->
165 Let defs body ->
161 do stmts <- mapM generateDef defs
166 do stmts <- mapM generateDef defs
@@ -175,17 +180,17 @@ generateCode expr =
175 Ctor tag members ->
180 Ctor tag members ->
178− "ctor" ==> StringLit () tag
183+ "ctor" ==> JS.String tag
180 toEntry entry n =
185 toEntry entry n =
181− ("_" ++ show n) ==> entry
186+ ("_" <> Text.pack (show n)) ==> entry
183 do jsMembers <- mapM generateJsExpr members
188 do jsMembers <- mapM generateJsExpr members
184− jsExpr $ ObjectLit () (ctor : zipWith toEntry jsMembers [ 0 :: Int .. ])
189+ jsExpr $ JS.Object (ctor : zipWith toEntry jsMembers [ 0 :: Int .. ])
186 CtorAccess dataExpr index ->
191 CtorAccess dataExpr index ->
187 do jsDataExpr <- generateJsExpr dataExpr
192 do jsDataExpr <- generateJsExpr dataExpr
188− jsExpr $ DotRef () jsDataExpr (var ("_" ++ show index))
193+ jsExpr $ JS.DotRef jsDataExpr (JS.Id ("_" <> Text.pack (show index)))
190 Cmd moduleName ->
195 Cmd moduleName ->
191 jsExpr $ BuiltIn.effect moduleName
196 jsExpr $ BuiltIn.effect moduleName
@@ -204,7 +209,7 @@ generateCode expr =
204 generateProgram kind body
209 generateProgram kind body
206 GLShader _uid src _tipe ->
211 GLShader _uid src _tipe ->
207− jsExpr $ ObjectLit () [(PropString () "src", Literal.literal (L.Str src))]
212+ jsExpr $ JS.Object [(JS.StringProp "src", Literal.literal (L.Str src))]
209 Crash home region maybeBranchProblem ->
214 Crash home region maybeBranchProblem ->
210 do maybeOptBranchProblem <- traverse generateJsExpr maybeBranchProblem
215 do maybeOptBranchProblem <- traverse generateJsExpr maybeBranchProblem
@@ -224,7 +229,7 @@ generateProgram kind body =
225 Can.NoFlags ->
230 Can.NoFlags ->
226 do almostProgram <- generateJsExpr body
231 do almostProgram <- generateJsExpr body
227− jsExpr (almostProgram `call` [])
232+ jsExpr (JS.Call almostProgram [])
229 Can.Flags tipe ->
234 Can.Flags tipe ->
230 do almostProgram <- generateJsExpr body
235 do almostProgram <- generateJsExpr body
@@ -236,22 +241,22 @@ generateProgram kind body =
236-- FUNCTIONS
241-- FUNCTIONS
239−generateFunction :: [String] -> Opt.Expr -> State Int Code
244+generateFunction :: [Text] -> Opt.Expr -> State Int Code
240generateFunction args body =
245generateFunction args body =
241 do code <- generateCode body
246 do code <- generateCode body
242 jsExpr (generateFunctionWithArity args code)
247 jsExpr (generateFunctionWithArity args code)
245−generateTailFunction :: String -> [String] -> Opt.Expr -> State Int (Expression ())
250+generateTailFunction :: Text -> [Text] -> Opt.Expr -> State Int JS.Expr
246generateTailFunction name args body =
251generateTailFunction name args body =
247 do code <- generateCode body
252 do code <- generateCode body
248 return $ generateFunctionWithArity args $ JsBlock $ (:[]) $
253 return $ generateFunctionWithArity args $ JsBlock $ (:[]) $
249− LabelledStmt ()
254+ JS.Labelled
250− (Id () (Var.safe name))
255+ (JS.Id (Var.safe name))
251− (WhileStmt () (BoolLit () True) (toStatement code))
256+ (JS.While (JS.Bool True) (toStatement code))
254−generateFunctionWithArity :: [String] -> Code -> Expression ()
259+generateFunctionWithArity :: [Text] -> Code -> JS.Expr
255generateFunctionWithArity rawArgs code =
260generateFunctionWithArity rawArgs code =
257 args = map Var.safe rawArgs
262 args = map Var.safe rawArgs
@@ -259,7 +264,7 @@ generateFunctionWithArity rawArgs code =
260 if 2 <= arity && arity <= 9 then
265 if 2 <= arity && arity <= 9 then
262− fN = "F" ++ show arity
267+ fN = "F" <> Text.pack (show arity)
264 ref fN <| function args (toStatementList code)
269 ref fN <| function args (toStatementList code)
@@ -267,7 +272,7 @@ generateFunctionWithArity rawArgs code =
267 (lastArg:otherArgs) = reverse args
272 (lastArg:otherArgs) = reverse args
268 innerBody = function [lastArg] (toStatementList code)
273 innerBody = function [lastArg] (toStatementList code)
270− foldl (\body arg -> function [arg] [ReturnStmt () (Just body)]) innerBody otherArgs
275+ foldl (\body arg -> function [arg] [JS.Return (Just body)]) innerBody otherArgs
@@ -281,7 +286,7 @@ generateCall func args =
281 case getUnaryOp var of
286 case getUnaryOp var of
282 Just op ->
287 Just op ->
283 do jsArg <- generateJsExpr arg
288 do jsArg <- generateJsExpr arg
284− jsExpr $ PrefixExpr () op jsArg
289+ jsExpr $ JS.Prefix op jsArg
286 Nothing ->
291 Nothing ->
287 generateCallHelp func args
292 generateCallHelp func args
@@ -291,7 +296,7 @@ generateCall func args =
291 Just (op, left, right) ->
296 Just (op, left, right) ->
292 do jsLeft <- generateJsExpr left
297 do jsLeft <- generateJsExpr left
293 jsRight <- generateJsExpr right
298 jsRight <- generateJsExpr right
294− jsExpr $ InfixExpr () op jsLeft jsRight
299+ jsExpr $ JS.Infix op jsLeft jsRight
296 Nothing ->
301 Nothing ->
297 generateCallHelp func args
302 generateCallHelp func args
@@ -304,58 +309,58 @@ generateCallHelp :: Opt.Expr -> [Opt.Expr] -> State Int Code
304generateCallHelp func args =
309generateCallHelp func args =
306 arity = length args
311 arity = length args
307− aN = "A" ++ show arity
312+ aN = "A" <> Text.pack (show arity)
309 do jsFunc <- generateJsExpr func
314 do jsFunc <- generateJsExpr func
310 jsArgs <- mapM generateJsExpr args
315 jsArgs <- mapM generateJsExpr args
312 if 2 <= arity && arity <= 9 then
317 if 2 <= arity && arity <= 9 then
313− ref aN `call` (jsFunc:jsArgs)
318+ JS.Call (ref aN) (jsFunc:jsArgs)
315 foldl1 (<|) (jsFunc:jsArgs)
320 foldl1 (<|) (jsFunc:jsArgs)
318−getUnaryOp :: Var.Canonical -> Maybe PrefixOp
323+getUnaryOp :: Var.Canonical -> Maybe JS.PrefixOp
319getUnaryOp var =
324getUnaryOp var =
320 if var == bitwiseComplement then
325 if var == bitwiseComplement then
321− Just PrefixBNot
326+ Just JS.PrefixBNot
323 else if var == basicsNot then
328 else if var == basicsNot then
324− Just PrefixLNot
329+ Just JS.PrefixLNot
330−getBinaryOp :: Var.Canonical -> Opt.Expr -> Opt.Expr -> Maybe (InfixOp, Opt.Expr, Opt.Expr)
335+getBinaryOp :: Var.Canonical -> Opt.Expr -> Opt.Expr -> Maybe (JS.InfixOp, Opt.Expr, Opt.Expr)
331getBinaryOp (Var.Canonical home name) left right =
336getBinaryOp (Var.Canonical home name) left right =
332 if home /= bitwise then
337 if home /= bitwise then
336 case name of
341 case name of
337− "and" -> Just ( OpBAnd, left, right )
342+ "and" -> Just ( JS.OpBAnd, left, right )
338− "or" -> Just ( OpBOr, left, right )
343+ "or" -> Just ( JS.OpBOr, left, right )
339− "xor" -> Just ( OpBXor, left, right )
344+ "xor" -> Just ( JS.OpBXor, left, right )
340− "shiftLeftBy" -> Just ( OpLShift, right, left )
345+ "shiftLeftBy" -> Just ( JS.OpLShift, right, left )
341− "shiftRightBy" -> Just ( OpSpRShift, right, left )
346+ "shiftRightBy" -> Just ( JS.OpSpRShift, right, left )
342− "shiftRightZfBy" -> Just ( OpZfRShift, right, left )
347+ "shiftRightZfBy" -> Just ( JS.OpZfRShift, right, left )
343 _ -> Nothing
348 _ -> Nothing
346bitwiseComplement :: Var.Canonical
351bitwiseComplement :: Var.Canonical
347bitwiseComplement =
352bitwiseComplement =
348− Var.inCore ["Bitwise"] "complement"
353+ Var.inCore "Bitwise" "complement"
351basicsNot :: Var.Canonical
356basicsNot :: Var.Canonical
352basicsNot =
357basicsNot =
353− Var.inCore ["Basics"] "not"
358+ Var.inCore "Basics" "not"
356bitwise :: Var.Home
361bitwise :: Var.Home
358− Var.Module (ModuleName.inCore ["Bitwise"])
363+ Var.Module (ModuleName.inCore "Bitwise")
@@ -372,10 +377,10 @@ generateIf givenBranches givenFinally =
372 (,) <$> generateJsExpr condition <*> generateCode expr
377 (,) <$> generateJsExpr condition <*> generateCode expr
374 ifExpression (condition, branch) otherwise =
379 ifExpression (condition, branch) otherwise =
375− CondExpr () condition branch otherwise
380+ JS.If condition branch otherwise
377 ifStatement (condition, branch) otherwise =
382 ifStatement (condition, branch) otherwise =
378− IfStmt () condition branch otherwise
383+ JS.IfStmt condition branch otherwise
380 do jsBranches <- mapM convertBranch branches
385 do jsBranches <- mapM convertBranch branches
381 jsFinally <- generateCode finally
386 jsFinally <- generateCode finally
@@ -421,11 +426,7 @@ crushIfsHelp visitedBranches unvisitedBranches finally =
421-- CASE EXPRESSIONS
426-- CASE EXPRESSIONS
426− -> Opt.Decider Opt.Choice
429+generateCase :: Text -> Opt.Decider Opt.Choice -> [(Int, Opt.Expr)] -> State Int [JS.Stmt]
427− -> [(Int, Opt.Expr)]
428− -> State Int [Statement ()]
429generateCase exprName decider jumps =
430generateCase exprName decider jumps =
430 do labelRoot <- Var.fresh
431 do labelRoot <- Var.fresh
431 decider <- generateDecider exprName labelRoot decider
432 decider <- generateDecider exprName labelRoot decider
@@ -436,76 +437,68 @@ generateCase exprName decider jumps =
436-- handle any jumps
437-- handle any jumps
439−goto :: String -> [Statement ()] -> (Int, Opt.Expr) -> State Int [Statement ()]
440+goto :: Text -> [JS.Stmt] -> (Int, Opt.Expr) -> State Int [JS.Stmt]
440goto labelRoot deciderStmts (target, branch) =
441goto labelRoot deciderStmts (target, branch) =
442 labeledDeciderStmt =
443 labeledDeciderStmt =
443− LabelledStmt ()
444+ JS.Labelled
444 (toLabel labelRoot target)
445 (toLabel labelRoot target)
445− (DoWhileStmt () (BlockStmt () deciderStmts) (BoolLit () False))
446+ (JS.DoWhile (JS.Block deciderStmts) (JS.Bool False))
447 do code <- generateCode branch
448 do code <- generateCode branch
448 return (labeledDeciderStmt : toStatementList code)
449 return (labeledDeciderStmt : toStatementList code)
451−toLabel :: String -> Int -> Id ()
452+toLabel :: Text -> Int -> JS.Id
452toLabel root target =
453toLabel root target =
453− Id () (root ++ "_" ++ show target)
454+ JS.Id (root <> "_" <> Text.pack (show target))
457-- turn deciders into ifs and switches
458-- turn deciders into ifs and switches
463− -> Opt.Decider Opt.Choice
461+generateDecider :: Text -> Text -> Opt.Decider Opt.Choice -> State Int [JS.Stmt]
464− -> State Int [Statement ()]
465generateDecider exprName labelRoot decisionTree =
462generateDecider exprName labelRoot decisionTree =
466 case decisionTree of
463 case decisionTree of
467 Opt.Leaf (Opt.Inline branch) ->
464 Opt.Leaf (Opt.Inline branch) ->
468 toStatementList <$> generateCode branch
465 toStatementList <$> generateCode branch
470 Opt.Leaf (Opt.Jump target) ->
467 Opt.Leaf (Opt.Jump target) ->
471− return [ BreakStmt () (Just (toLabel labelRoot target)) ]
468+ return [ JS.Break (Just (toLabel labelRoot target)) ]
473 Opt.Chain testChain success failure ->
470 Opt.Chain testChain success failure ->
475 makeTest (path, test) =
472 makeTest (path, test) =
476 do testExpr <- pathToTestableExpr exprName path test
473 do testExpr <- pathToTestableExpr exprName path test
477− return (InfixExpr () OpStrictEq testExpr (testToExpr test))
474+ return (JS.Infix JS.OpStrictEq testExpr (testToExpr test))
479 do testExprs <- mapM makeTest testChain
476 do testExprs <- mapM makeTest testChain
480− let cond = List.foldl1' (InfixExpr () OpLAnd) testExprs
477+ let cond = List.foldl1' (JS.Infix JS.OpLAnd) testExprs
481 thenBranch <- generateDecider exprName labelRoot success
478 thenBranch <- generateDecider exprName labelRoot success
482 elseBranch <- generateDecider exprName labelRoot failure
479 elseBranch <- generateDecider exprName labelRoot failure
483− return [ IfStmt () cond (BlockStmt () thenBranch) (BlockStmt () elseBranch) ]
480+ return [ JS.IfStmt cond (JS.Block thenBranch) (JS.Block elseBranch) ]
485 Opt.FanOut path edges fallback ->
482 Opt.FanOut path edges fallback ->
486 do testExpr <- pathToTestableExpr exprName path (fst (head edges))
483 do testExpr <- pathToTestableExpr exprName path (fst (head edges))
487− caseClauses <- mapM (edgeToCaseClause exprName labelRoot) edges
484+ caseClauses <- mapM (edgeToCase exprName labelRoot) edges
488− caseDefault <- CaseDefault () <$> generateDecider exprName labelRoot fallback
485+ caseDefault <- JS.Default <$> generateDecider exprName labelRoot fallback
489− return [ SwitchStmt () testExpr (caseClauses ++ [caseDefault]) ]
486+ return [ JS.Switch testExpr (caseClauses ++ [caseDefault]) ]
495− -> (DT.Test, Opt.Decider Opt.Choice)
489+edgeToCase :: Text -> Text -> (DT.Test, Opt.Decider Opt.Choice) -> State Int JS.Case
496− -> State Int (CaseClause ())
497−edgeToCaseClause exprName labelRoot (test, subTree) =
490+edgeToCase exprName labelRoot (test, subTree) =
498− CaseClause () (testToExpr test) <$> generateDecider exprName labelRoot subTree
491+ JS.Case (testToExpr test) <$> generateDecider exprName labelRoot subTree
501−testToExpr :: DT.Test -> Expression ()
494+testToExpr :: DT.Test -> JS.Expr
502testToExpr test =
495testToExpr test =
503 case test of
496 case test of
504 DT.Constructor (Var.Canonical _ tag) ->
497 DT.Constructor (Var.Canonical _ tag) ->
505− StringLit () tag
498+ JS.String tag
507 DT.Literal (L.Chr char) ->
500 DT.Literal (L.Chr char) ->
508− StringLit () [char]
501+ JS.String (Text.singleton char)
510 DT.Literal lit ->
503 DT.Literal lit ->
511 Literal.literal lit
504 Literal.literal lit
@@ -515,21 +508,21 @@ testToExpr test =
515-- work with paths
508-- work with paths
518−pathToTestableExpr :: String -> DT.Path -> DT.Test -> State Int (Expression ())
511+pathToTestableExpr :: Text -> DT.Path -> DT.Test -> State Int JS.Expr
519pathToTestableExpr root path exampleTest =
512pathToTestableExpr root path exampleTest =
520 do accessExpr <- generateJsExpr (pathToExpr root path)
513 do accessExpr <- generateJsExpr (pathToExpr root path)
521 case exampleTest of
514 case exampleTest of
522 DT.Constructor _ ->
515 DT.Constructor _ ->
523− return (DotRef () accessExpr (Id () "ctor"))
516+ return $ JS.DotRef accessExpr (JS.Id "ctor")
525 DT.Literal (L.Chr _) ->
518 DT.Literal (L.Chr _) ->
526− return (DotRef () accessExpr (Id () "valueOf") `call` [])
519+ return $ JS.Call (JS.DotRef accessExpr (JS.Id "valueOf")) []
528 DT.Literal _ ->
521 DT.Literal _ ->
529 return accessExpr
522 return accessExpr
532−pathToExpr :: String -> DT.Path -> Opt.Expr
525+pathToExpr :: Text -> DT.Path -> Opt.Expr
533pathToExpr root fullPath =
526pathToExpr root fullPath =
534 go (Opt.Var (Var.local root)) fullPath
527 go (Opt.Var (Var.local root)) fullPath
@@ -567,11 +560,11 @@ binop func left right =
567-- BINARY OPERATOR HELPERS
560-- BINARY OPERATOR HELPERS
570−binopHelp :: Var.Canonical -> Expression () -> Expression () -> Expression ()
563+binopHelp :: Var.Canonical -> JS.Expr -> JS.Expr -> JS.Expr
571binopHelp qualifiedOp@(Var.Canonical home op) leftExpr rightExpr =
564binopHelp qualifiedOp@(Var.Canonical home op) leftExpr rightExpr =
573 simpleMake left right =
566 simpleMake left right =
574− ref "A2" `call` [ Var.canonical qualifiedOp, left, right ]
567+ JS.Call (ref "A2") [ Var.canonical qualifiedOp, left, right ]
576 if home == basicsModule then
569 if home == basicsModule then
577 (Map.findWithDefault simpleMake op basicOps) leftExpr rightExpr
570 (Map.findWithDefault simpleMake op basicOps) leftExpr rightExpr
@@ -585,52 +578,52 @@ binopHelp qualifiedOp@(Var.Canonical home op) leftExpr rightExpr =
586listModule :: Var.Home
579listModule :: Var.Home
587listModule =
580listModule =
588− Var.Module (ModuleName.inCore ["List"])
581+ Var.Module (ModuleName.inCore "List")
591listModuleInternals :: Var.Home
584listModuleInternals :: Var.Home
592listModuleInternals =
585listModuleInternals =
593− Var.TopLevel (ModuleName.inCore ["List"])
586+ Var.TopLevel (ModuleName.inCore "List")
596basicsModule :: Var.Home
589basicsModule :: Var.Home
597basicsModule =
590basicsModule =
598− Var.Module (ModuleName.inCore ["Basics"])
591+ Var.Module (ModuleName.inCore "Basics")
601−basicOps :: Map.Map String (Expression () -> Expression () -> Expression ())
594+basicOps :: Map.Map Text (JS.Expr -> JS.Expr -> JS.Expr)
602basicOps =
595basicOps =
603 Map.fromList (infixOps ++ specialOps)
596 Map.fromList (infixOps ++ specialOps)
606−infixOps :: [(String, Expression () -> Expression () -> Expression ())]
599+infixOps :: [(Text, JS.Expr -> JS.Expr -> JS.Expr)]
607infixOps =
600infixOps =
609 infixOp str op =
602 infixOp str op =
610− (str, InfixExpr () op)
603+ (str, JS.Infix op)
612− [ infixOp "+" OpAdd
605+ [ infixOp "+" JS.OpAdd
613− , infixOp "-" OpSub
606+ , infixOp "-" JS.OpSub
614− , infixOp "*" OpMul
607+ , infixOp "*" JS.OpMul
615− , infixOp "/" OpDiv
608+ , infixOp "/" JS.OpDiv
616− , infixOp "&&" OpLAnd
609+ , infixOp "&&" JS.OpLAnd
617− , infixOp "||" OpLOr
610+ , infixOp "||" JS.OpLOr
621−specialOps :: [(String, Expression () -> Expression () -> Expression ())]
614+specialOps :: [(Text, JS.Expr -> JS.Expr -> JS.Expr)]
622specialOps =
615specialOps =
623− [ (,) "^" $ \a b -> obj ["Math","pow"] `call` [a,b]
616+ [ (,) "^" $ \a b -> JS.Call (obj ["Math","pow"]) [a,b]
624 , (,) "==" $ \a b -> BuiltIn.eq a b
617 , (,) "==" $ \a b -> BuiltIn.eq a b
625− , (,) "/=" $ \a b -> PrefixExpr () PrefixLNot (BuiltIn.eq a b)
618+ , (,) "/=" $ \a b -> JS.Prefix JS.PrefixLNot (BuiltIn.eq a b)
626− , (,) "<" $ cmp OpLT 0
619+ , (,) "<" $ cmp JS.OpLT 0
627− , (,) ">" $ cmp OpGT 0
620+ , (,) ">" $ cmp JS.OpGT 0
628− , (,) "<=" $ cmp OpLT 1
621+ , (,) "<=" $ cmp JS.OpLT 1
629− , (,) ">=" $ cmp OpGT (-1)
622+ , (,) ">=" $ cmp JS.OpGT (-1)
630− , (,) "//" $ \a b -> InfixExpr () OpBOr (InfixExpr () OpDiv a b) (IntLit () 0)
623+ , (,) "//" $ \a b -> JS.Infix JS.OpBOr (JS.Infix JS.OpDiv a b) (JS.Int 0)
634−cmp :: InfixOp -> Int -> Expression () -> Expression () -> Expression ()
627+cmp :: JS.InfixOp -> Int -> JS.Expr -> JS.Expr -> JS.Expr
635cmp op n a b =
628cmp op n a b =
636− InfixExpr () op (BuiltIn.cmp a b) (IntLit () n)
629+ JS.Infix op (BuiltIn.cmp a b) (JS.Int n)