continuations.h 3.3 KB

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