]>
gcc.gnu.org Git - gcc.git/blob - libchill/exh.c
1 /* Implement runtime actions for CHILL.
2 Copyright (C) 1992,1993 Free Software Foundation, Inc.
5 This file is part of GNU CC.
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
22 /* As a special exception, if you link this library with other files,
23 some of which are compiled with GCC, to produce an executable,
24 this library does not by itself cause the resulting executable
25 to be covered by the GNU General Public License.
26 This exception does not however invalidate any other reasons why
27 the executable file might be covered by the GNU General Public License. */
36 extern void cause_exception (char *exname
, char *file
, int lineno
, int user_arg
);
37 extern void unhandled_exception (char *exname
, char *file
, int lineno
, int user_arg
);
39 /* An action with a handler:
40 BODY ON (e1, e2): H12; (e3): H3; ELSE HE; END;
43 struct __ch_handler __tmp;
44 static struct __ch_handler_excepts _H[4] =
49 { __ch_else_except, 3 },
51 __ch_link_handler(&__tmp);
53 switch (setmp(&__tmp.jbuf))
55 case 0: BODY; __ch_unlink_handler(&__tmp); break;
62 /* this part contains all neccessary functions to handle exceptions in CHILL */
64 /* These two trivial function aren't inlines, to allow for
65 more flexibility (e.g. a per-thread exception stack). */
67 extern void __setexceptionStack (TExceptionHandlerStack
*new);
68 extern TExceptionHandlerStack
* __getexceptionStack (void);
71 __ch_link_handler (handler
)
72 struct __ch_handler
*handler
;
74 handler
->prev
= __getexceptionStack ();
75 __setexceptionStack (handler
);
79 __ch_unlink_handler (handler
)
80 struct __ch_handler
*handler
;
82 __setexceptionStack (handler
->prev
);
86 * function __cause_exception
89 * exnum name string of exception to raise
90 * file filename of CAUSE statement
91 * lineno linenumber of CAUSE statement
92 * user_arg user specified argument
95 * never leave function with longjmp or abort
98 * search exceptionstack for last handler of caused exception,
99 * call userdefined function to signal exception,
100 * jump to handler with longjmp or call unhandled_exception
105 __cause_exception (ex
, file
, lineno
, user_arg
)
111 register struct __ch_handler
*handler
= __getexceptionStack();
113 /* call user defined cause function */
114 cause_exception (ex
, file
, lineno
, user_arg
);
116 for ( ; handler
!= NULL
; handler
= handler
->prev
)
118 register struct __ch_handled_excepts
*list
= handler
->handlers
;
119 for ( ; list
->code
!= 0; list
++ )
121 if (list
->ex
== __ch_else_except
|| EX_EQ(list
->ex
, ex
)) /* found */
123 __setexceptionStack (handler
->prev
);
124 longjmp(handler
->jbuf
, list
->code
);
129 /* no handler found -- call unhandled_exception */
130 unhandled_exception (ex
, file
, lineno
, user_arg
);
135 * function __cause_ex1
138 * exnum name string of exception to raise
139 * file filename of CAUSE statement
140 * lineno linenumber of CAUSE statement
143 * never leave function with longjmp or abort
146 * This is the function the compiler generated code calls.
147 * Search exceptionstack for last handler of caused exception,
148 * call userdefined function to signal exception,
149 * jump to handler with longjmp or call unhandled_exception
154 __cause_ex1 (ex
, file
, lineno
)
159 __cause_exception (ex
, file
, lineno
, 0);
This page took 0.043142 seconds and 5 git commands to generate.