Forum > Windows

Function return parameter code generation misery

(1/2) > >>

cryborg2:
How to tell the compiler to generate a code that treat Pointer type function return parameter as a "var" parameter just like it does with string type function return parameters?


function Test1{EAX}: string; assembler;
asm
// from here it is like we have a header like this: procedure Test1(var S{EAX}: string); assembler;
end;

function Test2{EAX}: Pointer; assembler;
asm
// from here it is like we have a header like this: procedure Test2(out P{EAX}: Pointer); assembler;
end;


procedure Test;
  var
    s: string;
    P: Pointer;
begin
  GetMem(P, MemBytes);

  s:=Test1; // In this case we pass the string to Test1 as a "var" parameter! Then Test1 can access the string as it was a real "var" parameter.
  {
    assembler:
    LEA     EAX,DWORD PTR [EBP-12]      (lea -0xc(%ebp),%eax)
    CALL    <TEST1>
  }

  P:=Test2; // In this case we not pass the pointer's address, we just get an address defined by Test2.
  {
    assembler:
    CALL    <TEST2>
    MOV     DWORD PTR [EBP-16],EAX      (mov %eax,-0x10(%ebp))
  }

  FreeMem(P);
end;

 %)

cryborg2:
This is important to me because I want to use my custom string data type with the same fashion as the built-in strings (except for concatenation of course).

PascalDragon:
How types are passed is fixed by the ABI and is not up to a user. So a Pointer will always be passed by value in the result register.

alpine:

--- Quote from: cryborg2 on November 05, 2022, 07:45:29 pm ---This is important to me because I want to use my custom string data type with the same fashion as the built-in strings (except for concatenation of course).

--- End quote ---
IMO It is due to the fact that String have a special treatment in FPC.
With the help of advanced records and operator/function overloading you can define whatever custom data type you want.
What do you mean with "the same fashion as"?

cryborg2:

--- Quote from: y.ivanov on November 05, 2022, 11:44:37 pm ---
--- Quote from: cryborg2 on November 05, 2022, 07:45:29 pm ---This is important to me because I want to use my custom string data type with the same fashion as the built-in strings (except for concatenation of course).

--- End quote ---
IMO It is due to the fact that String have a special treatment in FPC.
With the help of advanced records and operator/function overloading you can define whatever custom data type you want.
What do you mean with "the same fashion as"?

--- End quote ---

I want to use the ":=" operator to get my virtual string type return value, and to do so, the called function must have acces to my VirtualString object -which have it's own memory management- to transfer data through function return mechanism.

Navigation

[0] Message Index

[#] Next page

Go to full version