on master help sign in
Fix generation of bignum literals
ac88f4fAlex Queiroz
src/IRTS/CodegenC.hs+4−2
@@ -179,8 +179,10 @@ bcc i (ASSIGNCONST l c)
179 = indent i ++ creg l ++ " = " ++ mkConst c ++ ";\n"
179 = indent i ++ creg l ++ " = " ++ mkConst c ++ ";\n"
180 where
180 where
181 mkConst (I i) = "MKINT(" ++ show i ++ ")"
181 mkConst (I i) = "MKINT(" ++ show i ++ ")"
182+ mkConst (BI i) = let maxInt = 2^30
183+ in if i >= -maxInt && i < maxInt
182− mkConst (BI i) | i > ((-2)^30) && i < (2^30) = "MKINT(" ++ show i ++ ")"
184+ then "MKINT(" ++ show i ++ ")"
183− | otherwise = "MKBIGC(vm,\"" ++ show i ++ "\")"
185+ else "MKBIGC(vm,\"" ++ show i ++ "\")"
184 mkConst (Fl f) = "MKFLOAT(vm, " ++ (map toUpper $ show f) ++ ")"
186 mkConst (Fl f) = "MKFLOAT(vm, " ++ (map toUpper $ show f) ++ ")"
185 mkConst (Ch c) = "MKINT(" ++ show (fromEnum c) ++ ")"
187 mkConst (Ch c) = "MKINT(" ++ show (fromEnum c) ++ ")"
186 mkConst (Str s) = "MKSTR(vm, " ++ showCStr s ++ ")"
188 mkConst (Str s) = "MKSTR(vm, " ++ showCStr s ++ ")"
test/bignum002/bignum002.idr+10−2
@@ -2,5 +2,13 @@ module Main
2
2
3main : IO ()
3main : IO ()
4main = do
4main = do
5− putStrLn $ show $ divNat 1809022195644390369852458 91238741987
5+ printLn $ divNat 1809022195644390369852458 91238741987
6− putStrLn $ show $ div (-432642342742368327462378462387) 36473264372
6+ printLn $ div (-432642342742368327462378462387) 36473264372
7+
8+ -- values at the border between C ints and bignums
9+ printLn $ div 1073741822 73892
10+ printLn $ div 1073741823 73892
11+ printLn $ div 1073741824 73892
12+ printLn $ div (-1073741823) 73892
13+ printLn $ div (-1073741824) 73892
14+ printLn $ div (-1073741825) 73892
test/bignum002/expected+6
@@ -1,2 +1,8 @@
119827346982734
119827346982734
2-11861903511836511836
2-11861903511836511836
3+14531
4+14531
5+14531
6+-14531
7+-14531
8+-14531