File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -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"
Original file line number Diff line number Diff line change @@ -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 " /"
Original file line number Diff line number Diff line change @@ -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
You can’t perform that action at this time.
0 commit comments