1 #ifndef SCM_THROW_H
2 #define SCM_THROW_H
3 
4 /* Copyright 1995-1996,1998,2000,2006,2008,2010,2014,2017-2019
5      Free Software Foundation, Inc.
6 
7    This file is part of Guile.
8 
9    Guile is free software: you can redistribute it and/or modify it
10    under the terms of the GNU Lesser General Public License as published
11    by the Free Software Foundation, either version 3 of the License, or
12    (at your option) any later version.
13 
14    Guile is distributed in the hope that it will be useful, but WITHOUT
15    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
17    License for more details.
18 
19    You should have received a copy of the GNU Lesser General Public
20    License along with Guile.  If not, see
21    <https://www.gnu.org/licenses/>.  */
22 
23 
24 
25 #include "libguile/scm.h"
26 #include "libguile/exceptions.h"
27 
28 
29 
30 typedef scm_t_thunk scm_t_catch_body;
31 typedef SCM (*scm_t_catch_handler) (void *data,
32                                     SCM tag, SCM throw_args);
33 
34 SCM_INTERNAL SCM scm_i_make_catch_handler (scm_t_catch_handler h, void *data);
35 
36 SCM_API SCM scm_c_catch (SCM tag,
37 			 scm_t_catch_body body,
38 			 void *body_data,
39 			 scm_t_catch_handler handler,
40 			 void *handler_data,
41 			 scm_t_catch_handler pre_unwind_handler,
42 			 void *pre_unwind_handler_data);
43 
44 SCM_API SCM scm_c_with_throw_handler (SCM tag,
45 				      scm_t_catch_body body,
46 				      void *body_data,
47 				      scm_t_catch_handler handler,
48 				      void *handler_data,
49 				      int lazy_catch_p);
50 
51 SCM_API SCM scm_internal_catch (SCM tag,
52 				scm_t_catch_body body,
53 				void *body_data,
54 				scm_t_catch_handler handler,
55 				void *handler_data);
56 
57 /* The first argument to scm_body_thunk should be a pointer to one of
58    these.  See the implementation of catch in throw.c.  */
59 struct scm_body_thunk_data
60 {
61   /* The tag being caught.  We only use it to figure out what
62      arguments to pass to the body procedure; see scm_catch_thunk_body for
63      details.  */
64   SCM tag;
65 
66   /* The Scheme procedure object constituting the catch body.
67      scm_body_by_proc invokes this.  */
68   SCM body_proc;
69 };
70 
71 SCM_API SCM scm_body_thunk (void *);
72 
73 
74 SCM_API SCM scm_handle_by_proc (void *, SCM, SCM);
75 SCM_API SCM scm_handle_by_proc_catching_all (void *, SCM, SCM);
76 SCM_API SCM scm_handle_by_message (void *, SCM, SCM);
77 SCM_API SCM scm_handle_by_message_noexit (void *, SCM, SCM);
78 SCM_API SCM scm_handle_by_throw (void *, SCM, SCM);
79 SCM_API int scm_exit_status (SCM args);
80 
81 SCM_API SCM scm_catch_with_pre_unwind_handler (SCM tag, SCM thunk, SCM handler, SCM lazy_handler);
82 SCM_API SCM scm_catch (SCM tag, SCM thunk, SCM handler);
83 SCM_API SCM scm_with_throw_handler (SCM tag, SCM thunk, SCM handler);
84 SCM_API SCM scm_ithrow (SCM key, SCM args, int no_return) SCM_NORETURN;
85 
86 SCM_API SCM scm_throw (SCM key, SCM args) SCM_NORETURN;
87 SCM_INTERNAL void scm_init_throw (void);
88 
89 #endif  /* SCM_THROW_H */
90