Recent

Author Topic: Feature request: nested procedure referrable as procedure of object  (Read 5935 times)

deanon

  • New Member
  • *
  • Posts: 12
1) Currently, if we have something like this, we get "address of procedure is nested".

Code: [Select]
type        opr = procedure of object;

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

procedure   test3();
            begin
            end;

            begin
            test( @test3 );
            end;

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: [Select]

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;

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

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Feature request: nested procedure referrable as procedure of object
« Reply #1 on: August 01, 2015, 12:24:45 pm »
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?
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

deanon

  • New Member
  • *
  • Posts: 12
Re: Feature request: nested procedure referrable as procedure of object
« Reply #2 on: August 01, 2015, 12:37:44 pm »
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

  • Hero Member
  • *****
  • Posts: 1058

deanon

  • New Member
  • *
  • Posts: 12
Re: Feature request: nested procedure referrable as procedure of object
« Reply #4 on: August 01, 2015, 05:33:24 pm »
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: [Select]
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)

« Last Edit: August 01, 2015, 05:35:21 pm by deanon »

Jonas Maebe

  • Hero Member
  • *****
  • Posts: 1058
Re: Feature request: nested procedure referrable as procedure of object
« Reply #5 on: August 01, 2015, 05:39:44 pm »
Delphi does not support "is nested", so it's not enabled by default in {$mode delphi}. As the manual states: "This requires that the sources be compiled in macpas or ISO mode, or that the nestedprocvars modeswitch be activated". The example in the manual also shows how to activate that modeswitch.

It needs to be different because the calling convention for nested routines is completely different from methods. The only way to do all of that transparently behind the scenes would be by turning procvars into reference-counted heap-allocated entities, which would slow them down significantly and which would probably break tons of existing hackish code (you may not care about either of those things, but you're not the one having to deal with the resulting bug reports and complaints either). Pascal is not Lisp.

deanon

  • New Member
  • *
  • Posts: 12
Re: Feature request: nested procedure referrable as procedure of object
« Reply #6 on: August 01, 2015, 06:09:43 pm »
This statement sounds like tombstone which significantly constraints the further language evolution and usability.
But, again, isn't it possible at least to make 'is nested' and 'of object' compatible?
Why not to generate internal stubs this way ?

Code: [Select]

type nestedproc = procedure is nested;
type objectproc = procedure of object;

type stub = object np: nestedproc; procedure proc(); end;
procedure stub.proc(); begin np() end;

procedure call( op: objectproc ); begin...end;

procedure blah();
var s: stub;
procedure nested(); begin ... end;
begin
  s.np := @nested;
  call( @s.proc );
end;



Jonas Maebe

  • Hero Member
  • *****
  • Posts: 1058
Re: Feature request: nested procedure referrable as procedure of object
« Reply #7 on: August 01, 2015, 07:13:51 pm »
This statement sounds like tombstone which significantly constraints the further language evolution and usability.
So does breaking backward compatibility every other full moon because the language maintainers decided that it hamstrung them. Constantly breaking code that currently works is much more of a tombstone, because nobody wants to rewrite their code all the time (then they can just as well start using a different language). In fact, if you want to fix everything in a language, you have to design a language from scratch.

Quote
But, again, isn't it possible at least to make 'is nested' and 'of object' compatible?
Why not to generate internal stubs this way ?
It would result in a lot of code bloat.

 

TinyPortal © 2005-2018