on master help sign in
javascript: WIP
commitd55726778770377d9d3d630dbc5fd91be03b2ced authorraichoo <raichoo@googlemail.com> dateSat 21 Jun 2014, 22:18 (12 years ago) parentc47bd86
2 files changed+20−20
jsrts/Runtime-common.js+2−4 src/IRTS/CodegenJavaScript.hs+18−16
jsrts/Runtime-common.js+2−4
@@ -30,16 +30,14 @@ var i$RESERVE = function(vm,n) {
3030}
3131
3232var __IDRRT__charCode = function(str) {
33− var type = typeof str;
34− if (type == "string")
33+ if (typeof str == "string")
3534 return str.charCodeAt(0);
3635 else
3736 return str;
3837}
3938
4039var __IDRRT__fromCharCode = function(chr) {
41− var type = typeof chr;
42− if (type == "string")
40+ if (typeof chr == "string")
4341 return chr;
4442 else
4543 return String.fromCharCode(chr);
src/IRTS/CodegenJavaScript.hs+18−16
@@ -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 $ (