continuations.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620
  1. /* Copyright (C) 1995,1996,1998,2000,2001,2004, 2006, 2008, 2009, 2010, 2011, 2012 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 License
  5. * as published by the Free Software Foundation; either version 3 of
  6. * the License, or (at your option) any later version.
  7. *
  8. * This library is distributed in the hope that it will be useful, but
  9. * 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., 51 Franklin Street, Fifth Floor, Boston, MA
  16. * 02110-1301 USA
  17. */
  18. #ifdef HAVE_CONFIG_H
  19. # include <config.h>
  20. #endif
  21. #include "libguile/_scm.h"
  22. #include <string.h>
  23. #include <stdio.h>
  24. #include "libguile/async.h"
  25. #include "libguile/debug.h"
  26. #include "libguile/root.h"
  27. #include "libguile/stackchk.h"
  28. #include "libguile/smob.h"
  29. #include "libguile/ports.h"
  30. #include "libguile/dynwind.h"
  31. #include "libguile/eval.h"
  32. #include "libguile/vm.h"
  33. #include "libguile/instructions.h"
  34. #include "libguile/validate.h"
  35. #include "libguile/continuations.h"
  36. static scm_t_bits tc16_continuation;
  37. #define SCM_CONTREGSP(x) SCM_TYP16_PREDICATE (tc16_continuation, x)
  38. #define SCM_CONTREGS(x) ((scm_t_contregs *) SCM_SMOB_DATA_1 (x))
  39. #define SCM_CONTINUATION_LENGTH(x) (SCM_CONTREGS (x)->num_stack_items)
  40. #define SCM_SET_CONTINUATION_LENGTH(x, n)\
  41. (SCM_CONTREGS (x)->num_stack_items = (n))
  42. #define SCM_JMPBUF(x) ((SCM_CONTREGS (x))->jmpbuf)
  43. #define SCM_DYNENV(x) ((SCM_CONTREGS (x))->dynenv)
  44. #define SCM_CONTINUATION_ROOT(x) ((SCM_CONTREGS (x))->root)
  45. #define SCM_DFRAME(x) ((SCM_CONTREGS (x))->dframe)
  46. /* scm_i_make_continuation will return a procedure whose objcode contains an
  47. instruction to reinstate the continuation. Here, as in gsubr.c and smob.c, we
  48. define the form of that trampoline function.
  49. */
  50. #ifdef WORDS_BIGENDIAN
  51. #define OBJCODE_HEADER(main,meta) 0, 0, 0, main, 0, 0, 0, meta+8
  52. #define META_HEADER(meta) 0, 0, 0, meta, 0, 0, 0, 0
  53. #else
  54. #define OBJCODE_HEADER(main,meta) main, 0, 0, 0, meta+8, 0, 0, 0
  55. #define META_HEADER(meta) meta, 0, 0, 0, 0, 0, 0, 0
  56. #endif
  57. #define OBJCODE_TAG SCM_MAKE_OBJCODE_TAG (SCM_OBJCODE_TYPE_STATIC, 0)
  58. #if defined (SCM_ALIGNED) && 0
  59. #define SCM_DECLARE_STATIC_ALIGNED_ARRAY(type, sym) \
  60. static const type sym[]
  61. #define SCM_STATIC_ALIGNED_ARRAY(alignment, type, sym) \
  62. static SCM_ALIGNED (alignment) const type sym[]
  63. #define SCM_STATIC_OBJCODE(sym) \
  64. SCM_DECLARE_STATIC_ALIGNED_ARRAY (scm_t_uint8, sym##__bytecode); \
  65. SCM_STATIC_ALIGNED_ARRAY (8, scm_t_cell, sym##__cells) = { \
  66. { SCM_PACK (OBJCODE_TAG), SCM_PACK (sym##__bytecode) }, \
  67. { SCM_BOOL_F, SCM_PACK (0) } \
  68. }; \
  69. static const SCM sym = SCM_PACK (sym##__cells); \
  70. SCM_STATIC_ALIGNED_ARRAY (8, scm_t_uint8, sym##__bytecode)
  71. #else
  72. #define SCM_STATIC_OBJCODE(sym) \
  73. static SCM sym; \
  74. static scm_t_uint8 *sym##_bytecode; \
  75. SCM_SNARF_INIT(sym##_bytecode = scm_gc_malloc_pointerless (sizeof(sym##_bytecode__unaligned), "partial continuation stub"); \
  76. memcpy (sym##_bytecode, sym##_bytecode__unaligned, sizeof(sym##_bytecode__unaligned));) \
  77. SCM_SNARF_INIT(sym = scm_double_cell (OBJCODE_TAG, \
  78. (scm_t_bits)sym##_bytecode, \
  79. SCM_UNPACK (SCM_BOOL_F), \
  80. 0);) \
  81. static const scm_t_uint8 sym##_bytecode__unaligned[]
  82. #endif
  83. SCM_STATIC_OBJCODE (cont_objcode) = {
  84. /* This code is the same as in gsubr.c, except we use continuation_call
  85. instead of subr_call. */
  86. OBJCODE_HEADER (8, 19),
  87. /* leave args on the stack */
  88. /* 0 */ scm_op_object_ref, 0, /* push scm_t_contregs smob */
  89. /* 2 */ scm_op_continuation_call, /* and longjmp (whee) */
  90. /* 3 */ scm_op_nop, /* pad to 8 bytes */
  91. /* 4 */ scm_op_nop, scm_op_nop, scm_op_nop, scm_op_nop,
  92. /* 8 */
  93. /* We could put some meta-info to say that this proc is a continuation. Not sure
  94. how to do that, though. */
  95. META_HEADER (19),
  96. /* 0 */ scm_op_make_eol, /* bindings */
  97. /* 1 */ scm_op_make_eol, /* sources */
  98. /* 2 */ scm_op_make_int8, 0, scm_op_make_int8, 3, /* arity: from ip 0 to ip 3 */
  99. /* 6 */ scm_op_make_int8_0, /* the arity is 0 required args */
  100. /* 7 */ scm_op_make_int8_0, /* 0 optionals */
  101. /* 8 */ scm_op_make_true, /* and a rest arg */
  102. /* 9 */ scm_op_list, 0, 5, /* make a list of those 5 vals */
  103. /* 12 */ scm_op_list, 0, 1, /* and the arities will be a list of that one list */
  104. /* 15 */ scm_op_list, 0, 3, /* pack bindings, sources, and arities into list */
  105. /* 18 */ scm_op_return /* and return */
  106. /* 19 */
  107. };
  108. SCM_STATIC_OBJCODE (call_cc_objcode) = {
  109. /* Before Scheme's call/cc is compiled, eval.c will use this hand-coded
  110. call/cc. */
  111. OBJCODE_HEADER (8, 17),
  112. /* 0 */ scm_op_assert_nargs_ee, 0, 1, /* assert that nargs==1 */
  113. /* 3 */ scm_op_local_ref, 0, /* push the proc */
  114. /* 5 */ scm_op_tail_call_cc, /* and call/cc */
  115. /* 6 */ scm_op_nop, scm_op_nop, /* pad to 8 bytes */
  116. /* 8 */
  117. META_HEADER (17),
  118. /* 0 */ scm_op_make_eol, /* bindings */
  119. /* 1 */ scm_op_make_eol, /* sources */
  120. /* 2 */ scm_op_make_int8, 3, scm_op_make_int8, 6, /* arity: from ip 0 to ip 6 */
  121. /* 6 */ scm_op_make_int8_1, /* the arity is 0 required args */
  122. /* 7 */ scm_op_list, 0, 3, /* make a list of those 5 vals */
  123. /* 10 */ scm_op_list, 0, 1, /* and the arities will be a list of that one list */
  124. /* 13 */ scm_op_list, 0, 3, /* pack bindings, sources, and arities into list */
  125. /* 16 */ scm_op_return /* and return */
  126. /* 17 */
  127. };
  128. static SCM
  129. make_continuation_trampoline (SCM contregs)
  130. {
  131. SCM ret = scm_make_program (cont_objcode,
  132. scm_c_make_vector (1, contregs),
  133. SCM_BOOL_F);
  134. SCM_SET_CELL_WORD_0 (ret,
  135. SCM_CELL_WORD_0 (ret) | SCM_F_PROGRAM_IS_CONTINUATION);
  136. return ret;
  137. }
  138. /* {Continuations}
  139. */
  140. static int
  141. continuation_print (SCM obj, SCM port, scm_print_state *state SCM_UNUSED)
  142. {
  143. scm_t_contregs *continuation = SCM_CONTREGS (obj);
  144. scm_puts_unlocked ("#<continuation ", port);
  145. scm_intprint (continuation->num_stack_items, 10, port);
  146. scm_puts_unlocked (" @ ", port);
  147. scm_uintprint (SCM_SMOB_DATA_1 (obj), 16, port);
  148. scm_putc_unlocked ('>', port);
  149. return 1;
  150. }
  151. /* James Clark came up with this neat one instruction fix for
  152. * continuations on the SPARC. It flushes the register windows so
  153. * that all the state of the process is contained in the stack.
  154. */
  155. #if defined (sparc) || defined (__sparc__) || defined (__sparc)
  156. # define SCM_FLUSH_REGISTER_WINDOWS asm("ta 3")
  157. #else
  158. # define SCM_FLUSH_REGISTER_WINDOWS /* empty */
  159. #endif
  160. /* this may return more than once: the first time with the escape
  161. procedure, then subsequently with SCM_UNDEFINED (the vals already having been
  162. placed on the VM stack). */
  163. #define FUNC_NAME "scm_i_make_continuation"
  164. SCM
  165. scm_i_make_continuation (int *first, SCM vm, SCM vm_cont)
  166. {
  167. scm_i_thread *thread = SCM_I_CURRENT_THREAD;
  168. SCM cont;
  169. scm_t_contregs *continuation;
  170. long stack_size;
  171. SCM_STACKITEM * src;
  172. SCM_FLUSH_REGISTER_WINDOWS;
  173. stack_size = scm_stack_size (thread->continuation_base);
  174. continuation = scm_gc_malloc (sizeof (scm_t_contregs)
  175. + (stack_size - 1) * sizeof (SCM_STACKITEM),
  176. "continuation");
  177. continuation->num_stack_items = stack_size;
  178. continuation->dynenv = scm_i_dynwinds ();
  179. continuation->root = thread->continuation_root;
  180. src = thread->continuation_base;
  181. #if ! SCM_STACK_GROWS_UP
  182. src -= stack_size;
  183. #endif
  184. continuation->offset = continuation->stack - src;
  185. memcpy (continuation->stack, src, sizeof (SCM_STACKITEM) * stack_size);
  186. continuation->vm = vm;
  187. continuation->vm_cont = vm_cont;
  188. SCM_NEWSMOB (cont, tc16_continuation, continuation);
  189. *first = !SCM_I_SETJMP (continuation->jmpbuf);
  190. if (*first)
  191. {
  192. #ifdef __ia64__
  193. continuation->backing_store_size =
  194. (char *) scm_ia64_ar_bsp(&continuation->jmpbuf.ctx)
  195. -
  196. (char *) thread->register_backing_store_base;
  197. continuation->backing_store = NULL;
  198. continuation->backing_store =
  199. scm_gc_malloc (continuation->backing_store_size,
  200. "continuation backing store");
  201. memcpy (continuation->backing_store,
  202. (void *) thread->register_backing_store_base,
  203. continuation->backing_store_size);
  204. #endif /* __ia64__ */
  205. return make_continuation_trampoline (cont);
  206. }
  207. else
  208. return SCM_UNDEFINED;
  209. }
  210. #undef FUNC_NAME
  211. SCM
  212. scm_i_call_with_current_continuation (SCM proc)
  213. {
  214. static SCM call_cc = SCM_BOOL_F;
  215. if (scm_is_false (call_cc))
  216. call_cc = scm_make_program (call_cc_objcode, SCM_BOOL_F, SCM_BOOL_F);
  217. return scm_call_1 (call_cc, proc);
  218. }
  219. SCM
  220. scm_i_continuation_to_frame (SCM continuation)
  221. {
  222. SCM contregs;
  223. scm_t_contregs *cont;
  224. contregs = scm_c_vector_ref (scm_program_objects (continuation), 0);
  225. cont = SCM_CONTREGS (contregs);
  226. if (scm_is_true (cont->vm_cont))
  227. {
  228. struct scm_vm_cont *data = SCM_VM_CONT_DATA (cont->vm_cont);
  229. return scm_c_make_frame (cont->vm_cont,
  230. data->fp + data->reloc,
  231. data->sp + data->reloc,
  232. data->ra,
  233. data->reloc);
  234. }
  235. else
  236. return SCM_BOOL_F;
  237. }
  238. SCM
  239. scm_i_contregs_vm (SCM contregs)
  240. {
  241. return SCM_CONTREGS (contregs)->vm;
  242. }
  243. SCM
  244. scm_i_contregs_vm_cont (SCM contregs)
  245. {
  246. return SCM_CONTREGS (contregs)->vm_cont;
  247. }
  248. /* {Apply}
  249. */
  250. /* Invoking a continuation proceeds as follows:
  251. *
  252. * - the stack is made large enough for the called continuation
  253. * - the old windchain is unwound down to the branching point
  254. * - the continuation stack is copied into place
  255. * - the windchain is rewound up to the continuation's context
  256. * - the continuation is invoked via longjmp (or setcontext)
  257. *
  258. * This order is important so that unwind and rewind handlers are run
  259. * with their correct stack.
  260. */
  261. static void scm_dynthrow (SCM);
  262. /* Grow the stack by a fixed amount to provide space to copy in the
  263. * continuation. Possibly this function has to be called several times
  264. * recursively before enough space is available. Make sure the compiler does
  265. * not optimize the growth array away by storing it's address into a global
  266. * variable.
  267. */
  268. static scm_t_bits scm_i_dummy;
  269. static void
  270. grow_stack (SCM cont)
  271. {
  272. scm_t_bits growth[100];
  273. scm_i_dummy = (scm_t_bits) growth;
  274. scm_dynthrow (cont);
  275. }
  276. /* Copy the continuation stack into the current stack. Calling functions from
  277. * within this function is safe, since only stack frames below this function's
  278. * own frame are overwritten. Thus, memcpy can be used for best performance.
  279. */
  280. typedef struct {
  281. scm_t_contregs *continuation;
  282. SCM_STACKITEM *dst;
  283. } copy_stack_data;
  284. static void
  285. copy_stack (void *data)
  286. {
  287. copy_stack_data *d = (copy_stack_data *)data;
  288. memcpy (d->dst, d->continuation->stack,
  289. sizeof (SCM_STACKITEM) * d->continuation->num_stack_items);
  290. #ifdef __ia64__
  291. SCM_I_CURRENT_THREAD->pending_rbs_continuation = d->continuation;
  292. #endif
  293. }
  294. static void
  295. copy_stack_and_call (scm_t_contregs *continuation,
  296. SCM_STACKITEM * dst)
  297. {
  298. long delta;
  299. copy_stack_data data;
  300. delta = scm_ilength (scm_i_dynwinds ()) - scm_ilength (continuation->dynenv);
  301. data.continuation = continuation;
  302. data.dst = dst;
  303. scm_i_dowinds (continuation->dynenv, delta, copy_stack, &data);
  304. SCM_I_LONGJMP (continuation->jmpbuf, 1);
  305. }
  306. #ifdef __ia64__
  307. void
  308. scm_ia64_longjmp (scm_i_jmp_buf *JB, int VAL)
  309. {
  310. scm_i_thread *t = SCM_I_CURRENT_THREAD;
  311. if (t->pending_rbs_continuation)
  312. {
  313. memcpy (t->register_backing_store_base,
  314. t->pending_rbs_continuation->backing_store,
  315. t->pending_rbs_continuation->backing_store_size);
  316. t->pending_rbs_continuation = NULL;
  317. }
  318. setcontext (&JB->ctx);
  319. }
  320. #endif
  321. /* Call grow_stack until the stack space is large enough, then, as the current
  322. * stack frame might get overwritten, let copy_stack_and_call perform the
  323. * actual copying and continuation calling.
  324. */
  325. static void
  326. scm_dynthrow (SCM cont)
  327. {
  328. scm_i_thread *thread = SCM_I_CURRENT_THREAD;
  329. scm_t_contregs *continuation = SCM_CONTREGS (cont);
  330. SCM_STACKITEM *dst = thread->continuation_base;
  331. SCM_STACKITEM stack_top_element;
  332. if (thread->critical_section_level)
  333. {
  334. fprintf (stderr, "continuation invoked from within critical section.\n");
  335. abort ();
  336. }
  337. #if SCM_STACK_GROWS_UP
  338. if (dst + continuation->num_stack_items >= &stack_top_element)
  339. grow_stack (cont);
  340. #else
  341. dst -= continuation->num_stack_items;
  342. if (dst <= &stack_top_element)
  343. grow_stack (cont);
  344. #endif /* def SCM_STACK_GROWS_UP */
  345. SCM_FLUSH_REGISTER_WINDOWS;
  346. copy_stack_and_call (continuation, dst);
  347. }
  348. void
  349. scm_i_check_continuation (SCM cont)
  350. {
  351. scm_i_thread *thread = SCM_I_CURRENT_THREAD;
  352. scm_t_contregs *continuation = SCM_CONTREGS (cont);
  353. if (!scm_is_eq (continuation->root, thread->continuation_root))
  354. scm_misc_error
  355. ("%continuation-call",
  356. "invoking continuation would cross continuation barrier: ~A",
  357. scm_list_1 (cont));
  358. }
  359. void
  360. scm_i_reinstate_continuation (SCM cont)
  361. {
  362. scm_dynthrow (cont);
  363. }
  364. SCM
  365. scm_i_with_continuation_barrier (scm_t_catch_body body,
  366. void *body_data,
  367. scm_t_catch_handler handler,
  368. void *handler_data,
  369. scm_t_catch_handler pre_unwind_handler,
  370. void *pre_unwind_handler_data)
  371. {
  372. SCM_STACKITEM stack_item;
  373. scm_i_thread *thread = SCM_I_CURRENT_THREAD;
  374. SCM old_controot;
  375. SCM_STACKITEM *old_contbase;
  376. SCM result;
  377. /* Establish a fresh continuation root.
  378. */
  379. old_controot = thread->continuation_root;
  380. old_contbase = thread->continuation_base;
  381. thread->continuation_root = scm_cons (thread->handle, old_controot);
  382. thread->continuation_base = &stack_item;
  383. /* Call FUNC inside a catch all. This is now guaranteed to return
  384. directly and exactly once.
  385. */
  386. result = scm_c_catch (SCM_BOOL_T,
  387. body, body_data,
  388. handler, handler_data,
  389. pre_unwind_handler, pre_unwind_handler_data);
  390. /* Return to old continuation root.
  391. */
  392. thread->continuation_base = old_contbase;
  393. thread->continuation_root = old_controot;
  394. return result;
  395. }
  396. static int
  397. should_print_backtrace (SCM tag, SCM stack)
  398. {
  399. return SCM_BACKTRACE_P
  400. && scm_is_true (stack)
  401. && scm_initialized_p
  402. /* It's generally not useful to print backtraces for errors reading
  403. or expanding code in these fallback catch statements. */
  404. && !scm_is_eq (tag, scm_from_latin1_symbol ("read-error"))
  405. && !scm_is_eq (tag, scm_from_latin1_symbol ("syntax-error"));
  406. }
  407. static void
  408. print_exception_and_backtrace (SCM port, SCM tag, SCM args)
  409. {
  410. SCM stack, frame;
  411. /* We get here via a throw to a catch-all. In that case there is the
  412. throw frame active, and this catch closure, so narrow by two
  413. frames. */
  414. stack = scm_make_stack (SCM_BOOL_T, scm_list_1 (scm_from_int (2)));
  415. frame = scm_is_true (stack) ? scm_stack_ref (stack, SCM_INUM0) : SCM_BOOL_F;
  416. if (should_print_backtrace (tag, stack))
  417. {
  418. scm_puts_unlocked ("Backtrace:\n", port);
  419. scm_display_backtrace_with_highlights (stack, port,
  420. SCM_BOOL_F, SCM_BOOL_F,
  421. SCM_EOL);
  422. scm_newline (port);
  423. }
  424. scm_print_exception (port, frame, tag, args);
  425. }
  426. struct c_data {
  427. void *(*func) (void *);
  428. void *data;
  429. void *result;
  430. };
  431. static SCM
  432. c_body (void *d)
  433. {
  434. struct c_data *data = (struct c_data *)d;
  435. data->result = data->func (data->data);
  436. return SCM_UNSPECIFIED;
  437. }
  438. static SCM
  439. c_handler (void *d, SCM tag, SCM args)
  440. {
  441. struct c_data *data;
  442. /* If TAG is `quit', exit() the process. */
  443. if (scm_is_eq (tag, scm_from_latin1_symbol ("quit")))
  444. exit (scm_exit_status (args));
  445. data = (struct c_data *)d;
  446. data->result = NULL;
  447. return SCM_UNSPECIFIED;
  448. }
  449. static SCM
  450. pre_unwind_handler (void *error_port, SCM tag, SCM args)
  451. {
  452. /* Print the exception unless TAG is `quit'. */
  453. if (!scm_is_eq (tag, scm_from_latin1_symbol ("quit")))
  454. print_exception_and_backtrace (SCM_PACK_POINTER (error_port), tag, args);
  455. return SCM_UNSPECIFIED;
  456. }
  457. void *
  458. scm_c_with_continuation_barrier (void *(*func) (void *), void *data)
  459. {
  460. struct c_data c_data;
  461. c_data.func = func;
  462. c_data.data = data;
  463. scm_i_with_continuation_barrier (c_body, &c_data,
  464. c_handler, &c_data,
  465. pre_unwind_handler,
  466. SCM_UNPACK_POINTER (scm_current_error_port ()));
  467. return c_data.result;
  468. }
  469. struct scm_data {
  470. SCM proc;
  471. };
  472. static SCM
  473. scm_body (void *d)
  474. {
  475. struct scm_data *data = (struct scm_data *)d;
  476. return scm_call_0 (data->proc);
  477. }
  478. static SCM
  479. scm_handler (void *d, SCM tag, SCM args)
  480. {
  481. /* Print a message. Note that if TAG is `quit', this will exit() the
  482. process. */
  483. scm_handle_by_message_noexit (NULL, tag, args);
  484. return SCM_BOOL_F;
  485. }
  486. SCM_DEFINE (scm_with_continuation_barrier, "with-continuation-barrier", 1,0,0,
  487. (SCM proc),
  488. "Call @var{proc} and return its result. Do not allow the invocation of\n"
  489. "continuations that would leave or enter the dynamic extent of the call\n"
  490. "to @code{with-continuation-barrier}. Such an attempt causes an error\n"
  491. "to be signaled.\n"
  492. "\n"
  493. "Throws (such as errors) that are not caught from within @var{proc} are\n"
  494. "caught by @code{with-continuation-barrier}. In that case, a short\n"
  495. "message is printed to the current error port and @code{#f} is returned.\n"
  496. "\n"
  497. "Thus, @code{with-continuation-barrier} returns exactly once.\n")
  498. #define FUNC_NAME s_scm_with_continuation_barrier
  499. {
  500. struct scm_data scm_data;
  501. scm_data.proc = proc;
  502. return scm_i_with_continuation_barrier (scm_body, &scm_data,
  503. scm_handler, &scm_data,
  504. pre_unwind_handler,
  505. SCM_UNPACK_POINTER (scm_current_error_port ()));
  506. }
  507. #undef FUNC_NAME
  508. void
  509. scm_init_continuations ()
  510. {
  511. tc16_continuation = scm_make_smob_type ("continuation", 0);
  512. scm_set_smob_print (tc16_continuation, continuation_print);
  513. #include "libguile/continuations.x"
  514. }
  515. /*
  516. Local Variables:
  517. c-file-style: "gnu"
  518. End:
  519. */