Debian Codegraph @

gcc/testsuite/gm2/iso/run/pass/except8.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 except8 ;
19
20 FROM libc IMPORT printf ;
21 FROM Storage IMPORT ALLOCATE, DEALLOCATE ;
22 FROM SYSTEM IMPORT ADR, WORD, THROW ;
23
24
25 PROCEDURE fly ;
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 *)
39
40 PROCEDURE tryFlying ;
41 BEGIN
42 printf("tryFlying main body\n");
43 fly ;
44 EXCEPT
45 printf("inside tryFlying exception routine\n") ;
46 IF (ip#NIL) AND (ip^=0)
47 THEN
48 printf("set value\n") ;
49 ip^ := 1 ;
50 RETRY
51 END
52 END tryFlying ;
53
54
55 PROCEDURE keepFlying ;
56 BEGIN
57 printf("keepFlying main body\n") ;
58 tryFlying ;
59 EXCEPT
60 printf("inside keepFlying exception routine\n") ;
61 IF ip=NIL
62 THEN
63 printf("allocate memory\n") ;
64 NEW(ip) ;
65 ip^ := 0 ;
66 RETRY
67 END
68 END keepFlying ;
69
70
71 VAR
72 ip: POINTER TO INTEGER ;
73 BEGIN
74 ip := NIL ;
75 keepFlying ;
76 printf("all done\n")
77 END except8.