git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Ensure all integer ops are in the Int32 range
6aca6f6Gary Burgess
src/Language/PureScript/CodeGen/JS/Optimizer/Inliner.hs+7−2
@@ -92,14 +92,20 @@ inlineValues = everywhereOnJS convert
92 | isDict boundedBoolean dict && isFn fnTop fn = JSBooleanLiteral True
92 | isDict boundedBoolean dict && isFn fnTop fn = JSBooleanLiteral True
93 convert (JSApp fn [value]) | isFn fromNumber fn = JSBinary BitwiseOr value (JSNumericLiteral (Left 0))
93 convert (JSApp fn [value]) | isFn fromNumber fn = JSBinary BitwiseOr value (JSNumericLiteral (Left 0))
94 convert (JSApp (JSApp (JSApp fn [dict]) [x]) [y])
94 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))
95 | isDict moduloSemiringInt dict && isFn fnDivide fn = JSBinary BitwiseOr (JSBinary Divide x y) (JSNumericLiteral (Left 0))
97 | 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))
96 convert other = other
99 convert other = other
97 fnZero = (C.prelude, C.zero)
100 fnZero = (C.prelude, C.zero)
98 fnOne = (C.prelude, C.one)
101 fnOne = (C.prelude, C.one)
99 fnBottom = (C.prelude, C.bottom)
102 fnBottom = (C.prelude, C.bottom)
100 fnTop = (C.prelude, C.top)
103 fnTop = (C.prelude, C.top)
101 fromNumber = (C.dataInt, C.fromNumber)
104 fromNumber = (C.dataInt, C.fromNumber)
105+ fnAdd = (C.prelude, (C.+))
102 fnDivide = (C.prelude, (C./))
106 fnDivide = (C.prelude, (C./))
107+ fnMultiply = (C.prelude, (C.*))
108+ fnSubtract = (C.prelude, (C.-))
103
109
104inlineOperator :: (String, String) -> (JS -> JS -> JS) -> JS -> JS
110inlineOperator :: (String, String) -> (JS -> JS -> JS) -> JS -> JS
105inlineOperator (m, op) f = everywhereOnJS convert
111inlineOperator (m, op) f = everywhereOnJS convert
@@ -115,8 +121,6 @@ inlineCommonOperators :: JS -> JS
115inlineCommonOperators = applyAll $
121inlineCommonOperators = applyAll $
116 [ binary semiringNumber (C.+) Add
122 [ binary semiringNumber (C.+) Add
117 , binary semiringNumber (C.*) Multiply
123 , binary semiringNumber (C.*) Multiply
118− , binary semiringInt (C.+) Add
119− , binary semiringInt (C.*) Multiply
120
124
121 , binary ringNumber (C.-) Subtract
125 , binary ringNumber (C.-) Subtract
122 , unary ringNumber C.negate Negate
126 , unary ringNumber C.negate Negate
@@ -124,6 +128,7 @@ inlineCommonOperators = applyAll $
124 , unary ringInt C.negate Negate
128 , unary ringInt C.negate Negate
125
129
126 , binary moduloSemiringNumber (C./) Divide
130 , binary moduloSemiringNumber (C./) Divide
131+ , binary moduloSemiringInt C.mod Modulus
127
132
128 , binary eqNumber (C.==) EqualTo
133 , binary eqNumber (C.==) EqualTo
129 , binary eqNumber (C./=) NotEqualTo
134 , binary eqNumber (C./=) NotEqualTo