Skip to content

Commit e36bfea

Browse files
committed
Update rule for %
1 parent bbf00f2 commit e36bfea

File tree

1 file changed

+4
-5
lines changed
  • src/Language/PureScript/CodeGen/JS/Optimizer

1 file changed

+4
-5
lines changed

src/Language/PureScript/CodeGen/JS/Optimizer/Inliner.hs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ inlineValues = everywhereOnJS convert
8686
convert :: JS -> JS
8787
convert (JSApp fn [dict]) | isPreludeDict C.semiringNumber dict && isPreludeFn C.zero fn = JSNumericLiteral (Left 0)
8888
convert (JSApp fn [dict]) | isPreludeDict C.semiringNumber dict && isPreludeFn C.one fn = JSNumericLiteral (Left 1)
89+
convert (JSApp (JSApp fn [x]) [y]) | isPreludeFn (C.%) fn = JSBinary Modulus x y
8990
convert other = other
9091

9192
inlineOperator :: (String, String) -> (JS -> JS -> JS) -> JS -> JS
@@ -105,7 +106,6 @@ inlineCommonOperators = applyAll $
105106
, binary C.ringNumber (C.-) Subtract
106107
, unary C.ringNumber C.negate Negate
107108
, binary C.moduloRingNumber (C./) Divide
108-
--, binary C.numNumber (C.%) Modulus
109109

110110
, binary C.ordNumber (C.<) LessThan
111111
, binary C.ordNumber (C.>) GreaterThan
@@ -140,11 +140,8 @@ inlineCommonOperators = applyAll $
140140
binary dictName opString op = everywhereOnJS convert
141141
where
142142
convert :: JS -> JS
143-
convert (JSApp (JSApp (JSApp fn [dict]) [x]) [y]) | isOp fn && isPreludeDict dictName dict = JSBinary op x y
143+
convert (JSApp (JSApp (JSApp fn [dict]) [x]) [y]) | isPreludeDict dictName dict && isPreludeFn opString fn = JSBinary op x y
144144
convert other = other
145-
isOp (JSAccessor longForm (JSAccessor prelude (JSVar _))) = prelude == C.prelude && longForm == identToJs (Op opString)
146-
isOp (JSIndexer (JSStringLiteral op') (JSVar prelude)) = prelude == C.prelude && opString == op'
147-
isOp _ = False
148145
binaryFunction :: String -> String -> BinaryOperator -> JS -> JS
149146
binaryFunction dictName fnName op = everywhereOnJS convert
150147
where
@@ -199,4 +196,6 @@ isPreludeDict _ _ = False
199196

200197
isPreludeFn :: String -> JS -> Bool
201198
isPreludeFn fnName (JSAccessor fnName' (JSVar prelude)) = prelude == C.prelude && fnName' == fnName
199+
isPreludeFn fnName (JSIndexer (JSStringLiteral fnName') (JSVar prelude)) = prelude == C.prelude && fnName' == fnName
200+
isPreludeFn fnName (JSAccessor longForm (JSAccessor prelude (JSVar _))) = prelude == C.prelude && longForm == identToJs (Op fnName)
202201
isPreludeFn _ _ = False

0 commit comments

Comments
 (0)