on master help sign in
javascript: make bounded001 pass
a461b62raichoo
src/IRTS/CodegenJavaScript.hs+30
@@ -56,6 +56,8 @@ data JSNum = JSInt Int
56
56
57data JSWord = JSWord8 Word8
57data JSWord = JSWord8 Word8
58 | JSWord16 Word16
58 | JSWord16 Word16
59+ | JSWord32 Word32
60+ | JSWord64 Word64
59 deriving Eq
61 deriving Eq
60
62
61
63
@@ -267,6 +269,9 @@ compileJS (JSWhile cond body) =
267compileJS (JSWord word)
269compileJS (JSWord word)
268 | JSWord8 b <- word = show b
270 | JSWord8 b <- word = show b
269 | JSWord16 b <- word = show b
271 | JSWord16 b <- word = show b
272+ | JSWord32 b <- word = show b
273+ | JSWord64 b <- word = idrRTNamespace ++ "bigInt(\"" ++ show b ++ "\")"
274+
270
275
271jsTailcall :: JS -> JS
276jsTailcall :: JS -> JS
272jsTailcall call =
277jsTailcall call =
@@ -1452,6 +1457,7 @@ codegenJS_all target definitions includes filename outputType = do
1452
1457
1453 match :: JS -> Bool
1458 match :: JS -> Bool
1454 match (JSIdent "__IDRRT__bigInt") = True
1459 match (JSIdent "__IDRRT__bigInt") = True
1460+ match (JSWord (JSWord64 _)) = True
1455 match (JSNum (JSInteger _)) = True
1461 match (JSNum (JSInteger _)) = True
1456 match js = False
1462 match js = False
1457
1463
@@ -1646,6 +1652,8 @@ translateConstant Forgot = JSType JSForgotTy
1646translateConstant (BI i) = jsBigInt $ JSString (show i)
1652translateConstant (BI i) = jsBigInt $ JSString (show i)
1647translateConstant (B8 b) = JSWord (JSWord8 b)
1653translateConstant (B8 b) = JSWord (JSWord8 b)
1648translateConstant (B16 b) = JSWord (JSWord16 b)
1654translateConstant (B16 b) = JSWord (JSWord16 b)
1655+translateConstant (B32 b) = JSWord (JSWord32 b)
1656+translateConstant (B64 b) = JSWord (JSWord64 b)
1649translateConstant c =
1657translateConstant c =
1650 jsError $ "Unimplemented Constant: " ++ show c
1658 jsError $ "Unimplemented Constant: " ++ show c
1651
1659
@@ -1827,6 +1835,16 @@ translateExpression (SOp op vars)
1827 | (LLSHR (ITFixed IT8)) <- op
1835 | (LLSHR (ITFixed IT8)) <- op
1828 , (lhs:rhs:_) <- vars = translateBinaryOp ">>" lhs rhs
1836 , (lhs:rhs:_) <- vars = translateBinaryOp ">>" lhs rhs
1829
1837
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+
1830 | (LZExt _ ITBig) <- op = jsBigInt $ jsCall "String" [JSVar (last vars)]
1848 | (LZExt _ ITBig) <- op = jsBigInt $ jsCall "String" [JSVar (last vars)]
1831 | (LPlus (ATInt ITBig)) <- op
1849 | (LPlus (ATInt ITBig)) <- op
1832 , (lhs:rhs:_) <- vars = invokeMeth lhs "add" [rhs]
1850 , (lhs:rhs:_) <- vars = invokeMeth lhs "add" [rhs]
@@ -1878,6 +1896,18 @@ translateExpression (SOp op vars)
1878 )
1896 )
1879 ]
1897 ]
1880
1898
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+
1881 | (LPlus _) <- op
1911 | (LPlus _) <- op
1882 , (lhs:rhs:_) <- vars = translateBinaryOp "+" lhs rhs
1912 , (lhs:rhs:_) <- vars = translateBinaryOp "+" lhs rhs
1883 | (LMinus _) <- op
1913 | (LMinus _) <- op
test/Makefile+1−1
@@ -11,7 +11,7 @@ test_java:
11 perl ./runtest.pl without sugar004 buffer001 --codegen Java
11 perl ./runtest.pl without sugar004 buffer001 --codegen Java
12
12
13test_js:
13test_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
15
15
16test_llvm:
16test_llvm:
17 @perl ./runtest.pl without sugar004 io003 buffer001 --codegen llvm
17 @perl ./runtest.pl without sugar004 io003 buffer001 --codegen llvm