[Oberon] Procedure variables and local procedures
Skulski, Wojciech
skulski at pas.rochester.edu
Fri Sep 29 14:34:06 CEST 2017
________________________________________
From: Oberon [oberon-bounces at lists.inf.ethz.ch] on behalf of Andreas Pirklbauer [andreas_pirklbauer at yahoo.com]
Sent: Friday, September 29, 2017 6:04 AM
To: ETH Oberon and related systems
Subject: [Oberon] Procedure variables and local procedures
> And this in turn means that the enclosing scope doesn’t have to be around anymore when a procedure P is executed.
What happens when the enclosing procedure GlobalProc declares its local variables, which are then used within its local procedure? Local variables are allocated on the stack. Does the "counter" exist when the procedure IncCounter is called by a client module?
Wojtek
MODULE M;
TYPE Proc* = PROCEDURE;
VAR GlobalProc*: Proc; (*exported*)
LocalProc: Proc; (*not exported*)
PROCEDURE GlobalProc2;
VAR LocalVar2: Proc;
counter: INTEGER; (*allocated on the stack*)
PROCEDURE ZeroCounter; BEGIN counter := 0 END ZeroCounter;
PROCEDURE IncCounter; BEGIN counter := counter + 1 END IncCounter;
BEGIN (*GlobalProc2*)
GlobalProc := IncCounter; (*allowed (LocalProc2 visible in current scope)*)
LocalProc := ZeroCounter; (*allowed (LocalProc2 visible in current scope)*)
END GlobalProc2;
BEGIN (*M*)
GlobalProc2(); (*assign the variables*)
ZeroCounter (); (*calling proc local to the module via proc variable*)
(*IncCounter can now be called by clients. Can it be really?*)
END M.
More information about the Oberon
mailing list