summaryrefslogtreecommitdiffstats
path: root/share
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2015-10-29 06:49:49 -0700
committerKaz Kylheku <kaz@kylheku.com>2015-10-29 06:49:49 -0700
commit927a2b27edc8e29d4c0a3e572c516738fd5d4341 (patch)
tree49999f0febe323235dea07d261341fe4c5b0bf26 /share
parent2764d8e78d0d72f7c0d8fcc4e41cf4df41017026 (diff)
downloadtxr-927a2b27edc8e29d4c0a3e572c516738fd5d4341.tar.gz
txr-927a2b27edc8e29d4c0a3e572c516738fd5d4341.tar.bz2
txr-927a2b27edc8e29d4c0a3e572c516738fd5d4341.zip
Provide a way to free the continuation stacks.
* share/txr/stdlib/yield.tl (sys:obtain-impl): Pass sys:cont-free symbol to each abandoned continuation to release its stack buffer. (obtain): Handle the sys:cont-free symbol in the lambda, so the initial lambda can be treated uniformly with continuation functions. * txr.1: Documented sys:obtain-impl. * unwind.c (sys_cont_free_s): New symbol variable. (cont_mark): Check for null stack pointer and avoid marking. (revive_cont): If arg is sys:cont-free, then free the continuation and return nil. If the continuation has a null stack buffer, throw an error. (uw_late_init): Initialize sys_cont_free_s.
Diffstat (limited to 'share')
-rw-r--r--share/txr/stdlib/yield.tl7
1 files changed, 5 insertions, 2 deletions
diff --git a/share/txr/stdlib/yield.tl b/share/txr/stdlib/yield.tl
index ea9bb4d2..236faaa8 100644
--- a/share/txr/stdlib/yield.tl
+++ b/share/txr/stdlib/yield.tl
@@ -31,6 +31,7 @@
(let ((yi (call fun reply)))
(cond
((eq (typeof yi) 'sys:yld-item)
+ (call fun 'sys:cont-free)
(set fun yi.cont)
yi.val)
(t yi))))
@@ -44,8 +45,10 @@
(cdr cont))))
(defmacro obtain (. body)
- (let ((ignored (gensym "ign")))
- ^(sys:obtain-impl (lambda (,ignored) ,*body))))
+ (let ((arg (gensym "arg")))
+ ^(sys:obtain-impl (lambda (,arg)
+ (unless (eq ,arg 'sys:cont-free)
+ ,*body)))))
(defmacro obtain-block (name . body)
^(obtain (block ,name ,*body)))