| 1 | /* classes: h_files */ |
| 2 | |
| 3 | #ifndef SCM_CONTINUATIONS_H |
| 4 | #define SCM_CONTINUATIONS_H |
| 5 | |
| 6 | /* Copyright (C) 1995,1996,2000,2001, 2006, 2008, 2009, 2010, 2012, 2013, 2014 Free Software Foundation, Inc. |
| 7 | * |
| 8 | * This library is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU Lesser General Public License |
| 10 | * as published by the Free Software Foundation; either version 3 of |
| 11 | * the License, or (at your option) any later version. |
| 12 | * |
| 13 | * This library is distributed in the hope that it will be useful, but |
| 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 | * Lesser General Public License for more details. |
| 17 | * |
| 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 |
| 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
| 21 | * 02110-1301 USA |
| 22 | */ |
| 23 | |
| 24 | \f |
| 25 | |
| 26 | #include "libguile/__scm.h" |
| 27 | |
| 28 | #ifdef __ia64__ |
| 29 | #include <signal.h> |
| 30 | #include <ucontext.h> |
| 31 | #endif /* __ia64__ */ |
| 32 | \f |
| 33 | |
| 34 | #define SCM_CONTINUATIONP(x) \ |
| 35 | (SCM_PROGRAM_P (x) && SCM_PROGRAM_IS_CONTINUATION (x)) |
| 36 | |
| 37 | /* a continuation SCM is a non-immediate pointing to a heap cell with: |
| 38 | word 0: bits 0-15: smob type tag: scm_tc16_continuation. |
| 39 | bits 16-31: unused. |
| 40 | word 1: malloc block containing an scm_t_contregs structure with a |
| 41 | tail array of SCM_STACKITEM. the size of the array is stored |
| 42 | in the num_stack_items field of the structure. |
| 43 | */ |
| 44 | |
| 45 | typedef struct |
| 46 | { |
| 47 | scm_i_jmp_buf jmpbuf; |
| 48 | #ifdef __ia64__ |
| 49 | void *backing_store; |
| 50 | unsigned long backing_store_size; |
| 51 | #endif /* __ia64__ */ |
| 52 | size_t num_stack_items; /* size of the saved stack. */ |
| 53 | SCM root; /* continuation root identifier. */ |
| 54 | struct scm_vm *vp; /* vm */ |
| 55 | SCM vm_cont; /* vm's stack and regs */ |
| 56 | |
| 57 | /* The offset from the live stack location to this copy. This is |
| 58 | used to adjust pointers from within the copied stack to the stack |
| 59 | itself. |
| 60 | |
| 61 | Thus, when you read a pointer from the copied stack that points |
| 62 | into the live stack, you need to add OFFSET so that it points |
| 63 | into the copy. |
| 64 | */ |
| 65 | scm_t_ptrdiff offset; |
| 66 | |
| 67 | SCM_STACKITEM stack[1]; /* copied stack of size num_stack_items. */ |
| 68 | } scm_t_contregs; |
| 69 | |
| 70 | |
| 71 | \f |
| 72 | |
| 73 | SCM_INTERNAL SCM scm_i_make_continuation (int *first, |
| 74 | struct scm_vm *vp, |
| 75 | SCM vm_cont); |
| 76 | SCM_INTERNAL void scm_i_check_continuation (SCM cont); |
| 77 | SCM_INTERNAL void scm_i_reinstate_continuation (SCM cont); |
| 78 | |
| 79 | struct scm_frame; |
| 80 | SCM_INTERNAL int scm_i_continuation_to_frame (SCM cont, |
| 81 | struct scm_frame *frame); |
| 82 | |
| 83 | SCM_INTERNAL struct scm_vm* scm_i_contregs_vp (SCM contregs); |
| 84 | SCM_INTERNAL SCM scm_i_contregs_vm_cont (SCM contregs); |
| 85 | |
| 86 | SCM_API void *scm_c_with_continuation_barrier (void *(*func)(void*), void *); |
| 87 | SCM_API SCM scm_with_continuation_barrier (SCM proc); |
| 88 | |
| 89 | SCM_INTERNAL SCM |
| 90 | scm_i_with_continuation_barrier (scm_t_catch_body body, |
| 91 | void *body_data, |
| 92 | scm_t_catch_handler handler, |
| 93 | void *handler_data, |
| 94 | scm_t_catch_handler pre_unwind_handler, |
| 95 | void *pre_unwind_handler_data); |
| 96 | |
| 97 | SCM_INTERNAL void scm_init_continuations (void); |
| 98 | |
| 99 | #endif /* SCM_CONTINUATIONS_H */ |
| 100 | |
| 101 | /* |
| 102 | Local Variables: |
| 103 | c-file-style: "gnu" |
| 104 | End: |
| 105 | */ |