summaryrefslogtreecommitdiffstats
path: root/share
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2015-10-29 06:46:05 -0700
committerKaz Kylheku <kaz@kylheku.com>2015-10-29 06:46:05 -0700
commit2764d8e78d0d72f7c0d8fcc4e41cf4df41017026 (patch)
tree4e6a9264ad0261282fd5bee6c6f7d47da798c35a /share
parentd651ee10089e684686d9255e6f479fa16c7576db (diff)
downloadtxr-2764d8e78d0d72f7c0d8fcc4e41cf4df41017026.tar.gz
txr-2764d8e78d0d72f7c0d8fcc4e41cf4df41017026.tar.bz2
txr-2764d8e78d0d72f7c0d8fcc4e41cf4df41017026.zip
Finalize obtain continuator function.
* share/txr/stdlib/yield.tl (sys:obtain-impl): Add a finalizer to the returned closure which will feed sys:cont-poison object to the most recently captured continuation. Thus abandoned obtain blocks which have become garbage shall have their unwinding performed. * txr.1: Documented the finalization behavior.
Diffstat (limited to 'share')
-rw-r--r--share/txr/stdlib/yield.tl17
1 files changed, 10 insertions, 7 deletions
diff --git a/share/txr/stdlib/yield.tl b/share/txr/stdlib/yield.tl
index ef0518e6..ea9bb4d2 100644
--- a/share/txr/stdlib/yield.tl
+++ b/share/txr/stdlib/yield.tl
@@ -26,13 +26,16 @@
(defstruct (sys:yld-item val cont) nil val cont)
(defun sys:obtain-impl (fun)
- (lambda (: reply)
- (let ((yi (call fun reply)))
- (cond
- ((eq (typeof yi) 'sys:yld-item)
- (set fun yi.cont)
- yi.val)
- (t yi)))))
+ (finalize
+ (lambda (: reply)
+ (let ((yi (call fun reply)))
+ (cond
+ ((eq (typeof yi) 'sys:yld-item)
+ (set fun yi.cont)
+ yi.val)
+ (t yi))))
+ (lambda (cont)
+ (call cont 'sys:cont-poison))))
(defun sys:yield-impl (name fun ctx-form)
(let ((cont (sys:capture-cont name ctx-form)))