Local procedures as actual anonymous procedure parameter in macpas mod.
Original Reporter info from Mantis: Adriaan van Os
-
Reporter name: Adriaan van Os
Original Reporter info from Mantis: Adriaan van Os
- Reporter name: Adriaan van Os
Description:
The attached diff implements local procedures as actual anonymous procedure parameter in macpas mode. It does so
- without changing the ABI of current software
- without changing code generation and code efficiency of current software
- without using trampolines or an executable stack.
These prerequisites require the use of a directive, (NESTED) to denote that an actual anonymous procedure parameter can be local. Another directive (NESTEDCALL) can be attached to a global procedure to make it compatible with the calling conventions of local (nested) procedures. It does so by passing a dummy (nil) parent frame pointer.
This patch only affects anomymous procedures in macpas mode, but the idea could be extended to procedure types.
This adds two test files to the testsuite. tests/test/tmaclocalprocparam.pp (slightly modified) now passes the testsuite.
Steps to reproduce:
Additional information:
Example:
{$mode macpas}
program tmaclocalprocparam2;
procedure p1( nested procedure pp( pi: longint); i: longint);
begin
pp( i)
end;
procedure p2( nested procedure pp( pi: longint); i: longint);
begin
p1( pp, i)
end;
procedure n( ri: longint); nestedcall;
begin
if ri = 1 then
writeln( 'success for n')
else
begin
writeln( 'fail');
halt( 1)
end
end;
procedure q;
var qi: longint;
procedure r( ri: longint);
begin
if qi = ri then
writeln( 'success for r')
else
begin
writeln( 'fail');
halt( 1)
end
end;
begin
qi:= 1;
p1( r, qi);
p2( r, qi);
p1( n, qi);
p2( n, qi);
end;
begin
q
end.
Mantis conversion info:
- Mantis ID: 15925
- OS: Mac OS X
- OS Build: 10.5.4
- Build: fpc svn trunk r14993
- Platform: i386-apple-darwin
- Version: 2.5.1
- Fixed in version: 2.6.0
- Fixed in revision: 15694 (#57bd6d26)
- Monitored by: » @MageSlayer (Denis Golovan)