1 /* do not edit automatically generated by mc from RTExceptions. */
2 /* RTExceptions.mod runtime exception handler routines.
4 Copyright (C) 2008-2024 Free Software Foundation, Inc.
5 Contributed by Gaius Mulley <gaius.mulley@southwales.ac.uk>.
7 This file is part of GNU Modula-2.
9 GNU Modula-2 is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3, or (at your option)
14 GNU Modula-2 is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 General Public License for more details.
19 Under Section 7 of GPL version 3, you are granted additional
20 permissions described in the GCC Runtime Library Exception, version
21 3.1, as published by the Free Software Foundation.
23 You should have received a copy of the GNU General Public License and
24 a copy of the GCC Runtime Library Exception along with this program;
25 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
26 <http://www.gnu.org/licenses/>. */
31 # if !defined (PROC_D)
33 typedef void (*PROC_t
) (void);
34 typedef struct { PROC_t proc
; } PROC
;
41 # include "GStorage.h"
44 extern void throw (unsigned int);
46 #if defined(__cplusplus)
50 #define _RTExceptions_C
52 #include "GRTExceptions.h"
55 # include "GStorage.h"
59 # include "GSysExceptions.h"
60 # include "GM2EXCEPTION.h"
62 typedef struct RTExceptions_ProcedureHandler_p RTExceptions_ProcedureHandler
;
64 # define MaxBuffer 4096
65 typedef struct RTExceptions__T1_r RTExceptions__T1
;
67 typedef char *RTExceptions_PtrToChar
;
69 typedef struct RTExceptions__T2_a RTExceptions__T2
;
71 typedef struct RTExceptions__T3_r RTExceptions__T3
;
73 typedef RTExceptions__T3
*RTExceptions_Handler
;
75 typedef RTExceptions__T1
*RTExceptions_EHBlock__opaque
;
77 struct RTExceptions__T2_a
{ char array
[MaxBuffer
+1]; };
78 struct RTExceptions__T1_r
{
79 RTExceptions__T2 buffer
;
81 RTExceptions_Handler handlers
;
82 RTExceptions_EHBlock__opaque right
;
85 struct RTExceptions__T3_r
{
86 RTExceptions_ProcedureHandler p
;
88 RTExceptions_Handler right
;
89 RTExceptions_Handler left
;
90 RTExceptions_Handler stack
;
93 static bool inException
;
94 static RTExceptions_Handler freeHandler
;
95 static RTExceptions_EHBlock__opaque freeEHB
;
96 static RTExceptions_EHBlock__opaque currentEHB
;
97 static void * currentSource
;
100 Raise - invoke the exception handler associated with, number,
101 in the active EHBlock. It keeps a record of the number
102 and message in the EHBlock for later use.
105 extern "C" void RTExceptions_Raise (unsigned int number
, void * file
, unsigned int line
, unsigned int column
, void * function
, void * message
) __attribute__ ((noreturn
));
108 SetExceptionBlock - sets, source, as the active EHB.
111 extern "C" void RTExceptions_SetExceptionBlock (RTExceptions_EHBlock source
);
114 GetExceptionBlock - returns the active EHB.
117 extern "C" RTExceptions_EHBlock
RTExceptions_GetExceptionBlock (void);
120 GetTextBuffer - returns the address of the EHB buffer.
123 extern "C" void * RTExceptions_GetTextBuffer (RTExceptions_EHBlock e
);
126 GetTextBufferSize - return the size of the EHB text buffer.
129 extern "C" unsigned int RTExceptions_GetTextBufferSize (RTExceptions_EHBlock e
);
132 GetNumber - return the exception number associated with,
136 extern "C" unsigned int RTExceptions_GetNumber (RTExceptions_EHBlock source
);
139 InitExceptionBlock - creates and returns a new exception block.
142 extern "C" RTExceptions_EHBlock
RTExceptions_InitExceptionBlock (void);
145 KillExceptionBlock - destroys the EHB, e, and all its handlers.
148 extern "C" RTExceptions_EHBlock
RTExceptions_KillExceptionBlock (RTExceptions_EHBlock e
);
151 PushHandler - install a handler in EHB, e.
154 extern "C" void RTExceptions_PushHandler (RTExceptions_EHBlock e
, unsigned int number
, RTExceptions_ProcedureHandler p
);
157 PopHandler - removes the handler associated with, number, from
161 extern "C" void RTExceptions_PopHandler (RTExceptions_EHBlock e
, unsigned int number
);
164 DefaultErrorCatch - displays the current error message in
165 the current exception block and then
169 extern "C" void RTExceptions_DefaultErrorCatch (void);
172 BaseExceptionsThrow - configures the Modula-2 exceptions to call
173 THROW which in turn can be caught by an
174 exception block. If this is not called then
175 a Modula-2 exception will simply call an
176 error message routine and then HALT.
179 extern "C" void RTExceptions_BaseExceptionsThrow (void);
182 IsInExceptionState - returns TRUE if the program is currently
183 in the exception state.
186 extern "C" bool RTExceptions_IsInExceptionState (void);
189 SetExceptionState - returns the current exception state and
190 then sets the current exception state to,
194 extern "C" bool RTExceptions_SetExceptionState (bool to
);
197 SwitchExceptionState - assigns, from, with the current exception
198 state and then assigns the current exception
202 extern "C" void RTExceptions_SwitchExceptionState (bool *from
, bool to
);
205 GetBaseExceptionBlock - returns the initial language exception block
209 extern "C" RTExceptions_EHBlock
RTExceptions_GetBaseExceptionBlock (void);
212 SetExceptionSource - sets the current exception source to, source.
215 extern "C" void RTExceptions_SetExceptionSource (void * source
);
218 GetExceptionSource - returns the current exception source.
221 extern "C" void * RTExceptions_GetExceptionSource (void);
224 ErrorString - writes a string to stderr.
227 static void ErrorString (const char *a_
, unsigned int _a_high
);
233 static RTExceptions_Handler
findHandler (RTExceptions_EHBlock__opaque e
, unsigned int number
);
236 InvokeHandler - invokes the associated handler for the current
237 exception in the active EHB.
240 static void InvokeHandler (void) __attribute__ ((noreturn
));
243 DoThrow - throw the exception number in the exception block.
246 static void DoThrow (void);
249 addChar - adds, ch, to the current exception handler text buffer
250 at index, i. The index in then incremented.
253 static void addChar (char ch
, unsigned int *i
);
256 stripPath - returns the filename from the path.
259 static void * stripPath (void * s
);
262 addFile - adds the filename determined by, s, however it strips
266 static void addFile (void * s
, unsigned int *i
);
269 addStr - adds a C string from address, s, into the current
273 static void addStr (void * s
, unsigned int *i
);
276 addNum - adds a number, n, to the current handler
280 static void addNum (unsigned int n
, unsigned int *i
);
283 New - returns a new EHBlock.
286 static RTExceptions_EHBlock__opaque
New (void);
289 NewHandler - returns a new handler.
292 static RTExceptions_Handler
NewHandler (void);
295 KillHandler - returns, NIL, and places, h, onto the free list.
298 static RTExceptions_Handler
KillHandler (RTExceptions_Handler h
);
301 KillHandlers - kills all handlers in the list.
304 static RTExceptions_Handler
KillHandlers (RTExceptions_Handler h
);
310 static RTExceptions_Handler
InitHandler (RTExceptions_Handler h
, RTExceptions_Handler l
, RTExceptions_Handler r
, RTExceptions_Handler s
, unsigned int number
, RTExceptions_ProcedureHandler proc
);
316 static void SubHandler (RTExceptions_Handler h
);
319 AddHandler - add, e, to the end of the list of handlers.
322 static void AddHandler (RTExceptions_EHBlock__opaque e
, RTExceptions_Handler h
);
325 indexf - raise an index out of bounds exception.
328 static void indexf (void * a
);
331 range - raise an assignment out of range exception.
334 static void range (void * a
);
337 casef - raise a case selector out of range exception.
340 static void casef (void * a
);
343 invalidloc - raise an invalid location exception.
346 static void invalidloc (void * a
);
349 function - raise a ... function ... exception. --fixme-- what does this exception catch?
352 static void function (void * a
);
355 wholevalue - raise an illegal whole value exception.
358 static void wholevalue (void * a
);
361 wholediv - raise a division by zero exception.
364 static void wholediv (void * a
);
367 realvalue - raise an illegal real value exception.
370 static void realvalue (void * a
);
373 realdiv - raise a division by zero in a real number exception.
376 static void realdiv (void * a
);
379 complexvalue - raise an illegal complex value exception.
382 static void complexvalue (void * a
);
385 complexdiv - raise a division by zero in a complex number exception.
388 static void complexdiv (void * a
);
391 protection - raise a protection exception.
394 static void protection (void * a
);
397 systemf - raise a system exception.
400 static void systemf (void * a
);
403 coroutine - raise a coroutine exception.
406 static void coroutine (void * a
);
409 exception - raise a exception exception.
412 static void exception (void * a
);
415 Init - initialises this module.
418 static void Init (void);
421 TidyUp - deallocate memory used by this module.
424 static void TidyUp (void);
428 ErrorString - writes a string to stderr.
431 static void ErrorString (const char *a_
, unsigned int _a_high
)
436 /* make a local copy of each unbounded array. */
437 memcpy (a
, a_
, _a_high
+1);
439 n
= static_cast<int> (libc_write (2, const_cast<void*> (static_cast<const void*>(a
)), static_cast<size_t> (StrLib_StrLen ((const char *) a
, _a_high
))));
447 static RTExceptions_Handler
findHandler (RTExceptions_EHBlock__opaque e
, unsigned int number
)
449 RTExceptions_Handler h
;
451 h
= e
->handlers
->right
;
452 while ((h
!= e
->handlers
) && (number
!= h
->n
))
456 if (h
== e
->handlers
)
464 /* static analysis guarentees a RETURN statement will be used before here. */
465 __builtin_unreachable ();
470 InvokeHandler - invokes the associated handler for the current
471 exception in the active EHB.
474 static void InvokeHandler (void)
476 RTExceptions_Handler h
;
478 h
= findHandler (currentEHB
, currentEHB
->number
);
481 throw (RTExceptions_GetNumber (RTExceptions_GetExceptionBlock ()));
487 __builtin_unreachable ();
493 DoThrow - throw the exception number in the exception block.
496 static void DoThrow (void)
498 throw (RTExceptions_GetNumber (RTExceptions_GetExceptionBlock ()));
503 addChar - adds, ch, to the current exception handler text buffer
504 at index, i. The index in then incremented.
507 static void addChar (char ch
, unsigned int *i
)
509 if (((*i
) <= MaxBuffer
) && (currentEHB
!= NULL
))
511 currentEHB
->buffer
.array
[(*i
)] = ch
;
518 stripPath - returns the filename from the path.
521 static void * stripPath (void * s
)
523 RTExceptions_PtrToChar f
;
524 RTExceptions_PtrToChar p
;
526 p
= static_cast<RTExceptions_PtrToChar
> (s
);
527 f
= static_cast<RTExceptions_PtrToChar
> (s
);
528 while ((*p
) != ASCII_nul
)
540 return static_cast<void *> (f
);
541 /* static analysis guarentees a RETURN statement will be used before here. */
542 __builtin_unreachable ();
547 addFile - adds the filename determined by, s, however it strips
551 static void addFile (void * s
, unsigned int *i
)
553 RTExceptions_PtrToChar p
;
555 p
= static_cast<RTExceptions_PtrToChar
> (stripPath (s
));
556 while ((p
!= NULL
) && ((*p
) != ASCII_nul
))
565 addStr - adds a C string from address, s, into the current
569 static void addStr (void * s
, unsigned int *i
)
571 RTExceptions_PtrToChar p
;
573 p
= static_cast<RTExceptions_PtrToChar
> (s
);
574 while ((p
!= NULL
) && ((*p
) != ASCII_nul
))
583 addNum - adds a number, n, to the current handler
587 static void addNum (unsigned int n
, unsigned int *i
)
591 addChar ( ((char) ((n
% 10)+ ((unsigned int) ('0')))), i
);
602 New - returns a new EHBlock.
605 static RTExceptions_EHBlock__opaque
New (void)
607 RTExceptions_EHBlock__opaque e
;
611 Storage_ALLOCATE ((void **) &e
, sizeof (RTExceptions__T1
));
616 freeEHB
= freeEHB
->right
;
619 /* static analysis guarentees a RETURN statement will be used before here. */
620 __builtin_unreachable ();
625 NewHandler - returns a new handler.
628 static RTExceptions_Handler
NewHandler (void)
630 RTExceptions_Handler h
;
632 if (freeHandler
== NULL
)
634 Storage_ALLOCATE ((void **) &h
, sizeof (RTExceptions__T3
));
639 freeHandler
= freeHandler
->right
;
642 /* static analysis guarentees a RETURN statement will be used before here. */
643 __builtin_unreachable ();
648 KillHandler - returns, NIL, and places, h, onto the free list.
651 static RTExceptions_Handler
KillHandler (RTExceptions_Handler h
)
653 h
->right
= freeHandler
;
656 /* static analysis guarentees a RETURN statement will be used before here. */
657 __builtin_unreachable ();
662 KillHandlers - kills all handlers in the list.
665 static RTExceptions_Handler
KillHandlers (RTExceptions_Handler h
)
667 h
->left
->right
= freeHandler
;
670 /* static analysis guarentees a RETURN statement will be used before here. */
671 __builtin_unreachable ();
679 static RTExceptions_Handler
InitHandler (RTExceptions_Handler h
, RTExceptions_Handler l
, RTExceptions_Handler r
, RTExceptions_Handler s
, unsigned int number
, RTExceptions_ProcedureHandler proc
)
687 /* static analysis guarentees a RETURN statement will be used before here. */
688 __builtin_unreachable ();
696 static void SubHandler (RTExceptions_Handler h
)
698 h
->right
->left
= h
->left
;
699 h
->left
->right
= h
->right
;
704 AddHandler - add, e, to the end of the list of handlers.
707 static void AddHandler (RTExceptions_EHBlock__opaque e
, RTExceptions_Handler h
)
709 h
->right
= e
->handlers
;
710 h
->left
= e
->handlers
->left
;
711 e
->handlers
->left
->right
= h
;
712 e
->handlers
->left
= h
;
717 indexf - raise an index out of bounds exception.
720 static void indexf (void * a
)
722 RTExceptions_Raise ( ((unsigned int) (M2EXCEPTION_indexException
)), const_cast<void*> (static_cast<const void*>("../../gcc/m2/gm2-libs/RTExceptions.mod")), 614, 9, const_cast<void*> (static_cast<const void*>("indexf")), const_cast<void*> (static_cast<const void*>("array index out of bounds")));
727 range - raise an assignment out of range exception.
730 static void range (void * a
)
732 RTExceptions_Raise ( ((unsigned int) (M2EXCEPTION_rangeException
)), const_cast<void*> (static_cast<const void*>("../../gcc/m2/gm2-libs/RTExceptions.mod")), 626, 9, const_cast<void*> (static_cast<const void*>("range")), const_cast<void*> (static_cast<const void*>("assignment out of range")));
737 casef - raise a case selector out of range exception.
740 static void casef (void * a
)
742 RTExceptions_Raise ( ((unsigned int) (M2EXCEPTION_caseSelectException
)), const_cast<void*> (static_cast<const void*>("../../gcc/m2/gm2-libs/RTExceptions.mod")), 638, 9, const_cast<void*> (static_cast<const void*>("casef")), const_cast<void*> (static_cast<const void*>("case selector out of range")));
747 invalidloc - raise an invalid location exception.
750 static void invalidloc (void * a
)
752 RTExceptions_Raise ( ((unsigned int) (M2EXCEPTION_invalidLocation
)), const_cast<void*> (static_cast<const void*>("../../gcc/m2/gm2-libs/RTExceptions.mod")), 650, 9, const_cast<void*> (static_cast<const void*>("invalidloc")), const_cast<void*> (static_cast<const void*>("invalid address referenced")));
757 function - raise a ... function ... exception. --fixme-- what does this exception catch?
760 static void function (void * a
)
762 RTExceptions_Raise ( ((unsigned int) (M2EXCEPTION_functionException
)), const_cast<void*> (static_cast<const void*>("../../gcc/m2/gm2-libs/RTExceptions.mod")), 662, 9, const_cast<void*> (static_cast<const void*>("function")), const_cast<void*> (static_cast<const void*>("... function ... "))); /* --fixme-- what has happened ? */
767 wholevalue - raise an illegal whole value exception.
770 static void wholevalue (void * a
)
772 RTExceptions_Raise ( ((unsigned int) (M2EXCEPTION_wholeValueException
)), const_cast<void*> (static_cast<const void*>("../../gcc/m2/gm2-libs/RTExceptions.mod")), 674, 9, const_cast<void*> (static_cast<const void*>("wholevalue")), const_cast<void*> (static_cast<const void*>("illegal whole value exception")));
777 wholediv - raise a division by zero exception.
780 static void wholediv (void * a
)
782 RTExceptions_Raise ( ((unsigned int) (M2EXCEPTION_wholeDivException
)), const_cast<void*> (static_cast<const void*>("../../gcc/m2/gm2-libs/RTExceptions.mod")), 686, 9, const_cast<void*> (static_cast<const void*>("wholediv")), const_cast<void*> (static_cast<const void*>("illegal whole value exception")));
787 realvalue - raise an illegal real value exception.
790 static void realvalue (void * a
)
792 RTExceptions_Raise ( ((unsigned int) (M2EXCEPTION_realValueException
)), const_cast<void*> (static_cast<const void*>("../../gcc/m2/gm2-libs/RTExceptions.mod")), 698, 9, const_cast<void*> (static_cast<const void*>("realvalue")), const_cast<void*> (static_cast<const void*>("illegal real value exception")));
797 realdiv - raise a division by zero in a real number exception.
800 static void realdiv (void * a
)
802 RTExceptions_Raise ( ((unsigned int) (M2EXCEPTION_realDivException
)), const_cast<void*> (static_cast<const void*>("../../gcc/m2/gm2-libs/RTExceptions.mod")), 710, 9, const_cast<void*> (static_cast<const void*>("realdiv")), const_cast<void*> (static_cast<const void*>("real number division by zero exception")));
807 complexvalue - raise an illegal complex value exception.
810 static void complexvalue (void * a
)
812 RTExceptions_Raise ( ((unsigned int) (M2EXCEPTION_complexValueException
)), const_cast<void*> (static_cast<const void*>("../../gcc/m2/gm2-libs/RTExceptions.mod")), 722, 9, const_cast<void*> (static_cast<const void*>("complexvalue")), const_cast<void*> (static_cast<const void*>("illegal complex value exception")));
817 complexdiv - raise a division by zero in a complex number exception.
820 static void complexdiv (void * a
)
822 RTExceptions_Raise ( ((unsigned int) (M2EXCEPTION_complexDivException
)), const_cast<void*> (static_cast<const void*>("../../gcc/m2/gm2-libs/RTExceptions.mod")), 734, 9, const_cast<void*> (static_cast<const void*>("complexdiv")), const_cast<void*> (static_cast<const void*>("complex number division by zero exception")));
827 protection - raise a protection exception.
830 static void protection (void * a
)
832 RTExceptions_Raise ( ((unsigned int) (M2EXCEPTION_protException
)), const_cast<void*> (static_cast<const void*>("../../gcc/m2/gm2-libs/RTExceptions.mod")), 746, 9, const_cast<void*> (static_cast<const void*>("protection")), const_cast<void*> (static_cast<const void*>("protection exception")));
837 systemf - raise a system exception.
840 static void systemf (void * a
)
842 RTExceptions_Raise ( ((unsigned int) (M2EXCEPTION_sysException
)), const_cast<void*> (static_cast<const void*>("../../gcc/m2/gm2-libs/RTExceptions.mod")), 758, 9, const_cast<void*> (static_cast<const void*>("systemf")), const_cast<void*> (static_cast<const void*>("system exception")));
847 coroutine - raise a coroutine exception.
850 static void coroutine (void * a
)
852 RTExceptions_Raise ( ((unsigned int) (M2EXCEPTION_coException
)), const_cast<void*> (static_cast<const void*>("../../gcc/m2/gm2-libs/RTExceptions.mod")), 770, 9, const_cast<void*> (static_cast<const void*>("coroutine")), const_cast<void*> (static_cast<const void*>("coroutine exception")));
857 exception - raise a exception exception.
860 static void exception (void * a
)
862 RTExceptions_Raise ( ((unsigned int) (M2EXCEPTION_exException
)), const_cast<void*> (static_cast<const void*>("../../gcc/m2/gm2-libs/RTExceptions.mod")), 782, 9, const_cast<void*> (static_cast<const void*>("exception")), const_cast<void*> (static_cast<const void*>("exception exception")));
867 Init - initialises this module.
870 static void Init (void)
874 freeEHB
= static_cast<RTExceptions_EHBlock__opaque
> (NULL
);
875 currentEHB
= static_cast<RTExceptions_EHBlock__opaque
> (RTExceptions_InitExceptionBlock ());
876 currentSource
= NULL
;
877 RTExceptions_BaseExceptionsThrow ();
878 SysExceptions_InitExceptionHandlers ((SysExceptions_PROCEXCEPTION
) {(SysExceptions_PROCEXCEPTION_t
) indexf
}, (SysExceptions_PROCEXCEPTION
) {(SysExceptions_PROCEXCEPTION_t
) range
}, (SysExceptions_PROCEXCEPTION
) {(SysExceptions_PROCEXCEPTION_t
) casef
}, (SysExceptions_PROCEXCEPTION
) {(SysExceptions_PROCEXCEPTION_t
) invalidloc
}, (SysExceptions_PROCEXCEPTION
) {(SysExceptions_PROCEXCEPTION_t
) function
}, (SysExceptions_PROCEXCEPTION
) {(SysExceptions_PROCEXCEPTION_t
) wholevalue
}, (SysExceptions_PROCEXCEPTION
) {(SysExceptions_PROCEXCEPTION_t
) wholediv
}, (SysExceptions_PROCEXCEPTION
) {(SysExceptions_PROCEXCEPTION_t
) realvalue
}, (SysExceptions_PROCEXCEPTION
) {(SysExceptions_PROCEXCEPTION_t
) realdiv
}, (SysExceptions_PROCEXCEPTION
) {(SysExceptions_PROCEXCEPTION_t
) complexvalue
}, (SysExceptions_PROCEXCEPTION
) {(SysExceptions_PROCEXCEPTION_t
) complexdiv
}, (SysExceptions_PROCEXCEPTION
) {(SysExceptions_PROCEXCEPTION_t
) protection
}, (SysExceptions_PROCEXCEPTION
) {(SysExceptions_PROCEXCEPTION_t
) systemf
}, (SysExceptions_PROCEXCEPTION
) {(SysExceptions_PROCEXCEPTION_t
) coroutine
}, (SysExceptions_PROCEXCEPTION
) {(SysExceptions_PROCEXCEPTION_t
) exception
});
883 TidyUp - deallocate memory used by this module.
886 static void TidyUp (void)
888 RTExceptions_Handler f
;
889 RTExceptions_EHBlock__opaque e
;
891 if (currentEHB
!= NULL
)
893 currentEHB
= static_cast<RTExceptions_EHBlock__opaque
> (RTExceptions_KillExceptionBlock (static_cast<RTExceptions_EHBlock
> (currentEHB
)));
895 while (freeHandler
!= NULL
)
898 freeHandler
= freeHandler
->right
;
899 Storage_DEALLOCATE ((void **) &f
, sizeof (RTExceptions__T3
));
901 while (freeEHB
!= NULL
)
904 freeEHB
= freeEHB
->right
;
905 Storage_DEALLOCATE ((void **) &e
, sizeof (RTExceptions__T1
));
911 Raise - invoke the exception handler associated with, number,
912 in the active EHBlock. It keeps a record of the number
913 and message in the EHBlock for later use.
916 extern "C" void RTExceptions_Raise (unsigned int number
, void * file
, unsigned int line
, unsigned int column
, void * function
, void * message
)
920 currentEHB
->number
= number
;
932 addStr (function
, &i
);
933 addChar (ASCII_nl
, &i
);
940 addStr (message
, &i
);
941 addChar (ASCII_nl
, &i
);
942 addChar (ASCII_nul
, &i
);
948 SetExceptionBlock - sets, source, as the active EHB.
951 extern "C" void RTExceptions_SetExceptionBlock (RTExceptions_EHBlock source
)
953 currentEHB
= static_cast<RTExceptions_EHBlock__opaque
> (source
);
958 GetExceptionBlock - returns the active EHB.
961 extern "C" RTExceptions_EHBlock
RTExceptions_GetExceptionBlock (void)
963 return static_cast<RTExceptions_EHBlock
> (currentEHB
);
964 /* static analysis guarentees a RETURN statement will be used before here. */
965 __builtin_unreachable ();
970 GetTextBuffer - returns the address of the EHB buffer.
973 extern "C" void * RTExceptions_GetTextBuffer (RTExceptions_EHBlock e
)
975 return &static_cast<RTExceptions_EHBlock__opaque
> (e
)->buffer
;
976 /* static analysis guarentees a RETURN statement will be used before here. */
977 __builtin_unreachable ();
982 GetTextBufferSize - return the size of the EHB text buffer.
985 extern "C" unsigned int RTExceptions_GetTextBufferSize (RTExceptions_EHBlock e
)
987 return sizeof (static_cast<RTExceptions_EHBlock__opaque
> (e
)->buffer
);
988 /* static analysis guarentees a RETURN statement will be used before here. */
989 __builtin_unreachable ();
994 GetNumber - return the exception number associated with,
998 extern "C" unsigned int RTExceptions_GetNumber (RTExceptions_EHBlock source
)
1000 return static_cast<RTExceptions_EHBlock__opaque
> (source
)->number
;
1001 /* static analysis guarentees a RETURN statement will be used before here. */
1002 __builtin_unreachable ();
1007 InitExceptionBlock - creates and returns a new exception block.
1010 extern "C" RTExceptions_EHBlock
RTExceptions_InitExceptionBlock (void)
1012 RTExceptions_EHBlock__opaque e
;
1015 e
->number
= UINT_MAX
;
1016 e
->handlers
= NewHandler (); /* add the dummy onto the head */
1017 e
->handlers
->right
= e
->handlers
; /* add the dummy onto the head */
1018 e
->handlers
->left
= e
->handlers
;
1020 return static_cast<RTExceptions_EHBlock
> (e
);
1021 /* static analysis guarentees a RETURN statement will be used before here. */
1022 __builtin_unreachable ();
1027 KillExceptionBlock - destroys the EHB, e, and all its handlers.
1030 extern "C" RTExceptions_EHBlock
RTExceptions_KillExceptionBlock (RTExceptions_EHBlock e
)
1032 static_cast<RTExceptions_EHBlock__opaque
> (e
)->handlers
= KillHandlers (static_cast<RTExceptions_EHBlock__opaque
> (e
)->handlers
);
1033 static_cast<RTExceptions_EHBlock__opaque
> (e
)->right
= freeEHB
;
1034 freeEHB
= static_cast<RTExceptions_EHBlock__opaque
> (e
);
1035 return static_cast<RTExceptions_EHBlock
> (NULL
);
1036 /* static analysis guarentees a RETURN statement will be used before here. */
1037 __builtin_unreachable ();
1042 PushHandler - install a handler in EHB, e.
1045 extern "C" void RTExceptions_PushHandler (RTExceptions_EHBlock e
, unsigned int number
, RTExceptions_ProcedureHandler p
)
1047 RTExceptions_Handler h
;
1048 RTExceptions_Handler i
;
1050 h
= findHandler (static_cast<RTExceptions_EHBlock__opaque
> (e
), number
);
1053 i
= InitHandler (NewHandler (), NULL
, NULL
, NULL
, number
, p
);
1059 /* stack it onto a new handler */
1060 i
= InitHandler (NewHandler (), NULL
, NULL
, h
, number
, p
);
1062 /* add new handler */
1063 AddHandler (static_cast<RTExceptions_EHBlock__opaque
> (e
), i
);
1068 PopHandler - removes the handler associated with, number, from
1072 extern "C" void RTExceptions_PopHandler (RTExceptions_EHBlock e
, unsigned int number
)
1074 RTExceptions_Handler h
;
1076 h
= findHandler (static_cast<RTExceptions_EHBlock__opaque
> (e
), number
);
1081 if (h
->stack
!= NULL
)
1083 AddHandler (static_cast<RTExceptions_EHBlock__opaque
> (e
), h
->stack
);
1085 h
= KillHandler (h
);
1091 DefaultErrorCatch - displays the current error message in
1092 the current exception block and then
1096 extern "C" void RTExceptions_DefaultErrorCatch (void)
1098 RTExceptions_EHBlock__opaque e
;
1101 e
= static_cast<RTExceptions_EHBlock__opaque
> (RTExceptions_GetExceptionBlock ());
1102 n
= static_cast<int> (libc_write (2, RTExceptions_GetTextBuffer (static_cast<RTExceptions_EHBlock
> (e
)), libc_strlen (RTExceptions_GetTextBuffer (static_cast<RTExceptions_EHBlock
> (e
)))));
1104 __builtin_unreachable ();
1109 BaseExceptionsThrow - configures the Modula-2 exceptions to call
1110 THROW which in turn can be caught by an
1111 exception block. If this is not called then
1112 a Modula-2 exception will simply call an
1113 error message routine and then HALT.
1116 extern "C" void RTExceptions_BaseExceptionsThrow (void)
1118 M2EXCEPTION_M2Exceptions i
;
1120 for (i
=M2EXCEPTION_indexException
; i
<=M2EXCEPTION_exException
; i
= static_cast<M2EXCEPTION_M2Exceptions
>(static_cast<int>(i
+1)))
1122 RTExceptions_PushHandler (RTExceptions_GetExceptionBlock (), (unsigned int ) (i
), (RTExceptions_ProcedureHandler
) {(RTExceptions_ProcedureHandler_t
) DoThrow
});
1128 IsInExceptionState - returns TRUE if the program is currently
1129 in the exception state.
1132 extern "C" bool RTExceptions_IsInExceptionState (void)
1135 /* static analysis guarentees a RETURN statement will be used before here. */
1136 __builtin_unreachable ();
1141 SetExceptionState - returns the current exception state and
1142 then sets the current exception state to,
1146 extern "C" bool RTExceptions_SetExceptionState (bool to
)
1153 /* static analysis guarentees a RETURN statement will be used before here. */
1154 __builtin_unreachable ();
1159 SwitchExceptionState - assigns, from, with the current exception
1160 state and then assigns the current exception
1164 extern "C" void RTExceptions_SwitchExceptionState (bool *from
, bool to
)
1166 (*from
) = inException
;
1172 GetBaseExceptionBlock - returns the initial language exception block
1176 extern "C" RTExceptions_EHBlock
RTExceptions_GetBaseExceptionBlock (void)
1178 if (currentEHB
== NULL
)
1180 M2RTS_Halt ((const char *) "currentEHB has not been initialized yet", 39, (const char *) "../../gcc/m2/gm2-libs/RTExceptions.mod", 38, (const char *) "GetBaseExceptionBlock", 21, 600);
1184 return static_cast<RTExceptions_EHBlock
> (currentEHB
);
1186 ReturnException ("../../gcc/m2/gm2-libs/RTExceptions.def", 25, 1);
1187 __builtin_unreachable ();
1192 SetExceptionSource - sets the current exception source to, source.
1195 extern "C" void RTExceptions_SetExceptionSource (void * source
)
1197 currentSource
= source
;
1202 GetExceptionSource - returns the current exception source.
1205 extern "C" void * RTExceptions_GetExceptionSource (void)
1207 return currentSource
;
1208 /* static analysis guarentees a RETURN statement will be used before here. */
1209 __builtin_unreachable ();
1212 extern "C" void _M2_RTExceptions_init (__attribute__((unused
)) int argc
, __attribute__((unused
)) char *argv
[], __attribute__((unused
)) char *envp
[])
1217 extern "C" void _M2_RTExceptions_fini (__attribute__((unused
)) int argc
, __attribute__((unused
)) char *argv
[], __attribute__((unused
)) char *envp
[])