# HG changeset patch # User alfadur # Date 1663732531 -10800 # Node ID c09063ea0267b1a016a3a682f6d8cb39c3f7300d # Parent 9cd8d7748199d732cf7e5b0b245f1159bc86f0ea fix the other 2 pred/succ conversions diff -r 9cd8d7748199 -r c09063ea0267 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 @@ -1094,10 +1096,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