Issue 58: Division with integer constants

git-svn-id: http://code.remobjects.com/svn/pascalscript@192 5c9d2617-0215-0410-a2ee-e80e04d1c6d8
This commit is contained in:
carlokok 2009-12-07 16:22:32 +00:00
parent 3a20e22223
commit 46a475884e
2 changed files with 65 additions and 9 deletions

View File

@ -48,7 +48,11 @@
{
Defines:
IFPS3_NOSMARTLIST - Don't use the smart list option
PS_NOSMARTLIST - Don't use the smart list option
PS_NOIDISPATCH
PS_NOWIDESTRING
PS_NOINT64
PS_DELPHIDIV
}
{$UNDEF DEBUG}

View File

@ -873,7 +873,7 @@ type
TPSBinOperatorType = (otAdd, otSub, otMul, otDiv, otMod, otShl, otShr, otAnd, otOr, otXor, otAs,
TPSBinOperatorType = (otAdd, otSub, otMul, otDiv, otMod, otShl, otShr, otAnd, otOr, otXor, otAs, otIntDiv,
otGreaterEqual, otLessEqual, otGreater, otLess, otEqual,
otNotEqual, otIs, otIn);
@ -3215,7 +3215,34 @@ begin
else Result := False;
end;
end;
{$IFDEF PS_DELPHIDIV}
otDiv:
begin { / }
if IsIntType(var1.FType.BaseType) then
ConvertToFloat(self, FUseUsedTypes, var1, Self.FindType('EXTENDED'));
case Var1.FType.BaseType of
btSingle: var1^.tsingle := var1^.tsingle / GetReal( Var2, Result);
btDouble: var1^.tdouble := var1^.tdouble / GetReal( Var2, Result);
btExtended: var1^.textended := var1^.textended / GetReal( Var2, Result);
btCurrency: var1^.tcurrency := var1^.tcurrency / GetReal( Var2, Result);
else Result := False;
end;
end;
otIntDiv:
begin { / }
case Var1.FType.BaseType of
btU8: var1^.tu8 := var1^.tu8 div GetUint(Var2, Result);
btS8: var1^.ts8 := var1^.ts8 div Getint(Var2, Result);
btU16: var1^.tu16 := var1^.tu16 div GetUint(Var2, Result);
btS16: var1^.ts16 := var1^.ts16 div Getint(Var2, Result);
btU32: var1^.tu32 := var1^.tu32 div GetUint(Var2, Result);
btS32: var1^.ts32 := var1^.ts32 div Getint(Var2, Result);
{$IFNDEF PS_NOINT64}btS64: var1^.ts64 := var1^.ts64 div GetInt64(Var2, Result); {$ENDIF}
else Result := False;
end;
end;
{$ELSE}
otDiv, otIntDiv:
begin { / }
case Var1.FType.BaseType of
btU8: var1^.tu8 := var1^.tu8 div GetUint(Var2, Result);
@ -3232,6 +3259,7 @@ begin
else Result := False;
end;
end;
{$ENDIF}
otMod:
begin { MOD }
case Var1.FType.BaseType of
@ -5791,6 +5819,16 @@ function TPSPascalCompiler.ProcessSub(BlockInfo: TPSBlockInfo): Boolean;
BVal.Val2 := tmpp;
end;
end else begin
if (BVal.aType <> nil) and (BVal.aType <> GetTypeNo(BlockInfo, Output)) then begin
tmpp := AllocStackReg(BVal.aType);
PreWriteOutrec(tmpp, nil);
DoBinCalc(BVal, tmpp);
afterwriteoutrec(tmpp);
result := WriteCalculation(tmpp, output);
tmpp.Free;
exit;
end;
if not PreWriteOutRec(Output, nil) then
begin
Result := False;
@ -5836,6 +5874,9 @@ function TPSPascalCompiler.ProcessSub(BlockInfo: TPSBlockInfo): Boolean;
exit;
end;
BlockWriteByte(BlockInfo, Cm_CA);
if BVAL.Operator = otIntDiv then
BlockWriteByte(BlockInfo, Ord(otDiv))
else
BlockWriteByte(BlockInfo, Ord(BVal.Operator));
if not (WriteOutRec(Output, False) and WriteOutRec(BVal.FVal2, True)) then
begin
@ -8122,7 +8163,8 @@ function TPSPascalCompiler.ProcessSub(BlockInfo: TPSBlockInfo): Boolean;
else
Result := nil;
end;
otSub, otMul, otDiv: { - * / }
otSub, otMul, otIntDiv, otDiv: { - * / }
begin
if ((t1.BaseType = btVariant) or (t1.BaseType = btNotificationVariant)) and (
((t2.BaseType = btVariant) or (t2.BaseType = btNotificationVariant)) or
@ -8139,15 +8181,23 @@ function TPSPascalCompiler.ProcessSub(BlockInfo: TPSBlockInfo): Boolean;
((t1.BaseType = btVariant) or (t1.BaseType = btNotificationVariant)) or
(isIntRealType(t1.BaseType))) then
Result := t2
else if IsIntType(t1.BaseType) and IsIntType(t2.BaseType) then
Result := t1
else if IsIntRealType(t1.BaseType) and
else if IsIntType(t1.BaseType) and IsIntType(t2.BaseType) then begin
Result := t1;
{$IFDEF PS_DELPHIDIV}
if Cmd = otDiv then
result := FindBaseType(btExtended);
{$ENDIF}
end else if IsIntRealType(t1.BaseType) and
IsIntRealType(t2.BaseType) then
begin
if IsRealType(t1.BaseType) then
Result := t1
else
Result := t2;
{$IFDEF PS_DELPHIDIV}
if Cmd = otIntDiv then //intdiv only works
result := nil;
{$ENDIF}
end
else
Result := nil;
@ -8409,7 +8459,8 @@ function TPSPascalCompiler.ProcessSub(BlockInfo: TPSBlockInfo): Boolean;
end;
case Token of
CSTI_Multiply: Op := otMul;
CSTII_div, CSTI_Divide: Op := otDiv;
CSTI_Divide: Op := otDiv;
CSTII_div: Op := otIntDiv;
CSTII_mod: Op := otMod;
CSTII_and: Op := otAnd;
CSTII_shl: Op := otShl;
@ -12603,7 +12654,8 @@ function TPSPascalCompiler.ReadConstant(FParser: TPSPascalParser; StopOn: TPSPas
end;
case Token of
CSTI_Multiply: Op := otMul;
CSTII_div, CSTI_Divide: Op := otDiv;
CSTI_Divide: Op := otDiv;
CSTII_Div: Op := otIntDiv;
CSTII_mod: Op := otMod;
CSTII_and: Op := otAnd;
CSTII_shl: Op := otShl;