pas2c stuff again
authorunc0rr
Sat, 12 May 2012 23:55:09 +0400
changeset 7069 bcf9d8e64e92
parent 7068 b1b7eb9c8cc9
child 7070 8d4189609e90
pas2c stuff again
hedgewars/pas2c.h
hedgewars/pas2cSystem.pas
hedgewars/uGearsHedgehog.pas
hedgewars/uGearsList.pas
hedgewars/uLandObjects.pas
hedgewars/uLocale.pas
hedgewars/uRender.pas
hedgewars/uRenderUtils.pas
hedgewars/uWorld.pas
tools/PascalParser.hs
tools/pas2c.hs
--- a/hedgewars/pas2c.h	Sat May 12 22:50:33 2012 +0400
+++ b/hedgewars/pas2c.h	Sat May 12 23:55:09 2012 +0400
@@ -84,6 +84,7 @@
 int Length(string255 a);
 string255 copy(string255 a, int s, int l);
 string255 delete(string255 a, int s, int l);
+string255 trim(string255 a);
 
 #define STRINIT(a) {.len = sizeof(a) - 1, .str = a}
 
@@ -97,7 +98,8 @@
 
 #define assign(a, b) assign_(&(a), b)
 void assign_(int * f, string255 fileName);
-void reset(int f, int size);
+void reset_1(int f, int size);
+void reset_2(int f, int size);
 #define BlockRead(a, b, c, d) BlockRead_(a, &(b), c, &(d))
 void BlockRead_(int f, void * p, int size, int * sizeRead);
 #define BlockWrite(a, b, c) BlockWrite_(a, &(b), c)
@@ -136,3 +138,6 @@
 void _val(string255 str, LongInt * a);
 
 extern double pi;
+
+string255 EnumToStr(int a);
+string255 ExtractFileName(string255 f);
--- a/hedgewars/pas2cSystem.pas	Sat May 12 22:50:33 2012 +0400
+++ b/hedgewars/pas2cSystem.pas	Sat May 12 23:55:09 2012 +0400
@@ -24,7 +24,6 @@
     real = float;
     extended = float;
     GLfloat = float;
-    gl_float = float;
 
     boolean = boolean;
     LongBool = boolean;
@@ -123,7 +122,7 @@
     GL_TEXTURE_WRAP_T, GL_TRIANGLE_FAN, GL_TRUE, GL_VENDOR,
     GL_VERSION, GL_VERTEX_ARRAY, GLenum,  GL_FRAMEBUFFER_EXT,
     GL_RENDERBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT,
-    GL_COLOR_ATTACHMENT0_EXT : integer;
+    GL_COLOR_ATTACHMENT0_EXT, GL_FLOAT, GL_UNSIGNED_BYTE : integer;
 
     TThreadId : function : integer;
     BeginThread, ThreadSwitch : procedure;
--- a/hedgewars/uGearsHedgehog.pas	Sat May 12 22:50:33 2012 +0400
+++ b/hedgewars/uGearsHedgehog.pas	Sat May 12 23:55:09 2012 +0400
@@ -140,23 +140,23 @@
         color:= Gear^.Hedgehog^.Team^.Clan^.Color;
         case Gear^.MsgParam of
             1: begin
-               AddCaption(format(trmsg[sidBounce], trmsg[sidBounce1]), color, capgrpAmmostate);
+               AddCaption(FormatA(trmsg[sidBounce], trmsg[sidBounce1]), color, capgrpAmmostate);
                CurWeapon^.Bounciness:= 350;
                end;
             2: begin
-               AddCaption(format(trmsg[sidBounce], trmsg[sidBounce2]), color, capgrpAmmostate);
+               AddCaption(FormatA(trmsg[sidBounce], trmsg[sidBounce2]), color, capgrpAmmostate);
                CurWeapon^.Bounciness:= 700;
                end;
             3: begin
-               AddCaption(format(trmsg[sidBounce], trmsg[sidBounce3]), color, capgrpAmmostate);
+               AddCaption(FormatA(trmsg[sidBounce], trmsg[sidBounce3]), color, capgrpAmmostate);
                CurWeapon^.Bounciness:= 1000;
                end;
             4: begin
