2Module : IRTS.JavaScript.Codegen
3Description : The JavaScript common code generator.
6Maintainer : The Idris Community.
8{-# LANGUAGE OverloadedStrings #-}
10module IRTS.JavaScript.Codegen( codegenJs
16import IRTS.CodegenCommon
18import IRTS.JavaScript.AST
19import IRTS.JavaScript.LangTransforms
20import IRTS.JavaScript.Name
21import IRTS.JavaScript.PrimOp
22import IRTS.JavaScript.Specialize
26import Control.Applicative (pure, (<$>))
28import Control.Monad.Trans.State
29import Data.Foldable (foldMap)
30import Data.Generics.Uniplate.Data
32import Data.Map.Strict (Map)
33import qualified Data.Map.Strict as Map
35import qualified Data.Set as Set
36import Data.Text (Text)
37import qualified Data.Text as T
38import qualified Data.Text.IO as TIO
39import System.Directory (doesFileExist)
40import System.Environment
43-- | Code generation stats hold information about the generated user
44-- code. Based on that information we add additional code to make
46data CGStats = CGStats { usedBigInt :: Bool
47 , partialApplications :: Set Partial
48 , hiddenClasses :: Set HiddenClass
51-- If we generate code for two declarations we want to merge their code
53instance Monoid CGStats where
54 mempty = CGStats { partialApplications = Set.empty
55 , hiddenClasses = Set.empty
58 mappend x y = CGStats { partialApplications = partialApplications x `Set.union` partialApplications y
59 , hiddenClasses = hiddenClasses x `Set.union` hiddenClasses y
60 , usedBigInt = usedBigInt x || usedBigInt y
64data CGConf = CGConf { header :: Text
67 , extraRunTime :: String
71getInclude :: FilePath -> IO Text
74 libs <- getIdrisLibDir
75 let libPath = libs </> p
76 exitsInLib <- doesFileExist libPath
81getIncludes :: [FilePath] -> IO Text
83 incs <- mapM getInclude l
84 return $ T.intercalate "\n\n" incs
86includeLibs :: [String] -> String
94 concatMap (\lib -> "var " ++ (repl <$> lib) ++ " = require(\"" ++ lib ++"\");\n")
96isYes :: Maybe String -> Bool
97isYes (Just "Y") = True
98isYes (Just "y") = True
101makeExportDecls :: Map Name LDecl -> ExportIFace -> [Text]
102makeExportDecls defs (Export _ _ e) =
103 concatMap makeExport e
105 uncurryF name argTy (Just args) =
106 if length argTy == length args then name
107 else T.concat [ "function(){ return "
109 , ".apply(this, Array.prototype.slice.call(arguments, 0,", T.pack $ show $ length args,"))"
110 , T.concat $ map (\x -> T.concat ["(arguments[", T.pack $ show x , "])"]) [length args .. (length argTy - 1)]
113 uncurryF name argTy Nothing = name
115 makeExport (ExportData _) =
117 makeExport (ExportFun name (FStr exportname) retTy argTy) =
118 [T.concat [ T.pack $ exportname
120 , uncurryF (jsName name) argTy (getArgList' name defs)
124codegenJs :: CGConf -> CodeGenerator
127 debug <- isYes <$> lookupEnv "IDRISJS_DEBUG"
128 let defs' = Map.fromList $ liftDecls ci
129 let defs = globlToCon defs'
130 let iface = interfaces ci
131 let used = if iface then
132 Map.elems $ removeDeadCode defs (getExpNames $ exportDecls ci)
133 else Map.elems $ removeDeadCode defs [sMN 0 "runMain"]
135 writeFile (outputFile ci ++ ".LDeclsDebug") $ (unlines $ intersperse "" $ map show used) ++ "\n\n\n"
136 putStrLn $ "Finished calculating used"
138 let (out, stats) = doCodegen defs used
140 path <- getIdrisJSRTSDir
141 jsbn <- if usedBigInt stats
142 then TIO.readFile $ path </> jsbnPath conf
145 runtimeCommon <- TIO.readFile $ path </> "Runtime-common.js"
146 extraRT <- TIO.readFile $ path </> (extraRunTime conf)
148 includes <- getIncludes $ includes ci
149 let libs = T.pack $ includeLibs $ compileLibs ci
150 TIO.writeFile (outputFile ci) $ T.concat [ header conf
151 , "\"use strict\";\n\n"
154 , runtimeCommon, "\n"
157 -- external libraries
161 , doPartials (partialApplications stats), "\n"
162 , doHiddenClasses (hiddenClasses stats), "\n"
164 , if iface then T.concat ["module.exports = {\n", T.intercalate ",\n" $ concatMap (makeExportDecls defs) (exportDecls ci), "\n};\n"]
165 else jsName (sMN 0 "runMain") `T.append` "();\n"
170doPartials :: Set Partial -> Text
172 T.intercalate "\n" (map f $ Set.toList x)
174 f p@(Partial n i j) =
175 let vars1 = map (T.pack . ("x"++) . show) [1..i]
176 vars2 = map (T.pack . ("x"++) . show) [(i+1)..j]
178 JsFun (jsNamePartial p) vars1 $ JsReturn $
179 jsCurryLam vars2 (jsAppN (jsName n) (map JsVar (vars1 ++ vars2)) )
181doHiddenClasses :: Set HiddenClass -> Text
183 T.intercalate "\n" (map f $ Set.toList x)
185 f p@(HiddenClass n id 0) = jsStmt2Text $ JsDecConst (jsNameHiddenClass p) $ JsObj [("type", JsInt id)]
186 f p@(HiddenClass n id arity) =
187 let vars = map dataPartName $ take arity [1..]
189 JsFun (jsNameHiddenClass p) vars $ JsSeq (JsSet (JsProp JsThis "type") (JsInt id)) $ seqJs
190 $ map (\tv -> JsSet (JsProp JsThis tv) (JsVar tv)) vars
193-- | Generate code for each declaration and collect stats.
194-- LFunctions are turned into JS function declarations. They are
195-- preceded by a comment that gives their name. Constructor
196-- declarations are ignored.
197doCodegen :: Map Name LDecl -> [LDecl] -> (Text, CGStats)
198doCodegen defs = foldMap (doCodegenDecl defs)
200 doCodegenDecl :: Map Name LDecl -> LDecl -> (Text, CGStats)
201 doCodegenDecl defs (LFun _ name args def) =
202 let (ast, stats) = cgFun defs name args def
203 fnComment = jsStmt2Text (JsComment $ T.pack $ show name)
204 in (T.concat [fnComment, "\n", jsStmt2Text ast, "\n"], stats)
205 doCodegenDecl defs (LConstructor n i sz) = ("", mempty)
208seqJs :: [JsStmt] -> JsStmt
210seqJs (x:xs) = JsSeq x (seqJs xs)
213data CGBodyState = CGBodyState { defs :: Map Name LDecl
215 , reWrittenNames :: Map.Map Name JsExpr
216 , currentFnNameAndArgs :: (Text, [Text])
217 , usedArgsTailCallOptim :: Set (Text, Text)
220 , partialApps :: Set Partial
221 , hiddenCls :: Set HiddenClass
224getNewCGName :: State CGBodyState Text
228 let v = lastIntName st + 1
229 put $ st {lastIntName = v}
230 return $ jsNameGenerated v
232addPartial :: Partial -> State CGBodyState ()
234 modify (\s -> s {partialApps = Set.insert p (partialApps s) })
236addHiddenClass :: HiddenClass -> State CGBodyState ()
238 modify (\s -> s {hiddenCls = Set.insert p (hiddenCls s) })
240addUsedArgsTailCallOptim :: Set (Text, Text) -> State CGBodyState ()
241addUsedArgsTailCallOptim p =
242 modify (\s -> s {usedArgsTailCallOptim = Set.union p (usedArgsTailCallOptim s) })
244getConsId :: Name -> State CGBodyState (Int, Int)
248 case Map.lookup n (defs st) of
249 Just (LConstructor _ conId arity) -> pure (conId, arity)
250 _ -> error $ "Internal JS Backend error " ++ showCG n ++ " is not a constructor."
252getArgList' :: Name -> Map Name LDecl -> Maybe [Name]
254 case Map.lookup n defs of
255 Just (LFun _ _ a _) -> Just a
258getArgList :: Name -> State CGBodyState (Maybe [Name])
262 pure $ getArgList' n (defs st)
264data BodyResTarget = ReturnBT
270cgFun :: Map Name LDecl -> Name -> [Name] -> LExp -> (JsStmt, CGStats)
271cgFun dfs n args def = do
272 let fnName = jsName n
273 let argNames = map jsName args
274 let ((decs, res),st) = runState
275 (cgBody ReturnBT def)
276 (CGBodyState { defs = dfs
278 , reWrittenNames = Map.empty
279 , currentFnNameAndArgs = (fnName, argNames)
280 , usedArgsTailCallOptim = Set.empty
283 , partialApps = Set.empty
284 , hiddenCls = Set.empty
287 let body = if isTailRec st then JsSeq (declareUsedOptimArgs $ usedArgsTailCallOptim st) (JsForever ((seqJs decs) `JsSeq` res)) else (seqJs decs) `JsSeq` res
288 let fn = JsFun fnName argNames body
289 let state' = CGStats { partialApplications = partialApps st
290 , hiddenClasses = hiddenCls st
291 , usedBigInt = usedITBig st
295addRT :: BodyResTarget -> JsExpr -> JsStmt
296addRT ReturnBT x = JsReturn x
297addRT (DecBT n) x = JsDecLet n x
298addRT (DecConstBT n) x = JsDecConst n x
299addRT (SetBT n) x = JsSet (JsVar n) x
300addRT GetExpBT x = JsExprStmt x
302declareUsedOptimArgs :: Set (Text, Text) -> JsStmt
303declareUsedOptimArgs x = seqJs $ map (\(x,y) -> JsDecLet x (JsVar y) ) (Set.toList x)
305tailCallOptimRefreshArgs :: [(Text, JsExpr)] -> Set Text -> ((JsStmt, JsStmt), Set (Text, Text))
306tailCallOptimRefreshArgs [] s = ((JsEmpty, JsEmpty), Set.empty)
307tailCallOptimRefreshArgs ((n,x):r) s =
308 let ((y1,y2), y3) = tailCallOptimRefreshArgs r (Set.insert n s) --
309 in if Set.null $ (Set.fromList [ z | z <- universeBi x ]) `Set.intersection` s then
310 ((y1, jsSetVar n x `JsSeq` y2), y3)
312 let n' = jsTailCallOptimName n
313 in ((jsSetVar n' x `JsSeq` y1, jsSetVar n (JsVar n') `JsSeq` y2), Set.insert (n',n) y3)
315cgName :: Name -> State CGBodyState JsExpr
318 case Map.lookup b (reWrittenNames st) of
320 _ -> pure $ JsVar $ jsName b
322cgBody :: BodyResTarget -> LExp -> State CGBodyState ([JsStmt], JsStmt)
325 (LCase _ (LOp oper [x, y]) [LConstCase (I 0) (LCon _ _ ff []), LDefaultCase (LCon _ _ tt [])])
326 | (ff == qualifyN "Prelude.Bool" "False" &&
327 tt == qualifyN "Prelude.Bool" "True") ->
328 case (Map.lookup oper primDB) of
329 Just (needBI, pti, c) | pti == PTBool -> do
330 z <- mapM (cgBody GetExpBT) [x, y]
331 when needBI setUsedITBig
332 let res = jsPrimCoerce pti PTBool $ c $ map (jsStmt2Expr . snd) z
333 pure $ (concat $ map fst z, addRT rt res)
335 (LCase _ e [LConCase _ n _ (LCon _ _ tt []), LDefaultCase (LCon _ _ ff [])])
336 | (ff == qualifyN "Prelude.Bool" "False" &&
337 tt == qualifyN "Prelude.Bool" "True") -> do
338 (d, v) <- cgBody GetExpBT e
339 test <- formConTest n (jsStmt2Expr v)
340 pure $ (d, addRT rt $ JsUniOp (T.pack "!") $ JsUniOp (T.pack "!") test)
341 (LCase _ e [LConCase _ n _ (LCon _ _ tt []), LConCase _ _ _ (LCon _ _ ff [])])
342 | (ff == qualifyN "Prelude.Bool" "False" &&
343 tt == qualifyN "Prelude.Bool" "True") -> do
344 (d, v) <- cgBody GetExpBT e
345 test <- formConTest n (jsStmt2Expr v)
346 pure $ (d, addRT rt $ JsUniOp (T.pack "!") $ JsUniOp (T.pack "!") test)
347 (LCase _ e [LConCase _ n _ (LCon _ _ ff []), LDefaultCase (LCon _ _ tt [])])
348 | (ff == qualifyN "Prelude.Bool" "False" &&
349 tt == qualifyN "Prelude.Bool" "True") -> do
350 (d, v) <- cgBody GetExpBT e
351 test <- formConTest n (jsStmt2Expr v)
352 pure $ (d, addRT rt $ JsUniOp (T.pack "!") test)
353 (LCase _ e [LConCase _ n _ (LCon _ _ ff []), LConCase _ _ _ (LCon _ _ tt [])])
354 | (ff == qualifyN "Prelude.Bool" "False" &&
355 tt == qualifyN "Prelude.Bool" "True") -> do
356 (d, v) <- cgBody GetExpBT e
357 test <- formConTest n (jsStmt2Expr v)
358 pure $ (d, addRT rt $ JsUniOp (T.pack "!") test)
359 (LCase f e [LConCase nf ff [] alt, LConCase nt tt [] conseq])
360 | (ff == qualifyN "Prelude.Bool" "False" &&
361 tt == qualifyN "Prelude.Bool" "True") ->
362 cgBody' rt $ LCase f e [LConCase nt tt [] conseq, LConCase nf ff [] alt]
363 expr -> cgBody' rt expr
365cgBody' :: BodyResTarget -> LExp -> State CGBodyState ([JsStmt], JsStmt)
368 argsFn <- getArgList n
370 Just a -> cgBody' rt (LApp False (LV n) [])
373 pure $ ([], addRT rt n')
374cgBody' rt (LApp tailcall (LV fn) args) =
376 let fname = jsName fn
378 let (currFn, argN) = currentFnNameAndArgs st
379 z <- mapM (cgBody GetExpBT) args
380 let argVals = map (jsStmt2Expr . snd) z
381 let preDecs = concat $ map fst z
382 case (fname == currFn && (length args) == (length argN), rt) of
385 modify (\x-> x {isTailRec = True})
386 let ((y1,y2), y3) = tailCallOptimRefreshArgs (zip argN argVals) Set.empty
387 addUsedArgsTailCallOptim y3
388 pure (preDecs, y1 `JsSeq` y2)
390 app <- formApp fn argVals
391 pure (preDecs, addRT rt app)
393cgBody' rt (LForce (LLazyApp n args)) = cgBody rt (LApp False (LV n) args)
394cgBody' rt (LLazyApp n args) =
396 (d,v) <- cgBody ReturnBT (LApp False (LV n) args)
397 pure ([], addRT rt $ jsLazy $ jsStmt2Expr $ JsSeq (seqJs d) v)
398cgBody' rt (LForce e) =
400 (d,v) <- cgBody GetExpBT e
401 pure (d, addRT rt $ JsForce $ jsStmt2Expr v)
402cgBody' rt (LLet n v sc) =
404 (d1, v1) <- cgBody (DecConstBT $ jsName n) v
405 (d2, v2) <- cgBody rt sc
406 pure $ ((d1 ++ v1 : d2), v2)
407cgBody' rt (LProj e i) =
409 (d, v) <- cgBody GetExpBT e
410 pure $ (d, addRT rt $ JsArrayProj (JsInt $ i+1) $ jsStmt2Expr v)
411cgBody' rt (LCon _ conId n args) =
413 z <- mapM (cgBody GetExpBT) args
414 con <- formCon n (map (jsStmt2Expr . snd) z)
415 pure $ (concat $ map fst z, addRT rt con)
416cgBody' rt (LCase _ e alts) = do
417 (d, v) <- cgBody GetExpBT e
418 resName <- getNewCGName
420 case (all altHasNoProj alts && length alts <= 2, v) of
421 (True, _) -> pure (JsEmpty, jsStmt2Expr v)
422 (False, JsExprStmt (JsVar n)) -> pure (JsEmpty, jsStmt2Expr v)
424 swName <- getNewCGName
425 pure (JsDecConst swName $ jsStmt2Expr v, JsVar swName)
426 sw' <- cgIfTree rt resName entry alts
430 Nothing -> JsExprStmt JsNull
432 ReturnBT -> pure (d ++ [decSw], sw)
433 (DecBT nvar) -> pure (d ++ [decSw, JsDecLet nvar JsNull], sw)
434 (DecConstBT nvar) -> pure (d ++ [decSw, JsDecLet nvar JsNull], sw)
435 (SetBT nvar) -> pure (d ++ [decSw], sw)
438 (d ++ [decSw, JsDecLet resName JsNull, sw], JsExprStmt $ JsVar resName)
439cgBody' rt (LConst c) =
442 pure ([], (addRT rt) $ cst)
443cgBody' rt (LOp op args) =
445 z <- mapM (cgBody GetExpBT) args
446 res <- cgOp op (map (jsStmt2Expr . snd) z)
447 pure $ (concat $ map fst z, addRT rt $ res)
448cgBody' rt LNothing = pure ([], addRT rt JsNull)
449cgBody' rt (LError x) = pure ([], JsError $ JsStr x)
450cgBody' rt x@(LForeign dres (FStr code) args ) =
452 z <- mapM (cgBody GetExpBT) (map snd args)
453 jsArgs <- sequence $ map cgForeignArg (zip (map fst args) (map (jsStmt2Expr . snd) z))
454 jsDres <- cgForeignRes dres $ JsForeign (T.pack code) jsArgs
455 pure $ (concat $ map fst z, addRT rt $ jsDres)
456cgBody' _ x = error $ "Instruction " ++ show x ++ " not compilable yet"
458altsRT :: Text -> BodyResTarget -> BodyResTarget
459altsRT rn ReturnBT = ReturnBT
460altsRT rn (DecBT n) = SetBT n
461altsRT rn (SetBT n) = SetBT n
462altsRT rn (DecConstBT n) = SetBT n
463altsRT rn GetExpBT = SetBT rn
465altHasNoProj :: LAlt -> Bool
466altHasNoProj (LConCase _ _ args _) = args == []
469formApp :: Name -> [JsExpr] -> State CGBodyState JsExpr
470formApp fn argVals = case specialCall fn of
471 Just (arity, g) | arity == length argVals -> pure $ g argVals
473 argsFn <- getArgList fn
476 Nothing -> pure $ jsCurryApp fname argVals
478 let lenAgFn = length agFn
479 let lenArgs = length argVals
480 case compare lenAgFn lenArgs of
481 EQ -> pure $ JsApp fname argVals
482 LT -> pure $ jsCurryApp (JsApp fname (take lenAgFn argVals)) (drop lenAgFn argVals)
484 let part = Partial fn lenArgs lenAgFn
486 pure $ jsAppN (jsNamePartial part) argVals
488formCon :: Name -> [JsExpr] -> State CGBodyState JsExpr
490 case specialCased n of
491 Just (ctor, test, match) -> pure $ ctor args
493 (conId, arity) <- getConsId n
494 let hc = HiddenClass n conId arity
496 pure $ if (arity > 0)
497 then JsNew (JsVar $ jsNameHiddenClass hc) args
498 else JsVar $ jsNameHiddenClass hc
500formConTest :: Name -> JsExpr -> State CGBodyState JsExpr
502 case specialCased n of
503 Just (ctor, test, match) -> pure $ test x
505 (conId, arity) <- getConsId n
506 pure $ JsBinOp "===" (JsProp x (T.pack "type")) (JsInt conId)
508 -- then pure $ JsBinOp "===" (JsProp x (T.pack "type")) (JsInt conId)
509 -- else pure $ JsBinOp "===" x (JsInt conId)
511formProj :: Name -> JsExpr -> Int -> JsExpr
513 case specialCased n of
514 Just (ctor, test, proj) -> proj v i
515 Nothing -> JsProp v (dataPartName i)
517smartif :: JsExpr -> JsStmt -> Maybe JsStmt -> JsStmt
518smartif cond conseq (Just alt) = JsIf cond conseq (Just alt)
519smartif cond conseq Nothing = conseq
521formConstTest :: JsExpr -> Const -> State CGBodyState JsExpr
522formConstTest scrvar t = case t of
525 cgOp' PTBool (LEq (ATInt ITBig)) [scrvar, t']
528 pure $ JsBinOp "===" scrvar t'
530cgIfTree :: BodyResTarget
534 -> State CGBodyState (Maybe JsStmt)
535cgIfTree _ _ _ [] = pure Nothing
536cgIfTree rt resName scrvar ((LConstCase t exp):r) = do
537 (d, v) <- cgBody (altsRT resName rt) exp
538 alternatives <- cgIfTree rt resName scrvar r
539 test <- formConstTest scrvar t
541 smartif test (JsSeq (seqJs d) v) alternatives
542cgIfTree rt resName scrvar ((LDefaultCase exp):r) = do
543 (d, v) <- cgBody (altsRT resName rt) exp
544 pure $ Just $ JsSeq (seqJs d) v
545cgIfTree rt resName scrvar ((LConCase _ n args exp):r) = do
546 alternatives <- cgIfTree rt resName scrvar r
547 test <- formConTest n scrvar
549 let rwn = reWrittenNames st
554 (\m (n, j) -> Map.insert n (formProj n scrvar j) m)
558 (d, v) <- cgBody (altsRT resName rt) exp
560 put $ st1 {reWrittenNames = rwn}
561 let branchBody = JsSeq (seqJs d) v
562 pure $ Just $ smartif test branchBody alternatives
565cgForeignArg :: (FDesc, JsExpr) -> State CGBodyState JsExpr
566cgForeignArg (FApp (UN "JS_IntT") _, v) = pure v
567cgForeignArg (FCon (UN "JS_Str"), v) = pure v
568cgForeignArg (FCon (UN "JS_Ptr"), v) = pure v
569cgForeignArg (FCon (UN "JS_Unit"), v) = pure v
570cgForeignArg (FCon (UN "JS_Float"), v) = pure v
571cgForeignArg (FApp (UN "JS_FnT") [_,FApp (UN "JS_Fn") [_,_, a, FApp (UN "JS_FnBase") [_,b]]], f) =
573cgForeignArg (FApp (UN "JS_FnT") [_,FApp (UN "JS_Fn") [_,_, a, FApp (UN "JS_FnIO") [_,_, b]]], f) =
575 jsx <- cgForeignArg (a, JsVar "x")
576 jsres <- cgForeignRes b $ jsCurryApp (jsCurryApp f [jsx]) [JsNull]
577 pure $ JsLambda ["x"] $ JsReturn jsres
578cgForeignArg (desc, _) =
581 error $ "Foreign arg type " ++ show desc ++ " not supported. While generating function " ++ (show $ fst $ currentFnNameAndArgs st)
583cgForeignRes :: FDesc -> JsExpr -> State CGBodyState JsExpr
584cgForeignRes (FApp (UN "JS_IntT") _) x = pure x
585cgForeignRes (FCon (UN "JS_Unit")) x = pure x
586cgForeignRes (FCon (UN "JS_Str")) x = pure x
587cgForeignRes (FCon (UN "JS_Ptr")) x = pure x
588cgForeignRes (FCon (UN "JS_Float")) x = pure x
589cgForeignRes desc val =
592 error $ "Foreign return type " ++ show desc ++ " not supported. While generating function " ++ (show $ fst $ currentFnNameAndArgs st)
594setUsedITBig :: State CGBodyState ()
595setUsedITBig = modify (\s -> s {usedITBig = True})
598cgConst :: Const -> State CGBodyState JsExpr
599cgConst (I i) = pure $ JsInt i
603 pure $ JsForeign "new $JSRTS.jsbn.BigInteger(%0)" [JsStr $ show i]
604cgConst (Ch c) = pure $ JsStr [c]
605cgConst (Str s) = pure $ JsStr s
606cgConst (Fl f) = pure $ JsDouble f
607cgConst (B8 x) = pure $ JsForeign (T.pack $ show x ++ " & 0xFF") []
608cgConst (B16 x) = pure $ JsForeign (T.pack $ show x ++ " & 0xFFFF") []
609cgConst (B32 x) = pure $ JsForeign (T.pack $ show x ++ "|0" ) []
613 pure $ JsForeign "new $JSRTS.jsbn.BigInteger(%0).and(new $JSRTS.jsbn.BigInteger(%1))" [JsStr $ show x, JsStr $ show 0xFFFFFFFFFFFFFFFF]
614cgConst x | isTypeConst x = pure $ JsInt 0
615cgConst x = error $ "Constant " ++ show x ++ " not compilable yet"
617cgOp :: PrimFn -> [JsExpr] -> State CGBodyState JsExpr
620cgOp' :: JsPrimTy -> PrimFn -> [JsExpr] -> State CGBodyState JsExpr
621cgOp' pt (LExternal name) _ | name == sUN "prim__null" = pure JsNull
622cgOp' pt (LExternal name) [l,r] | name == sUN "prim__eqPtr" = pure $ JsBinOp "==" l r
623cgOp' pt op exps = case Map.lookup op primDB of
624 Just (useBigInt, pti, combinator) -> do
625 when useBigInt setUsedITBig
626 pure $ jsPrimCoerce pti pt $ combinator exps
627 Nothing -> error ("Operator " ++ show (op, exps) ++ " not implemented")
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