Commit | Line | Data |
---|---|---|
0f2d19dd JB |
1 | /* classes: h_files */ |
2 | ||
b29058ff DH |
3 | #ifndef SCM_CONTINUATIONS_H |
4 | #define SCM_CONTINUATIONS_H | |
5 | ||
102dbb6f | 6 | /* Copyright (C) 1995,1996,2000,2001, 2006, 2008 Free Software Foundation, Inc. |
b29058ff | 7 | * |
73be1d9e MV |
8 | * This library is free software; you can redistribute it and/or |
9 | * modify it under the terms of the GNU Lesser General Public | |
10 | * License as published by the Free Software Foundation; either | |
11 | * version 2.1 of the License, or (at your option) any later version. | |
b29058ff | 12 | * |
73be1d9e | 13 | * This library is distributed in the hope that it will be useful, |
0f2d19dd | 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
73be1d9e MV |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
16 | * Lesser General Public License for more details. | |
b29058ff | 17 | * |
73be1d9e MV |
18 | * You should have received a copy of the GNU Lesser General Public |
19 | * License along with this library; if not, write to the Free Software | |
92205699 | 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
73be1d9e | 21 | */ |
b29058ff | 22 | |
0f2d19dd | 23 | \f |
b29058ff | 24 | |
b4309c3c | 25 | #include "libguile/__scm.h" |
0f2d19dd | 26 | |
766c5eaf | 27 | #ifdef __ia64__ |
6a535440 | 28 | #include <signal.h> |
78b6566e | 29 | #include <ucontext.h> |
87855fa2 | 30 | #endif /* __ia64__ */ |
0f2d19dd JB |
31 | \f |
32 | ||
5f144b10 | 33 | /* a continuation SCM is a non-immediate pointing to a heap cell with: |
2dbec7b5 GH |
34 | word 0: bits 0-15: smob type tag: scm_tc16_continuation. |
35 | bits 16-31: unused. | |
92c2555f | 36 | word 1: malloc block containing an scm_t_contregs structure with a |
5f144b10 GH |
37 | tail array of SCM_STACKITEM. the size of the array is stored |
38 | in the num_stack_items field of the structure. | |
39 | */ | |
40 | ||
87855fa2 | 41 | SCM_API scm_t_bits scm_tc16_continuation; |
5f144b10 | 42 | |
0f2d19dd JB |
43 | typedef struct |
44 | { | |
45 | SCM throw_value; | |
46 | jmp_buf jmpbuf; | |
47 | SCM dynenv; | |
766c5eaf | 48 | #ifdef __ia64__ |
766c5eaf RB |
49 | void *backing_store; |
50 | unsigned long backing_store_size; | |
51 | #endif /* __ia64__ */ | |
c014a02e | 52 | size_t num_stack_items; /* size of the saved stack. */ |
9de87eea | 53 | SCM root; /* continuation root identifier. */ |
0f2d19dd | 54 | |
9de87eea | 55 | /* The offset from the live stack location to this copy. This is |
5c5c27dc MV |
56 | used to adjust pointers from within the copied stack to the stack |
57 | itself. | |
58 | ||
59 | Thus, when you read a pointer from the copied stack that points | |
60 | into the live stack, you need to add OFFSET so that it points | |
61 | into the copy. | |
62 | */ | |
63 | scm_t_ptrdiff offset; | |
64 | ||
65 | /* The most recently created debug frame on the live stack, before | |
9de87eea | 66 | it was saved. This needs to be adjusted with OFFSET, above. |
5c5c27dc | 67 | */ |
92c2555f | 68 | struct scm_t_debug_frame *dframe; |
d0f6ceb8 | 69 | |
5f144b10 | 70 | SCM_STACKITEM stack[1]; /* copied stack of size num_stack_items. */ |
92c2555f | 71 | } scm_t_contregs; |
1be6b49c | 72 | |
e841c3e0 | 73 | #define SCM_CONTINUATIONP(x) SCM_TYP16_PREDICATE (scm_tc16_continuation, x) |
8b3bda20 | 74 | |
92c2555f | 75 | #define SCM_CONTREGS(x) ((scm_t_contregs *) SCM_CELL_WORD_1 (x)) |
8b3bda20 | 76 | |
5f144b10 | 77 | #define SCM_CONTINUATION_LENGTH(x) (SCM_CONTREGS (x)->num_stack_items) |
34d19ef6 | 78 | #define SCM_SET_CONTINUATION_LENGTH(x, n)\ |
5f144b10 | 79 | (SCM_CONTREGS (x)->num_stack_items = (n)) |
9de87eea MV |
80 | #define SCM_JMPBUF(x) ((SCM_CONTREGS (x))->jmpbuf) |
81 | #define SCM_DYNENV(x) ((SCM_CONTREGS (x))->dynenv) | |
82 | #define SCM_THROW_VALUE(x) ((SCM_CONTREGS (x))->throw_value) | |
83 | #define SCM_CONTINUATION_ROOT(x) ((SCM_CONTREGS (x))->root) | |
84 | #define SCM_DFRAME(x) ((SCM_CONTREGS (x))->dframe) | |
0f2d19dd JB |
85 | |
86 | \f | |
87 | ||
87855fa2 | 88 | SCM_API SCM scm_make_continuation (int *first); |
9de87eea MV |
89 | |
90 | SCM_API void *scm_c_with_continuation_barrier (void *(*func)(void*), void *); | |
91 | SCM_API SCM scm_with_continuation_barrier (SCM proc); | |
92 | ||
102dbb6f LC |
93 | SCM_INTERNAL SCM |
94 | scm_i_with_continuation_barrier (scm_t_catch_body body, | |
95 | void *body_data, | |
96 | scm_t_catch_handler handler, | |
97 | void *handler_data, | |
98 | scm_t_catch_handler pre_unwind_handler, | |
99 | void *pre_unwind_handler_data); | |
9de87eea | 100 | |
102dbb6f | 101 | SCM_INTERNAL void scm_init_continuations (void); |
0f2d19dd | 102 | |
b29058ff | 103 | #endif /* SCM_CONTINUATIONS_H */ |
89e00824 ML |
104 | |
105 | /* | |
106 | Local Variables: | |
107 | c-file-style: "gnu" | |
108 | End: | |
109 | */ |