System Procedures GetMem and FreeMem

This function processes system procedure GetMem.
Function Proc_GetMem: Word; Far;
Var PointerVariable, Size: TExpression;
begin
  ExpectTokenAndGetNext (Token_LeftParenthesis);
  PointerVariable.ExpectPointerVariable;
  ExpectTokenAndGetNext (Token_Comma);
  With Size do
    begin
      ExpectIntegerExpression;
      CheckOrdinalRange (Ptr (SystemUnitSegment, Word_TypeOffset));
      ExpectTokenAndGetNext (Token_RightParenthesis);
      Calculate;
      Push;
      GenerateInstruction_CALL_FAR (SysProc_NewPtr);
      EndIntermediateCodeSubroutine;
      Location := elRegister;
      DataType := [it32Bit, it16Bit, itSigned];
      UsedRegisters := [urBX, urDX, urCX, urAX];
      LocationData.Register := rDX_AX;
      TypeDefPtr := Ptr (SystemUnitSegment, Pointer_TypeOffset);
    end;
  GenerateAssignmentIntermediateCode (PointerVariable, Size);
  Proc_GetMem := PointerVariable.IntermediateCodeOffset;
end;
This function processes system procedure FreeMem.
Function Proc_FreeMem: Word; Far;
Var PointerVariable, Size: TExpression;
begin
  ExpectTokenAndGetNext (Token_LeftParenthesis);
  PointerVariable.ExpectPointerVariable;
  ExpectTokenAndGetNext (Token_Comma);
  With Size do
    begin
      ExpectIntegerExpression;
      CheckOrdinalRange (Ptr (SystemUnitSegment, Word_TypeOffset));
    end;
  ExpectTokenAndGetNext (Token_RightParenthesis);
  With PointerVariable do
    begin
      Calculate;
      Push
    end;
  With Size do
    begin
      Calculate;
      Push
    end;
  GenerateInstruction_CALL_FAR (SysProc_DisposePtr);
  Proc_FreeMem := PointerVariable.IntermediateCodeOffset;
end;
 
 
 
© 2017 Turbo Pascal | Privacy Policy