[Oberon] Module finalization in PO2013
Andreas Pirklbauer
andreas_pirklbauer at yahoo.com
Fri Jan 1 09:18:59 CET 2021
> BTW, in the TCP.Init you will see the call Kernel.InstallTermHandler(Terminate).
> It means that finalization was implemented in V4. It seems to be different from
> the recent Andreas' implementation. So there will be some (minor?)
> incompatibilities which needs fixing. Hopefully there will be very few of these.
Hi Wojtek,
You’re right, there are some minor differences. The V4 implementation [1]
allows one to install a finalization sequence within a *different* module.
I.e. writing Kernel.InstallTermHandler(B.Terminate) in module A will in fact
install procedure B.Terminate as a finalization routine of module B (!), not A.
In the (proposed) Project Oberon 2013 version of module finalization this
is not allowed. Nor should it be. I.e. The finalization routine must be a
(parameterless) procedure declared in the *same* module In addition,
it it must be installed *in* the initialization code of the module.
This was done to effectively mimic the CLOSE language construct
of Componenent Pascal [3].
-ap
[1] V4 Linz implementation of module finalization:
PROCEDURE
InstallTermHandler* (h: TerminationHandler);
VAR codebase, handlerAdr: LONGINT; m: Module; found: BOOLEAN;
BEGIN
m := modules; handlerAdr := S.VAL(LONGINT, h); found := FALSE;
WHILE (m # NIL) & ~found DO
codebase := S.ADR(m.code^);
IF (codebase <= handlerAdr) & (handlerAdr <= codebase + LEN(m.code^)) THEN found := TRUE
ELSE m := m.next
END
END ;
IF found THEN m.term := h END
END InstallTermHandler;
[2] (Proposed) Project Oberon 2013 implementation of module finalization:
PROCEDURE Close*(close: Command); (*set module finalization sequence*)
VAR u, v, w: INTEGER; mod: Module;
BEGIN u := SYSTEM.REG(LNK); mod := root;
WHILE (mod # NIL) & ((u < mod.code) OR (u >= mod.imp)) DO mod := mod.next END ; (*search for caller*)
IF mod # NIL THEN v := SYSTEM.VAL(INTEGER, close);
SYSTEM.GET(mod.ent, w); w := mod.code + w; (*module initialization body*)
IF (v >= mod.code) & (v < w) & (w <= u) THEN mod.close := close ELSE res := badclose END
END
END Close;
See: https://github.com/andreaspirklbauer/Oberon-module-finalization
[3] Component Pascal implementation of module finalization:
MODULE M;
PROCEDURE Init; BEGIN .. END Init;
PROCEDURE Finalize; BEGIN .. END Finalize;
CLOSE Finalize
BEGIN Init
END M.
More information about the Oberon
mailing list