System Function Random

This procedure processes system function Random.
Procedure Func_Random; Far;
begin
  If CheckAndGetNextToken (Token_LeftParenthesis) then
    begin
      Expression^.ExpectIntegerExpression;
      ExpectTokenAndGetNext (Token_RightParenthesis);
      Expression^.CheckOrdinalRange (Ptr (SystemUnitSegment, Word_TypeOffset));
      Expression^.PushExpression;
      Expression^.Calculate;
      GenerateInstruction_CALL_FAR (SysProc_RandInt);
      With Expression^ do
        begin
          Expression^.EndIntermediateCodeSubroutine;
          Location := elRegister;
          DataType := [itUnsigned, it16Bit];
          UsedRegisters := [urSP, urDX, urAX];
          LocationData.Register := rDX_AX;
          TypeDefPtr := Ptr (SystemUnitSegment, LongInt_TypeOffset);
        end;
      Exit;
    end;
  Case Instructions80x87 in StatementCompilerSwitches of
    True: begin
            GenerateInstruction_CALL_FAR (SysProc_RandFloat);
            With Expression^ do
              begin
                Expression^.EndIntermediateCodeSubroutine;
                Location := elStackFrame;
                DataType := [itUnsigned];
                UsedRegisters := [urSP, urDX, urAX];
                TypeDefPtr := Ptr (SystemUnitSegment, Extended_TypeOffset);
              end;
          end;
    False: begin
             GenerateInstruction_CALL_FAR (SysProc_RandReal);
             With Expression^ do
               begin
                 Expression^.EndIntermediateCodeSubroutine;
                 Location := elRegister;
                 DataType := [it16Bit];
                 UsedRegisters := [urSP, urDX, urAX];
                 TypeDefPtr := Ptr (SystemUnitSegment, Real_TypeOffset);
               end;
            end;
  end;
end;
 
 
 
© 2017 Turbo Pascal | Privacy Policy