git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Merge pull request #811 from philopon/fix/#807

fixed #807

commit4d2c9cfbeefd28d2687dfd023f2c40f3305e8e7f authorPhil Freeman <paf31@cantab.net> dateTue 13 Jan 2015, 10:41 (12 years ago) parentf5b2d4ef4d7c2f
3 files changed+25−6
examples/passing/Operators.purs+12 src/Language/PureScript/Pretty/JS.hs+13−4 src/Language/PureScript/Sugar/Operators.hs−2
examples/passing/Operators.purs+12
@@ -64,6 +64,15 @@ module Main where
6464 test16 :: Number -> Number -> Number
6565 test16 x y = x .|. y .&. y
6666
67+ test17 :: Number
68+ test17 = negate (-1)
69+
70+ test18 :: Number
71+ test18 = negate $ negate 1
72+
73+ test19 :: Number
74+ test19 = negate $ negate (-1)
75+
6776 main = do
6877 let t1 = test1 1 2 (\x y -> x + y)
6978 let t2 = test2
@@ -81,4 +90,7 @@ module Main where
8190 let t14 = test14 1 2
8291 let t15 = test15 1 2
8392 let t16 = test16 1 2
93+ let t17 = test17
94+ let t18 = test18
95+ let t19 = test19
8496 trace "Done"
src/Language/PureScript/Pretty/JS.hs+13−4
@@ -209,15 +209,24 @@ instanceOf = mkPattern match
209209 match (JSInstanceOf val ty) = Just (val, ty)
210210 match _ = Nothing
211211
212−unary :: UnaryOperator -> String -> Operator PrinterState JS String
213−unary op str = Wrap match (++)
212+unary' :: UnaryOperator -> (JS -> String) -> Operator PrinterState JS String
213+unary' op mkStr = Wrap match (++)
214214 where
215215 match :: Pattern PrinterState JS (String, JS)
216216 match = mkPattern match'
217217 where
218− match' (JSUnary op' val) | op' == op = Just (str, val)
218+ match' (JSUnary op' val) | op' == op = Just (mkStr val, val)
219219 match' _ = Nothing
220220
221+unary :: UnaryOperator -> String -> Operator PrinterState JS String
222+unary op str = unary' op (const str)
223+
224+negateOperator :: Operator PrinterState JS String
225+negateOperator = unary' Negate (\v -> if isNegate v then "- " else "-")
226+ where
227+ isNegate (JSUnary Negate _) = True
228+ isNegate _ = False
229+
221230binary :: BinaryOperator -> String -> Operator PrinterState JS String
222231binary op str = AssocL match (\v1 v2 -> v1 ++ " " ++ str ++ " " ++ v2)
223232 where
@@ -271,7 +280,7 @@ prettyPrintJS' = A.runKleisli $ runPattern matchValue
271280 , [ AssocR instanceOf $ \v1 v2 -> v1 ++ " instanceof " ++ v2 ]
272281 , [ unary Not "!" ]
273282 , [ unary BitwiseNot "~" ]
274− , [ unary Negate "-" ]
283+ , [ negateOperator ]
275284 , [ unary Positive "+" ]
276285 , [ binary Multiply "*"
277286 , binary Divide "/"
src/Language/PureScript/Sugar/Operators.hs−2
@@ -58,8 +58,6 @@ removeSignedLiterals (Module mn ds exts) = Module mn (map f' ds) exts
5858 where
5959 (f', _, _) = everywhereOnValues id go id
6060
61− go (UnaryMinus (NumericLiteral (Left n))) = NumericLiteral (Left $ negate n)
62− go (UnaryMinus (NumericLiteral (Right n))) = NumericLiteral (Right $ negate n)
6361 go (UnaryMinus val) = App (Var (Qualified (Just (ModuleName [ProperName C.prelude])) (Ident C.negate))) val
6462 go other = other
6563