tools/pas2c/Pas2C.hs
changeset 15872 c09063ea0267
parent 15871 9cd8d7748199
child 15886 5e8d2a8eb473
equal deleted inserted replaced
15871:9cd8d7748199 15872:c09063ea0267
   709                   (Identifier "LongWord" _) -> return $ text "4294967295"
   709                   (Identifier "LongWord" _) -> return $ text "4294967295"
   710                   _ -> error $ "BuiltInFunction 'high' in initExpr: " ++ show e'
   710                   _ -> error $ "BuiltInFunction 'high' in initExpr: " ++ show e'
   711          a -> error $ "BuiltInFunction 'high' in initExpr: " ++ show a ++ ": " ++ show hi
   711          a -> error $ "BuiltInFunction 'high' in initExpr: " ++ show a ++ ": " ++ show hi
   712 initExpr2C' (BuiltInFunction "succ" [BuiltInFunction "pred" [e]]) = initExpr2C' e
   712 initExpr2C' (BuiltInFunction "succ" [BuiltInFunction "pred" [e]]) = initExpr2C' e
   713 initExpr2C' (BuiltInFunction "pred" [BuiltInFunction "succ" [e]]) = initExpr2C' e
   713 initExpr2C' (BuiltInFunction "pred" [BuiltInFunction "succ" [e]]) = initExpr2C' e
   714 initExpr2C' (BuiltInFunction "succ" [e]) = liftM (\e' ->  text "(" <> e' <> text " + 1)") $ initExpr2C' e
   714 initExpr2C' (BuiltInFunction "succ" [e]) = 
   715 initExpr2C' (BuiltInFunction "pred" [e]) = liftM (\e' ->  text "(" <> e' <> text " - 1)") $ initExpr2C' e
   715     liftM (parens . (<> text " + 1")) $ initExpr2C' e
       
   716 initExpr2C' (BuiltInFunction "pred" [e]) = 
       
   717     liftM (parens . (<> text " - 1")) $ initExpr2C' e
   716 initExpr2C' b@(BuiltInFunction _ _) = error $ show b
   718 initExpr2C' b@(BuiltInFunction _ _) = error $ show b
   717 initExpr2C' (InitTypeCast t' i) = do
   719 initExpr2C' (InitTypeCast t' i) = do
   718     e <- initExpr2C i
   720     e <- initExpr2C i
   719     t <- id2C IOLookup t'
   721     t <- id2C IOLookup t'
   720     return . parens $ parens t <> e
   722     return . parens $ parens t <> e
  1092                   "longint" -> return $ int (2147483647)
  1094                   "longint" -> return $ int (2147483647)
  1093          BTString -> return $ int 255
  1095          BTString -> return $ int 255
  1094          BTArray (RangeFromTo _ n) _ _ -> initExpr2C n
  1096          BTArray (RangeFromTo _ n) _ _ -> initExpr2C n
  1095          _ -> error $ "BuiltInFunCall 'high' from " ++ show e ++ "\ntype: " ++ show lt
  1097          _ -> error $ "BuiltInFunCall 'high' from " ++ show e ++ "\ntype: " ++ show lt
  1096 expr2C (BuiltInFunCall [e] (SimpleReference (Identifier "ord" _))) = liftM parens $ expr2C e
  1098 expr2C (BuiltInFunCall [e] (SimpleReference (Identifier "ord" _))) = liftM parens $ expr2C e
  1097 expr2C (BuiltInFunCall [e] (SimpleReference (Identifier "succ" _))) = liftM (<> text " + 1") $ expr2C e
  1099 expr2C (BuiltInFunCall [e] (SimpleReference (Identifier "succ" _))) = 
  1098 expr2C (BuiltInFunCall [e] (SimpleReference (Identifier "pred" _))) = do
  1100     liftM (parens . (<> text " + 1")) $ expr2C e
  1099     e'<- expr2C e
  1101 expr2C (BuiltInFunCall [e] (SimpleReference (Identifier "pred" _))) = 
  1100     return $ text "(int)" <> parens e' <> text " - 1"
  1102     liftM (parens . (<> text " - 1") . ((text "(int)") <>) . parens) $ expr2C e
  1101 expr2C (BuiltInFunCall [e] (SimpleReference (Identifier "length" _))) = do
  1103 expr2C (BuiltInFunCall [e] (SimpleReference (Identifier "length" _))) = do
  1102     e' <- expr2C e
  1104     e' <- expr2C e
  1103     lt <- gets lastType
  1105     lt <- gets lastType
  1104     modify (\s -> s{lastType = BTInt True})
  1106     modify (\s -> s{lastType = BTInt True})
  1105     case lt of
  1107     case lt of