OSDN Git Service

* config/i386/i386.c (internal_label_prefix): New.
[pf3gnuchains/gcc-fork.git] / libchill / exh.c
1 /* Implement runtime actions for CHILL.
2    Copyright (C) 1992,1993 Free Software Foundation, Inc.
3    Author: Wilfried Moser
4
5 This file is part of GNU CC.
6
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)
10 any later version.
11
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.
16
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.  */
21
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.  */
28
29
30 #define __CHILL_LIB__
31
32 #include <stdio.h>
33 #include <stdlib.h>
34 #include <string.h>
35 #include <setjmp.h>
36 #include "rtltypes.h"
37
38 extern void cause_exception (char *exname, char *file, int lineno, int user_arg);
39 extern void unhandled_exception (char *exname, char *file, int lineno, int user_arg);
40
41 /* An action with a handler:
42         BODY ON (e1, e2): H12; (e3): H3; ELSE HE; END;
43    is translated into:
44
45     struct __ch_handler __tmp;
46     static struct __ch_handler_excepts _H[4] =
47       {
48         { <<e1>>, 1 },
49         { <<e2>>, 1 },
50         { <<e3>>, 2 },
51         { __ch_else_except, 3 },
52       };
53     __ch_link_handler(&__tmp);
54     __tmp.handlers = _H;
55     switch (setmp(&__tmp.jbuf))
56       { 
57       case 0:  BODY; __ch_unlink_handler(&__tmp); break;
58       case 1:  H12; break;
59       case 2:  H3; break;
60       case 3:  HE; break;
61       }
62 */
63
64 /* this part contains all neccessary functions to handle exceptions in CHILL */
65
66 /* These two trivial function aren't inlines, to allow for
67    more flexibility (e.g. a per-thread exception stack). */
68
69 extern void __setexceptionStack (TExceptionHandlerStack *new);
70 extern TExceptionHandlerStack * __getexceptionStack (void);
71
72 void
73 __ch_link_handler (handler)
74      struct __ch_handler *handler;
75 {
76   handler->prev = __getexceptionStack ();
77   __setexceptionStack (handler);
78 }
79
80  void
81 __ch_unlink_handler (handler)
82      struct __ch_handler *handler;
83 {
84   __setexceptionStack (handler->prev);
85 }
86
87 /*
88  * function __cause_exception
89  *
90  * parameters:
91  *  exnum               name string of exception to raise
92  *  file                filename of CAUSE statement
93  *  lineno              linenumber of CAUSE statement
94  *  user_arg            user specified argument
95  *
96  * returns:
97  *  never               leave function with longjmp or abort
98  *
99  * abstract:
100  *  search exceptionstack for last handler of caused exception,
101  *  call userdefined function to signal exception,
102  *  jump to handler with longjmp or call unhandled_exception
103  *
104  */
105
106 void
107 __cause_exception  (ex, file, lineno, user_arg)
108      char *ex;
109      char *file;
110      int  lineno;
111      int user_arg;
112 {
113   register struct __ch_handler *handler = __getexceptionStack();
114
115   /* call user defined cause function */
116   cause_exception (ex, file, lineno, user_arg);
117   
118   for ( ; handler != NULL; handler = handler->prev)
119     {
120       register struct __ch_handled_excepts *list = handler->handlers;
121       for ( ; list->code != 0; list++ )
122         {
123           if (list->ex == __ch_else_except || EX_EQ(list->ex, ex)) /* found */
124             {
125               __setexceptionStack (handler->prev);
126               longjmp(handler->jbuf, list->code);         
127             }
128         }
129     }
130
131   /* no handler found -- call unhandled_exception */
132   unhandled_exception (ex, file, lineno, user_arg);
133   abort ();
134 }
135
136 /*
137  * function __cause_ex1
138  *
139  * parameters:
140  *  exnum               name string of exception to raise
141  *  file                filename of CAUSE statement
142  *  lineno              linenumber of CAUSE statement
143  *
144  * returns:
145  *  never               leave function with longjmp or abort
146  *
147  * abstract:
148  *  This is the function the compiler generated code calls.
149  *  Search exceptionstack for last handler of caused exception,
150  *  call userdefined function to signal exception,
151  *  jump to handler with longjmp or call unhandled_exception
152  *
153  */
154
155 void
156 __cause_ex1  (ex, file, lineno)
157      char *ex;
158      char *file;
159      int  lineno;
160 {
161   __cause_exception (ex, file, lineno, 0);
162 }