mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2026-01-08 11:01:41 +01:00
* also allow by-value open array parameters for the tail recursion optimization
* adjusted test git-svn-id: trunk@44012 -
This commit is contained in:
parent
4fc02d3d09
commit
9a42625cfb
@ -123,7 +123,9 @@ unit opttail;
|
||||
begin
|
||||
useaddr:=(paranode.parasym.varspez in [vs_var,vs_constref]) or
|
||||
((paranode.parasym.varspez=vs_const) and
|
||||
paramanager.push_addr_param(paranode.parasym.varspez,paranode.parasym.vardef,p.proccalloption));
|
||||
paramanager.push_addr_param(paranode.parasym.varspez,paranode.parasym.vardef,p.proccalloption)) or
|
||||
((paranode.parasym.varspez=vs_value) and
|
||||
is_open_array(paranode.parasym.vardef));
|
||||
if useaddr then
|
||||
begin
|
||||
tempnode:=ctempcreatenode.create(voidpointertype,voidpointertype.size,tt_persistent,true);
|
||||
|
||||
@ -56,6 +56,23 @@ begin
|
||||
Test3 := Test3(Values, 0);
|
||||
end;
|
||||
|
||||
function Test4(Values: array of LongInt; Res: LongInt): LongInt;
|
||||
begin
|
||||
if not Assigned(stack) then
|
||||
stack := get_frame
|
||||
else if stack <> get_frame then
|
||||
Halt(7);
|
||||
if Length(Values) = 0 then
|
||||
Test4 := Res
|
||||
else
|
||||
Test4 := Test4(Values[0..High(Values) - 1], Res + Values[High(Values)]);
|
||||
end;
|
||||
|
||||
function Test4(Values: array of LongInt): LongInt;
|
||||
begin
|
||||
Test4 := Test4(Values, 0);
|
||||
end;
|
||||
|
||||
begin
|
||||
if Test1([1, 2, 3, 4]) <> 10 then
|
||||
Halt(2);
|
||||
@ -65,5 +82,8 @@ begin
|
||||
stack := Nil;
|
||||
if Test3([1, 2, 3, 4]) <> 10 then
|
||||
Halt(6);
|
||||
stack := Nil;
|
||||
if Test4([1, 2, 3, 4]) <> 10 then
|
||||
Halt(8);
|
||||
writeln('ok');
|
||||
end.
|
||||
|
||||
Loading…
Reference in New Issue
Block a user