[Oberon] Intermediate scopes in Oberon-07

Andreas Pirklbauer andreas_pirklbauer at yahoo.com
Sun Feb 25 19:30:16 CET 2018


  > How shall it be, if a nested procedure can only access
  > its own parameters and local stuff? No access to outer scopes! 
  > ...
  > Yours sincerely,
  > Srinivas Nayak

Yes, one can of course always TRY to use NESTING (with the above
restrictions, i.e. with no access to intermediate objects) to
eliminate forward references, instead of using PROCEDURE VARIABLES.

However, nesting cannot be used in all cases. As outlined in

http://people.inf.ethz.ch/wirth/Oberon/PortingOberon.pdf

nesting can ONLY be used IF all nested procedures are
ONLY called from within the OTHER nested procedures.

For example, in module ORP of the compiler itself, this is
just not the case. Try it, i.e. start rewriting ORP...

PROCEDURE expression(VAR x: ORG.Item);
  PROCEDURE SimpleExpression(VAR x: ORG.Item);
    PROCEDURE term(VAR x: ORG.Item);
      PROCEDURE factor(VAR x: ORG.Item);
        (*call expression here*)

but THEN you see that can’t simply also move procedure ‘selector’
(which is both called by ‘factor' and itself calls ‘expression’)
inside the innermost scope (=scope of ‘factor’), simply because
procedure ’selector' is ALSO used OUTSIDE the above nested
construct, namely in procedure ‘ORP.StatSequence'.

So in THIS particular case one cannot use NESTING to eliminate
the forward references (at least not in a straightforward way), but
one HAS to use installed procedures instead (as is in fact done
in the current implementation of ORP).

Of course, if forward declarations of procedures WERE still
allowed in the Oberon language, one could use THEM (and wouldn’t
need any nesting at all). This would also come with faster
procedure activations, as shown in an earlier post.

But forward declarations of procedures were removed
in Oberon-07 in 2007, so this is not an option here.

So we are down to 2 options for ORP:

a) nesting (which however is not possible in this case)
b) procedure variables (=the current implementation)

Andreas




More information about the Oberon mailing list