Previous: Interrupt Procedure To the Table of Content Next: Using Statement as Procedure

- 2.2.12.5 -
TMT Pascal Language Description
Pascal Language Structure
Procedures and Functions

Procedural Value

TMT Pascal has a notion of a procedural value. It gives an opportunity to use procedure or function in a program as a usual simple type object such as enumerate type or subrange type. One can declare an variable of the procedural type, make an assignment to it, and invoke the procedure body from.

By default the procedural value implemented in the TMT Pascal occupies 4 bytes of memory.



It's also possible to declare the extended ("old-style") procedural values by means of arg_proc_based calling convention modifier. These procedural values which occupy 8 bytes of memory and consist of two parts: the entry point to the routine and the reference to the local environment of the routine (known as a routine base). A format of the extended procedural value is following:



The first part is needed for calling of the routine. The second part is used to access the routine variables. Such format of the procedural value is incompatible with the Borland Pascal format which has only the entry point.

Furthermore, the stack frame structure and parameter passing conventions differ from those in Borland Pascal.

Thus the approach used in TVision and CLassLib for writing iterations cannot be used. However, we offer this correct and reliable (and more standard) way:
type
  list = object
    next: ^list;
    procedure for_all(procedure body(var v));
  end;

procedure list.for_all;
var
  p: ^list;
begin
  p := @self;
  repeat
    body(p);
    p := p^.next;
  end;
end;
 ...

type
  int_list = object (list)
    value: integer;
    function first_positive: ^int_list;
  end;

function int_list.first_positive;
label OK;
var
  res: ^int_list;
  procedure do_item(var v);
  begin
    if int_list (v).value > 0 then
      begin
        res := @v;
        goto OK;
     end
   end;

begin
  res := nil;
  for_all(do_item);
OK:
  first_positive := res;
end;
 ...
The procedural value from a method of object can be obtained by selecting this method from some object value (not from a type). The parameters of this procedural value must match the parameters of the method. The invocation of such a procedural value is an invocation of the corresponding method of the object. The reference to the object is transferred through the base of the procedural value.

You can use only global procedural values to initialize a type constant.

Procedural values may be used only while the environment where they were formed is still in existence. Thus,


Previous: Interrupt Procedure To the Table of Content Next: Using Statement as Procedure
Interrupt Procedure Table of Content Using Statement as Procedure

- 2.2.12.5 -