From 3ac0654ecebb31ebaaf553446244408fcf0f79fc Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Mon, 2 Nov 2015 18:30:50 -0800 Subject: Moving sys:capture-cont to call/cc style API. * unwind.c (revive_cont): Don't wrap cons cell around passed arg; just pass it directly. We don't need that convention any more. * capture_cont: Take functional argument. Pass the captured continuation to the function. If the function returns, return whatever it returned. When resuming, return the continuation argument. (uw_capture_cont): Take functional second argument and pass to capture_cont. Context form becomes third argument. (uw_late_init): Update registration of sys:capture-cont to three arguments, two required. * unwind.h (uw_capture_cont): Declaration updated. * share/txr/stdlib/yield.tl (sys:yield-impl): Not needed any more; all this was doing was implementing a call/cc style interface around sys:capture-cont which can now be used directly. (yield-from): Use sys:capture-cont directly. (suspend): Simplified to the point of triviality with new sys:capture-cont. * txr.1: Documented. --- share/txr/stdlib/yield.tl | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) (limited to 'share') diff --git a/share/txr/stdlib/yield.tl b/share/txr/stdlib/yield.tl index 3b58ace2..43fa57ee 100644 --- a/share/txr/stdlib/yield.tl +++ b/share/txr/stdlib/yield.tl @@ -38,12 +38,6 @@ (lambda (cont) (call cont 'sys:cont-poison)))) -(defun sys:yield-impl (name fun ctx-form) - (let ((cont (sys:capture-cont name ctx-form))) - (if (car cont) - (call fun cont) - (cdr cont)))) - (defmacro obtain (. body) (let ((arg (gensym "arg"))) ^(sys:obtain-impl (lambda (,arg) @@ -55,20 +49,17 @@ (defmacro yield-from (:form ctx-form name form) (let ((cont-sym (gensym))) - ^(sys:yield-impl ',name - (lambda (,cont-sym) - (sys:abscond-from ,name - (new (sys:yld-item - ,form (cdr ,cont-sym))))) - ',ctx-form))) + ^(sys:capture-cont ',name + (lambda (,cont-sym) + (sys:abscond-from ,name + (new (sys:yld-item + ,form ,cont-sym)))) + ',ctx-form))) (defmacro yield (form) ^(yield-from nil ,form)) (defmacro suspend (:form form name var . body) - (with-gensyms (cap val) - ^(tree-bind (,cap . ,val) (sys:capture-cont ',name ',form) - (if ,cap - (let ((,var ,val)) - (sys:abscond-from ,name ,*body)) - ,val)))) + ^(sys:capture-cont ',name (lambda (,var) + (sys:abscond-from ,name ,*body)) + ',form)) -- cgit v1.2.3