1{-# OPTIONS_GHC -Wall #-}
2{-# LANGUAGE OverloadedStrings #-}
3module Generate.JavaScript.BuiltIn
8 , effect, outgoingPort, incomingPort
13import Data.Text (Text)
15import qualified AST.Module.Name as ModuleName
16import qualified Generate.JavaScript.Builder as JS
17import Generate.JavaScript.Helpers ((<|), (==>))
18import qualified Generate.JavaScript.Variable as Var
19import qualified Reporting.Region as R
23utils :: Text -> [JS.Expr] -> JS.Expr
25 JS.Call (Var.coreNative "Utils" func) args
32character :: Text -> JS.Expr
34 utils "chr" [ JS.String char ]
41list :: [JS.Expr] -> JS.Expr
43 Var.coreNative "List" "fromArray" <| JS.Array elements
46cons :: JS.Expr -> JS.Expr -> JS.Expr
48 JS.Call (Var.coreNative "List" "Cons") [front, back]
55recordUpdate :: JS.Expr -> [(Text, JS.Expr)] -> JS.Expr
56recordUpdate record fields =
59 , JS.Object (map (uncurry (==>)) fields)
67eq :: JS.Expr -> JS.Expr -> JS.Expr
69 utils "eq" [ left, right ]
72cmp :: JS.Expr -> JS.Expr -> JS.Expr
74 utils "cmp" [ left, right ]
81effect :: ModuleName.Canonical -> JS.Expr
83 Var.coreNative "Platform" "leaf" <|
84 JS.String (ModuleName.canonicalToText effectName)
87outgoingPort :: Text -> JS.Expr -> JS.Expr
88outgoingPort name converter =
90 (Var.coreNative "Platform" "outgoingPort")
91 [ JS.String name, converter ]
94incomingPort :: Text -> JS.Expr -> JS.Expr
95incomingPort name converter =
97 (Var.coreNative "Platform" "incomingPort")
98 [ JS.String name, converter ]
105crash :: ModuleName.Canonical -> R.Region -> Maybe (JS.Expr) -> JS.Expr
106crash home region maybeCaseCrashValue =
109 JS.String (ModuleName.canonicalToText home)
111 case maybeCaseCrashValue of
113 utils "crash" [ homeString, regionToJs region ]
116 utils "crashCase" [ homeString, regionToJs region, crashValue ]
119regionToJs :: R.Region -> JS.Expr
120regionToJs (R.Region start end) =
122 [ "start" ==> positionToJs start
123 , "end" ==> positionToJs end
127positionToJs :: R.Position -> JS.Expr
128positionToJs (R.Position line column) =
130 [ "line" ==> JS.Int line
131 , "column" ==> JS.Int column
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list