random.def
Traps.def
CSP.def
+Epilogue.def
--- /dev/null
+(*$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.
RealInOut.def Storage.def Arguments.def Conversion.def \
random.def Semaphores.def Unix.def RealConver.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:
{ M2_NORESULT, "no RETURN from procedure function"},
{ M2_UOVFL, "cardinal overflow"},
{ 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}
};
+#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()
{
exit(0);
sig
asp EM_PSIZE
cal $_M2M
- loc 0
+ cal $_halt
+ loc 0 ; should not get here
ret EM_WSIZE
end