-               AddCaption(format(trmsg[sidBounce], trmsg[sidBounce4]), color, capgrpAmmostate);
+               AddCaption(FormatA(trmsg[sidBounce], trmsg[sidBounce4]), color, capgrpAmmostate);
                CurWeapon^.Bounciness:= 2000;
                end;
             5: begin
-               AddCaption(format(trmsg[sidBounce], trmsg[sidBounce5]), color, capgrpAmmostate);
+               AddCaption(FormatA(trmsg[sidBounce], trmsg[sidBounce5]), color, capgrpAmmostate);
                CurWeapon^.Bounciness:= 4000;
                end
             end
--- a/hedgewars/uGearsList.pas	Sat May 12 22:50:33 2012 +0400
+++ b/hedgewars/uGearsList.pas	Sat May 12 23:55:09 2012 +0400
@@ -170,7 +170,7 @@
                     begin
                     Pos:= 0;
                     Radius:= 1;
-                    DirAngle:= random * 360;
+                    DirAngle:= random(360);
                     if State and gstTmpFlag = 0 then
                         begin
                         dx.isNegative:= GetRandom(2) = 0;
--- a/hedgewars/uLandObjects.pas	Sat May 12 22:50:33 2012 +0400
+++ b/hedgewars/uLandObjects.pas	Sat May 12 23:55:09 2012 +0400
@@ -803,17 +803,17 @@
 end;
 
 procedure AddObjects();
-var i, int: Longword;
+var i, g: Longword;
 begin
 InitRects;
 if hasGirders then
     begin
-    int:= max(playWidth div 8, 256);
-    i:=leftX+int;
+    g:= max(playWidth div 8, 256);
+    i:= leftX + g;
     repeat
         AddGirder(i);
-        i:=i+int;
-    until (i>rightX-int);
+        i:=i + g;
+    until (i > rightX - g);
     end;
 if (GameFlags and gfDisableLandObjects) = 0 then
     AddThemeObjects(ThemeObjects);
--- a/hedgewars/uLocale.pas	Sat May 12 22:50:33 2012 +0400
+++ b/hedgewars/uLocale.pas	Sat May 12 23:55:09 2012 +0400
@@ -26,7 +26,7 @@
 
 procedure LoadLocale(FileName: shortstring);
 function  Format(fmt: shortstring; var arg: shortstring): shortstring;
-function  Format(fmt: ansistring; var arg: ansistring): ansistring;
+function  FormatA(fmt: ansistring; var arg: ansistring): ansistring;
 function  GetEventString(e: TEventId): ansistring;
 
 {$IFDEF HWLIBRARY}
@@ -122,14 +122,14 @@
     Format:= copy(fmt, 1, i - 1) + arg + Format(copy(fmt, i + 2, Length(fmt) - i - 1), arg)
 end;
 
-function Format(fmt: ansistring; var arg: ansistring): ansistring;
+function FormatA(fmt: ansistring; var arg: ansistring): ansistring;
 var i: LongInt;
 begin
 i:= Pos('%1', fmt);
 if i = 0 then
-    Format:= fmt
+    FormatA:= fmt
 else
-    Format:= copy(fmt, 1, i - 1) + arg + Format(copy(fmt, i + 2, Length(fmt) - i - 1), arg)
+    FormatA:= copy(fmt, 1, i - 1) + arg + FormatA(copy(fmt, i + 2, Length(fmt) - i - 1), arg)
 end;
 
 {$IFDEF HWLIBRARY}
--- a/hedgewars/uRender.pas	Sat May 12 22:50:33 2012 +0400
+++ b/hedgewars/uRender.pas	Sat May 12 23:55:09 2012 +0400
@@ -408,10 +408,10 @@
 
 procedure DrawHedgehog(X, Y: LongInt; Dir: LongInt; Pos, Step: LongWord; Angle: real);
 const VertexBuffer: array [0..3] of TVertex2f = (
-        (x: -16; y: -16),
-        (x:  16; y: -16),
-        (x:  16; y:  16),
-        (x: -16; y:  16));
+        (X: -16; Y: -16),
+        (X:  16; Y: -16),
+        (X:  16; Y:  16),
+        (X: -16; Y:  16));
 var l, r, t, b: real;
     TextureBuffer: array [0..3] of TVertex2f;
 begin
