on master help sign in
cosmetic: add additional whitespace and suppress warning about unused declaration _home
commit8d31d3579c896bfe88464c06e3e6176c56e39db6 authorEvan Czaplicki <info@elm-lang.org> dateTue 9 Feb 2016, 18:17 (11 years ago) parentf63020a
1 file changed+23−1
src/Generate/JavaScript/Expression.hs+23−1
src/Generate/JavaScript/Expression.hs+23−1
@@ -17,8 +17,10 @@ import qualified Generate.JavaScript.Variable as Var
1717import qualified Optimize.DecisionTree as DT
1818
1919
20+
2021-- CODE CHUNKS
2122
23+
2224data Code
2325 = JsExpr (Expression ())
2426 | JsBlock [Statement ()]
@@ -74,11 +76,13 @@ toExpr code =
7476 function [] stmts `call` []
7577
7678
79+
7780-- DEFINITIONS
7881
82+
7983generateDef :: Opt.Def -> State Int (Statement ())
8084generateDef def =
81− do (home, name, jsBody) <-
85+ do (_home, name, jsBody) <-
8286 case def of
8387 Opt.TailDef (Opt.Facts home _) name argNames body ->
8488 (,,) home name <$> generateTailFunction name argNames body
@@ -89,8 +93,10 @@ generateDef def =
8993 return (Var.define name jsBody)
9094
9195
96+
9297-- EXPRESSIONS
9398
99+
94100generateJsExpr :: Opt.Expr -> State Int (Expression ())
95101generateJsExpr optExpr =
96102 toExpr <$> generateCode optExpr
@@ -199,8 +205,10 @@ generateCode expr =
199205 jsExpr $ BuiltIn.crash home region maybeOptBranchProblem
200206
201207
208+
202209-- FUNCTIONS
203210
211+
204212generateFunction :: [String] -> Opt.Expr -> State Int Code
205213generateFunction args body =
206214 do code <- generateCode body
@@ -235,8 +243,10 @@ generateFunctionWithArity rawArgs code =
235243 foldl (\body arg -> function [arg] [ReturnStmt () (Just body)]) innerBody otherArgs
236244
237245
246+
238247-- GENERATE IFS
239248
249+
240250generateIf :: [(Opt.Expr, Opt.Expr)] -> Opt.Expr -> State Int Code
241251generateIf givenBranches givenFinally =
242252 let
@@ -292,8 +302,10 @@ crushIfsHelp visitedBranches unvisitedBranches finally =
292302 crushIfsHelp (visiting : visitedBranches) unvisited finally
293303
294304
305+
295306-- CASE EXPRESSIONS
296307
308+
297309generateCase
298310 :: String
299311 -> Opt.Decider Opt.Choice
@@ -305,8 +317,10 @@ generateCase exprName decider jumps =
305317 foldM (goto labelRoot) decider jumps
306318
307319
320+
308321-- handle any jumps
309322
323+
310324goto :: String -> [Statement ()] -> (Int, Opt.Expr) -> State Int [Statement ()]
311325goto labelRoot deciderStmts (target, branch) =
312326 let
@@ -324,8 +338,10 @@ toLabel root target =
324338 Id () (root ++ "_" ++ show target)
325339
326340
341+
327342-- turn deciders into ifs and switches
328343
344+
329345generateDecider
330346 :: String
331347 -> String
@@ -380,8 +396,10 @@ testToExpr test =
380396 Literal.literal lit
381397
382398
399+
383400-- work with paths
384401
402+
385403pathToTestableExpr :: String -> DT.Path -> DT.Test -> State Int (Expression ())
386404pathToTestableExpr root path exampleTest =
387405 do accessExpr <- generateJsExpr (pathToExpr root path)
@@ -415,8 +433,10 @@ pathToExpr root fullPath =
415433 expr
416434
417435
436+
418437-- BINARY OPERATORS
419438
439+
420440binop
421441 :: Var.Canonical
422442 -> Opt.Expr
@@ -428,8 +448,10 @@ binop func left right =
428448 jsExpr (makeExpr func jsLeft jsRight)
429449
430450
451+
431452-- BINARY OPERATOR HELPERS
432453
454+
433455makeExpr :: Var.Canonical -> (Expression () -> Expression () -> Expression ())
434456makeExpr qualifiedOp@(Var.Canonical home op) =
435457 let