Debian Codegraph @

gcc/testsuite/gm2/exceptions/run/pass/libexcept.mod

raw
1 (* Copyright (C) 2008 Free Software Foundation, Inc. *)
2 (* This file is part of GNU Modula-2.
3
4 GNU Modula-2 is free software; you can redistribute it and/or modify it under
5 the terms of the GNU General Public License as published by the Free
6 Software Foundation; either version 2, or (at your option) any later
7 version.
8
9 GNU Modula-2 is distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 for more details.
13
14 You should have received a copy of the GNU General Public License along
15 with gm2; see the file COPYING. If not, write to the Free Software
16 Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *)
17
18 MODULE libexcept ;
19
20
21 FROM libc IMPORT exit, write, exit, printf ;
22 FROM ASCII IMPORT nul, nl ;
23 FROM SYSTEM IMPORT ADR, THROW ;
24 FROM M2RTS IMPORT Length ;
25 FROM NumberIO IMPORT CardToStr ;
26 FROM RTExceptions IMPORT IsInExceptionState ;
27
28
29 PROCEDURE Assert (c: BOOLEAN; line: CARDINAL; column: CARDINAL;
30 message: ARRAY OF CHAR) ;
31 VAR
32 r: INTEGER ;
33 a: ARRAY [0..10] OF CHAR ;
34 BEGIN
35 IF NOT c
36 THEN
37 r := write(2, ADR(__FILE__), Length(__FILE__)) ;
38 r := write(2, ADR(": "), Length(":")) ;
39 CardToStr(line, 0, a) ;
40 r := write(2, ADR(a), Length(a)) ;
41 r := write(2, ADR(": "), Length(":")) ;
42 CardToStr(column, 0, a) ;
43 r := write(2, ADR(a), Length(a)) ;
44 r := write(2, ADR(": "), Length(":")) ;
45 r := write(2, ADR(message), Length(message)) ;
46 a[0] := nl ;
47 a[1] := nul ;
48 r := write(2, ADR(a), Length(a)) ;
49 e := 1
50 END
51 END Assert ;
52
53 VAR
54 e, r: INTEGER ;
55 BEGIN
56 Assert(NOT IsInExceptionState(), __LINE__, __COLUMN__, "should not be in the exception state") ;
57 THROW(1) ;
58 exit(1)
59 EXCEPT
60 Assert(IsInExceptionState(), __LINE__, __COLUMN__, "should be in the exception state") ;
61 r := printf("correctly in exception handler, about to exit with code %d\n", e) ;
62 exit(e)
63 END libexcept.