]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/m2/gm2-libs/M2EXCEPTION.mod
Update copyright years.
[thirdparty/gcc.git] / gcc / m2 / gm2-libs / M2EXCEPTION.mod
1 (* M2EXCEPTION.mod implement M2Exception and IsM2Exception.
2
3 Copyright (C) 2001-2024 Free Software Foundation, Inc.
4 Contributed by Gaius Mulley <gaius.mulley@southwales.ac.uk>.
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 IMPLEMENTATION MODULE M2EXCEPTION ;
28
29 FROM SYSTEM IMPORT ADR ;
30 FROM RTExceptions IMPORT EHBlock, GetExceptionBlock, GetNumber, Raise,
31 SetExceptionBlock, InitExceptionBlock ;
32
33
34 (* If the program or coroutine is in the exception state then return the enumeration
35 value representing the exception cause. If it is not in the exception state then
36 raises and exception (exException). *)
37
38 PROCEDURE M2Exception () : M2Exceptions;
39 VAR
40 e: EHBlock ;
41 n: CARDINAL ;
42 BEGIN
43 e := GetExceptionBlock () ;
44 n := GetNumber (e) ;
45 IF n = MAX (CARDINAL)
46 THEN
47 Raise (ORD (exException), ADR (__FILE__), __LINE__, __COLUMN__, ADR (__FUNCTION__),
48 ADR ('current coroutine is not in the exceptional execution state'))
49 ELSE
50 RETURN VAL (M2Exceptions, n)
51 END
52 END M2Exception ;
53
54
55 (* Returns TRUE if the program or coroutine is in the exception state.
56 Returns FALSE if the program or coroutine is not in the exception state. *)
57
58 PROCEDURE IsM2Exception () : BOOLEAN;
59 VAR
60 e: EHBlock ;
61 BEGIN
62 e := GetExceptionBlock () ;
63 RETURN GetNumber (e) # MAX (CARDINAL)
64 END IsM2Exception ;
65
66
67 BEGIN
68 SetExceptionBlock (InitExceptionBlock ())
69 END M2EXCEPTION.