Some more progress with pas2c
authorunc0rr
Fri, 20 Apr 2012 01:50:47 +0400
changeset 6894 555a8d8db228
parent 6893 69cc0166be8d
child 6895 31def088a870
Some more progress with pas2c
hedgewars/pas2c.h
hedgewars/pas2cSystem.pas
hedgewars/uAIAmmoTests.pas
hedgewars/uUtils.pas
hedgewars/uVariables.pas
tools/pas2c.hs
--- a/hedgewars/pas2c.h	Thu Apr 19 23:36:20 2012 +0400
+++ b/hedgewars/pas2c.h	Fri Apr 20 01:50:47 2012 +0400
@@ -38,3 +38,11 @@
 typedef LongInt * PLongInt;
 typedef Integer * PInteger;
 
+#define new(a) __new(a, sizeof(*(a)))
+void __new(pointer p);
+
+#define FillChar(a, b, c) __FillChar(&(a), b, c)
+
+void __FillChar(pointer p, int size, char fill);
+string255 _strconcat(string255 a, string255 b);
+
--- a/hedgewars/pas2cSystem.pas	Thu Apr 19 23:36:20 2012 +0400
+++ b/hedgewars/pas2cSystem.pas	Fri Apr 20 01:50:47 2012 +0400
@@ -139,3 +139,5 @@
     png_create_info_struct, png_destroy_write_struct,
     png_write_row, png_set_ihdr, png_write_info,
     png_write_end : procedure;
+
+    EnumToStr : function : string;
--- a/hedgewars/uAIAmmoTests.pas	Thu Apr 19 23:36:20 2012 +0400
+++ b/hedgewars/uAIAmmoTests.pas	Fri Apr 20 01:50:47 2012 +0400
@@ -166,7 +166,7 @@
             value:= - Metric(Targ.X, Targ.Y, EX, EY) div 64;
         if valueResult <= value then
             begin
-            ap.Angle:= DxDy2AttackAngle(Vx, Vy) + AIrndSign(random((Level - 1) * 9));
+            ap.Angle:= DxDy2AttackAnglef(Vx, Vy) + AIrndSign(random((Level - 1) * 9));
             ap.Power:= trunc(sqrt(r) * cMaxPower) - random((Level - 1) * 17 + 1);
             ap.ExplR:= 100;
             ap.ExplX:= EX;
@@ -223,7 +223,7 @@
 
         if valueResult <= value then
             begin
-            ap.Angle:= DxDy2AttackAngle(Vx, Vy) + AIrndSign(random((Level - 1) * 9));
+            ap.Angle:= DxDy2AttackAnglef(Vx, Vy) + AIrndSign(random((Level - 1) * 9));
             ap.Power:= trunc(sqrt(r) * cMaxPower) - random((Level - 1) * 17 + 1);
             ap.ExplR:= 0;
             ap.ExplX:= EX;
@@ -273,7 +273,7 @@
                   
         if valueResult < Score then
             begin
-            ap.Angle:= DxDy2AttackAngle(Vx, Vy) + AIrndSign(random(Level));
+            ap.Angle:= DxDy2AttackAnglef(Vx, Vy) + AIrndSign(random(Level));
             ap.Power:= trunc(sqrt(r) * cMaxPower) + AIrndSign(random(Level) * 15);
             ap.Time:= TestTime;
             ap.ExplR:= 100;
@@ -327,7 +327,7 @@
 
     if valueResult < Score then
         begin
-        ap.Angle:= DxDy2AttackAngle(Vx, Vy) + AIrndSign(random(Level));
+        ap.Angle:= DxDy2AttackAnglef(Vx, Vy) + AIrndSign(random(Level));
         ap.Power:= trunc(sqrt(r) * cMaxPower) + AIrndSign(random(Level) * 15);
         ap.Time:= TestTime;
         ap.ExplR:= 100;
@@ -384,7 +384,7 @@
 
      if valueResult < Score then
         begin
-        ap.Angle:= DxDy2AttackAngle(Vx, Vy) + AIrndSign(random(Level));
+        ap.Angle:= DxDy2AttackAnglef(Vx, Vy) + AIrndSign(random(Level));
         ap.Power:= trunc(sqrt(r) * cMaxPower * 0.9) + AIrndSign(random(Level) * 15);
         ap.Time:= TestTime;
         ap.ExplR:= 90;
@@ -436,7 +436,7 @@
         
     if valueResult < Score then
         begin
-        ap.Angle:= DxDy2AttackAngle(Vx, Vy) + AIrndSign(random(Level));
+        ap.Angle:= DxDy2AttackAnglef(Vx, Vy) + AIrndSign(random(Level));
         ap.Power:= trunc(sqrt(r) * cMaxPower * 0.9) + AIrndSign(random(Level) * 15);
         ap.Time:= TestTime;
         ap.ExplR:= 300;
@@ -522,7 +522,7 @@
 
     if valueResult < Score then
         begin
-        ap.Angle:= DxDy2AttackAngle(Vx, Vy) + AIrndSign(random(Level));
+        ap.Angle:= DxDy2AttackAnglef(Vx, Vy) + AIrndSign(random(Level));
         ap.Power:= 1;
         ap.ExplR:= 100;
         ap.ExplX:= EX;
@@ -551,7 +551,7 @@
     exit(BadTurn);
 Vx:= (Targ.X - x) * 1 / 1024;
 Vy:= (Targ.Y - y) * 1 / 1024;
-ap.Angle:= DxDy2AttackAngle(Vx, -Vy);
+ap.Angle:= DxDy2AttackAnglef(Vx, -Vy);
 repeat
     x:= x + vX;
     y:= y + vY;
