summaryrefslogtreecommitdiffstats
path: root/share
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2015-11-02 18:30:50 -0800
committerKaz Kylheku <kaz@kylheku.com>2015-11-02 18:30:50 -0800
commit3ac0654ecebb31ebaaf553446244408fcf0f79fc (patch)
tree186eab038084aa05c1598b86ba2b684cb7572440 /share
parent18dd42f65e620326bb21ffcde92004cc9705cbf8 (diff)
downloadtxr-3ac0654ecebb31ebaaf553446244408fcf0f79fc.tar.gz
txr-3ac0654ecebb31ebaaf553446244408fcf0f79fc.tar.bz2
txr-3ac0654ecebb31ebaaf553446244408fcf0f79fc.zip
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.
Diffstat (limited to 'share')
-rw-r--r--share/txr/stdlib/yield.tl27
1 files changed, 9 insertions, 18 deletions
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))