Debian Codegraph @

gcc/testsuite/gm2/iso/run/pass/except4.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 except4 ;
19
20 FROM libc IMPORT printf ;
21 FROM Storage IMPORT ALLOCATE, DEALLOCATE ;
22 FROM SYSTEM IMPORT ADR, WORD ;
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 * 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 builtin longjmp/set interpretation.
41 *)
42
43 PROCEDURE tryFlying ;
44 BEGIN
45 printf("tryFlying main body\n");
46 fly ;
47 EXCEPT
48 printf("inside tryFlying exception routine\n") ;
49 IF ip=NIL
50 THEN
51 NEW(ip) ;
52 ip^ := 0 ;
53 RETRY
54 END ;
55 IF ip^=0
56 THEN
57 ip^ := 1 ;
58 RETRY
59 END
60 END tryFlying ;
61
62 VAR
63 ip: POINTER TO INTEGER ;
64 BEGIN
65 ip := NIL ;
66 tryFlying ;
67 printf("all done\n")
68 END except4.