# HG changeset patch # User unc0rr # Date 1323341050 -14400 # Node ID 6fecdc5d182f15a7c6c748ed793b1401daa836c7 # Parent b0dc69bb1f54f68ed4675f9ebbb2e531a0956e7d Some more work on scopes diff -r b0dc69bb1f54 -r 6fecdc5d182f hedgewars/pas2cSystem.pas --- a/hedgewars/pas2cSystem.pas Wed Dec 07 19:38:33 2011 -0500 +++ b/hedgewars/pas2cSystem.pas Thu Dec 08 14:44:10 2011 +0400 @@ -5,6 +5,11 @@ LongWord = integer; Cardinal = integer; PtrInt = integer; + Word = integer; + Integer = integer; + Byte = integer; + SmallInt = integer; + ShortInt = integer; pointer = pointer; PChar = pointer; @@ -21,7 +26,16 @@ ansistring = string; char = char; + + PByte = ^Byte; + PLongInt = ^LongInt; + PLongWord = ^LongWord; + PInteger = ^Integer; var false, true: boolean; - write, writeln, read, readln: procedure; - strlen : function : integer; + write, writeLn, read, readLn, inc, dec: procedure; + StrLen, ord, Succ, Pred : function : integer; + Low, High : function : integer; + Now : function : integer; + SysUtils.StrPas, FormatDateTime : function : shortstring; + exit : procedure; diff -r b0dc69bb1f54 -r 6fecdc5d182f tools/PascalBasics.hs --- a/tools/PascalBasics.hs Wed Dec 07 19:38:33 2011 -0500 +++ b/tools/PascalBasics.hs Thu Dec 08 14:44:10 2011 +0400 @@ -26,7 +26,7 @@ , "procedure", "function", "with", "for", "to" , "downto", "div", "mod", "record", "set", "nil" , "cdecl", "external", "if", "then", "else" - ] ++ builtin + ] -- ++ builtin , reservedOpNames= [] , caseSensitive = False } diff -r b0dc69bb1f54 -r 6fecdc5d182f tools/pas2c.hs --- a/tools/pas2c.hs Wed Dec 07 19:38:33 2011 -0500 +++ b/tools/pas2c.hs Thu Dec 08 14:44:10 2011 +0400 @@ -72,10 +72,12 @@ extractTVs (Unit _ (Interface _ (TypesAndVars tv)) _ _ _) = tv tv2id :: TypeVarDeclaration -> [(String, String)] + tv2id (TypeDeclaration i (Sequence ids)) = map (\(Identifier i _) -> fi i) $ i : ids tv2id (TypeDeclaration (Identifier i _) _) = [(map toLower i, i)] - tv2id (VarDeclaration _ (ids, _) _) = map (\(Identifier i _) -> (map toLower i, i)) ids - tv2id (FunctionDeclaration (Identifier i _) _ _ _) = [(map toLower i, i)] - tv2id (OperatorDeclaration i _ _ _ _) = [(map toLower i, i)] + tv2id (VarDeclaration _ (ids, _) _) = map (\(Identifier i _) -> fi i) ids + tv2id (FunctionDeclaration (Identifier i _) _ _ _) = [fi i] + tv2id (OperatorDeclaration i _ _ _ _) = [fi i] + fi i = (map toLower i, i) toCFiles :: Map.Map String [(String, String)] -> (String, PascalUnit) -> IO () @@ -214,12 +216,15 @@ type2C UnknownType = return $ text "void" type2C (String l) = return $ text $ "string" ++ show l type2C (SimpleType i) = id2C False i +type2C (PointerTo (SimpleType i)) = liftM (<> text "*") $ id2C True i type2C (PointerTo t) = liftM (<> text "*") $ type2C t type2C (RecordType tvs union) = do t <- mapM (tvar2C False) tvs return $ text "{" $+$ (nest 4 . vcat $ t) $+$ text "}" type2C (RangeType r) = return $ text "<>" -type2C (Sequence ids) = return $ text "<>" +type2C (Sequence ids) = do + mapM_ (id2C True) ids + return $ text "<>" type2C (ArrayDecl r t) = return $ text "<>" type2C (Set t) = return $ text "<>" type2C (FunctionType returnType params) = return $ text "<>"