I'm converting to Free Pascal's native mode as much as possible.
Ran into a closure problem.
p2dump.i(245,27) Error: Incompatible type for arg no. 1: Got "<address of procedure(varnodep) is nested;Register>", expected "<procedure variable type of procedure(varnodep);Register>"This program has lots of "drive" procedures which iterate over complex data structures and call a procedure for each one. By declaring a procedure type, I can get that to work.
type
pvarnodep = procedure(v: varnodep); { procedure param }
...
procedure vardrive(eachvar: pvarnodep); { called for each var }
begin
...
end;
So far so good. But here's some code that uses it. There's an outer procedure, with a file argument where the output is supposed to go. There's an inner procedure, "dumpvarowner", which imports that variable from the outer procedure scope. Then "dumpvarowner" is passed to "vardrive".
That's a closure, and Free Pascal doesn't like it.
{
dumpvarownership -- dump variable ownership data
}
procedure dumpvarownership(var f: text); { output file }
{
dumpvarowner -- dump ownership data for one variable
}
procedure dumpvarowner(v: varnodep);
begin
write(f,' ':8,v^.vardata.itemname,' ':4);
...
end {dumpvarowner};
begin {dumpvarownership}
vardrive(@dumpvarowner);
writeln(f);
end {dumpvarownership};
This is really a closure - a passed scope with access to an outer scope. (Closures, lambdas, and anonymous functions are not the same thing.)
This program is full of this kind of construct. It's something that was done before objects were invented.
I tried putting
{$MODESWITCH NESTEDPROCVARS}
at the beginning of the program, and adding "is nested" to the procedure pointer type declaration.
pvarnodep = procedure(v: varnodep) is nested;
Now all the closures are accepted by the compiler. Not ready to run yet; a few more minor problems remain. Thanks.