@@ -595,7 +595,7 @@
 t:= 0.5 / sqrt(sqr(Targ.X - x)+sqr(Targ.Y-y));
 Vx:= (Targ.X - x) * t;
 Vy:= (Targ.Y - y) * t;
-ap.Angle:= DxDy2AttackAngle(Vx, -Vy);
+ap.Angle:= DxDy2AttackAnglef(Vx, -Vy);
 d:= 0;
 
 repeat
--- a/hedgewars/uUtils.pas	Thu Apr 19 23:36:20 2012 +0400
+++ b/hedgewars/uUtils.pas	Fri Apr 20 01:50:47 2012 +0400
@@ -26,12 +26,14 @@
 procedure SplitBySpace(var a, b: shortstring);
 procedure SplitByChar(var a, b: ansistring; c: char);
 
+{$IFNDEF PAS2C}
 function  EnumToStr(const en : TGearType) : shortstring; overload;
 function  EnumToStr(const en : TVisualGearType) : shortstring; overload;
 function  EnumToStr(const en : TSound) : shortstring; overload;
 function  EnumToStr(const en : TAmmoType) : shortstring; overload;
 function  EnumToStr(const en : THogEffect) : shortstring; overload;
 function  EnumToStr(const en : TCapGroup) : shortstring; overload;
+{$ENDIF}
 
 function  Min(a, b: LongInt): LongInt; inline;
 function  Max(a, b: LongInt): LongInt; inline;
@@ -42,7 +44,7 @@
 function  DxDy2Angle(const _dY, _dX: hwFloat): GLfloat;
 function  DxDy2Angle32(const _dY, _dX: hwFloat): LongInt;
 function  DxDy2AttackAngle(const _dY, _dX: hwFloat): LongInt;
-function  DxDy2AttackAngle(const _dY, _dX: extended): LongInt;
+function  DxDy2AttackAnglef(const _dY, _dX: extended): LongInt;
 
 procedure SetLittle(var r: hwFloat);
 
@@ -102,6 +104,7 @@
     end else b:= '';
 end;
 
+{$IFNDEF PAS2C}
 function EnumToStr(const en : TGearType) : shortstring; overload;
 begin
 EnumToStr:= GetEnumName(TypeInfo(TGearType), ord(en))
@@ -130,7 +133,7 @@
 begin
 EnumToStr := GetEnumName(TypeInfo(TCapGroup), ord(en))
 end;
-
+{$ENDIF}
 
 function Min(a, b: LongInt): LongInt;
 begin
@@ -198,9 +201,9 @@
 DxDy2AttackAngle:= trunc(arctan2(dY, dX) * MaxAngleDivPI)
 end;
 
-function DxDy2AttackAngle(const _dY, _dX: extended): LongInt; inline;
+function DxDy2AttackAnglef(const _dY, _dX: extended): LongInt; inline;
 begin
-DxDy2AttackAngle:= trunc(arctan2(_dY, _dX) * (cMaxAngle/pi))
+DxDy2AttackAnglef:= trunc(arctan2(_dY, _dX) * (cMaxAngle/pi))
 end;
 
 
--- a/hedgewars/uVariables.pas	Thu Apr 19 23:36:20 2012 +0400
+++ b/hedgewars/uVariables.pas	Fri Apr 20 01:50:47 2012 +0400
@@ -1120,7 +1120,7 @@
                 Bounciness: 1000);
             Slot: 3;
             TimeAfterTurn: 3000;
-            MinAngle: 0;
+            minAngle: 0;
             maxAngle: 0;
             isDamaging: true;
             SkipTurns: 0;
@@ -1144,7 +1144,7 @@
                 Bounciness: 1000);
             Slot: 3;
             TimeAfterTurn: 3000;
-            MinAngle: 0;
+            minAngle: 0;
             maxAngle: 0;
             isDamaging: true;
             SkipTurns: 0;
@@ -2062,7 +2062,7 @@
                 Bounciness: 1000);
             Slot: 3;
             TimeAfterTurn: 3000;
-            MinAngle: 0;
+            minAngle: 0;
             maxAngle: 0;
             isDamaging: true;
             SkipTurns: 0;
--- a/tools/pas2c.hs	Thu Apr 19 23:36:20 2012 +0400
+++ b/tools/pas2c.hs	Fri Apr 20 01:50:47 2012 +0400
@@ -439,15 +439,13 @@
             struct2C tvs = do
                 t <- withState' id $ mapM (tvar2C False) tvs
                 return $ text "struct" $+$ braces (nest 4 (vcat . map (<> semi) . concat $ t)) <> semi
-    type2C' (RangeType r) = return (text "<<range type>>" <+>)
+    type2C' (RangeType r) = return (text "int" <+>)
     type2C' (Sequence ids) = do
         is <- mapM (id2C IOInsert . setBaseType bt) ids
         return (text "enum" <+> (braces . vcat . punctuate comma . map (\(a, b) -> a <+> equals <+> text "0x" <> text (showHex b "")) $ zip is [1..]) <+>)
         where
             bt = BTEnum $ map (\(Identifier i _) -> map toLower i) ids
-    type2C' (ArrayDecl Nothing t) = do
-        t' <- type2C t
-        return $ \i -> t' i <> brackets empty
+    type2C' (ArrayDecl Nothing t) = type2C (PointerTo t)
     type2C' (ArrayDecl (Just r) t) = do
         t' <- type2C t
         r' <- initExpr2C (InitRange r)