4c9690996c
* src/mes.c (eval_apply): Iterative recursive macro expand. * src/posix.c (set_current_input_port): Return previous port. * module/mes/catch.mes (%eh): Use core:display. * module/mes/display.mes (display-cut, display-cut2): Move macro definitions to toplevel.
57 lines
2 KiB
Scheme
57 lines
2 KiB
Scheme
;;; -*-scheme-*-
|
|
|
|
;;; Mes --- Maxwell Equations of Software
|
|
;;; Copyright © 2016,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
|
;;;
|
|
;;; This file is part of Mes.
|
|
;;;
|
|
;;; Mes is free software; you can redistribute it and/or modify it
|
|
;;; under the terms of the GNU General Public License as published by
|
|
;;; the Free Software Foundation; either version 3 of the License, or (at
|
|
;;; your option) any later version.
|
|
;;;
|
|
;;; Mes is distributed in the hope that it will be useful, but
|
|
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
;;; GNU General Public License for more details.
|
|
;;;
|
|
;;; You should have received a copy of the GNU General Public License
|
|
;;; along with Mes. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
(mes-use-module (mes let))
|
|
(mes-use-module (mes fluids))
|
|
|
|
(define %eh (make-fluid
|
|
(lambda (key . args)
|
|
(if #f ;;(defined? 'simple-format)
|
|
(simple-format (current-error-port) "unhandled exception:~a:~a\n" key args)
|
|
(begin
|
|
(core:display-error "unhandled exception:")
|
|
(core:display-error key)
|
|
(core:display-error ":")
|
|
(core:write-error args)
|
|
(core:display-error "\n")))
|
|
(exit 1))))
|
|
|
|
(define (catch key thunk handler)
|
|
(let ((previous-eh (fluid-ref %eh)))
|
|
(with-fluid*
|
|
%eh #f
|
|
(lambda ()
|
|
(call/cc
|
|
(lambda (cc)
|
|
(fluid-set! %eh
|
|
(lambda (k . args)
|
|
(let ((handler (if (or (eq? key #t) (eq? key k)) handler
|
|
previous-eh)))
|
|
(cc
|
|
(lambda (x)
|
|
(apply handler (cons k args)))))))
|
|
(thunk)))))))
|
|
|
|
(define (throw key . args)
|
|
(let ((handler (fluid-ref %eh)))
|
|
(apply handler (cons key args))))
|
|
|
|
(define with-throw-handler catch) ; FIXME: hack for Nyacc 0.75
|