# HG changeset patch # User unc0rr # Date 1336846436 -14400 # Node ID 12cc2bd84b0bc1b54ccc9be39be801396eee7988 # Parent e80e0d3273c59ef16cfa206ac4a4b66f1e6b32c4 Make pas2c even more happier with uGears.c, allow assigning arrays in some cases diff -r e80e0d3273c5 -r 12cc2bd84b0b hedgewars/GSHandlers.inc --- a/hedgewars/GSHandlers.inc Sat May 12 00:25:49 2012 +0400 +++ b/hedgewars/GSHandlers.inc Sat May 12 22:13:56 2012 +0400 @@ -466,7 +466,7 @@ begin Frame:= 2; Tint:= $41B83ED0 - i * $10081000; - Angle:= random * 360; + Angle:= random(360); dx:= 0.0000001; dy:= 0; if random(2) = 0 then @@ -1090,7 +1090,7 @@ begin cLaserSighting := true; HHGear^.Message := 0; - if (HHGear^.Angle - 32 >= 0) then + if (HHGear^.Angle >= 32) then dec(HHGear^.Angle,32) end; @@ -1120,7 +1120,7 @@ inc(HHGear^.Angle) end else - if (HHGear^.Angle - 1 >= 0) then + if (HHGear^.Angle >= 1) then dec(HHGear^.Angle); if (TurnTimeLeft > 0) then @@ -2838,7 +2838,7 @@ if sparkles <> nil then begin sparkles^.Tint:= ((random(210)+45) shl 24) or ((random(210)+45) shl 16) or ((random(210)+45) shl 8) or $FF; - sparkles^.Angle:= random * 360; + sparkles^.Angle:= random(360); end end; @@ -2893,7 +2893,7 @@ with sparkles^ do begin Tint:= ((random(210)+45) shl 24) or ((random(210)+45) shl 16) or ((random(210)+45) shl 8) or $FF; - Angle:= random * 360; + Angle:= random(360); dx:= 0.001 * (random(200)); dy:= 0.001 * (random(200)); if random(2) = 0 then @@ -4559,7 +4559,7 @@ doMakeExplosion(hwRound(Gear^.X), hwRound(Gear^.Y), 80 + r0, Gear^.Hedgehog, EXPLAutoSound); for r0:= 0 to 4 do AddVisualGear(hwRound(Gear^.X), hwRound(Gear^.Y), vgtNote); - Gear^.dY := odY * -1 + cGravity * 2; + Gear^.dY := cGravity * 2 - odY; Gear^.Pos := Gear^.Pos + 1; end else diff -r e80e0d3273c5 -r 12cc2bd84b0b hedgewars/pas2cSystem.pas --- a/hedgewars/pas2cSystem.pas Sat May 12 00:25:49 2012 +0400 +++ b/hedgewars/pas2cSystem.pas Sat May 12 22:13:56 2012 +0400 @@ -69,6 +69,7 @@ Length, StrToInt : function : integer; SetLength, val : procedure; _pchar : function : PChar; + memcpy : procedure; assign, rewrite, reset, flush, BlockWrite, BlockRead, close : procedure; IOResult : integer; @@ -143,4 +144,4 @@ png_write_end : procedure; EnumToStr : function : string; -function glGetString + diff -r e80e0d3273c5 -r 12cc2bd84b0b hedgewars/uGearsUtils.pas --- a/hedgewars/uGearsUtils.pas Sat May 12 00:25:49 2012 +0400 +++ b/hedgewars/uGearsUtils.pas Sat May 12 22:13:56 2012 +0400 @@ -20,7 +20,7 @@ unit uGearsUtils; interface -uses uTypes, math; +uses uTypes; procedure doMakeExplosion(X, Y, Radius: LongInt; AttackingHog: PHedgehog; Mask: Longword); inline; procedure doMakeExplosion(X, Y, Radius: LongInt; AttackingHog: PHedgehog; Mask: Longword; const Tint: LongWord); @@ -46,7 +46,7 @@ uses uFloat, uSound, uCollisions, uUtils, uConsts, uVisualGears, uAIMisc, uVariables, uLandGraphics, uScript, uStats, uCaptions, uTeams, uStore, uLocale, uTextures, uRenderUtils, uRandom, SDLh, uDebug, uGears, - uGearsList; + uGearsList, Math; procedure doMakeExplosion(X, Y, Radius: LongInt; AttackingHog: PHedgehog; Mask: Longword); inline; begin diff -r e80e0d3273c5 -r 12cc2bd84b0b hedgewars/uVariables.pas --- a/hedgewars/uVariables.pas Sat May 12 00:25:49 2012 +0400 +++ b/hedgewars/uVariables.pas Sat May 12 22:13:56 2012 +0400 @@ -202,7 +202,7 @@ {$ENDIF} -const +var // these consts are here because they would cause circular dependencies in uConsts/uTypes cPathz: array[TPathType] of shortstring = ( '', // ptNone diff -r e80e0d3273c5 -r 12cc2bd84b0b tools/PascalParser.hs --- a/tools/PascalParser.hs Sat May 12 00:25:49 2012 +0400 +++ b/tools/PascalParser.hs Sat May 12 22:13:56 2012 +0400 @@ -563,14 +563,16 @@ return (i ,e) table = [ - [ Infix (char '*' >> return (InitBinOp "*")) AssocLeft + [ + Prefix (char '-' >> return (InitPrefixOp "-")) + ] + , [ Infix (char '*' >> return (InitBinOp "*")) AssocLeft , Infix (char '/' >> return (InitBinOp "/")) AssocLeft , Infix (try (string "div") >> return (InitBinOp "div")) AssocLeft , Infix (try (string "mod") >> return (InitBinOp "mod")) AssocLeft ] , [ Infix (char '+' >> return (InitBinOp "+")) AssocLeft , Infix (char '-' >> return (InitBinOp "-")) AssocLeft - , Prefix (char '-' >> return (InitPrefixOp "-")) ] , [ Infix (try (string "<>") >> return (InitBinOp "<>")) AssocNone , Infix (try (string "<=") >> return (InitBinOp "<=")) AssocNone diff -r e80e0d3273c5 -r 12cc2bd84b0b tools/pas2c.hs --- a/tools/pas2c.hs Sat May 12 00:25:49 2012 +0400 +++ b/tools/pas2c.hs Sat May 12 22:13:56 2012 +0400 @@ -553,14 +553,18 @@ 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..]) <+>) + return (text "enum" <+> (braces . vcat . punctuate comma . map (\(a, b) -> a <+> equals <+> text "0x" <> text (showHex b "")) $ zip is [0..]) <+>) where bt = BTEnum $ map (\(Identifier i _) -> map toLower i) ids type2C' (ArrayDecl Nothing t) = type2C (PointerTo t) type2C' (ArrayDecl (Just r) t) = do t' <- type2C t + lt <- gets lastType + ft <- case lt of + BTFunction {} -> type2C (PointerTo t) + _ -> return t' r' <- initExpr2C (InitRange r) - return $ \i -> t' i <> brackets r' + return $ \i -> ft i <> brackets r' type2C' (Set t) = return (text "<>" <+>) type2C' (FunctionType returnType params) = do t <- type2C returnType @@ -601,10 +605,22 @@ phrase2C (Assignment ref expr) = do r <- ref2C ref t <- gets lastType - e <- case (t, expr) of - (BTFunction {}, (Reference r')) -> ref2C r' - _ -> expr2C expr - return $ r <+> text "=" <+> e <> semi + case (t, expr) of + (BTFunction {}, (Reference r')) -> do + e <- ref2C r' + return $ r <+> text "=" <+> e <> semi + (BTArray (Range _) _ _, _) -> phrase2C $ + ProcCall (FunCall + [ + Reference $ Address ref + , Reference $ Address $ RefExpression expr + , Reference $ FunCall [expr] (SimpleReference (Identifier "sizeof" BTUnknown)) + ] + (SimpleReference (Identifier "memcpy" BTUnknown)) + ) [] + _ -> do + e <- expr2C expr + return $ r <+> text "=" <+> e <> semi phrase2C (WhileCycle expr phrase) = do e <- expr2C expr p <- phrase2C $ wrapPhrase phrase