Arithmetic System Functions

This procedure processes system functions Int, Frac, Sqrt, Sin, Cos, Ln, Exp and ArcTan.
Procedure Func_ArithmeticFunctions; Far;
begin
  Expression^.ExpectIntegerOrFloatingPointExpressionInParentheses;
  ArithmeticFunctions;
end;
This procedure processes system functions Trunc and Round.
Procedure Func_Trunc_Round; Far;
begin
  Expression^.ExpectIntegerOrFloatingPointExpressionInParentheses;
  With Expression^ do
    begin
      If Location = elConstant then
        begin
          Expression^.ConvertIntegerToExtended;
          Case FuncParameter of
            8: Value.LongInt := Trunc (Value.Extended);
            9: Value.LongInt := Round (Value.Extended);
          end;
          If Value.LongInt = $80000000 then Error (ConstantOutOfRange); { ??? !!! }
          Expression^.CheckOrdinalOverflowAndStore (Value.LongInt, False);
          TypeDefPtr := Ptr (SystemUnitSegment, LongInt_TypeOffset);
          Exit;
        end;
      ArithmeticFunctions;
      Location := elRegister;
      DataType := [it32Bit, it16Bit, itSigned];
      LocationData.B9 := 0;
      TypeDefPtr := Ptr (SystemUnitSegment, LongInt_TypeOffset);
    end;
end;
This procedure prepares expression and generates a call to compiler routine for system functions Int, Frac, Sqrt, Sin, Cos, Ln, Exp, ArcTan, Trunc and Round.
Procedure ArithmeticFunctions;
Const Table: Array [0..9, Boolean] of Word = (
        (SysProc_RInt,    SysProc_FInt),
        (SysProc_RFrac,   SysProc_FFrac),
        (SysProc_RSqrt,   SysProc_FSqrt),
        (SysProc_RSin,    SysProc_FSin),
        (SysProc_RCos,    SysProc_FCos),
        (SysProc_RLn,     SysProc_FLn),
        (SysProc_RExp,    SysProc_FExp),
        (SysProc_RArcTan, SysProc_FArcTan),
        (SysProc_RTrunc,  SysProc_FTrunc),
        (SysProc_RRound,  SysProc_FRound));

begin
  If Instructions80x87 in StatementCompilerSwitches then
    begin
      Expression^.ConvertIntegerToExtended;
      Expression^.ConvertRealToExtended;
      Expression^.LoadExpressionToFPU;
      Expression^.Calculate;
    end else begin
               Expression^.ConvertIntegerToReal;
               Expression^.ConvertExtendedToReal;
               Expression^.Calculate;
               Expression^.LoadRealExpressionToRegisterSet (rAX_BX_DX);
             end;
  GenerateInstruction_CALL_FAR (Table [FuncParameter, Instructions80x87 in StatementCompilerSwitches]);
  Expression^.EndIntermediateCodeSubroutine;
  Expression^.UsedRegisters := [urSP, urDX, urAX];
end;
 
 
 
© 2017 Turbo Pascal | Privacy Policy