--- a/hedgewars/uRenderUtils.pas	Sat May 12 22:50:33 2012 +0400
+++ b/hedgewars/uRenderUtils.pas	Sat May 12 23:55:09 2012 +0400
@@ -257,7 +257,7 @@
 var w, h: LongInt;
     finalSurface: PSDL_Surface;
 begin
-    if length(s) = 0 then s:= ' ';
+    if length(s) = 0 then s:= _S' ';
     font:= CheckCJKFont(s, font);
     w:= 0; h:= 0; // avoid compiler hints
     TTF_SizeUTF8(Fontz[font].Handle, Str2PChar(s), @w, @h);
--- a/hedgewars/uWorld.pas	Sat May 12 22:50:33 2012 +0400
+++ b/hedgewars/uWorld.pas	Sat May 12 23:55:09 2012 +0400
@@ -96,7 +96,7 @@
     if (GameFlags and gf) <> 0 then
         begin
         t:= inttostr(i);
-        s:= s + format(trgoal[si], t) + '|'
+        s:= s + FormatA(trgoal[si], t) + '|'
         end;
     AddGoal:= s;
 end;
--- a/tools/PascalParser.hs	Sat May 12 22:50:33 2012 +0400
+++ b/tools/PascalParser.hs	Sat May 12 23:55:09 2012 +0400
@@ -382,7 +382,6 @@
            , Infix (try (string ">=") >> return (BinOp ">=")) AssocNone
            , Infix (char '<' >> return (BinOp "<")) AssocNone
            , Infix (char '>' >> return (BinOp ">")) AssocNone
-           , Infix (char '=' >> return (BinOp "=")) AssocNone
           ]
         , [  Infix (try $ string "shl" >> return (BinOp "shl")) AssocNone
            , Infix (try $ string "shr" >> return (BinOp "shr")) AssocNone
@@ -391,6 +390,9 @@
            , Infix (try $ string "or" >> return (BinOp "or")) AssocLeft
            , Infix (try $ string "xor" >> return (BinOp "xor")) AssocLeft
           ]
+        , [
+             Infix (char '=' >> return (BinOp "=")) AssocNone
+          ]
         ]
     strOrChar [a] = CharCode . show . ord $ a
     strOrChar a = StringLiteral a    
--- a/tools/pas2c.hs	Sat May 12 22:50:33 2012 +0400
+++ b/tools/pas2c.hs	Sat May 12 23:55:09 2012 +0400
@@ -127,7 +127,11 @@
     where
     toNamespace :: Map.Map String Records -> PascalUnit -> Records
     toNamespace nss (System tvs) = 
-        currentScope $ execState (mapM_ (tvar2C True) tvs) (emptyState nss)
+        currentScope $ execState f (emptyState nss)
+        where
+        f = do
+            checkDuplicateFunDecls tvs
+            mapM_ (tvar2C True) tvs                
     toNamespace _ (Program {}) = Map.empty
     toNamespace nss (Unit (Identifier i _) interface _ _ _) = 
         currentScope $ execState (interface2C interface) (emptyState nss){currentUnit = map toLower i ++ "_"}
@@ -208,8 +212,10 @@
 
 checkDuplicateFunDecls :: [TypeVarDeclaration] -> State RenderState ()
 checkDuplicateFunDecls tvs =
-    modify $ \s -> s{toMangle = Map.keysSet . Map.filter (> 1) . foldr ins Map.empty $ tvs}
+    modify $ \s -> s{toMangle = Map.keysSet . Map.filter (> 1) . foldr ins initMap $ tvs}
     where
+        initMap = Map.empty
+        --initMap = Map.fromList [("reset", 2)]
         ins (FunctionDeclaration (Identifier i _) _ _ _) m = Map.insertWith (+) (map toLower i) 1 m
         ins _ m = m
 
@@ -766,8 +772,9 @@
 expr2C (BuiltInFunCall [e] (SimpleReference (Identifier "length" _))) = do
     e' <- expr2C e
     lt <- gets lastType
+    modify (\s -> s{lastType = BTInt})
     case lt of
-         BTString -> return $ text "length" <> parens e'
+         BTString -> return $ text "Length" <> parens e'
          BTArray {} -> return $ text "length_ar" <> parens e'
          _ -> error $ "length() called on " ++ show lt
 expr2C (BuiltInFunCall params ref) = do