1{-# OPTIONS_GHC -Wall #-}
2{-# LANGUAGE OverloadedStrings #-}
3module Generate.JavaScript.BuiltIn
8 , effect, outgoingPort, incomingPort
13import qualified Data.Text as Text
14import Data.Text (Text)
16import qualified AST.Module.Name as ModuleName
17import qualified Generate.JavaScript.Builder as JS
18import Generate.JavaScript.Helpers ((<|), (==>))
19import qualified Generate.JavaScript.Variable as Var
20import qualified Reporting.Region as R
24utils :: Text -> [JS.Expr] -> JS.Expr
26 JS.Call (Var.coreNative "Utils" func) args
33character :: Char -> JS.Expr
35 utils "chr" [ JS.String (Text.singleton char) ]
42list :: [JS.Expr] -> JS.Expr
46 JS.Object [ "ctor" ==> JS.String "[]" ]
49 cons front (list back)
52cons :: JS.Expr -> JS.Expr -> JS.Expr
55 [ "ctor" ==> JS.String "::"
65recordUpdate :: JS.Expr -> [(Text, JS.Expr)] -> JS.Expr
66recordUpdate record fields =
69 , JS.Object (map (uncurry (==>)) fields)
77eq :: JS.Expr -> JS.Expr -> JS.Expr
79 utils "eq" [ left, right ]
82cmp :: JS.Expr -> JS.Expr -> JS.Expr
84 utils "cmp" [ left, right ]
91effect :: ModuleName.Canonical -> JS.Expr
93 Var.coreNative "Platform" "leaf" <|
94 JS.String (ModuleName.canonicalToText effectName)
97outgoingPort :: Text -> JS.Expr -> JS.Expr
98outgoingPort name converter =
100 (Var.coreNative "Platform" "outgoingPort")
101 [ JS.String name, converter ]
104incomingPort :: Text -> JS.Expr -> JS.Expr
105incomingPort name converter =
107 (Var.coreNative "Platform" "incomingPort")
108 [ JS.String name, converter ]
115crash :: ModuleName.Canonical -> R.Region -> Maybe (JS.Expr) -> JS.Expr
116crash home region maybeCaseCrashValue =
119 JS.String (ModuleName.canonicalToText home)
121 case maybeCaseCrashValue of
123 utils "crash" [ homeString, regionToJs region ]
126 utils "crashCase" [ homeString, regionToJs region, crashValue ]
129regionToJs :: R.Region -> JS.Expr
130regionToJs (R.Region start end) =
132 [ "start" ==> positionToJs start
133 , "end" ==> positionToJs end
137positionToJs :: R.Position -> JS.Expr
138positionToJs (R.Position line column) =
140 [ "line" ==> JS.Int line
141 , "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