# HG changeset patch # User unc0rr # Date 1336764875 -14400 # Node ID 7efe165757799d5c306025cb7fb5ae7448f20296 # Parent 4e0fc59ab1cec4566dabdf5ba2a37405ee354448 Recognize length on arrays as a separate function diff -r 4e0fc59ab1ce -r 7efe16575779 hedgewars/GSHandlers.inc --- a/hedgewars/GSHandlers.inc Fri May 11 23:22:01 2012 +0400 +++ b/hedgewars/GSHandlers.inc Fri May 11 23:34:35 2012 +0400 @@ -3030,7 +3030,7 @@ procedure doStepCakeWork(Gear: PGear); -const dirs: array[0..3] of TPoint = ((x: 0; y: -1), (x: 1; y: 0),(x: 0; y: 1),(x: -1; y: 0)); +const dirs: array[0..3] of TPoint = ((X: 0; Y: -1), (X: 1; Y: 0),(X: 0; Y: 1),(X: -1; Y: 0)); var xx, yy, xxn, yyn: LongInt; dA: LongInt; diff -r 4e0fc59ab1ce -r 7efe16575779 hedgewars/pas2c.h --- a/hedgewars/pas2c.h Fri May 11 23:22:01 2012 +0400 +++ b/hedgewars/pas2c.h Fri May 11 23:34:35 2012 +0400 @@ -87,6 +87,9 @@ #define STRINIT(a) {.len = sizeof(a) - 1, .str = a} + +int length_ar(void * a); + typedef int file; typedef int TextFile; extern int FileMode; @@ -131,3 +134,5 @@ #define val(a, b) _val(a, (LongInt*)&(b)) void _val(string255 str, LongInt * a); + +extern double pi; diff -r 4e0fc59ab1ce -r 7efe16575779 hedgewars/pas2cSystem.pas --- a/hedgewars/pas2cSystem.pas Fri May 11 23:22:01 2012 +0400 +++ b/hedgewars/pas2cSystem.pas Fri May 11 23:34:35 2012 +0400 @@ -82,7 +82,8 @@ ParamCount : function : integer; ParamStr : function : string; - sqrt, arctan2, pi, cos, sin, power : function : float; + sqrt, arctan2, cos, sin, power : function : float; + pi : float; TypeInfo, GetEnumName : function : shortstring; diff -r 4e0fc59ab1ce -r 7efe16575779 tools/PascalBasics.hs --- a/tools/PascalBasics.hs Fri May 11 23:22:01 2012 +0400 +++ b/tools/PascalBasics.hs Fri May 11 23:34:35 2012 +0400 @@ -8,7 +8,7 @@ import Text.Parsec.Language import Data.Char -builtin = ["succ", "pred", "low", "high", "ord", "inc", "dec", "exit", "break", "continue"] +builtin = ["succ", "pred", "low", "high", "ord", "inc", "dec", "exit", "break", "continue", "length"] pascalLanguageDef = emptyDef diff -r 4e0fc59ab1ce -r 7efe16575779 tools/pas2c.hs --- a/tools/pas2c.hs Fri May 11 23:22:01 2012 +0400 +++ b/tools/pas2c.hs Fri May 11 23:34:35 2012 +0400 @@ -747,6 +747,13 @@ 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" _))) = liftM (<> text " - 1") $ expr2C e +expr2C (BuiltInFunCall [e] (SimpleReference (Identifier "length" _))) = do + e' <- expr2C e + lt <- gets lastType + case lt of + BTString -> return $ text "length" <> parens e' + BTArray {} -> return $ text "length_ar" <> parens e' + _ -> error $ "length() called on " ++ show lt expr2C (BuiltInFunCall params ref) = do r <- ref2C ref t <- gets lastType