on master help sign in
javascript: make bounded001 pass
commita461b625a6e561d49edb13ebc4ec91608dbfb82b authorraichoo <raichoo@googlemail.com> dateSat 12 Apr 2014, 13:06 (13 years ago) parentb3bf583
2 files changed+31−1
src/IRTS/CodegenJavaScript.hs+30 test/Makefile+1−1
src/IRTS/CodegenJavaScript.hs+30
@@ -56,6 +56,8 @@ data JSNum = JSInt Int
5656
5757data JSWord = JSWord8 Word8
5858 | JSWord16 Word16
59+ | JSWord32 Word32
60+ | JSWord64 Word64
5961 deriving Eq
6062
6163
@@ -267,6 +269,9 @@ compileJS (JSWhile cond body) =
267269compileJS (JSWord word)
268270 | JSWord8 b <- word = show b
269271 | JSWord16 b <- word = show b
272+ | JSWord32 b <- word = show b
273+ | JSWord64 b <- word = idrRTNamespace ++ "bigInt(\"" ++ show b ++ "\")"
274+
270275
271276jsTailcall :: JS -> JS
272277jsTailcall call =
@@ -1452,6 +1457,7 @@ codegenJS_all target definitions includes filename outputType = do
14521457
14531458 match :: JS -> Bool
14541459 match (JSIdent "__IDRRT__bigInt") = True
1460+ match (JSWord (JSWord64 _)) = True
14551461 match (JSNum (JSInteger _)) = True
14561462 match js = False
14571463
@@ -1646,6 +1652,8 @@ translateConstant Forgot = JSType JSForgotTy
16461652translateConstant (BI i) = jsBigInt $ JSString (show i)
16471653translateConstant (B8 b) = JSWord (JSWord8 b)
16481654translateConstant (B16 b) = JSWord (JSWord16 b)
1655+translateConstant (B32 b) = JSWord (JSWord32 b)
1656+translateConstant (B64 b) = JSWord (JSWord64 b)
16491657translateConstant c =
16501658 jsError $ "Unimplemented Constant: " ++ show c
16511659
@@ -1827,6 +1835,16 @@ translateExpression (SOp op vars)
18271835 | (LLSHR (ITFixed IT8)) <- op
18281836 , (lhs:rhs:_) <- vars = translateBinaryOp ">>" lhs rhs
18291837
1838+ | (LLSHR (ITFixed IT16)) <- op
1839+ , (lhs:rhs:_) <- vars = translateBinaryOp ">>" lhs rhs
1840+
1841+ | (LLSHR (ITFixed IT32)) <- op
1842+ , (lhs:rhs:_) <- vars = translateBinaryOp ">>" lhs rhs
1843+
1844+ | (LLSHR (ITFixed IT64)) <- op
1845+ , (lhs:rhs:_) <- vars =
1846+ jsMeth (jsMeth (JSVar lhs) "shiftRight" [JSVar rhs]) "intValue" []
1847+
18301848 | (LZExt _ ITBig) <- op = jsBigInt $ jsCall "String" [JSVar (last vars)]
18311849 | (LPlus (ATInt ITBig)) <- op
18321850 , (lhs:rhs:_) <- vars = invokeMeth lhs "add" [rhs]
@@ -1878,6 +1896,18 @@ translateExpression (SOp op vars)
18781896 )
18791897 ]
18801898
1899+ | (LTrunc (ITFixed IT16) (ITFixed IT8)) <- op
1900+ , (arg:_) <- vars =
1901+ JSBinOp "&" (JSVar arg) (JSNum (JSInt 0xFF))
1902+
1903+ | (LTrunc (ITFixed IT32) (ITFixed IT16)) <- op
1904+ , (arg:_) <- vars =
1905+ JSBinOp "&" (JSVar arg) (JSNum (JSInt 0xFFFF))
1906+
1907+ | (LTrunc (ITFixed IT64) (ITFixed IT32)) <- op
1908+ , (arg:_) <- vars =
1909+ jsMeth (JSVar arg) "and" [jsBigInt (JSString $ show 0xFFFFFFFF)]
1910+
18811911 | (LPlus _) <- op
18821912 , (lhs:rhs:_) <- vars = translateBinaryOp "+" lhs rhs
18831913 | (LMinus _) <- op
test/Makefile+1−1
@@ -11,7 +11,7 @@ test_java:
1111 perl ./runtest.pl without sugar004 buffer001 --codegen Java
1212
1313test_js:
14− @perl ./runtest.pl without sugar004 reg029 io001 dsl002 io003 effects001 effects002 buffer001 bounded001 folding002 --codegen node
14+ @perl ./runtest.pl without sugar004 reg029 io001 dsl002 io003 effects001 effects002 buffer001 folding002 --codegen node
1515
1616test_llvm:
1717 @perl ./runtest.pl without sugar004 io003 buffer001 --codegen llvm