Debian Codegraph @

gcc/testsuite/gm2/iso/run/pass/except9.mod

raw
1 (* Copyright (C) 2025 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 except9 ;
19
20 FROM libc IMPORT printf ;
21 FROM Storage IMPORT ALLOCATE, DEALLOCATE ;
22 FROM SYSTEM IMPORT ADR, WORD ;
23
24
25 PROCEDURE fly (debug: BOOLEAN) ;
26 BEGIN
27 printf("fly main body\n") ;
28 IF 4 DIV ip^ = 4
29 THEN
30 printf("yes it worked\n")
31 ELSE
32 printf("no it failed\n")
33 END
34 END fly ;
35
36 (*
37 * a GNU M2 version of the Modula-2 example given in the ISO standard.
38 * This is a hand translation of the equivalent except.c file in this
39 * directory which is written to prove that the underlying runtime system
40 * will work with the GCC exception handling trees.
41 *)
42
43 PROCEDURE tryFlying (debug: BOOLEAN) ;
44 BEGIN
45 printf("tryFlying main body\n");
46 fly (debug) ;
47 EXCEPT
48 printf("inside tryFlying exception routine\n") ;
49 IF (ip#NIL) AND (ip^=0)
50 THEN
51 ip^ := 1 ;
52 RETRY
53 END
54 END tryFlying ;
55
56
57 PROCEDURE keepFlying (debug: BOOLEAN) ;
58 BEGIN
59 printf("keepFlying main body\n") ;
60 tryFlying (debug) ;
61 EXCEPT
62 printf("inside keepFlying exception routine\n") ;
63 IF ip=NIL
64 THEN
65 NEW(ip) ;
66 ip^ := 0 ;
67 RETRY
68 END
69 END keepFlying ;
70
71
72 VAR
73 ip: POINTER TO INTEGER ;
74 BEGIN
75 ip := NIL ;
76 keepFlying (FALSE) ;
77 printf("all done\n")
78 END except9.