Unwind before exit

This commit is contained in:
Yota Toyama 2023-10-13 16:37:39 +11:00
parent fe93067553
commit 70e5aa14a3

View file

@ -1,9 +1,18 @@
(define-library (scheme process-context)
(import (chibi) (srfi 98))
(cond-expand (windows (import (only (chibi win32 process-win32) exit)))
(else (import (only (chibi process) exit))))
(cond-expand (windows (import (rename (only (chibi win32 process-win32) exit) (exit emergency-exit))))
(else (import (rename (only (chibi process) exit) (exit emergency-exit)))))
(export get-environment-variable get-environment-variables
command-line exit emergency-exit)
;; TODO: Make exit unwind and finalize properly.
(begin (define emergency-exit exit)))
(begin
(define unwind #f)
((call/cc
(lambda (continuation)
(set! unwind continuation)
(lambda () #f))))
(define (exit . rest)
(unwind (lambda () (apply emergency-exit rest))))))