Added the Epilogue module
This commit is contained in:
parent
b19a178e2e
commit
e5b9c564af
6 changed files with 45 additions and 2 deletions
|
@ -22,3 +22,4 @@ head_m2.e
|
||||||
random.def
|
random.def
|
||||||
Traps.def
|
Traps.def
|
||||||
CSP.def
|
CSP.def
|
||||||
|
Epilogue.def
|
||||||
|
|
13
lang/m2/libm2/Epilogue.def
Normal file
13
lang/m2/libm2/Epilogue.def
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
(*$Foreign*)
|
||||||
|
DEFINITION MODULE Epilogue;
|
||||||
|
(* MODULA-2 offers a facility for the initialization of modules, but there
|
||||||
|
is no mechanism to have some code executed when the program finishes.
|
||||||
|
This module is a feeble attempt at solving this problem.
|
||||||
|
*)
|
||||||
|
PROCEDURE CallAtEnd(p: PROC);
|
||||||
|
(* Add procedure "p" to the list of procedures that must be executed when
|
||||||
|
the program finishes.
|
||||||
|
When the program finishes, these procedures are executed in the order in
|
||||||
|
which they were added to the list.
|
||||||
|
*)
|
||||||
|
END Epilogue.
|
|
@ -5,7 +5,8 @@ SOURCES = ASCII.def EM.def MathLib0.def Processes.def \
|
||||||
RealInOut.def Storage.def Arguments.def Conversion.def \
|
RealInOut.def Storage.def Arguments.def Conversion.def \
|
||||||
random.def Semaphores.def Unix.def RealConver.def \
|
random.def Semaphores.def Unix.def RealConver.def \
|
||||||
Strings.def InOut.def Terminal.def TTY.def \
|
Strings.def InOut.def Terminal.def TTY.def \
|
||||||
Mathlib.def PascalIO.def Traps.def CSP.def
|
Mathlib.def PascalIO.def Traps.def CSP.def \
|
||||||
|
Epilogue.def
|
||||||
|
|
||||||
all:
|
all:
|
||||||
|
|
||||||
|
|
|
@ -35,6 +35,7 @@ static struct errm {
|
||||||
{ M2_NORESULT, "no RETURN from procedure function"},
|
{ M2_NORESULT, "no RETURN from procedure function"},
|
||||||
{ M2_UOVFL, "cardinal overflow"},
|
{ M2_UOVFL, "cardinal overflow"},
|
||||||
{ M2_FORCH, "Warning: FOR-loop control variable was changed in the body"},
|
{ M2_FORCH, "Warning: FOR-loop control variable was changed in the body"},
|
||||||
|
{ M2_ENDPROCS, "too many procedures to be called on program termination"},
|
||||||
{ -1, 0}
|
{ -1, 0}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,29 @@
|
||||||
|
#define MAXPROCS 20
|
||||||
|
#include <m2_traps.h>
|
||||||
|
|
||||||
|
static int callindex;
|
||||||
|
static int (*proclist[MAXPROCS])();
|
||||||
|
|
||||||
|
_cleanup()
|
||||||
|
{
|
||||||
|
register int i;
|
||||||
|
|
||||||
|
for (i = 0; i < callindex; i++) {
|
||||||
|
(*proclist[i])();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
CallAtEnd(p)
|
||||||
|
int (*p)();
|
||||||
|
{
|
||||||
|
if (callindex >= MAXPROCS) {
|
||||||
|
TRP(M2_ENDPROCS);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
proclist[callindex++] = p;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
_halt()
|
_halt()
|
||||||
{
|
{
|
||||||
exit(0);
|
exit(0);
|
||||||
|
|
|
@ -91,6 +91,7 @@ mainroutine
|
||||||
sig
|
sig
|
||||||
asp EM_PSIZE
|
asp EM_PSIZE
|
||||||
cal $_M2M
|
cal $_M2M
|
||||||
loc 0
|
cal $_halt
|
||||||
|
loc 0 ; should not get here
|
||||||
ret EM_WSIZE
|
ret EM_WSIZE
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue