@@ -1,4 +1,4 @@
1−{-# LANGUAGE PatternGuards #-}
1+{-# LANGUAGE PatternGuards #-}
22module IRTS.CodegenJavaScript (codegenJavaScript, codegenNode, JSTarget(..)) where
33
44import Idris.AbsSyntax hiding (TypeCase)
@@ -582,7 +582,9 @@ jsIsNull :: JS -> JS
582582jsIsNull js = JSBinOp "==" js JSNull
583583
584584jsBigInt :: JS -> JS
585−jsBigInt = JSNum . JSInteger . JSBigIntExpr
585+jsBigInt (JSString "0") = JSNum (JSInteger JSBigZero)
586+jsBigInt (JSString "1") = JSNum (JSInteger JSBigOne)
587+jsBigInt js = JSNum $ JSInteger $ JSBigIntExpr js
586588
587589jsUnPackBits :: JS -> JS
588590jsUnPackBits js = JSIndex js $ JSNum (JSInt 0)
@@ -606,32 +608,32 @@ jsPackSBits16 js = JSNew "Int16Array" [JSArray [js]]
606608jsPackSBits32 :: JS -> JS
607609jsPackSBits32 js = JSNew "Int32Array" [JSArray [js]]
608610
609−jsTAG :: JS -> JS
610−jsTAG js =
611− JSTernary (jsIsNumber js `jsOr` jsIsNull js) (
612− JSNum (JSInt $ negate 1)
613− ) (JSTernary (js `jsInstanceOf` "i$CON") (
614− JSProj js "tag"
615− ) (JSNum (JSInt $ negate 1)))
616−
617−jsCTAG :: JS -> JS
618−jsCTAG js = JSProj js "tag"
619−
620611-- TODO unsafe
621612jsCASE :: Bool -> Reg -> [(Int, [BC])] -> Maybe [BC] -> JS
622613jsCASE safe reg cases def =
623− {-JSSwitch (tag safe (translateReg reg)) (-}
624− JSSwitch (JSTernary (translateReg reg `jsInstanceOf` "i$CON") (
625− JSProj (translateReg reg) "tag") (JSNum (JSInt $ negate 1))) (
614+ JSSwitch (tag safe $ translateReg reg) (
626615 map ((JSNum . JSInt) *** prepBranch) cases
627616 ) (fmap prepBranch def)
628617 where
629618 tag :: Bool -> JS -> JS
630619 tag True = jsCTAG
631620 tag False = jsTAG
621+
632622 prepBranch :: [BC] -> JS
633623 prepBranch bc = JSSeq $ map translateBC bc
634624
625+ jsTAG :: JS -> JS
626+ jsTAG js =
627+ JSTernary (jsIsNumber js `jsOr` jsIsNull js) (
628+ JSNum (JSInt $ negate 1)
629+ ) (JSTernary (js `jsInstanceOf` "i$CON") (
630+ JSProj js "tag"
631+ ) (JSNum (JSInt $ negate 1)))
632+
633+ jsCTAG :: JS -> JS
634+ jsCTAG js = JSProj js "tag"
635+
636+
635637jsCONSTCASE :: Reg -> [(Const, [BC])] -> Maybe [BC] -> JS
636638jsCONSTCASE reg cases def =
637639 JSCond $ (