1{-# LANGUAGE PatternGuards #-}
2{-# LANGUAGE OverloadedStrings #-}
3module IRTS.CodegenJavaScript (codegenJavaScript, codegenNode, JSTarget(..)) where
5import IRTS.JavaScript.AST
7import Idris.AbsSyntax hiding (TypeCase)
11import IRTS.Defunctionalise
12import IRTS.CodegenCommon
18import Control.Monad (mapM)
19import Control.Applicative ((<$>), (<*>), pure)
20import Control.Monad.RWS hiding (mapM)
21import Control.Monad.State
27import Data.Traversable hiding (mapM)
29import System.Directory
31import qualified Data.Map.Strict as M
32import qualified Data.Text as T
33import qualified Data.Text.IO as TIO
36data CompileInfo = CompileInfo { compileInfoApplyCases :: [Int]
37 , compileInfoEvalCases :: [Int]
38 , compileInfoNeedsBigInt :: Bool
42initCompileInfo :: [(Name, [BC])] -> CompileInfo
44 CompileInfo (collectCases "APPLY" bc) (collectCases "EVAL" bc) (lookupBigInt bc)
46 lookupBigInt :: [(Name, [BC])] -> Bool
47 lookupBigInt = any (needsBigInt . snd)
49 needsBigInt :: [BC] -> Bool
50 needsBigInt bc = any testBCForBigInt bc
52 testBCForBigInt :: BC -> Bool
53 testBCForBigInt (ASSIGNCONST _ c) =
56 testBCForBigInt (CONSTCASE _ c d) =
57 maybe False needsBigInt d
58 || any (needsBigInt . snd) c
59 || any (testConstForBigInt . fst) c
61 testBCForBigInt (CASE _ _ c d) =
62 maybe False needsBigInt d
63 || any (needsBigInt . snd) c
65 testBCForBigInt _ = False
67 testConstForBigInt :: Const -> Bool
68 testConstForBigInt (BI _) = True
69 testConstForBigInt (B64 _) = True
70 testConstForBigInt _ = False
73 collectCases :: String -> [(Name, [BC])] -> [Int]
74 collectCases fun bc = getCases $ findFunction fun bc
76 findFunction :: String -> [(Name, [BC])] -> [BC]
77 findFunction f ((MN 0 fun, bc):_)
79 findFunction f (_:bc) = findFunction f bc
81 getCases :: [BC] -> [Int]
82 getCases = concatMap analyze
84 analyze :: BC -> [Int]
85 analyze (CASE _ _ b _) = map fst b
89data JSTarget = Node | JavaScript deriving Eq
92codegenJavaScript :: CodeGenerator
94 codegenJS_all JavaScript (simpleDecls ci)
95 (includes ci) [] (outputFile ci) (outputType ci)
97codegenNode :: CodeGenerator
99 codegenJS_all Node (simpleDecls ci)
100 (includes ci) (compileLibs ci) (outputFile ci) (outputType ci)
110codegenJS_all target definitions includes libs filename outputType = do
111 let bytecode = map toBC definitions
112 let info = initCompileInfo bytecode
113 let js = concatMap (translateDecl info) bytecode
114 let full = concatMap processFunction js
115 let code = deadCodeElim full
116 let (cons, opt) = optimizeConstructors code
117 let (header, rt) = case target of
118 Node -> ("#!/usr/bin/env node\n", "-node")
119 JavaScript -> ("", "-browser")
121 included <- concat <$> getIncludes includes
122 path <- (++) <$> getDataDir <*> (pure "/jsrts/")
123 idrRuntime <- readFile $ path ++ "Runtime-common.js"
124 tgtRuntime <- readFile $ concat [path, "Runtime", rt, ".js"]
125 jsbn <- if compileInfoNeedsBigInt info
126 then readFile $ path ++ "jsbn/jsbn.js"
128 let runtime = ( header
135 TIO.writeFile filename ( T.pack runtime
136 `T.append` T.concat (map compileJS opt)
137 `T.append` T.concat (map compileJS cons)
139 `T.append` invokeMain
141 setPermissions filename (emptyPermissions { readable = True
142 , executable = target == Node
146 deadCodeElim :: [JS] -> [JS]
147 deadCodeElim js = concatMap collectFunctions js
149 collectFunctions :: JS -> [JS]
150 collectFunctions fun@(JSAlloc name _)
151 | name == translateName (sMN 0 "runMain") = [fun]
153 collectFunctions fun@(JSAlloc name (Just (JSFunction _ body))) =
154 let invokations = sum $ map (
155 \x -> execState (countInvokations name x) 0
157 in if invokations == 0
161 countInvokations :: String -> JS -> State Int ()
162 countInvokations name (JSAlloc _ (Just (JSFunction _ body))) =
163 countInvokations name body
165 countInvokations name (JSSeq seq) =
166 void $ traverse (countInvokations name) seq
168 countInvokations name (JSAssign _ rhs) =
169 countInvokations name rhs
171 countInvokations name (JSCond conds) =
173 runKleisli $ arr id *** Kleisli (countInvokations name)
176 countInvokations name (JSSwitch _ conds def) =
178 runKleisli $ arr id *** Kleisli (countInvokations name)
179 ) conds >> traverse (countInvokations name) def
181 countInvokations name (JSApp lhs rhs) =
182 void $ countInvokations name lhs >> traverse (countInvokations name) rhs
184 countInvokations name (JSNew _ args) =
185 void $ traverse (countInvokations name) args
187 countInvokations name (JSArray args) =
188 void $ traverse (countInvokations name) args
190 countInvokations name (JSIdent name')
191 | name == name' = get >>= put . (+1)
192 | otherwise = return ()
194 countInvokations _ _ = return ()
196 processFunction :: JS -> [JS]
198 collectSplitFunctions . (\x -> evalRWS (splitFunction x) () 0)
200 includeLibs :: [String] -> String
202 concatMap (\lib -> "var " ++ lib ++ " = require(\"" ++ lib ++"\");\n")
204 getIncludes :: [FilePath] -> IO [String]
205 getIncludes = mapM readFile
209 compileJS $ JSAlloc "main" (Just $
219 JSCond [ (exists document `jsAnd` isReady, mainFun)
220 , (exists window, windowMainFun)
225 exists js = jsTypeOf js `jsNotEq` JSString "undefined"
228 window = JSIdent "window"
231 document = JSIdent "document"
235 jsMeth window "addEventListener" [ JSString "DOMContentLoaded"
236 , JSFunction [] ( mainFun )
241 isReady = JSParens $ readyState `jsEq` JSString "complete" `jsOr` readyState `jsEq` JSString "loaded"
244 readyState = JSProj (JSIdent "document") "readyState"
248 JSSeq [ JSAlloc "vm" (Just $ JSNew "i$VM" [])
249 , JSApp (JSIdent "i$SCHED") [JSIdent "vm"]
251 JSIdent (translateName (sMN 0 "runMain"))
252 ) [JSNew "i$POINTER" [JSNum (JSInt 0)]]
253 , JSWhile (JSProj jsCALLSTACK "length") (
254 JSSeq [ JSAlloc "func" (Just jsPOP)
255 , JSAlloc "args" (Just jsPOP)
256 , JSApp (JSProj (JSIdent "func") "apply") [JSThis, JSIdent "args"]
262 invokeMain = compileJS $ JSApp (JSIdent "main") []
264optimizeConstructors :: [JS] -> ([JS], [JS])
265optimizeConstructors js =
266 let (js', cons) = runState (traverse optimizeConstructor' js) M.empty in
267 (map (allocCon . snd) (M.toList cons), js')
269 allocCon :: (String, JS) -> JS
270 allocCon (name, con) = JSAlloc name (Just con)
272 newConstructor :: Int -> String
273 newConstructor n = "i$CON$" ++ show n
275 optimizeConstructor' :: JS -> State (M.Map Int (String, JS)) JS
276 optimizeConstructor' js@(JSNew "i$CON" [ JSNum (JSInt tag)
282 case M.lookup tag s of
283 Just (i, c) -> return $ JSIdent i
284 Nothing -> do let n = newConstructor tag
285 put $ M.insert tag (n, js) s
288 optimizeConstructor' (JSSeq seq) =
289 JSSeq <$> traverse optimizeConstructor' seq
291 optimizeConstructor' (JSSwitch reg cond def) = do
292 cond' <- traverse (runKleisli $ arr id *** Kleisli optimizeConstructor') cond
293 def' <- traverse optimizeConstructor' def
294 return $ JSSwitch reg cond' def'
296 optimizeConstructor' (JSCond cond) =
297 JSCond <$> traverse (runKleisli $ arr id *** Kleisli optimizeConstructor') cond
299 optimizeConstructor' (JSAlloc fun (Just (JSFunction args body))) = do
300 body' <- optimizeConstructor' body
301 return $ JSAlloc fun (Just (JSFunction args body'))
303 optimizeConstructor' (JSAssign lhs rhs) = do
304 lhs' <- optimizeConstructor' lhs
305 rhs' <- optimizeConstructor' rhs
306 return $ JSAssign lhs' rhs'
308 optimizeConstructor' js = return js
310collectSplitFunctions :: (JS, [(Int,JS)]) -> [JS]
311collectSplitFunctions (fun, splits) = map generateSplitFunction splits ++ [fun]
313 generateSplitFunction :: (Int,JS) -> JS
314 generateSplitFunction (depth, JSAlloc name fun) =
315 JSAlloc (name ++ "$" ++ show depth) fun
317splitFunction :: JS -> RWS () [(Int,JS)] Int JS
318splitFunction (JSAlloc name (Just (JSFunction args body@(JSSeq _)))) = do
319 body' <- splitSequence body
320 return $ JSAlloc name (Just (JSFunction args body'))
322 splitCondition :: JS -> RWS () [(Int,JS)] Int JS
324 | JSCond branches <- js =
325 JSCond <$> processBranches branches
326 | JSSwitch cond branches def <- js =
327 JSSwitch cond <$> (processBranches branches) <*> (traverse splitSequence def)
328 | otherwise = return js
330 processBranches :: [(JS,JS)] -> RWS () [(Int,JS)] Int [(JS,JS)]
332 traverse (runKleisli (arr id *** Kleisli splitSequence))
334 splitSequence :: JS -> RWS () [(Int, JS)] Int JS
335 splitSequence js@(JSSeq seq) =
336 let (pre,post) = break isBranch seq in
338 [_] -> JSSeq <$> traverse splitCondition seq
339 [call@(JSCond _),rest@(JSApp _ _)] -> do
340 rest' <- splitCondition rest
341 call' <- splitCondition call
342 return $ JSSeq (pre ++ [rest', call'])
343 [call@(JSSwitch _ _ _),rest@(JSApp _ _)] -> do
344 rest' <- splitCondition rest
345 call' <- splitCondition call
346 return $ JSSeq (pre ++ [rest', call'])
350 new <- splitFunction (newFun rest)
352 call' <- splitCondition call
353 return $ JSSeq (pre ++ (newCall depth : [call']))
354 _ -> JSSeq <$> traverse splitCondition seq
356 splitSequence js = return js
358 isBranch :: JS -> Bool
359 isBranch (JSApp (JSIdent "i$CALL") _) = True
360 isBranch (JSCond _) = True
361 isBranch (JSSwitch _ _ _) = True
366 JSApp (JSIdent "i$CALL") [ JSIdent $ name ++ "$" ++ show depth
367 , JSArray [jsOLDBASE, jsMYOLDBASE]
372 JSAlloc name (Just $ JSFunction ["oldbase", "myoldbase"] (JSSeq seq))
374splitFunction js = return js
376translateDecl :: CompileInfo -> (Name, [BC]) -> [JS]
377translateDecl info (name@(MN 0 fun), bc)
378 | txt "APPLY" == fun =
379 allocCaseFunctions (snd body)
382 ) (Just $ JSFunction ["oldbase"] (
383 JSSeq $ jsFUNPRELUDE ++ map (translateBC info) (fst body) ++ [
384 JSCond [ ( (translateReg $ caseReg (snd body)) `jsInstanceOf` "i$CON" `jsAnd` (JSProj (translateReg $ caseReg (snd body)) "app")
385 , JSApp (JSProj (translateReg $ caseReg (snd body)) "app") [jsOLDBASE, jsMYOLDBASE]
388 , JSSeq $ map (translateBC info) (defaultCase (snd body))
396 | txt "EVAL" == fun =
397 allocCaseFunctions (snd body)
400 ) (Just $ JSFunction ["oldbase"] (
401 JSSeq $ jsFUNPRELUDE ++ map (translateBC info) (fst body) ++ [
402 JSCond [ ( (translateReg $ caseReg (snd body)) `jsInstanceOf` "i$CON" `jsAnd` (JSProj (translateReg $ caseReg (snd body)) "ev")
403 , JSApp (JSProj (translateReg $ caseReg (snd body)) "ev") [jsOLDBASE, jsMYOLDBASE]
406 , JSSeq $ map (translateBC info) (defaultCase (snd body))
415 body = break isCase bc
419 | CASE {} <- bc = True
422 defaultCase :: [BC] -> [BC]
423 defaultCase ((CASE _ _ _ (Just d)):_) = d
425 caseReg :: [BC] -> Reg
426 caseReg ((CASE _ r _ _):_) = r
428 allocCaseFunctions :: [BC] -> [JS]
429 allocCaseFunctions ((CASE _ _ c _):_) = splitBranches c
430 allocCaseFunctions _ = []
432 splitBranches :: [(Int, [BC])] -> [JS]
433 splitBranches = map prepBranch
435 prepBranch :: (Int, [BC]) -> JS
436 prepBranch (tag, code) =
438 translateName name ++ "$" ++ show tag
439 ) (Just $ JSFunction ["oldbase", "myoldbase"] (
440 JSSeq $ map (translateBC info) code
444translateDecl info (name, bc) =
447 ) (Just $ JSFunction ["oldbase"] (
448 JSSeq $ jsFUNPRELUDE ++ map (translateBC info)bc
454jsFUNPRELUDE = [jsALLOCMYOLDBASE]
456jsALLOCMYOLDBASE :: JS
457jsALLOCMYOLDBASE = JSAlloc "myoldbase" (Just $ JSNew "i$POINTER" [])
459translateReg :: Reg -> JS
461 | RVal <- reg = jsRET
462 | Tmp <- reg = JSRaw "//TMPREG"
463 | L n <- reg = jsLOC n
464 | T n <- reg = jsTOP n
466translateConstant :: Const -> JS
467translateConstant (I i) = JSNum (JSInt i)
468translateConstant (Fl f) = JSNum (JSFloat f)
469translateConstant (Ch c) = JSString $ translateChar c
470translateConstant (Str s) = JSString $ concatMap translateChar s
471translateConstant (AType (ATInt ITNative)) = JSType JSIntTy
472translateConstant StrType = JSType JSStringTy
473translateConstant (AType (ATInt ITBig)) = JSType JSIntegerTy
474translateConstant (AType ATFloat) = JSType JSFloatTy
475translateConstant (AType (ATInt ITChar)) = JSType JSCharTy
476translateConstant Forgot = JSType JSForgotTy
477translateConstant (BI 0) = JSNum (JSInteger JSBigZero)
478translateConstant (BI 1) = JSNum (JSInteger JSBigOne)
479translateConstant (BI i) = jsBigInt (JSString $ show i)
480translateConstant (B8 b) = JSWord (JSWord8 b)
481translateConstant (B16 b) = JSWord (JSWord16 b)
482translateConstant (B32 b) = JSWord (JSWord32 b)
483translateConstant (B64 b) = JSWord (JSWord64 b)
485 JSError $ "Unimplemented Constant: " ++ show c
488translateChar :: Char -> String
490 | '\a' <- ch = "\\u0007"
497 | '\SO' <- ch = "\\u000E"
498 | '\DEL' <- ch = "\\u007F"
499 | '\\' <- ch = "\\\\"
500 | '\"' <- ch = "\\\""
501 | '\'' <- ch = "\\\'"
502 | ch `elem` asciiTab = "\\u" ++ fill (showHex (ord ch) "")
503 | ord ch > 255 = "\\u" ++ fill (showHex (ord ch) "")
506 fill :: String -> String
507 fill s = case length s of
514 ['\NUL', '\SOH', '\STX', '\ETX', '\EOT', '\ENQ', '\ACK', '\BEL',
515 '\BS', '\HT', '\LF', '\VT', '\FF', '\CR', '\SO', '\SI',
516 '\DLE', '\DC1', '\DC2', '\DC3', '\DC4', '\NAK', '\SYN', '\ETB',
517 '\CAN', '\EM', '\SUB', '\ESC', '\FS', '\GS', '\RS', '\US']
519translateName :: Name -> String
520translateName n = "_idris_" ++ concatMap cchar (showCG n)
521 where cchar x | isAlphaNum x = [x]
522 | otherwise = "_" ++ show (fromEnum x) ++ "_"
524jsASSIGN :: CompileInfo -> Reg -> Reg -> JS
525jsASSIGN _ r1 r2 = JSAssign (translateReg r1) (translateReg r2)
527jsASSIGNCONST :: CompileInfo -> Reg -> Const -> JS
528jsASSIGNCONST _ r c = JSAssign (translateReg r) (translateConstant c)
530jsCALL :: CompileInfo -> Name -> JS
534 ) [JSIdent (translateName n), JSArray [jsMYOLDBASE]]
536jsTAILCALL :: CompileInfo -> Name -> JS
540 ) [JSIdent (translateName n), JSArray [jsOLDBASE]]
542jsFOREIGN :: CompileInfo -> Reg -> String -> [(FType, Reg)] -> JS
543jsFOREIGN _ reg n args
545 , [(FPtr, arg)] <- args =
549 JSBinOp "==" (translateReg arg) JSNull
553 , [(_, lhs),(_, rhs)] <- args =
557 JSBinOp "==" (translateReg lhs) (translateReg rhs)
563 JSFFI n (map generateWrapper args)
566 generateWrapper :: (FType, Reg) -> JS
567 generateWrapper (ty, reg)
569 JSApp (JSIdent "i$ffiWrap") [ translateReg reg
571 , JSIdent "myoldbase"
573 | FFunctionIO <- ty =
574 JSApp (JSIdent "i$ffiWrap") [ translateReg reg
576 , JSIdent "myoldbase"
579 generateWrapper (_, reg) =
582jsREBASE :: CompileInfo -> JS
583jsREBASE _ = JSAssign jsSTACKBASE (JSProj jsOLDBASE "addr")
585jsSTOREOLD :: CompileInfo ->JS
586jsSTOREOLD _ = JSAssign (JSProj jsMYOLDBASE "addr") jsSTACKBASE
588jsADDTOP :: CompileInfo -> Int -> JS
592 JSBinOp "+=" jsSTACKTOP (JSNum (JSInt n))
594jsTOPBASE :: CompileInfo -> Int -> JS
595jsTOPBASE _ 0 = JSAssign jsSTACKTOP jsSTACKBASE
596jsTOPBASE _ n = JSAssign jsSTACKTOP (JSBinOp "+" jsSTACKBASE (JSNum (JSInt n)))
599jsBASETOP :: CompileInfo -> Int -> JS
600jsBASETOP _ 0 = JSAssign jsSTACKBASE jsSTACKTOP
601jsBASETOP _ n = JSAssign jsSTACKBASE (JSBinOp "+" jsSTACKTOP (JSNum (JSInt n)))
603jsNULL :: CompileInfo -> Reg -> JS
604jsNULL _ r = JSAssign (translateReg r) JSNull
606jsERROR :: CompileInfo -> String -> JS
609jsSLIDE :: CompileInfo -> Int -> JS
610jsSLIDE _ 1 = JSAssign (jsLOC 0) (jsTOP 0)
611jsSLIDE _ n = JSApp (JSIdent "i$SLIDE") [JSNum (JSInt n)]
613jsMKCON :: CompileInfo -> Reg -> Int -> [Reg] -> JS
615 JSAssign (translateReg r) (
616 JSNew "i$CON" [ JSNum (JSInt t)
617 , JSArray (map translateReg rs)
618 , if t `elem` compileInfoApplyCases info
619 then JSIdent $ translateName (sMN 0 "APPLY") ++ "$" ++ show t
621 , if t `elem` compileInfoEvalCases info
622 then JSIdent $ translateName (sMN 0 "EVAL") ++ "$" ++ show t
627jsCASE :: CompileInfo -> Bool -> Reg -> [(Int, [BC])] -> Maybe [BC] -> JS
628jsCASE info safe reg cases def =
629 JSSwitch (tag safe $ translateReg reg) (
630 map ((JSNum . JSInt) *** prepBranch) cases
631 ) (fmap prepBranch def)
633 tag :: Bool -> JS -> JS
637 prepBranch :: [BC] -> JS
638 prepBranch bc = JSSeq $ map (translateBC info) bc
642 (JSTernary (js `jsInstanceOf` "i$CON") (
644 ) (JSNum (JSInt $ negate 1)))
647 jsCTAG js = JSProj js "tag"
650jsCONSTCASE :: CompileInfo -> Reg -> [(Const, [BC])] -> Maybe [BC] -> JS
651jsCONSTCASE info reg cases def =
653 map (jsEq (translateReg reg) . translateConstant *** prepBranch) cases
654 ) ++ (maybe [] ((:[]) . ((,) JSNoop) . prepBranch) def)
656 prepBranch :: [BC] -> JS
657 prepBranch bc = JSSeq $ map (translateBC info) bc
659jsPROJECT :: CompileInfo -> Reg -> Int -> Int -> JS
660jsPROJECT _ reg loc 0 = JSNoop
661jsPROJECT _ reg loc 1 =
662 JSAssign (jsLOC loc) (
664 JSProj (translateReg reg) "args"
669jsPROJECT _ reg loc ar =
670 JSApp (JSIdent "i$PROJECT") [ translateReg reg
675jsOP :: CompileInfo -> Reg -> PrimFn -> [Reg] -> JS
676jsOP _ reg op args = JSAssign (translateReg reg) jsOP'
680 | LNoOp <- op = translateReg (last args)
683 (_:str:_) <- args = JSAssign (translateReg reg)
684 (JSApp (JSIdent "i$putStr") [translateReg str])
686 | (LZExt (ITFixed IT8) ITNative) <- op = jsUnPackBits $ translateReg (last args)
687 | (LZExt (ITFixed IT16) ITNative) <- op = jsUnPackBits $ translateReg (last args)
688 | (LZExt (ITFixed IT32) ITNative) <- op = jsUnPackBits $ translateReg (last args)
690 | (LZExt _ ITBig) <- op = jsBigInt $ JSApp (JSIdent "String") [translateReg (last args)]
691 | (LPlus (ATInt ITBig)) <- op
692 , (lhs:rhs:_) <- args = invokeMeth lhs "add" [rhs]
693 | (LMinus (ATInt ITBig)) <- op
694 , (lhs:rhs:_) <- args = invokeMeth lhs "subtract" [rhs]
695 | (LTimes (ATInt ITBig)) <- op
696 , (lhs:rhs:_) <- args = invokeMeth lhs "multiply" [rhs]
697 | (LSDiv (ATInt ITBig)) <- op
698 , (lhs:rhs:_) <- args = invokeMeth lhs "divide" [rhs]
699 | (LSRem (ATInt ITBig)) <- op
700 , (lhs:rhs:_) <- args = invokeMeth lhs "mod" [rhs]
701 | (LEq (ATInt ITBig)) <- op
702 , (lhs:rhs:_) <- args = invokeMeth lhs "equals" [rhs]
703 | (LSLt (ATInt ITBig)) <- op
704 , (lhs:rhs:_) <- args = invokeMeth lhs "lesser" [rhs]
705 | (LSLe (ATInt ITBig)) <- op
706 , (lhs:rhs:_) <- args = invokeMeth lhs "lesserOrEquals" [rhs]
707 | (LSGt (ATInt ITBig)) <- op
708 , (lhs:rhs:_) <- args = invokeMeth lhs "greater" [rhs]
709 | (LSGe (ATInt ITBig)) <- op
710 , (lhs:rhs:_) <- args = invokeMeth lhs "greaterOrEquals" [rhs]
712 | (LPlus ATFloat) <- op
713 , (lhs:rhs:_) <- args = translateBinaryOp "+" lhs rhs
714 | (LMinus ATFloat) <- op
715 , (lhs:rhs:_) <- args = translateBinaryOp "-" lhs rhs
716 | (LTimes ATFloat) <- op
717 , (lhs:rhs:_) <- args = translateBinaryOp "*" lhs rhs
718 | (LSDiv ATFloat) <- op
719 , (lhs:rhs:_) <- args = translateBinaryOp "/" lhs rhs
720 | (LEq ATFloat) <- op
721 , (lhs:rhs:_) <- args = translateBinaryOp "==" lhs rhs
722 | (LSLt ATFloat) <- op
723 , (lhs:rhs:_) <- args = translateBinaryOp "<" lhs rhs
724 | (LSLe ATFloat) <- op
725 , (lhs:rhs:_) <- args = translateBinaryOp "<=" lhs rhs
726 | (LSGt ATFloat) <- op
727 , (lhs:rhs:_) <- args = translateBinaryOp ">" lhs rhs
728 | (LSGe ATFloat) <- op
729 , (lhs:rhs:_) <- args = translateBinaryOp ">=" lhs rhs
731 | (LPlus (ATInt ITChar)) <- op
732 , (lhs:rhs:_) <- args =
733 jsCall "i$fromCharCode" [
735 jsCall "i$charCode" [translateReg lhs]
737 jsCall "i$charCode" [translateReg rhs]
741 | (LTrunc (ITFixed IT16) (ITFixed IT8)) <- op
744 JSBinOp "&" (jsUnPackBits $ translateReg arg) (JSNum (JSInt 0xFF))
747 | (LTrunc (ITFixed IT32) (ITFixed IT16)) <- op
750 JSBinOp "&" (jsUnPackBits $ translateReg arg) (JSNum (JSInt 0xFFFF))
753 | (LTrunc (ITFixed IT64) (ITFixed IT32)) <- op
756 jsMeth (jsMeth (translateReg arg) "and" [
757 jsBigInt (JSString $ show 0xFFFFFFFF)
761 | (LTrunc ITBig (ITFixed IT64)) <- op
763 jsMeth (translateReg arg) "and" [
764 jsBigInt (JSString $ show 0xFFFFFFFFFFFFFFFF)
767 | (LLSHR (ITFixed IT8)) <- op
768 , (lhs:rhs:_) <- args =
770 JSBinOp ">>" (jsUnPackBits $ translateReg lhs) (jsUnPackBits $ translateReg rhs)
773 | (LLSHR (ITFixed IT16)) <- op
774 , (lhs:rhs:_) <- args =
776 JSBinOp ">>" (jsUnPackBits $ translateReg lhs) (jsUnPackBits $ translateReg rhs)
779 | (LLSHR (ITFixed IT32)) <- op
780 , (lhs:rhs:_) <- args =
782 JSBinOp ">>" (jsUnPackBits $ translateReg lhs) (jsUnPackBits $ translateReg rhs)
785 | (LLSHR (ITFixed IT64)) <- op
786 , (lhs:rhs:_) <- args =
787 jsMeth (translateReg lhs) "shiftRight" [translateReg rhs]
789 | (LSHL (ITFixed IT8)) <- op
790 , (lhs:rhs:_) <- args =
792 JSBinOp "<<" (jsUnPackBits $ translateReg lhs) (jsUnPackBits $ translateReg rhs)
795 | (LSHL (ITFixed IT16)) <- op
796 , (lhs:rhs:_) <- args =
798 JSBinOp "<<" (jsUnPackBits $ translateReg lhs) (jsUnPackBits $ translateReg rhs)
801 | (LSHL (ITFixed IT32)) <- op
802 , (lhs:rhs:_) <- args =
804 JSBinOp "<<" (jsUnPackBits $ translateReg lhs) (jsUnPackBits $ translateReg rhs)
807 | (LSHL (ITFixed IT64)) <- op
808 , (lhs:rhs:_) <- args =
809 jsMeth (jsMeth (translateReg lhs) "shiftLeft" [translateReg rhs]) "and" [
810 jsBigInt (JSString $ show 0xFFFFFFFFFFFFFFFF)
813 | (LAnd (ITFixed IT8)) <- op
814 , (lhs:rhs:_) <- args =
816 JSBinOp "&" (jsUnPackBits (translateReg lhs)) (jsUnPackBits (translateReg rhs))
819 | (LAnd (ITFixed IT16)) <- op
820 , (lhs:rhs:_) <- args =
822 JSBinOp "&" (jsUnPackBits (translateReg lhs)) (jsUnPackBits (translateReg rhs))
825 | (LAnd (ITFixed IT32)) <- op
826 , (lhs:rhs:_) <- args =
828 JSBinOp "&" (jsUnPackBits (translateReg lhs)) (jsUnPackBits (translateReg rhs))
831 | (LAnd (ITFixed IT64)) <- op
832 , (lhs:rhs:_) <- args =
833 jsMeth (translateReg lhs) "and" [translateReg rhs]
835 | (LOr (ITFixed IT8)) <- op
836 , (lhs:rhs:_) <- args =
838 JSBinOp "|" (jsUnPackBits (translateReg lhs)) (jsUnPackBits (translateReg rhs))
841 | (LOr (ITFixed IT16)) <- op
842 , (lhs:rhs:_) <- args =
844 JSBinOp "|" (jsUnPackBits (translateReg lhs)) (jsUnPackBits (translateReg rhs))
847 | (LOr (ITFixed IT32)) <- op
848 , (lhs:rhs:_) <- args =
850 JSBinOp "|" (jsUnPackBits (translateReg lhs)) (jsUnPackBits (translateReg rhs))
853 | (LOr (ITFixed IT64)) <- op
854 , (lhs:rhs:_) <- args =
855 jsMeth (translateReg lhs) "or" [translateReg rhs]
857 | (LXOr (ITFixed IT8)) <- op
858 , (lhs:rhs:_) <- args =
860 JSBinOp "^" (jsUnPackBits (translateReg lhs)) (jsUnPackBits (translateReg rhs))
863 | (LXOr (ITFixed IT16)) <- op
864 , (lhs:rhs:_) <- args =
866 JSBinOp "^" (jsUnPackBits (translateReg lhs)) (jsUnPackBits (translateReg rhs))
869 | (LXOr (ITFixed IT32)) <- op
870 , (lhs:rhs:_) <- args =
872 JSBinOp "^" (jsUnPackBits (translateReg lhs)) (jsUnPackBits (translateReg rhs))
875 | (LXOr (ITFixed IT64)) <- op
876 , (lhs:rhs:_) <- args =
877 jsMeth (translateReg lhs) "xor" [translateReg rhs]
879 | (LPlus (ATInt (ITFixed IT8))) <- op
880 , (lhs:rhs:_) <- args =
882 JSBinOp "+" (jsUnPackBits (translateReg lhs)) (jsUnPackBits (translateReg rhs))
885 | (LPlus (ATInt (ITFixed IT16))) <- op
886 , (lhs:rhs:_) <- args =
888 JSBinOp "+" (jsUnPackBits (translateReg lhs)) (jsUnPackBits (translateReg rhs))
891 | (LPlus (ATInt (ITFixed IT32))) <- op
892 , (lhs:rhs:_) <- args =
894 JSBinOp "+" (jsUnPackBits (translateReg lhs)) (jsUnPackBits (translateReg rhs))
897 | (LPlus (ATInt (ITFixed IT64))) <- op
898 , (lhs:rhs:_) <- args =
899 jsMeth (jsMeth (translateReg lhs) "add" [translateReg rhs]) "and" [
900 jsBigInt (JSString $ show 0xFFFFFFFFFFFFFFFF)
903 | (LMinus (ATInt (ITFixed IT8))) <- op
904 , (lhs:rhs:_) <- args =
906 JSBinOp "-" (jsUnPackBits (translateReg lhs)) (jsUnPackBits (translateReg rhs))
909 | (LMinus (ATInt (ITFixed IT16))) <- op
910 , (lhs:rhs:_) <- args =
912 JSBinOp "-" (jsUnPackBits (translateReg lhs)) (jsUnPackBits (translateReg rhs))
915 | (LMinus (ATInt (ITFixed IT32))) <- op
916 , (lhs:rhs:_) <- args =
918 JSBinOp "-" (jsUnPackBits (translateReg lhs)) (jsUnPackBits (translateReg rhs))
921 | (LMinus (ATInt (ITFixed IT64))) <- op
922 , (lhs:rhs:_) <- args =
923 jsMeth (jsMeth (translateReg lhs) "subtract" [translateReg rhs]) "and" [
924 jsBigInt (JSString $ show 0xFFFFFFFFFFFFFFFF)
927 | (LTimes (ATInt (ITFixed IT8))) <- op
928 , (lhs:rhs:_) <- args =
930 JSBinOp "*" (jsUnPackBits (translateReg lhs)) (jsUnPackBits (translateReg rhs))
933 | (LTimes (ATInt (ITFixed IT16))) <- op
934 , (lhs:rhs:_) <- args =
936 JSBinOp "*" (jsUnPackBits (translateReg lhs)) (jsUnPackBits (translateReg rhs))
939 | (LTimes (ATInt (ITFixed IT32))) <- op
940 , (lhs:rhs:_) <- args =
942 JSBinOp "*" (jsUnPackBits (translateReg lhs)) (jsUnPackBits (translateReg rhs))
945 | (LTimes (ATInt (ITFixed IT64))) <- op
946 , (lhs:rhs:_) <- args =
947 jsMeth (jsMeth (translateReg lhs) "multiply" [translateReg rhs]) "and" [
948 jsBigInt (JSString $ show 0xFFFFFFFFFFFFFFFF)
951 | (LEq (ATInt (ITFixed IT8))) <- op
952 , (lhs:rhs:_) <- args =
954 JSBinOp "==" (jsUnPackBits (translateReg lhs)) (jsUnPackBits (translateReg rhs))
957 | (LEq (ATInt (ITFixed IT16))) <- op
958 , (lhs:rhs:_) <- args =
960 JSBinOp "==" (jsUnPackBits (translateReg lhs)) (jsUnPackBits (translateReg rhs))
963 | (LEq (ATInt (ITFixed IT32))) <- op
964 , (lhs:rhs:_) <- args =
966 JSBinOp "==" (jsUnPackBits (translateReg lhs)) (jsUnPackBits (translateReg rhs))
969 | (LEq (ATInt (ITFixed IT64))) <- op
970 , (lhs:rhs:_) <- args =
971 jsMeth (jsMeth (translateReg lhs) "equals" [translateReg rhs]) "and" [
972 jsBigInt (JSString $ show 0xFFFFFFFFFFFFFFFF)
975 | (LLt (ITFixed IT8)) <- op
976 , (lhs:rhs:_) <- args =
978 JSBinOp "<" (jsUnPackBits (translateReg lhs)) (jsUnPackBits (translateReg rhs))
981 | (LLt (ITFixed IT16)) <- op
982 , (lhs:rhs:_) <- args =
984 JSBinOp "<" (jsUnPackBits (translateReg lhs)) (jsUnPackBits (translateReg rhs))
987 | (LLt (ITFixed IT32)) <- op
988 , (lhs:rhs:_) <- args =
990 JSBinOp "<" (jsUnPackBits (translateReg lhs)) (jsUnPackBits (translateReg rhs))
993 | (LLt (ITFixed IT64)) <- op
994 , (lhs:rhs:_) <- args = invokeMeth lhs "lesser" [rhs]
996 | (LLe (ITFixed IT8)) <- op
997 , (lhs:rhs:_) <- args =
999 JSBinOp "<=" (jsUnPackBits (translateReg lhs)) (jsUnPackBits (translateReg rhs))
1002 | (LLe (ITFixed IT16)) <- op
1003 , (lhs:rhs:_) <- args =
1005 JSBinOp "<=" (jsUnPackBits (translateReg lhs)) (jsUnPackBits (translateReg rhs))
1008 | (LLe (ITFixed IT32)) <- op
1009 , (lhs:rhs:_) <- args =
1011 JSBinOp "<=" (jsUnPackBits (translateReg lhs)) (jsUnPackBits (translateReg rhs))
1014 | (LLe (ITFixed IT64)) <- op
1015 , (lhs:rhs:_) <- args = invokeMeth lhs "lesserOrEquals" [rhs]
1017 | (LGt (ITFixed IT8)) <- op
1018 , (lhs:rhs:_) <- args =
1020 JSBinOp ">" (jsUnPackBits (translateReg lhs)) (jsUnPackBits (translateReg rhs))
1023 | (LGt (ITFixed IT16)) <- op
1024 , (lhs:rhs:_) <- args =
1026 JSBinOp ">" (jsUnPackBits (translateReg lhs)) (jsUnPackBits (translateReg rhs))
1028 | (LGt (ITFixed IT32)) <- op
1029 , (lhs:rhs:_) <- args =
1031 JSBinOp ">" (jsUnPackBits (translateReg lhs)) (jsUnPackBits (translateReg rhs))
1034 | (LGt (ITFixed IT64)) <- op
1035 , (lhs:rhs:_) <- args = invokeMeth lhs "greater" [rhs]
1037 | (LGe (ITFixed IT8)) <- op
1038 , (lhs:rhs:_) <- args =
1040 JSBinOp ">=" (jsUnPackBits (translateReg lhs)) (jsUnPackBits (translateReg rhs))
1043 | (LGe (ITFixed IT16)) <- op
1044 , (lhs:rhs:_) <- args =
1046 JSBinOp ">=" (jsUnPackBits (translateReg lhs)) (jsUnPackBits (translateReg rhs))
1048 | (LGe (ITFixed IT32)) <- op
1049 , (lhs:rhs:_) <- args =
1051 JSBinOp ">=" (jsUnPackBits (translateReg lhs)) (jsUnPackBits (translateReg rhs))
1054 | (LGe (ITFixed IT64)) <- op
1055 , (lhs:rhs:_) <- args = invokeMeth lhs "greaterOrEquals" [rhs]
1057 | (LUDiv (ITFixed IT8)) <- op
1058 , (lhs:rhs:_) <- args =
1060 JSBinOp "/" (jsUnPackBits (translateReg lhs)) (jsUnPackBits (translateReg rhs))
1063 | (LUDiv (ITFixed IT16)) <- op
1064 , (lhs:rhs:_) <- args =
1066 JSBinOp "/" (jsUnPackBits (translateReg lhs)) (jsUnPackBits (translateReg rhs))
1069 | (LUDiv (ITFixed IT32)) <- op
1070 , (lhs:rhs:_) <- args =
1072 JSBinOp "/" (jsUnPackBits (translateReg lhs)) (jsUnPackBits (translateReg rhs))
1075 | (LUDiv (ITFixed IT64)) <- op
1076 , (lhs:rhs:_) <- args = invokeMeth lhs "divide" [rhs]
1078 | (LSDiv (ATInt (ITFixed IT8))) <- op
1079 , (lhs:rhs:_) <- args =
1082 jsUnPackBits $ jsPackSBits8 $ jsUnPackBits (translateReg lhs)
1084 jsUnPackBits $ jsPackSBits8 $ jsUnPackBits (translateReg rhs)
1088 | (LSDiv (ATInt (ITFixed IT16))) <- op
1089 , (lhs:rhs:_) <- args =
1092 jsUnPackBits $ jsPackSBits16 $ jsUnPackBits (translateReg lhs)
1094 jsUnPackBits $ jsPackSBits16 $ jsUnPackBits (translateReg rhs)
1098 | (LSDiv (ATInt (ITFixed IT32))) <- op
1099 , (lhs:rhs:_) <- args =
1102 jsUnPackBits $ jsPackSBits32 $ jsUnPackBits (translateReg lhs)
1104 jsUnPackBits $ jsPackSBits32 $ jsUnPackBits (translateReg rhs)
1108 | (LSDiv (ATInt (ITFixed IT64))) <- op
1109 , (lhs:rhs:_) <- args = invokeMeth lhs "divide" [rhs]
1111 | (LSRem (ATInt (ITFixed IT8))) <- op
1112 , (lhs:rhs:_) <- args =
1115 jsUnPackBits $ jsPackSBits8 $ jsUnPackBits (translateReg lhs)
1117 jsUnPackBits $ jsPackSBits8 $ jsUnPackBits (translateReg rhs)
1121 | (LSRem (ATInt (ITFixed IT16))) <- op
1122 , (lhs:rhs:_) <- args =
1125 jsUnPackBits $ jsPackSBits16 $ jsUnPackBits (translateReg lhs)
1127 jsUnPackBits $ jsPackSBits16 $ jsUnPackBits (translateReg rhs)
1131 | (LSRem (ATInt (ITFixed IT32))) <- op
1132 , (lhs:rhs:_) <- args =
1135 jsUnPackBits $ jsPackSBits32 $ jsUnPackBits (translateReg lhs)
1137 jsUnPackBits $ jsPackSBits32 $ jsUnPackBits (translateReg rhs)
1141 | (LSRem (ATInt (ITFixed IT64))) <- op
1142 , (lhs:rhs:_) <- args = invokeMeth lhs "mod" [rhs]
1144 | (LCompl (ITFixed IT8)) <- op
1146 jsPackSBits8 $ JSPreOp "~" $ jsUnPackBits (translateReg arg)
1148 | (LCompl (ITFixed IT16)) <- op
1150 jsPackSBits16 $ JSPreOp "~" $ jsUnPackBits (translateReg arg)
1152 | (LCompl (ITFixed IT32)) <- op
1154 jsPackSBits32 $ JSPreOp "~" $ jsUnPackBits (translateReg arg)
1156 | (LCompl (ITFixed IT64)) <- op
1158 invokeMeth arg "not" []
1161 , (lhs:rhs:_) <- args = translateBinaryOp "+" lhs rhs
1163 , (lhs:rhs:_) <- args = translateBinaryOp "-" lhs rhs
1165 , (lhs:rhs:_) <- args = translateBinaryOp "*" lhs rhs
1167 , (lhs:rhs:_) <- args = translateBinaryOp "/" lhs rhs
1169 , (lhs:rhs:_) <- args = translateBinaryOp "%" lhs rhs
1171 , (lhs:rhs:_) <- args = translateBinaryOp "==" lhs rhs
1173 , (lhs:rhs:_) <- args = translateBinaryOp "<" lhs rhs
1175 , (lhs:rhs:_) <- args = translateBinaryOp "<=" lhs rhs
1177 , (lhs:rhs:_) <- args = translateBinaryOp ">" lhs rhs
1179 , (lhs:rhs:_) <- args = translateBinaryOp ">=" lhs rhs
1181 , (lhs:rhs:_) <- args = translateBinaryOp "&" lhs rhs
1183 , (lhs:rhs:_) <- args = translateBinaryOp "|" lhs rhs
1185 , (lhs:rhs:_) <- args = translateBinaryOp "^" lhs rhs
1187 , (lhs:rhs:_) <- args = translateBinaryOp "<<" rhs lhs
1189 , (lhs:rhs:_) <- args = translateBinaryOp ">>" rhs lhs
1191 , (arg:_) <- args = JSPreOp "~" (translateReg arg)
1194 , (lhs:rhs:_) <- args = translateBinaryOp "+" lhs rhs
1196 , (lhs:rhs:_) <- args = translateBinaryOp "==" lhs rhs
1198 , (lhs:rhs:_) <- args = translateBinaryOp "<" lhs rhs
1200 , (arg:_) <- args = JSProj (translateReg arg) "length"
1201 | (LStrInt ITNative) <- op
1202 , (arg:_) <- args = jsCall "parseInt" [translateReg arg]
1203 | (LIntStr ITNative) <- op
1204 , (arg:_) <- args = jsCall "String" [translateReg arg]
1205 | (LSExt ITNative ITBig) <- op
1206 , (arg:_) <- args = jsBigInt $ jsCall "String" [translateReg arg]
1207 | (LTrunc ITBig ITNative) <- op
1208 , (arg:_) <- args = jsMeth (translateReg arg) "intValue" []
1209 | (LIntStr ITBig) <- op
1210 , (arg:_) <- args = jsMeth (translateReg arg) "toString" []
1211 | (LStrInt ITBig) <- op
1212 , (arg:_) <- args = jsBigInt $ translateReg arg
1214 , (arg:_) <- args = jsCall "String" [translateReg arg]
1216 , (arg:_) <- args = jsCall "parseFloat" [translateReg arg]
1217 | (LIntFloat ITNative) <- op
1218 , (arg:_) <- args = translateReg arg
1219 | (LIntFloat ITBig) <- op
1220 , (arg:_) <- args = jsMeth (translateReg arg) "intValue" []
1221 | (LFloatInt ITNative) <- op
1222 , (arg:_) <- args = translateReg arg
1223 | (LChInt ITNative) <- op
1224 , (arg:_) <- args = jsCall "i$charCode" [translateReg arg]
1225 | (LIntCh ITNative) <- op
1226 , (arg:_) <- args = jsCall "i$fromCharCode" [translateReg arg]
1229 , (arg:_) <- args = jsCall "Math.exp" [translateReg arg]
1231 , (arg:_) <- args = jsCall "Math.log" [translateReg arg]
1233 , (arg:_) <- args = jsCall "Math.sin" [translateReg arg]
1235 , (arg:_) <- args = jsCall "Math.cos" [translateReg arg]
1237 , (arg:_) <- args = jsCall "Math.tan" [translateReg arg]
1239 , (arg:_) <- args = jsCall "Math.asin" [translateReg arg]
1241 , (arg:_) <- args = jsCall "Math.acos" [translateReg arg]
1243 , (arg:_) <- args = jsCall "Math.atan" [translateReg arg]
1245 , (arg:_) <- args = jsCall "Math.sqrt" [translateReg arg]
1247 , (arg:_) <- args = jsCall "Math.floor" [translateReg arg]
1249 , (arg:_) <- args = jsCall "Math.ceil" [translateReg arg]
1251 , (arg:_) <- args = JSPreOp "-" (translateReg arg)
1254 , (lhs:rhs:_) <- args = invokeMeth lhs "concat" [rhs]
1256 , (arg:_) <- args = JSIndex (translateReg arg) (JSNum (JSInt 0))
1258 , (arg:_) <- args = JSProj (translateReg arg) "split('').reverse().join('')"
1260 , (lhs:rhs:_) <- args = JSIndex (translateReg lhs) (translateReg rhs)
1263 let v = translateReg arg in
1264 JSApp (JSProj v "substr") [
1266 JSBinOp "-" (JSProj v "length") (JSNum (JSInt 1))
1270 , (arg:_) <- args = jsCall "i$systemInfo" [translateReg arg]
1271 | LExternal nul <- op
1272 , nul == sUN "prim__null"
1273 , (_) <- args = JSNull
1274 | otherwise = JSError $ "Not implemented: " ++ show op
1276 translateBinaryOp :: String -> Reg -> Reg -> JS
1277 translateBinaryOp op lhs rhs =
1278 JSBinOp op (translateReg lhs) (translateReg rhs)
1280 invokeMeth :: Reg -> String -> [Reg] -> JS
1281 invokeMeth obj meth args =
1282 JSApp (JSProj (translateReg obj) meth) $ map translateReg args
1285jsRESERVE :: CompileInfo -> Int -> JS
1286jsRESERVE _ _ = JSNoop
1289jsSTACK = JSIdent "i$valstack"
1292jsCALLSTACK = JSIdent "i$callstack"
1295jsSTACKBASE = JSIdent "i$valstack_base"
1298jsSTACKTOP = JSIdent "i$valstack_top"
1301jsOLDBASE = JSIdent "oldbase"
1304jsMYOLDBASE = JSIdent "myoldbase"
1307jsRET = JSIdent "i$ret"
1310jsLOC 0 = JSIndex jsSTACK jsSTACKBASE
1311jsLOC n = JSIndex jsSTACK (JSBinOp "+" jsSTACKBASE (JSNum (JSInt n)))
1314jsTOP 0 = JSIndex jsSTACK jsSTACKTOP
1315jsTOP n = JSIndex jsSTACK (JSBinOp "+" jsSTACKTOP (JSNum (JSInt n)))
1318jsPUSH args = JSApp (JSProj jsCALLSTACK "push") args
1321jsPOP = JSApp (JSProj jsCALLSTACK "pop") []
1323translateBC :: CompileInfo -> BC -> JS
1325 | ASSIGN r1 r2 <- bc = jsASSIGN info r1 r2
1326 | ASSIGNCONST r c <- bc = jsASSIGNCONST info r c
1327 | UPDATE r1 r2 <- bc = jsASSIGN info r1 r2
1328 | ADDTOP n <- bc = jsADDTOP info n
1329 | NULL r <- bc = jsNULL info r
1330 | CALL n <- bc = jsCALL info n
1331 | TAILCALL n <- bc = jsTAILCALL info n
1332 | FOREIGNCALL r _ (FStr n) args
1333 <- bc = jsFOREIGN info r n (map fcall args)
1334 | TOPBASE n <- bc = jsTOPBASE info n
1335 | BASETOP n <- bc = jsBASETOP info n
1336 | STOREOLD <- bc = jsSTOREOLD info
1337 | SLIDE n <- bc = jsSLIDE info n
1338 | REBASE <- bc = jsREBASE info
1339 | RESERVE n <- bc = jsRESERVE info n
1340 | MKCON r _ t rs <- bc = jsMKCON info r t rs
1341 | CASE s r c d <- bc = jsCASE info s r c d
1342 | CONSTCASE r c d <- bc = jsCONSTCASE info r c d
1343 | PROJECT r l a <- bc = jsPROJECT info r l a
1344 | OP r o a <- bc = jsOP info r o a
1345 | ERROR e <- bc = jsERROR info e
1346 | otherwise = JSRaw $ "//" ++ show bc
1347 where fcall (t, arg) = (toFType t, arg)
1350 | i == sUN "JS_IntChar" = ATInt ITChar
1351 | i == sUN "JS_IntNative" = ATInt ITNative
1352toAType t = error (show t ++ " not defined in toAType")
1354toFnType (FApp c [_,_,s,t])
1355 | c == sUN "JS_Fn" = toFnType t
1356toFnType (FApp c [_,_,r])
1357 | c == sUN "JS_FnIO" = FFunctionIO
1358toFnType (FApp c [_,r])
1359 | c == sUN "JS_FnBase" = FFunction
1360toFnType t = error (show t ++ " not defined in toFnType")
1363 | c == sUN "JS_Str" = FString
1364 | c == sUN "JS_Float" = FArith ATFloat
1365 | c == sUN "JS_Ptr" = FPtr
1366 | c == sUN "JS_Unit" = FUnit
1367toFType (FApp c [_,ity])
1368 | c == sUN "JS_IntT" = FArith (toAType ity)
1369toFType (FApp c [_,fty])
1370 | c == sUN "JS_FnT" = toFnType fty
1371toFType t = error (show t ++ " not yet defined in toFType")
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