git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Merge pull request #1032 from purescript/integer-clamping

Ensure all integer ops are in the Int32 range

commit062b5a51f21978bef0f69c0a935da26b81fac81e authorGary Burgess <gary.burgess@gmail.com> dateMon 6 Apr 2015, 11:57 (12 years ago) parentd7254946aca6f6
1 file changed+7−2
src/Language/PureScript/CodeGen/JS/Optimizer/Inliner.hs+7−2
src/Language/PureScript/CodeGen/JS/Optimizer/Inliner.hs+7−2
@@ -92,14 +92,20 @@ inlineValues = everywhereOnJS convert
9292 | isDict boundedBoolean dict && isFn fnTop fn = JSBooleanLiteral True
9393 convert (JSApp fn [value]) | isFn fromNumber fn = JSBinary BitwiseOr value (JSNumericLiteral (Left 0))
9494 convert (JSApp (JSApp (JSApp fn [dict]) [x]) [y])
95+ | isDict semiringInt dict && isFn fnAdd fn = JSBinary BitwiseOr (JSBinary Add x y) (JSNumericLiteral (Left 0))
96+ | isDict semiringInt dict && isFn fnMultiply fn = JSBinary BitwiseOr (JSBinary Multiply x y) (JSNumericLiteral (Left 0))
9597 | isDict moduloSemiringInt dict && isFn fnDivide fn = JSBinary BitwiseOr (JSBinary Divide x y) (JSNumericLiteral (Left 0))
98+ | isDict ringInt dict && isFn fnSubtract fn = JSBinary BitwiseOr (JSBinary Subtract x y) (JSNumericLiteral (Left 0))
9699 convert other = other
97100 fnZero = (C.prelude, C.zero)
98101 fnOne = (C.prelude, C.one)
99102 fnBottom = (C.prelude, C.bottom)
100103 fnTop = (C.prelude, C.top)
101104 fromNumber = (C.dataInt, C.fromNumber)
105+ fnAdd = (C.prelude, (C.+))
102106 fnDivide = (C.prelude, (C./))
107+ fnMultiply = (C.prelude, (C.*))
108+ fnSubtract = (C.prelude, (C.-))
103109
104110inlineOperator :: (String, String) -> (JS -> JS -> JS) -> JS -> JS
105111inlineOperator (m, op) f = everywhereOnJS convert
@@ -115,8 +121,6 @@ inlineCommonOperators :: JS -> JS
115121inlineCommonOperators = applyAll $
116122 [ binary semiringNumber (C.+) Add
117123 , binary semiringNumber (C.*) Multiply
118− , binary semiringInt (C.+) Add
119− , binary semiringInt (C.*) Multiply
120124
121125 , binary ringNumber (C.-) Subtract
122126 , unary ringNumber C.negate Negate
@@ -124,6 +128,7 @@ inlineCommonOperators = applyAll $
124128 , unary ringInt C.negate Negate
125129
126130 , binary moduloSemiringNumber (C./) Divide
131+ , binary moduloSemiringInt C.mod Modulus
127132
128133 , binary eqNumber (C.==) EqualTo
129134 , binary eqNumber (C./=) NotEqualTo