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
50recordUpdate :: JS.Expr -> [(Text, JS.Expr)] -> JS.Expr
51recordUpdate record fields =
54 , JS.Object (map (uncurry (==>)) fields)
62eq :: JS.Expr -> JS.Expr -> JS.Expr
64 utils "eq" [ left, right ]
67cmp :: JS.Expr -> JS.Expr -> JS.Expr
69 utils "cmp" [ left, right ]
76effect :: ModuleName.Canonical -> JS.Expr
78 Var.coreNative "Platform" "leaf" <|
79 JS.String (ModuleName.canonicalToText effectName)
82outgoingPort :: Text -> JS.Expr -> JS.Expr
83outgoingPort name converter =
85 (Var.coreNative "Platform" "outgoingPort")
86 [ JS.String name, converter ]
89incomingPort :: Text -> JS.Expr -> JS.Expr
90incomingPort name converter =
92 (Var.coreNative "Platform" "incomingPort")
93 [ JS.String name, converter ]
100crash :: ModuleName.Canonical -> R.Region -> Maybe (JS.Expr) -> JS.Expr
101crash home region maybeCaseCrashValue =
104 JS.String (ModuleName.canonicalToText home)
106 case maybeCaseCrashValue of
108 utils "crash" [ homeString, regionToJs region ]
111 utils "crashCase" [ homeString, regionToJs region, crashValue ]
114regionToJs :: R.Region -> JS.Expr
115regionToJs (R.Region start end) =
117 [ "start" ==> positionToJs start
118 , "end" ==> positionToJs end
122positionToJs :: R.Position -> JS.Expr
123positionToJs (R.Position line column) =
125 [ "line" ==> JS.Int line
126 , "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