tools/pas2c/Pas2C.hs
branch1.0.0
changeset 15896 fac577eb8756
parent 15895 f8a3f204242d
child 15912 5e8d2a8eb473
equal deleted inserted replaced
15895:f8a3f204242d 15896:fac577eb8756
   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
  1087                   "longint" -> return $ int (2147483647)
  1089                   "longint" -> return $ int (2147483647)
  1088          BTString -> return $ int 255
  1090          BTString -> return $ int 255
  1089          BTArray (RangeFromTo _ n) _ _ -> initExpr2C n
  1091          BTArray (RangeFromTo _ n) _ _ -> initExpr2C n
  1090          _ -> error $ "BuiltInFunCall 'high' from " ++ show e ++ "\ntype: " ++ show lt
  1092          _ -> error $ "BuiltInFunCall 'high' from " ++ show e ++ "\ntype: " ++ show lt
  1091 expr2C (BuiltInFunCall [e] (SimpleReference (Identifier "ord" _))) = liftM parens $ expr2C e
  1093 expr2C (BuiltInFunCall [e] (SimpleReference (Identifier "ord" _))) = liftM parens $ expr2C e
  1092 expr2C (BuiltInFunCall [e] (SimpleReference (Identifier "succ" _))) = liftM (<> text " + 1") $ expr2C e
  1094 expr2C (BuiltInFunCall [e] (SimpleReference (Identifier "succ" _))) = 
  1093 expr2C (BuiltInFunCall [e] (SimpleReference (Identifier "pred" _))) = do
  1095     liftM (parens . (<> text " + 1")) $ expr2C e
  1094     e'<- expr2C e
  1096 expr2C (BuiltInFunCall [e] (SimpleReference (Identifier "pred" _))) = 
  1095     return $ text "(int)" <> parens e' <> text " - 1"
  1097     liftM (parens . (<> text " - 1") . ((text "(int)") <>) . parens) $ expr2C e
  1096 expr2C (BuiltInFunCall [e] (SimpleReference (Identifier "length" _))) = do
  1098 expr2C (BuiltInFunCall [e] (SimpleReference (Identifier "length" _))) = do
  1097     e' <- expr2C e
  1099     e' <- expr2C e
  1098     lt <- gets lastType
  1100     lt <- gets lastType
  1099     modify (\s -> s{lastType = BTInt True})
  1101     modify (\s -> s{lastType = BTInt True})
  1100     case lt of
  1102     case lt of