| 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 except7 ; |
| 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 ip=NIL |
| 29 |
THEN |
| 30 |
THROW(1) |
| 31 |
END ; |
| 32 |
IF ip^=0 |
| 33 |
THEN |
| 34 |
THROW(2) |
| 35 |
END ; |
| 36 |
IF 4 DIV ip^ = 4 |
| 37 |
THEN |
| 38 |
printf("yes it worked\n") |
| 39 |
ELSE |
| 40 |
printf("no it failed\n") |
| 41 |
END |
| 42 |
END fly ; |
| 43 |
|
| 44 |
(* |
| 45 |
* a GNU M2 version of the Modula-2 example given in the ISO standard. |
| 46 |
* This is a hand translation of the equivalent except.c file in this |
| 47 |
* directory which is written to prove that the underlying runtime system |
| 48 |
* will work with the GCC builtin longjmp/set interpretation. |
| 49 |
*) |
| 50 |
|
| 51 |
PROCEDURE tryFlying ; |
| 52 |
BEGIN |
| 53 |
printf("tryFlying main body\n"); |
| 54 |
fly ; |
| 55 |
EXCEPT |
| 56 |
printf("inside tryFlying exception routine\n") ; |
| 57 |
IF (ip#NIL) AND (ip^=0) |
| 58 |
THEN |
| 59 |
printf("set value\n") ; |
| 60 |
ip^ := 1 ; |
| 61 |
RETRY |
| 62 |
END |
| 63 |
END tryFlying ; |
| 64 |
|
| 65 |
|
| 66 |
PROCEDURE keepFlying ; |
| 67 |
BEGIN |
| 68 |
printf("keepFlying main body\n") ; |
| 69 |
tryFlying ; |
| 70 |
EXCEPT |
| 71 |
printf("inside keepFlying exception routine\n") ; |
| 72 |
IF ip=NIL |
| 73 |
THEN |
| 74 |
printf("allocate memory\n") ; |
| 75 |
NEW(ip) ; |
| 76 |
ip^ := 0 ; |
| 77 |
RETRY |
| 78 |
END |
| 79 |
END keepFlying ; |
| 80 |
|
| 81 |
|
| 82 |
VAR |
| 83 |
ip: POINTER TO INTEGER ; |
| 84 |
BEGIN |
| 85 |
ip := NIL ; |
| 86 |
keepFlying ; |
| 87 |
printf("all done\n") |
| 88 |
END except7. |