summaryrefslogtreecommitdiffstats
path: root/stdlib
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2023-09-27 21:08:08 -0700
committerKaz Kylheku <kaz@kylheku.com>2023-09-27 21:08:08 -0700
commit9b5c23e7c88535f49dfbc8d5028ff5c82704435a (patch)
tree2974d99914ef067c7f7f8ca4e27d830410248b39 /stdlib
parentf1c442b84179092d93b42fbf629fe7337bf177ba (diff)
downloadtxr-9b5c23e7c88535f49dfbc8d5028ff5c82704435a.tar.gz
txr-9b5c23e7c88535f49dfbc8d5028ff5c82704435a.tar.bz2
txr-9b5c23e7c88535f49dfbc8d5028ff5c82704435a.zip
Integration with setjmp/longjmp.
Defining libpng bindings, with longjmp catching, is now possible. * autoload.c (ffi_set_entries): Add setjmp symbol, which is a new macro in stdlib/ffi.tl. * ffi.c (jmp_buf_s): New symbol variable. (mk_jmp_buf, rt_setjmp, longjmp_wrap): New functions. (ffi_init): Initialize jmp_buf_s. Register sys:rt-setjmp and longjmp intrinsics. * ffi.h (jmp_buf_s): Declared. * stdlib/ffi.h (setjmp): New macro. Rather than introducing a new special operator, we use a run-time support function called sys:rt-setjmp, which takes functional arguments. * unwind.[ch] (uw_snapshot, uw_restore): New functions. The rt_setjmp function needs these to restore our unwind frame stack into a sane state after catching a longjmp, which bails without unwinding it, leaving the pointers referring to frames that no longer exist. * tests/017/setjmp.tl, * tests/017/setjmp.expected: New files. * txr.1: Documented.
Diffstat (limited to 'stdlib')
-rw-r--r--stdlib/ffi.tl7
1 files changed, 7 insertions, 0 deletions
diff --git a/stdlib/ffi.tl b/stdlib/ffi.tl
index ea561091..b7a29110 100644
--- a/stdlib/ffi.tl
+++ b/stdlib/ffi.tl
@@ -167,3 +167,10 @@
'znew))
(let ((qpairs (mappend (aret ^(',@1 ,@2)) (tuples 2 pairs))))
^(make-zstruct (ffi ,type) ,*qpairs)))
+
+(defmacro setjmp (:form f jmp-buf longjmp-var try-expr . longjmp-exprs)
+ (unless (bindable longjmp-var)
+ (compile-error f "~s is not a bindable symbol" longjmp-var))
+ ^(sys:rt-setjmp ,jmp-buf
+ (lambda () ,try-expr)
+ (lambda (,longjmp-var) ,*longjmp-exprs)))