Forum > FPC development

Feature request: nested procedure referrable as procedure of object

(1/2) > >>

deanon:
1) Currently, if we have something like this, we get "address of procedure is nested".


--- Code: ---type        opr = procedure of object;

procedure   test( p: opr );
            begin
            end;
           
procedure   test2( p: opr );

procedure   test3();
            begin
            end;

            begin
            test( @test3 );
            end;

--- End code ---

2) We do want to use functional approach, which do drastically reduce memory management. To workaround example from p. 1), one could probably declare some utilitary object to make it var of procedure and copy the frame into object's state, which is obviously a duplication of what "nested procedure" is designed for:

--- Code: ---
type        opr = procedure of object;

procedure   test( p: opr );
            begin
            end;
           
type       stub = packed object args...; procedure test3(); end;...

procedure   test2( p: opr; args );
var        s: stub;

            begin
            s.args = args;
            test( @s.test3 );
            end;

--- End code ---

3) Solution: to allow use of nested procedures as "procedure of object"

taazz:
erm excuse me but what is the problem again? Oh by the way can you tell me what is the difference between a procedure and a procedure of object?

deanon:
Procedure is pointer, procedure of object is 2 pointers: pointer and self.
Nested procedure is 2 pointers: pointer and frame.
It seems, internally, procedure of object and nested procedure have to be handled in very similar way.

Jonas Maebe:
http://www.freepascal.org/docs-html/ref/refse17.html documents how to do that.

deanon:
Which version of fpc it applies to? 2.64 doesn't get 'is nested', or it should compile in delphi mode (i never use it)?
Anyway, i think 'is nested' is conceptually wrong solution for this.
'of object' is wrong as well, but it can exist due to legacy purposes and pointer size constraints. Compiler of my dream should allow to use plain procedural type (not 'of object') to be used in place of 'procedure of object's too. Invoker should not know the kind of procedural reference, because such knowledge involves a lot of additional management without any profits.
But okay, why not to make at least 'of object/is nested' the same, or at least, to allow to use 'of object' type to set 'is nested' references? I.e., introduce some levels of compatibility:


--- Code: ---type t1 = procedure;
type t2 = procedure of object;
type t3 = procedure is nested;

var v1 : t1; v2: t2; v3: t3;

v1 := v2; // not allow
v1 := v3; // not allow

v2 := v1; // allow - i suppose, it's not the problem to make stubs for this cases
v2 := v3; // maybe allow

v3 := v1; // allow (stubs)
v3 := v2; // allow (i believe that frame and object have the same nature)


--- End code ---

Navigation

[0] Message Index

[#] Next page

Go to full version