continuations.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /* classes: h_files */
  2. #ifndef SCM_CONTINUATIONS_H
  3. #define SCM_CONTINUATIONS_H
  4. /* Copyright (C) 1995,1996,2000,2001, 2006 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
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * This library is distributed in the hope that it will be useful,
  12. * but 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 02110-1301 USA
  19. */
  20. #include "libguile/__scm.h"
  21. #ifdef __ia64__
  22. #include <signal.h>
  23. #include <ucontext.h>
  24. #endif /* __ia64__ */
  25. /* a continuation SCM is a non-immediate pointing to a heap cell with:
  26. word 0: bits 0-15: smob type tag: scm_tc16_continuation.
  27. bits 16-31: unused.
  28. word 1: malloc block containing an scm_t_contregs structure with a
  29. tail array of SCM_STACKITEM. the size of the array is stored
  30. in the num_stack_items field of the structure.
  31. */
  32. SCM_API scm_t_bits scm_tc16_continuation;
  33. typedef struct
  34. {
  35. SCM throw_value;
  36. jmp_buf jmpbuf;
  37. SCM dynenv;
  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. /* The offset from the live stack location to this copy. This is
  45. used to adjust pointers from within the copied stack to the stack
  46. itself.
  47. Thus, when you read a pointer from the copied stack that points
  48. into the live stack, you need to add OFFSET so that it points
  49. into the copy.
  50. */
  51. scm_t_ptrdiff offset;
  52. /* The most recently created debug frame on the live stack, before
  53. it was saved. This needs to be adjusted with OFFSET, above.
  54. */
  55. struct scm_t_debug_frame *dframe;
  56. SCM_STACKITEM stack[1]; /* copied stack of size num_stack_items. */
  57. } scm_t_contregs;
  58. #define SCM_CONTINUATIONP(x) SCM_TYP16_PREDICATE (scm_tc16_continuation, x)
  59. #define SCM_CONTREGS(x) ((scm_t_contregs *) SCM_CELL_WORD_1 (x))
  60. #define SCM_CONTINUATION_LENGTH(x) (SCM_CONTREGS (x)->num_stack_items)
  61. #define SCM_SET_CONTINUATION_LENGTH(x, n)\
  62. (SCM_CONTREGS (x)->num_stack_items = (n))
  63. #define SCM_JMPBUF(x) ((SCM_CONTREGS (x))->jmpbuf)
  64. #define SCM_DYNENV(x) ((SCM_CONTREGS (x))->dynenv)
  65. #define SCM_THROW_VALUE(x) ((SCM_CONTREGS (x))->throw_value)
  66. #define SCM_CONTINUATION_ROOT(x) ((SCM_CONTREGS (x))->root)
  67. #define SCM_DFRAME(x) ((SCM_CONTREGS (x))->dframe)
  68. SCM_API SCM scm_make_continuation (int *first);
  69. SCM_API void *scm_c_with_continuation_barrier (void *(*func)(void*), void *);
  70. SCM_API SCM scm_with_continuation_barrier (SCM proc);
  71. SCM_API SCM scm_i_with_continuation_barrier (scm_t_catch_body body,
  72. void *body_data,
  73. scm_t_catch_handler handler,
  74. void *handler_data,
  75. scm_t_catch_handler pre_unwind_handler,
  76. void *pre_unwind_handler_data);
  77. SCM_API void scm_init_continuations (void);
  78. #endif /* SCM_CONTINUATIONS_H */
  79. /*
  80. Local Variables:
  81. c-file-style: "gnu"
  82. End:
  83. */