Changed license terms to the plain LGPL thru-out.
[bpt/guile.git] / libguile / throw.c
1 /* Copyright (C) 1995,1996,1997,1998,2000,2001 Free Software Foundation, Inc.
2 *
3 * This library is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU Lesser General Public
5 * License as published by the Free Software Foundation; either
6 * version 2.1 of the License, or (at your option) any later version.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this library; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 */
17
18
19 \f
20
21 #include <stdio.h>
22 #include "libguile/_scm.h"
23 #include "libguile/smob.h"
24 #include "libguile/alist.h"
25 #include "libguile/eval.h"
26 #include "libguile/eq.h"
27 #include "libguile/dynwind.h"
28 #include "libguile/backtrace.h"
29 #ifdef DEBUG_EXTENSIONS
30 #include "libguile/debug.h"
31 #endif
32 #include "libguile/continuations.h"
33 #include "libguile/stackchk.h"
34 #include "libguile/stacks.h"
35 #include "libguile/fluids.h"
36 #include "libguile/ports.h"
37 #include "libguile/lang.h"
38
39 #include "libguile/validate.h"
40 #include "libguile/throw.h"
41
42 \f
43 /* the jump buffer data structure */
44 static scm_t_bits tc16_jmpbuffer;
45
46 #define SCM_JMPBUFP(OBJ) SCM_TYP16_PREDICATE (tc16_jmpbuffer, OBJ)
47
48 #define JBACTIVE(OBJ) (SCM_CELL_WORD_0 (OBJ) & (1L << 16L))
49 #define ACTIVATEJB(x) \
50 (SCM_SET_CELL_WORD_0 ((x), (SCM_CELL_WORD_0 (x) | (1L << 16L))))
51 #define DEACTIVATEJB(x) \
52 (SCM_SET_CELL_WORD_0 ((x), (SCM_CELL_WORD_0 (x) & ~(1L << 16L))))
53
54 #define JBJMPBUF(OBJ) ((jmp_buf *) SCM_CELL_WORD_1 (OBJ))
55 #define SETJBJMPBUF(x, v) (SCM_SET_CELL_WORD_1 ((x), (v)))
56 #ifdef DEBUG_EXTENSIONS
57 #define SCM_JBDFRAME(x) ((scm_t_debug_frame *) SCM_CELL_WORD_2 (x))
58 #define SCM_SETJBDFRAME(x, v) (SCM_SET_CELL_WORD_2 ((x), (v)))
59 #endif
60
61 static int
62 jmpbuffer_print (SCM exp, SCM port, scm_print_state *pstate SCM_UNUSED)
63 {
64 scm_puts ("#<jmpbuffer ", port);
65 scm_puts (JBACTIVE(exp) ? "(active) " : "(inactive) ", port);
66 scm_intprint((long) JBJMPBUF (exp), 16, port);
67 scm_putc ('>', port);
68 return 1 ;
69 }
70
71 static SCM
72 make_jmpbuf (void)
73 {
74 SCM answer;
75 SCM_REDEFER_INTS;
76 {
77 #ifdef DEBUG_EXTENSIONS
78 SCM_NEWSMOB2 (answer, tc16_jmpbuffer, 0, 0);
79 #else
80 SCM_NEWSMOB (answer, tc16_jmpbuffer, 0);
81 #endif
82 SETJBJMPBUF(answer, (jmp_buf *)0);
83 DEACTIVATEJB(answer);
84 }
85 SCM_REALLOW_INTS;
86 return answer;
87 }
88
89 \f
90 /* scm_internal_catch (the guts of catch) */
91
92 struct jmp_buf_and_retval /* use only on the stack, in scm_catch */
93 {
94 jmp_buf buf; /* must be first */
95 SCM throw_tag;
96 SCM retval;
97 };
98
99
100 /* scm_internal_catch is the guts of catch. It handles all the
101 mechanics of setting up a catch target, invoking the catch body,
102 and perhaps invoking the handler if the body does a throw.
103
104 The function is designed to be usable from C code, but is general
105 enough to implement all the semantics Guile Scheme expects from
106 throw.
107
108 TAG is the catch tag. Typically, this is a symbol, but this
109 function doesn't actually care about that.
110
111 BODY is a pointer to a C function which runs the body of the catch;
112 this is the code you can throw from. We call it like this:
113 BODY (BODY_DATA)
114 where:
115 BODY_DATA is just the BODY_DATA argument we received; we pass it
116 through to BODY as its first argument. The caller can make
117 BODY_DATA point to anything useful that BODY might need.
118
119 HANDLER is a pointer to a C function to deal with a throw to TAG,
120 should one occur. We call it like this:
121 HANDLER (HANDLER_DATA, THROWN_TAG, THROW_ARGS)
122 where
123 HANDLER_DATA is the HANDLER_DATA argument we recevied; it's the
124 same idea as BODY_DATA above.
125 THROWN_TAG is the tag that the user threw to; usually this is
126 TAG, but it could be something else if TAG was #t (i.e., a
127 catch-all), or the user threw to a jmpbuf.
128 THROW_ARGS is the list of arguments the user passed to the THROW
129 function, after the tag.
130
131 BODY_DATA is just a pointer we pass through to BODY. HANDLER_DATA
132 is just a pointer we pass through to HANDLER. We don't actually
133 use either of those pointers otherwise ourselves. The idea is
134 that, if our caller wants to communicate something to BODY or
135 HANDLER, it can pass a pointer to it as MUMBLE_DATA, which BODY and
136 HANDLER can then use. Think of it as a way to make BODY and
137 HANDLER closures, not just functions; MUMBLE_DATA points to the
138 enclosed variables.
139
140 Of course, it's up to the caller to make sure that any data a
141 MUMBLE_DATA needs is protected from GC. A common way to do this is
142 to make MUMBLE_DATA a pointer to data stored in an automatic
143 structure variable; since the collector must scan the stack for
144 references anyway, this assures that any references in MUMBLE_DATA
145 will be found. */
146
147 SCM
148 scm_internal_catch (SCM tag, scm_t_catch_body body, void *body_data, scm_t_catch_handler handler, void *handler_data)
149 {
150 struct jmp_buf_and_retval jbr;
151 SCM jmpbuf;
152 SCM answer;
153
154 jmpbuf = make_jmpbuf ();
155 answer = SCM_EOL;
156 scm_dynwinds = scm_acons (tag, jmpbuf, scm_dynwinds);
157 SETJBJMPBUF(jmpbuf, &jbr.buf);
158 #ifdef DEBUG_EXTENSIONS
159 SCM_SETJBDFRAME(jmpbuf, scm_last_debug_frame);
160 #endif
161 if (setjmp (jbr.buf))
162 {
163 SCM throw_tag;
164 SCM throw_args;
165
166 #ifdef STACK_CHECKING
167 scm_stack_checking_enabled_p = SCM_STACK_CHECKING_P;
168 #endif
169 SCM_REDEFER_INTS;
170 DEACTIVATEJB (jmpbuf);
171 scm_dynwinds = SCM_CDR (scm_dynwinds);
172 SCM_REALLOW_INTS;
173 throw_args = jbr.retval;
174 throw_tag = jbr.throw_tag;
175 jbr.throw_tag = SCM_EOL;
176 jbr.retval = SCM_EOL;
177 answer = handler (handler_data, throw_tag, throw_args);
178 }
179 else
180 {
181 ACTIVATEJB (jmpbuf);
182 answer = body (body_data);
183 SCM_REDEFER_INTS;
184 DEACTIVATEJB (jmpbuf);
185 scm_dynwinds = SCM_CDR (scm_dynwinds);
186 SCM_REALLOW_INTS;
187 }
188 return answer;
189 }
190
191
192 \f
193 /* scm_internal_lazy_catch (the guts of lazy catching) */
194
195 /* The smob tag for lazy_catch smobs. */
196 static scm_t_bits tc16_lazy_catch;
197
198 /* This is the structure we put on the wind list for a lazy catch. It
199 stores the handler function to call, and the data pointer to pass
200 through to it. It's not a Scheme closure, but it is a function
201 with data, so the term "closure" is appropriate in its broader
202 sense.
203
204 (We don't need anything like this in the "eager" catch code,
205 because the same C frame runs both the body and the handler.) */
206 struct lazy_catch {
207 scm_t_catch_handler handler;
208 void *handler_data;
209 };
210
211 /* Strictly speaking, we could just pass a zero for our print
212 function, because we don't need to print them. They should never
213 appear in normal data structures, only in the wind list. However,
214 it might be nice for debugging someday... */
215 static int
216 lazy_catch_print (SCM closure, SCM port, scm_print_state *pstate SCM_UNUSED)
217 {
218 struct lazy_catch *c = (struct lazy_catch *) SCM_CELL_WORD_1 (closure);
219 char buf[200];
220
221 sprintf (buf, "#<lazy-catch 0x%lx 0x%lx>",
222 (long) c->handler, (long) c->handler_data);
223 scm_puts (buf, port);
224
225 return 1;
226 }
227
228
229 /* Given a pointer to a lazy catch structure, return a smob for it,
230 suitable for inclusion in the wind list. ("Ah yes, a Château
231 Gollombiere '72, non?"). */
232 static SCM
233 make_lazy_catch (struct lazy_catch *c)
234 {
235 SCM_RETURN_NEWSMOB (tc16_lazy_catch, c);
236 }
237
238 #define SCM_LAZY_CATCH_P(obj) (SCM_TYP16_PREDICATE (tc16_lazy_catch, obj))
239
240
241 /* Exactly like scm_internal_catch, except:
242 - It does not unwind the stack (this is the major difference).
243 - The handler is not allowed to return. */
244 SCM
245 scm_internal_lazy_catch (SCM tag, scm_t_catch_body body, void *body_data, scm_t_catch_handler handler, void *handler_data)
246 {
247 SCM lazy_catch, answer;
248 struct lazy_catch c;
249
250 c.handler = handler;
251 c.handler_data = handler_data;
252 lazy_catch = make_lazy_catch (&c);
253
254 SCM_REDEFER_INTS;
255 scm_dynwinds = scm_acons (tag, lazy_catch, scm_dynwinds);
256 SCM_REALLOW_INTS;
257
258 answer = (*body) (body_data);
259
260 SCM_REDEFER_INTS;
261 scm_dynwinds = SCM_CDR (scm_dynwinds);
262 SCM_REALLOW_INTS;
263
264 return answer;
265 }
266
267 \f
268 /* scm_internal_stack_catch
269 Use this one if you want debugging information to be stored in
270 scm_the_last_stack_fluid_var on error. */
271
272 static SCM
273 ss_handler (void *data SCM_UNUSED, SCM tag, SCM throw_args)
274 {
275 /* Save the stack */
276 scm_fluid_set_x (SCM_VARIABLE_REF (scm_the_last_stack_fluid_var),
277 scm_make_stack (SCM_BOOL_T, SCM_EOL));
278 /* Throw the error */
279 return scm_throw (tag, throw_args);
280 }
281
282 struct cwss_data
283 {
284 SCM tag;
285 scm_t_catch_body body;
286 void *data;
287 };
288
289 static SCM
290 cwss_body (void *data)
291 {
292 struct cwss_data *d = data;
293 return scm_internal_lazy_catch (d->tag, d->body, d->data, ss_handler, NULL);
294 }
295
296 SCM
297 scm_internal_stack_catch (SCM tag,
298 scm_t_catch_body body,
299 void *body_data,
300 scm_t_catch_handler handler,
301 void *handler_data)
302 {
303 struct cwss_data d;
304 d.tag = tag;
305 d.body = body;
306 d.data = body_data;
307 return scm_internal_catch (tag, cwss_body, &d, handler, handler_data);
308 }
309
310
311 \f
312 /* body and handler functions for use with any of the above catch variants */
313
314 /* This is a body function you can pass to scm_internal_catch if you
315 want the body to be like Scheme's `catch' --- a thunk.
316
317 BODY_DATA is a pointer to a scm_body_thunk_data structure, which
318 contains the Scheme procedure to invoke as the body, and the tag
319 we're catching. */
320
321 SCM
322 scm_body_thunk (void *body_data)
323 {
324 struct scm_body_thunk_data *c = (struct scm_body_thunk_data *) body_data;
325
326 return scm_call_0 (c->body_proc);
327 }
328
329
330 /* This is a handler function you can pass to scm_internal_catch if
331 you want the handler to act like Scheme's catch: (throw TAG ARGS ...)
332 applies a handler procedure to (TAG ARGS ...).
333
334 If the user does a throw to this catch, this function runs a
335 handler procedure written in Scheme. HANDLER_DATA is a pointer to
336 an SCM variable holding the Scheme procedure object to invoke. It
337 ought to be a pointer to an automatic variable (i.e., one living on
338 the stack), or the procedure object should be otherwise protected
339 from GC. */
340 SCM
341 scm_handle_by_proc (void *handler_data, SCM tag, SCM throw_args)
342 {
343 SCM *handler_proc_p = (SCM *) handler_data;
344
345 return scm_apply_1 (*handler_proc_p, tag, throw_args);
346 }
347
348 /* SCM_HANDLE_BY_PROC_CATCHING_ALL is like SCM_HANDLE_BY_PROC but
349 catches all throws that the handler might emit itself. The handler
350 used for these `secondary' throws is SCM_HANDLE_BY_MESSAGE_NO_EXIT. */
351
352 struct hbpca_data {
353 SCM proc;
354 SCM args;
355 };
356
357 static SCM
358 hbpca_body (void *body_data)
359 {
360 struct hbpca_data *data = (struct hbpca_data *)body_data;
361 return scm_apply_0 (data->proc, data->args);
362 }
363
364 SCM
365 scm_handle_by_proc_catching_all (void *handler_data, SCM tag, SCM throw_args)
366 {
367 SCM *handler_proc_p = (SCM *) handler_data;
368 struct hbpca_data data;
369 data.proc = *handler_proc_p;
370 data.args = scm_cons (tag, throw_args);
371
372 return scm_internal_catch (SCM_BOOL_T,
373 hbpca_body, &data,
374 scm_handle_by_message_noexit, NULL);
375 }
376
377 /* Derive the an exit status from the arguments to (quit ...). */
378 int
379 scm_exit_status (SCM args)
380 {
381 if (!SCM_NULL_OR_NIL_P (args))
382 {
383 SCM cqa = SCM_CAR (args);
384
385 if (SCM_INUMP (cqa))
386 return (SCM_INUM (cqa));
387 else if (SCM_FALSEP (cqa))
388 return 1;
389 }
390 return 0;
391 }
392
393
394 static void
395 handler_message (void *handler_data, SCM tag, SCM args)
396 {
397 char *prog_name = (char *) handler_data;
398 SCM p = scm_cur_errp;
399
400 if (scm_ilength (args) >= 3)
401 {
402 SCM stack = scm_make_stack (SCM_BOOL_T, SCM_EOL);
403 SCM subr = SCM_CAR (args);
404 SCM message = SCM_CADR (args);
405 SCM parts = SCM_CADDR (args);
406 SCM rest = SCM_CDDDR (args);
407
408 if (SCM_BACKTRACE_P && SCM_NFALSEP (stack))
409 {
410 scm_puts ("Backtrace:\n", p);
411 scm_display_backtrace (stack, p, SCM_UNDEFINED, SCM_UNDEFINED);
412 scm_newline (p);
413 }
414 scm_i_display_error (stack, p, subr, message, parts, rest);
415 }
416 else
417 {
418 if (! prog_name)
419 prog_name = "guile";
420
421 scm_puts (prog_name, p);
422 scm_puts (": ", p);
423
424 scm_puts ("uncaught throw to ", p);
425 scm_prin1 (tag, p, 0);
426 scm_puts (": ", p);
427 scm_prin1 (args, p, 1);
428 scm_putc ('\n', p);
429 }
430 }
431
432
433 /* This is a handler function to use if you want scheme to print a
434 message and die. Useful for dealing with throws to uncaught keys
435 at the top level.
436
437 At boot time, we establish a catch-all that uses this as its handler.
438 1) If the user wants something different, they can use (catch #t
439 ...) to do what they like.
440 2) Outside the context of a read-eval-print loop, there isn't
441 anything else good to do; libguile should not assume the existence
442 of a read-eval-print loop.
443 3) Given that we shouldn't do anything complex, it's much more
444 robust to do it in C code.
445
446 HANDLER_DATA, if non-zero, is assumed to be a char * pointing to a
447 message header to print; if zero, we use "guile" instead. That
448 text is followed by a colon, then the message described by ARGS. */
449
450 /* Dirk:FIXME:: The name of the function should make clear that the
451 * application gets terminated.
452 */
453
454 SCM
455 scm_handle_by_message (void *handler_data, SCM tag, SCM args)
456 {
457 if (SCM_NFALSEP (scm_eq_p (tag, scm_str2symbol ("quit"))))
458 {
459 exit (scm_exit_status (args));
460 }
461
462 handler_message (handler_data, tag, args);
463 exit (2);
464 }
465
466
467 /* This is just like scm_handle_by_message, but it doesn't exit; it
468 just returns #f. It's useful in cases where you don't really know
469 enough about the body to handle things in a better way, but don't
470 want to let throws fall off the bottom of the wind list. */
471 SCM
472 scm_handle_by_message_noexit (void *handler_data, SCM tag, SCM args)
473 {
474 handler_message (handler_data, tag, args);
475
476 return SCM_BOOL_F;
477 }
478
479
480 SCM
481 scm_handle_by_throw (void *handler_data SCM_UNUSED, SCM tag, SCM args)
482 {
483 scm_ithrow (tag, args, 1);
484 return SCM_UNSPECIFIED; /* never returns */
485 }
486
487
488 \f
489 /* the Scheme-visible CATCH and LAZY-CATCH functions */
490
491 SCM_DEFINE (scm_catch, "catch", 3, 0, 0,
492 (SCM key, SCM thunk, SCM handler),
493 "Invoke @var{thunk} in the dynamic context of @var{handler} for\n"
494 "exceptions matching @var{key}. If thunk throws to the symbol\n"
495 "@var{key}, then @var{handler} is invoked this way:\n"
496 "@lisp\n"
497 "(handler key args ...)\n"
498 "@end lisp\n"
499 "\n"
500 "@var{key} is a symbol or @code{#t}.\n"
501 "\n"
502 "@var{thunk} takes no arguments. If @var{thunk} returns\n"
503 "normally, that is the return value of @code{catch}.\n"
504 "\n"
505 "Handler is invoked outside the scope of its own @code{catch}.\n"
506 "If @var{handler} again throws to the same key, a new handler\n"
507 "from further up the call chain is invoked.\n"
508 "\n"
509 "If the key is @code{#t}, then a throw to @emph{any} symbol will\n"
510 "match this call to @code{catch}.")
511 #define FUNC_NAME s_scm_catch
512 {
513 struct scm_body_thunk_data c;
514
515 SCM_ASSERT (SCM_SYMBOLP (key) || SCM_EQ_P (key, SCM_BOOL_T),
516 key, SCM_ARG1, FUNC_NAME);
517
518 c.tag = key;
519 c.body_proc = thunk;
520
521 /* scm_internal_catch takes care of all the mechanics of setting up
522 a catch key; we tell it to call scm_body_thunk to run the body,
523 and scm_handle_by_proc to deal with any throws to this catch.
524 The former receives a pointer to c, telling it how to behave.
525 The latter receives a pointer to HANDLER, so it knows who to call. */
526 return scm_internal_catch (key,
527 scm_body_thunk, &c,
528 scm_handle_by_proc, &handler);
529 }
530 #undef FUNC_NAME
531
532
533 SCM_DEFINE (scm_lazy_catch, "lazy-catch", 3, 0, 0,
534 (SCM key, SCM thunk, SCM handler),
535 "This behaves exactly like @code{catch}, except that it does\n"
536 "not unwind the stack before invoking @var{handler}.\n"
537 "The @var{handler} procedure is not allowed to return:\n"
538 "it must throw to another catch, or otherwise exit non-locally.")
539 #define FUNC_NAME s_scm_lazy_catch
540 {
541 struct scm_body_thunk_data c;
542
543 SCM_ASSERT (SCM_SYMBOLP (key) || SCM_EQ_P (key, SCM_BOOL_T),
544 key, SCM_ARG1, FUNC_NAME);
545
546 c.tag = key;
547 c.body_proc = thunk;
548
549 /* scm_internal_lazy_catch takes care of all the mechanics of
550 setting up a lazy catch key; we tell it to call scm_body_thunk to
551 run the body, and scm_handle_by_proc to deal with any throws to
552 this catch. The former receives a pointer to c, telling it how
553 to behave. The latter receives a pointer to HANDLER, so it knows
554 who to call. */
555 return scm_internal_lazy_catch (key,
556 scm_body_thunk, &c,
557 scm_handle_by_proc, &handler);
558 }
559 #undef FUNC_NAME
560
561
562 \f
563 /* throwing */
564
565 SCM_DEFINE (scm_throw, "throw", 1, 0, 1,
566 (SCM key, SCM args),
567 "Invoke the catch form matching @var{key}, passing @var{args} to the\n"
568 "@var{handler}. \n\n"
569 "@var{key} is a symbol. It will match catches of the same symbol or of\n"
570 "@code{#t}.\n\n"
571 "If there is no handler at all, Guile prints an error and then exits.")
572 #define FUNC_NAME s_scm_throw
573 {
574 SCM_VALIDATE_SYMBOL (1, key);
575 return scm_ithrow (key, args, 1);
576 }
577 #undef FUNC_NAME
578
579 SCM
580 scm_ithrow (SCM key, SCM args, int noreturn SCM_UNUSED)
581 {
582 SCM jmpbuf = SCM_UNDEFINED;
583 SCM wind_goal;
584
585 SCM dynpair = SCM_UNDEFINED;
586 SCM winds;
587
588 /* Search the wind list for an appropriate catch.
589 "Waiter, please bring us the wind list." */
590 for (winds = scm_dynwinds; SCM_CONSP (winds); winds = SCM_CDR (winds))
591 {
592 dynpair = SCM_CAR (winds);
593 if (SCM_CONSP (dynpair))
594 {
595 SCM this_key = SCM_CAR (dynpair);
596
597 if (SCM_EQ_P (this_key, SCM_BOOL_T) || SCM_EQ_P (this_key, key))
598 break;
599 }
600 }
601
602 #ifdef __GNUC__
603 /* Dirk:FIXME:: This bugfix should be removed some time. */
604 /* GCC 2.95.2 has a bug in its optimizer that makes it generate
605 incorrect code sometimes. This barrier stops it from being too
606 clever. */
607 asm volatile ("" : "=g" (winds));
608 #endif
609
610 /* If we didn't find anything, print a message and abort the process
611 right here. If you don't want this, establish a catch-all around
612 any code that might throw up. */
613 if (SCM_NULLP (winds))
614 {
615 scm_handle_by_message (NULL, key, args);
616 abort ();
617 }
618
619 /* If the wind list is malformed, bail. */
620 if (!SCM_CONSP (winds))
621 abort ();
622
623 jmpbuf = SCM_CDR (dynpair);
624
625 for (wind_goal = scm_dynwinds;
626 !SCM_EQ_P (SCM_CDAR (wind_goal), jmpbuf);
627 wind_goal = SCM_CDR (wind_goal))
628 ;
629
630 /* Is a lazy catch? In wind list entries for lazy catches, the key
631 is bound to a lazy_catch smob, not a jmpbuf. */
632 if (SCM_LAZY_CATCH_P (jmpbuf))
633 {
634 struct lazy_catch *c = (struct lazy_catch *) SCM_CELL_WORD_1 (jmpbuf);
635 SCM handle, answer;
636 scm_dowinds (wind_goal, (scm_ilength (scm_dynwinds)
637 - scm_ilength (wind_goal)));
638 SCM_REDEFER_INTS;
639 handle = scm_dynwinds;
640 scm_dynwinds = SCM_CDR (scm_dynwinds);
641 SCM_REALLOW_INTS;
642 answer = (c->handler) (c->handler_data, key, args);
643 scm_misc_error ("throw", "lazy-catch handler did return.", SCM_EOL);
644 }
645
646 /* Otherwise, it's a normal catch. */
647 else if (SCM_JMPBUFP (jmpbuf))
648 {
649 struct jmp_buf_and_retval * jbr;
650 scm_dowinds (wind_goal, (scm_ilength (scm_dynwinds)
651 - scm_ilength (wind_goal)));
652 jbr = (struct jmp_buf_and_retval *)JBJMPBUF (jmpbuf);
653 jbr->throw_tag = key;
654 jbr->retval = args;
655 #ifdef DEBUG_EXTENSIONS
656 scm_last_debug_frame = SCM_JBDFRAME (jmpbuf);
657 #endif
658 longjmp (*JBJMPBUF (jmpbuf), 1);
659 }
660
661 /* Otherwise, it's some random piece of junk. */
662 else
663 abort ();
664 }
665
666
667 void
668 scm_init_throw ()
669 {
670 tc16_jmpbuffer = scm_make_smob_type ("jmpbuffer", 0);
671 scm_set_smob_print (tc16_jmpbuffer, jmpbuffer_print);
672
673 tc16_lazy_catch = scm_make_smob_type ("lazy-catch", 0);
674 scm_set_smob_print (tc16_lazy_catch, lazy_catch_print);
675
676 #include "libguile/throw.x"
677 }
678
679 /*
680 Local Variables:
681 c-file-style: "gnu"
682 End:
683 */