# HG changeset patch # User alfadur # Date 1663732531 -10800 # Node ID fac577eb8756fe3f3ab074177fad47575cef3838 # Parent f8a3f204242dfc671f0c79e5be09df5733340e96 fix the other 2 pred/succ conversions diff -r f8a3f204242d -r fac577eb8756 tools/pas2c/Pas2C.hs --- a/tools/pas2c/Pas2C.hs Wed Sep 21 06:36:05 2022 +0300 +++ b/tools/pas2c/Pas2C.hs Wed Sep 21 06:55:31 2022 +0300 @@ -711,8 +711,10 @@ a -> error $ "BuiltInFunction 'high' in initExpr: " ++ show a ++ ": " ++ show hi initExpr2C' (BuiltInFunction "succ" [BuiltInFunction "pred" [e]]) = initExpr2C' e initExpr2C' (BuiltInFunction "pred" [BuiltInFunction "succ" [e]]) = initExpr2C' e -initExpr2C' (BuiltInFunction "succ" [e]) = liftM (\e' -> text "(" <> e' <> text " + 1)") $ initExpr2C' e -initExpr2C' (BuiltInFunction "pred" [e]) = liftM (\e' -> text "(" <> e' <> text " - 1)") $ initExpr2C' e +initExpr2C' (BuiltInFunction "succ" [e]) = + liftM (parens . (<> text " + 1")) $ initExpr2C' e +initExpr2C' (BuiltInFunction "pred" [e]) = + liftM (parens . (<> text " - 1")) $ initExpr2C' e initExpr2C' b@(BuiltInFunction _ _) = error $ show b initExpr2C' (InitTypeCast t' i) = do e <- initExpr2C i @@ -1089,10 +1091,10 @@ BTArray (RangeFromTo _ n) _ _ -> initExpr2C n _ -> error $ "BuiltInFunCall 'high' from " ++ show e ++ "\ntype: " ++ show lt expr2C (BuiltInFunCall [e] (SimpleReference (Identifier "ord" _))) = liftM parens $ expr2C e -expr2C (BuiltInFunCall [e] (SimpleReference (Identifier "succ" _))) = liftM (<> text " + 1") $ expr2C e -expr2C (BuiltInFunCall [e] (SimpleReference (Identifier "pred" _))) = do - e'<- expr2C e - return $ text "(int)" <> parens e' <> text " - 1" +expr2C (BuiltInFunCall [e] (SimpleReference (Identifier "succ" _))) = + liftM (parens . (<> text " + 1")) $ expr2C e +expr2C (BuiltInFunCall [e] (SimpleReference (Identifier "pred" _))) = + liftM (parens . (<> text " - 1") . ((text "(int)") <>) . parens) $ expr2C e expr2C (BuiltInFunCall [e] (SimpleReference (Identifier "length" _))) = do e' <- expr2C e lt <- gets lastType