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
45 JS.Object [ "ctor" ==> JS.String "[]" ]
48 cons front (list back)
51cons :: JS.Expr -> JS.Expr -> JS.Expr
54 [ "ctor" ==> JS.String "::"
64recordUpdate :: JS.Expr -> [(Text, JS.Expr)] -> JS.Expr
65recordUpdate record fields =
68 , JS.Object (map (uncurry (==>)) fields)
76eq :: JS.Expr -> JS.Expr -> JS.Expr
78 utils "eq" [ left, right ]
81cmp :: JS.Expr -> JS.Expr -> JS.Expr
83 utils "cmp" [ left, right ]
90effect :: ModuleName.Canonical -> JS.Expr
92 Var.coreNative "Platform" "leaf" <|
93 JS.String (ModuleName.canonicalToText effectName)
96outgoingPort :: Text -> JS.Expr -> JS.Expr
97outgoingPort name converter =
99 (Var.coreNative "Platform" "outgoingPort")
100 [ JS.String name, converter ]
103incomingPort :: Text -> JS.Expr -> JS.Expr
104incomingPort name converter =
106 (Var.coreNative "Platform" "incomingPort")
107 [ JS.String name, converter ]
114crash :: ModuleName.Canonical -> R.Region -> Maybe (JS.Expr) -> JS.Expr
115crash home region maybeCaseCrashValue =
118 JS.String (ModuleName.canonicalToText home)
120 case maybeCaseCrashValue of
122 utils "crash" [ homeString, regionToJs region ]
125 utils "crashCase" [ homeString, regionToJs region, crashValue ]
128regionToJs :: R.Region -> JS.Expr
129regionToJs (R.Region start end) =
131 [ "start" ==> positionToJs start
132 , "end" ==> positionToJs end
136positionToJs :: R.Position -> JS.Expr
137positionToJs (R.Position line column) =
139 [ "line" ==> JS.Int line
140 , "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