Subversion Repositories tendra.SVN

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
6 7u83 1
/*
2
    		 Crown Copyright (c) 1997
3
 
4
    This TenDRA(r) Computer Program is subject to Copyright
5
    owned by the United Kingdom Secretary of State for Defence
6
    acting through the Defence Evaluation and Research Agency
7
    (DERA).  It is made available to Recipients with a
8
    royalty-free licence for its use, reproduction, transfer
9
    to other parties and amendment for any purpose not excluding
10
    product development provided that any such use et cetera
11
    shall be deemed to be acceptance of the following conditions:-
12
 
13
        (1) Its Recipients shall ensure that this Notice is
14
        reproduced upon any copies or amended versions of it;
15
 
16
        (2) Any amended version of it shall be clearly marked to
17
        show both the nature of and the organisation responsible
18
        for the relevant amendment or amendments;
19
 
20
        (3) Its onward transfer from a recipient to another
21
        party shall be deemed to be that party's acceptance of
22
        these conditions;
23
 
24
        (4) DERA gives no warranty or assurance as to its
25
        quality or suitability for any purpose and DERA accepts
26
        no liability whatsoever in relation to any use to which
27
        it may be put.
28
*/
29
 
30
 
31
/* This module gives possible definitions for Throw for single process
32
   error handling. In addition it gives a definition of the token TRY where:
33
   TRY(body, ev, handler) delivers the result of body if no exceptions occur;
34
   delivers the result of handler if the first exception in body has
35
   error_code ev; otherwise Throws ev to an outer context.
36
*/
37
 
38
Var handler_place:pointer(code_alignment);
39
	/* The label of the highest exception handler */
40
Var handler_env: pointer(unite_alignments(locals_alignment,
41
			callers_alignment(true)));
42
	/* the environment of the highest exception handler */
43
Var except_val: Int;
44
	/* The thrown exception value - just take it be an int */
45
 
46
 
47
 
48
Tokdef Throw = [err_val:NAT]EXP
49
{	
50
	except_val = + err_val(Int);
51
	long_jump( * handler_env, * handler_place)
52
};
53
 
54
Tokdef TRY = [body:EXP, err_val:NAT, handler:EXP]EXP
55
Let ohp = * handler_place
56
Let ohe = * handler_env
57
	/* stack old exception handler */
58
Labelled {
59
	handler_place = make_local_lv(place);
60
	handler_env = current_env;
61
	Let x = body
62
	{ handler_place = ohp;  handler_env = ohe;
63
	  	/* reinstate old exception handler on successful body */	
64
	  x
65
	 }
66
       | :place:
67
        ?{ handler_place = ohp;  handler_env = ohe;
68
        	/* reinstate old exception handler on exceptional body */	
69
           ?(* except_val == + err_val(Int));
70
           	/* is it the right exception? ... */
71
           handler
72
           	/* ... then do handler */
73
         | long_jump(ohp, ohe)
74
         	/* otherwise re-throw the exception */
75
         }
76
};
77
 
78
Keep ( handler_place, handler_env, Throw, TRY, except_val )