Press enter to see results or esc to cancel.

System Procedure New

This function processes system procedure New. It uses a common procedure for New as function and procedure.

Function Proc_New: Word; Far;
Var PointerVariable, Expression: TExpression;
begin
  ExpectTokenAndGetNext (Token_LeftParenthesis);
  PointerVariable.ExpectPointerVariable;
  Expression.Process_NEW;
  ExpectTokenAndGetNext (Token_RightParenthesis);
  GenerateAssignmentIntermediateCode (PointerVariable, Expression);
  Proc_New := PointerVariable.IntermediateCodeOffset;
end;

begin
  Saved_TypeDefPtr := TypeDefPtr;
  PointerBaseType := PointerFromOffsets (PPointerTypeDefinition (TypeDefPtr)^.PointerBaseTypeOffset);
  If (PointerBaseType^.BaseType = btObject) and (CheckAndGetNextToken (Token_Comma)) then
    begin
      IntermediateCodeOffset := 0;
      UsedRegisters := [];
      FindAndProcessMethodCall (PointerBaseType, [pfConstructor], [mcNew], ConstructorIdentifierExpected);
      CallProcedure;
    end else begin
               GenerateCodeToPushWord (PointerBaseType^.Size);
               GenerateInstruction_CALL_FAR (SysProc_NewPtr);
               EndIntermediateCodeSubroutine;
             end;
  TypeDefPtr := Saved_TypeDefPtr;
  Location := elRegister;
  DataType := itLongInt;
  UsedRegisters := [urBX, urDX, urCX, urAX];
  LocationData.Register := rDX_AX;
end;