TerminationImpl.mesa
Copyright Ó 1990, 1991 by Xerox Corporation. All rights reserved.
Created by Christian Jacobi, July 3, 1990 11:35 am PDT
DIRECTORY Rope, Termination;
TerminationImpl: CEDAR MONITOR
IMPORTS Rope
EXPORTS Termination ~
BEGIN
Closure: TYPE = RECORD [proc: PROC[REF], data: REF];
callbacks: LIST OF Closure ¬ NIL;
debuggingMode: PUBLIC BOOL ¬ FALSE;
quitWorld: PUBLIC ERROR [msg: Rope.ROPE] = CODE;
XRExitWorld: PROC [status: INT] = TRUSTED MACHINE CODE { "<xr/Threads.h>.XR𡤎xitWorld" };
XRWrite: PROC [c: CHAR] = TRUSTED MACHINE CODE { "XR�ugPutChar" };
SetDebuggingMode: PUBLIC PROC [] = {
debuggingMode ¬ TRUE
};
CallBeforeQuitWorld: PUBLIC ENTRY PROC [proc: PROC[REF], data: REF ¬ NIL] = {
callbacks ¬ CONS[[proc, data], callbacks];
};
QuitWorld: PUBLIC PROC [userMsg: Rope.ROPE, interceptable: BOOL] = {
EachChar: Rope.ActionType = {XRWrite[c]};
len: INT ¬ Rope.Length[userMsg];
IF debuggingMode AND interceptable THEN ERROR quitWorld[userMsg];
FOR l: LIST OF Closure ¬ callbacks, l.rest WHILE l#NIL DO l.first.proc[l.first.data] ENDLOOP;
[] ¬ Rope.Map[base: userMsg, action: EachChar];
IF len>0 AND Rope.Fetch[userMsg, len-1]#'\n THEN XRWrite['\n];
XRExitWorld[IF interceptable THEN 0 ELSE -1];
};
END.