tools/pas2c.hs
changeset 7036 d99934a827f0
parent 7034 e3639ce1d4f8
child 7037 7edce323558f
equal deleted inserted replaced
7035:823caba67738 7036:d99934a827f0
   683     modify(\s -> s{lastType = BTChar})
   683     modify(\s -> s{lastType = BTChar})
   684     return $ quotes $ text "\\x" <> text (showHex (read a) "")
   684     return $ quotes $ text "\\x" <> text (showHex (read a) "")
   685 expr2C (HexCharCode a) = return $ quotes $ text "\\x" <> text (map toLower a)
   685 expr2C (HexCharCode a) = return $ quotes $ text "\\x" <> text (map toLower a)
   686 expr2C (SetExpression ids) = mapM (id2C IOLookup) ids >>= return . parens . hcat . punctuate (text " | ")
   686 expr2C (SetExpression ids) = mapM (id2C IOLookup) ids >>= return . parens . hcat . punctuate (text " | ")
   687 
   687 
       
   688 expr2C (BuiltInFunCall [e] (SimpleReference (Identifier "low" _))) = do
       
   689     e' <- liftM (map toLower . render) $ expr2C e
       
   690     lt <- gets lastType
       
   691     case lt of
       
   692          BTEnum a -> return $ int 0
       
   693          BTInt -> case e' of
       
   694                   "longint" -> return $ int (-2147483648)
       
   695          BTArray {} -> return $ int 0
       
   696          _ -> error $ "BuiltInFunCall 'low' from " ++ show e ++ "\ntype: " ++ show lt
       
   697 expr2C (BuiltInFunCall [e] (SimpleReference (Identifier "high" _))) = do
       
   698     e' <- liftM (map toLower . render) $ expr2C e
       
   699     lt <- gets lastType
       
   700     case lt of
       
   701          BTEnum a -> return . int $ length a - 1
       
   702          BTInt -> case e' of
       
   703                   "longint" -> return $ int (2147483647)
       
   704          BTString -> return $ int 255
       
   705          BTArray (RangeFromTo _ n) _ _ -> initExpr2C n
       
   706          _ -> error $ "BuiltInFunCall 'high' from " ++ show e ++ "\ntype: " ++ show lt
   688 expr2C (BuiltInFunCall [e] (SimpleReference (Identifier "ord" _))) = liftM parens $ expr2C e
   707 expr2C (BuiltInFunCall [e] (SimpleReference (Identifier "ord" _))) = liftM parens $ expr2C e
   689 expr2C (BuiltInFunCall [e] (SimpleReference (Identifier "succ" _))) = liftM (<> text " + 1") $ expr2C e
   708 expr2C (BuiltInFunCall [e] (SimpleReference (Identifier "succ" _))) = liftM (<> text " + 1") $ expr2C e
   690 expr2C (BuiltInFunCall [e] (SimpleReference (Identifier "pred" _))) = liftM (<> text " - 1") $ expr2C e
   709 expr2C (BuiltInFunCall [e] (SimpleReference (Identifier "pred" _))) = liftM (<> text " - 1") $ expr2C e
   691 expr2C (BuiltInFunCall params ref) = do
   710 expr2C (BuiltInFunCall params ref) = do
   692     r <- ref2C ref 
   711     r <- ref2C ref