| 1 |
(* RTExceptions.def runtime exception handler routines. |
| 2 |
|
| 3 |
Copyright (C) 2008-2025 Free Software Foundation, Inc. |
| 4 |
Contributed by Gaius Mulley <[email protected]>. |
| 5 |
|
| 6 |
This file is part of GNU Modula-2. |
| 7 |
|
| 8 |
GNU Modula-2 is free software; you can redistribute it and/or modify |
| 9 |
it under the terms of the GNU General Public License as published by |
| 10 |
the Free Software Foundation; either version 3, or (at your option) |
| 11 |
any later version. |
| 12 |
|
| 13 |
GNU Modula-2 is distributed in the hope that it will be useful, but |
| 14 |
WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 |
General Public License for more details. |
| 17 |
|
| 18 |
Under Section 7 of GPL version 3, you are granted additional |
| 19 |
permissions described in the GCC Runtime Library Exception, version |
| 20 |
3.1, as published by the Free Software Foundation. |
| 21 |
|
| 22 |
You should have received a copy of the GNU General Public License and |
| 23 |
a copy of the GCC Runtime Library Exception along with this program; |
| 24 |
see the files COPYING3 and COPYING.RUNTIME respectively. If not, see |
| 25 |
<http://www.gnu.org/licenses/>. *) |
| 26 |
|
| 27 |
DEFINITION MODULE RTExceptions ; |
| 28 |
|
| 29 |
(* Runtime exception handler routines. This should |
| 30 |
be considered as a system module for GNU Modula-2 |
| 31 |
and allow the compiler to interface with exception |
| 32 |
handling. *) |
| 33 |
|
| 34 |
FROM SYSTEM IMPORT ADDRESS ; |
| 35 |
EXPORT QUALIFIED EHBlock, |
| 36 |
Raise, SetExceptionBlock, GetExceptionBlock, |
| 37 |
GetTextBuffer, GetTextBufferSize, GetNumber, |
| 38 |
InitExceptionBlock, KillExceptionBlock, |
| 39 |
PushHandler, PopHandler, |
| 40 |
BaseExceptionsThrow, DefaultErrorCatch, |
| 41 |
IsInExceptionState, SetExceptionState, |
| 42 |
SwitchExceptionState, GetBaseExceptionBlock, |
| 43 |
SetExceptionSource, GetExceptionSource ; |
| 44 |
|
| 45 |
TYPE |
| 46 |
EHBlock ; |
| 47 |
ProcedureHandler = PROCEDURE ; |
| 48 |
|
| 49 |
|
| 50 |
(* |
| 51 |
Raise - invoke the exception handler associated with, number, |
| 52 |
in the active EHBlock. It keeps a record of the number |
| 53 |
and message in the EHBlock for later use. |
| 54 |
*) |
| 55 |
|
| 56 |
PROCEDURE Raise (number: CARDINAL; |
| 57 |
file: ADDRESS; line: CARDINAL; |
| 58 |
column: CARDINAL; function: ADDRESS; |
| 59 |
message: ADDRESS) <* noreturn *> ; |
| 60 |
|
| 61 |
|
| 62 |
(* |
| 63 |
SetExceptionBlock - sets, source, as the active EHB. |
| 64 |
*) |
| 65 |
|
| 66 |
PROCEDURE SetExceptionBlock (source: EHBlock) ; |
| 67 |
|
| 68 |
|
| 69 |
(* |
| 70 |
GetExceptionBlock - returns the active EHB. |
| 71 |
*) |
| 72 |
|
| 73 |
PROCEDURE GetExceptionBlock () : EHBlock ; |
| 74 |
|
| 75 |
|
| 76 |
(* |
| 77 |
GetTextBuffer - returns the address of the EHB buffer. |
| 78 |
*) |
| 79 |
|
| 80 |
PROCEDURE GetTextBuffer (e: EHBlock) : ADDRESS ; |
| 81 |
|
| 82 |
|
| 83 |
(* |
| 84 |
GetTextBufferSize - return the size of the EHB text buffer. |
| 85 |
*) |
| 86 |
|
| 87 |
PROCEDURE GetTextBufferSize (e: EHBlock) : CARDINAL ; |
| 88 |
|
| 89 |
|
| 90 |
(* |
| 91 |
GetNumber - return the exception number associated with, |
| 92 |
source. |
| 93 |
*) |
| 94 |
|
| 95 |
PROCEDURE GetNumber (source: EHBlock) : CARDINAL ; |
| 96 |
|
| 97 |
|
| 98 |
(* |
| 99 |
InitExceptionBlock - creates and returns a new exception block. |
| 100 |
*) |
| 101 |
|
| 102 |
PROCEDURE InitExceptionBlock () : EHBlock ; |
| 103 |
|
| 104 |
|
| 105 |
(* |
| 106 |
KillExceptionBlock - destroys the EHB, e, and all its handlers. |
| 107 |
*) |
| 108 |
|
| 109 |
PROCEDURE KillExceptionBlock (e: EHBlock) : EHBlock ; |
| 110 |
|
| 111 |
|
| 112 |
(* |
| 113 |
PushHandler - install a handler in EHB, e. |
| 114 |
*) |
| 115 |
|
| 116 |
PROCEDURE PushHandler (e: EHBlock; number: CARDINAL; p: ProcedureHandler) ; |
| 117 |
|
| 118 |
|
| 119 |
(* |
| 120 |
PopHandler - removes the handler associated with, number, from |
| 121 |
EHB, e. |
| 122 |
*) |
| 123 |
|
| 124 |
PROCEDURE PopHandler (e: EHBlock; number: CARDINAL) ; |
| 125 |
|
| 126 |
|
| 127 |
(* |
| 128 |
DefaultErrorCatch - displays the current error message in |
| 129 |
the current exception block and then |
| 130 |
calls HALT. |
| 131 |
*) |
| 132 |
|
| 133 |
PROCEDURE DefaultErrorCatch ; |
| 134 |
|
| 135 |
|
| 136 |
(* |
| 137 |
BaseExceptionsThrow - configures the Modula-2 exceptions to call |
| 138 |
THROW which in turn can be caught by an |
| 139 |
exception block. If this is not called then |
| 140 |
a Modula-2 exception will simply call an |
| 141 |
error message routine and then HALT. |
| 142 |
*) |
| 143 |
|
| 144 |
PROCEDURE BaseExceptionsThrow ; |
| 145 |
|
| 146 |
|
| 147 |
(* |
| 148 |
IsInExceptionState - returns TRUE if the program is currently |
| 149 |
in the exception state. |
| 150 |
*) |
| 151 |
|
| 152 |
PROCEDURE IsInExceptionState () : BOOLEAN ; |
| 153 |
|
| 154 |
|
| 155 |
(* |
| 156 |
SetExceptionState - returns the current exception state and |
| 157 |
then sets the current exception state to, |
| 158 |
to. |
| 159 |
*) |
| 160 |
|
| 161 |
PROCEDURE SetExceptionState (to: BOOLEAN) : BOOLEAN ; |
| 162 |
|
| 163 |
|
| 164 |
(* |
| 165 |
SwitchExceptionState - assigns, from, with the current exception |
| 166 |
state and then assigns the current exception |
| 167 |
to, to. |
| 168 |
*) |
| 169 |
|
| 170 |
PROCEDURE SwitchExceptionState (VAR from: BOOLEAN; to: BOOLEAN) ; |
| 171 |
|
| 172 |
|
| 173 |
(* |
| 174 |
GetBaseExceptionBlock - returns the initial language exception block |
| 175 |
created. |
| 176 |
*) |
| 177 |
|
| 178 |
PROCEDURE GetBaseExceptionBlock () : EHBlock ; |
| 179 |
|
| 180 |
|
| 181 |
(* |
| 182 |
SetExceptionSource - sets the current exception source to, source. |
| 183 |
*) |
| 184 |
|
| 185 |
PROCEDURE SetExceptionSource (source: ADDRESS) ; |
| 186 |
|
| 187 |
|
| 188 |
(* |
| 189 |
GetExceptionSource - returns the current exception source. |
| 190 |
*) |
| 191 |
|
| 192 |
PROCEDURE GetExceptionSource () : ADDRESS ; |
| 193 |
|
| 194 |
|
| 195 |
END RTExceptions. |