mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-06-11 14:21:10 +02:00
repl.scm relies on `display-backtrace' to do everything, some naming tweaks
* module/ice-9/boot-9.scm (default-pre-unwind-handler): Rename from default-lazy-handler. (pre-unwind-handler-dispatch): Rename from lazy-hadler-dispatch. (error-catching-loop): Adjust caller. * module/system/repl/repl.scm (default-pre-unwind-handler): Remove this definition, in favor of the default one in boot-9. (default-catch-handler): Don't do a vm-backtrace, as we will soon be relying on core machinery to do that for us. (call-with-backtrace): Start a new stack for the thunk. (with-backtrace): Macro version of call-with-backtrace. (start-repl): Use with-backtrace for brevity. Start a stack with #t as the tag instead of repl-eval, because all traces of repl-eval are gone after it does a tail-call. * module/ice-9/debugger.scm: * module/ice-9/debugging/traps.scm: * module/ice-9/stack-catch.scm: Adapt to s/lazy/pre-unwind/ in boot-9.scm.
This commit is contained in:
parent
9a9f64874a
commit
9f0e9918f4
5 changed files with 47 additions and 55 deletions
|
@ -2323,12 +2323,12 @@ module '(ice-9 q) '(make-q q-length))}."
|
||||||
|
|
||||||
(define (set-repl-prompt! v) (set! scm-repl-prompt v))
|
(define (set-repl-prompt! v) (set! scm-repl-prompt v))
|
||||||
|
|
||||||
(define (default-lazy-handler key . args)
|
(define (default-pre-unwind-handler key . args)
|
||||||
(save-stack lazy-handler-dispatch)
|
(save-stack pre-unwind-handler-dispatch)
|
||||||
(apply throw key args))
|
(apply throw key args))
|
||||||
|
|
||||||
(define (lazy-handler-dispatch key . args)
|
(define (pre-unwind-handler-dispatch key . args)
|
||||||
(apply default-lazy-handler key args))
|
(apply default-pre-unwind-handler key args))
|
||||||
|
|
||||||
(define abort-hook (make-hook))
|
(define abort-hook (make-hook))
|
||||||
|
|
||||||
|
@ -2405,15 +2405,15 @@ module '(ice-9 q) '(make-q q-length))}."
|
||||||
(else
|
(else
|
||||||
(apply bad-throw key args)))))))
|
(apply bad-throw key args)))))))
|
||||||
|
|
||||||
;; Note that having just `lazy-handler-dispatch'
|
;; Note that having just `pre-unwind-handler-dispatch'
|
||||||
;; here is connected with the mechanism that
|
;; here is connected with the mechanism that
|
||||||
;; produces a nice backtrace upon error. If, for
|
;; produces a nice backtrace upon error. If, for
|
||||||
;; example, this is replaced with (lambda args
|
;; example, this is replaced with (lambda args
|
||||||
;; (apply lazy-handler-dispatch args)), the stack
|
;; (apply pre-unwind-handler-dispatch args)), the stack
|
||||||
;; cutting (in save-stack) goes wrong and ends up
|
;; cutting (in save-stack) goes wrong and ends up
|
||||||
;; saving no stack at all, so there is no
|
;; saving no stack at all, so there is no
|
||||||
;; backtrace.
|
;; backtrace.
|
||||||
lazy-handler-dispatch)))
|
pre-unwind-handler-dispatch)))
|
||||||
|
|
||||||
(if next (loop next) status)))
|
(if next (loop next) status)))
|
||||||
(set! set-batch-mode?! (lambda (arg)
|
(set! set-batch-mode?! (lambda (arg)
|
||||||
|
|
|
@ -131,16 +131,16 @@ Indicates that the debugger should display an introductory message.
|
||||||
|
|
||||||
(define (debug-on-error syms)
|
(define (debug-on-error syms)
|
||||||
"Enable or disable debug on error."
|
"Enable or disable debug on error."
|
||||||
(set! lazy-handler-dispatch
|
(set! pre-unwind-handler-dispatch
|
||||||
(if syms
|
(if syms
|
||||||
(lambda (key . args)
|
(lambda (key . args)
|
||||||
(if (memq key syms)
|
(if (memq key syms)
|
||||||
(begin
|
(begin
|
||||||
(debug-stack (make-stack #t lazy-handler-dispatch)
|
(debug-stack (make-stack #t pre-unwind-handler-dispatch)
|
||||||
#:with-introduction
|
#:with-introduction
|
||||||
#:continuable)
|
#:continuable)
|
||||||
(throw 'abort key)))
|
(throw 'abort key)))
|
||||||
(apply default-lazy-handler key args))
|
(apply default-pre-unwind-handler key args))
|
||||||
default-lazy-handler)))
|
default-pre-unwind-handler)))
|
||||||
|
|
||||||
;;; (ice-9 debugger) ends here.
|
;;; (ice-9 debugger) ends here.
|
||||||
|
|
|
@ -59,7 +59,7 @@
|
||||||
trap-ordering
|
trap-ordering
|
||||||
behaviour-ordering
|
behaviour-ordering
|
||||||
throw->trap-context
|
throw->trap-context
|
||||||
on-lazy-handler-dispatch
|
on-pre-unwind-handler-dispatch
|
||||||
;; Interface for authors of new <trap> subclasses.
|
;; Interface for authors of new <trap> subclasses.
|
||||||
<trap-context>
|
<trap-context>
|
||||||
<trap>
|
<trap>
|
||||||
|
@ -467,14 +467,14 @@ it twice."
|
||||||
;;; same code for certain events that are trap-like, but not actually
|
;;; same code for certain events that are trap-like, but not actually
|
||||||
;;; traps in the sense of the calls made by libguile's evaluator.
|
;;; traps in the sense of the calls made by libguile's evaluator.
|
||||||
|
|
||||||
;;; The main example of this is when an error is signalled. Guile
|
;;; The main example of this is when an error is signalled. Guile
|
||||||
;;; doesn't yet have a 100% reliable way of hooking into errors, but
|
;;; doesn't yet have a 100% reliable way of hooking into errors, but in
|
||||||
;;; in practice most errors go through a lazy-catch whose handler is
|
;;; practice most errors go through a catch whose pre-unwind handler is
|
||||||
;;; lazy-handler-dispatch (defined in ice-9/boot-9.scm), which in turn
|
;;; pre-unwind-handler-dispatch (defined in ice-9/boot-9.scm), which in
|
||||||
;;; calls default-lazy-handler. So we can present most errors as
|
;;; turn calls default-pre-unwind-handler. So we can present most errors
|
||||||
;;; pseudo-traps by modifying default-lazy-handler.
|
;;; as pseudo-traps by modifying default-pre-unwind-handler.
|
||||||
|
|
||||||
(define default-default-lazy-handler default-lazy-handler)
|
(define default-default-pre-unwind-handler default-pre-unwind-handler)
|
||||||
|
|
||||||
(define (throw->trap-context key args . stack-args)
|
(define (throw->trap-context key args . stack-args)
|
||||||
(let ((ctx (make <trap-context>
|
(let ((ctx (make <trap-context>
|
||||||
|
@ -489,16 +489,16 @@ it twice."
|
||||||
(apply make-stack #t stack-args))))
|
(apply make-stack #t stack-args))))
|
||||||
ctx))
|
ctx))
|
||||||
|
|
||||||
(define (on-lazy-handler-dispatch behaviour . ignored-keys)
|
(define (on-pre-unwind-handler-dispatch behaviour . ignored-keys)
|
||||||
(set! default-lazy-handler
|
(set! default-pre-unwind-handler
|
||||||
(if behaviour
|
(if behaviour
|
||||||
(lambda (key . args)
|
(lambda (key . args)
|
||||||
(or (memq key ignored-keys)
|
(or (memq key ignored-keys)
|
||||||
(behaviour (throw->trap-context key
|
(behaviour (throw->trap-context key
|
||||||
args
|
args
|
||||||
lazy-handler-dispatch)))
|
pre-unwind-handler-dispatch)))
|
||||||
(apply default-default-lazy-handler key args))
|
(apply default-default-pre-unwind-handler key args))
|
||||||
default-default-lazy-handler)))
|
default-default-pre-unwind-handler)))
|
||||||
|
|
||||||
;;; {Trap Classes}
|
;;; {Trap Classes}
|
||||||
|
|
||||||
|
|
|
@ -40,4 +40,4 @@ this call to @code{catch}."
|
||||||
(catch key
|
(catch key
|
||||||
thunk
|
thunk
|
||||||
handler
|
handler
|
||||||
lazy-handler-dispatch))
|
pre-unwind-handler-dispatch))
|
||||||
|
|
|
@ -51,11 +51,6 @@
|
||||||
(with-fluid* current-reader (meta-reader lread)
|
(with-fluid* current-reader (meta-reader lread)
|
||||||
(lambda () (repl-reader (lambda () (repl-prompt repl)))))))
|
(lambda () (repl-reader (lambda () (repl-prompt repl)))))))
|
||||||
|
|
||||||
(define (default-pre-unwind-handler key . args)
|
|
||||||
(save-stack default-pre-unwind-handler)
|
|
||||||
(vm-save-stack (the-vm))
|
|
||||||
(apply throw key args))
|
|
||||||
|
|
||||||
(define (default-catch-handler . args)
|
(define (default-catch-handler . args)
|
||||||
(pmatch args
|
(pmatch args
|
||||||
((quit . _)
|
((quit . _)
|
||||||
|
@ -66,8 +61,6 @@
|
||||||
(apply format #t msg args)
|
(apply format #t msg args)
|
||||||
(newline))
|
(newline))
|
||||||
((,key ,subr ,msg ,args . ,rest)
|
((,key ,subr ,msg ,args . ,rest)
|
||||||
(vm-backtrace (the-vm))
|
|
||||||
(newline)
|
|
||||||
(let ((cep (current-error-port)))
|
(let ((cep (current-error-port)))
|
||||||
(cond ((not (stack? (fluid-ref the-last-stack))))
|
(cond ((not (stack? (fluid-ref the-last-stack))))
|
||||||
((memq 'backtrace (debug-options-interface))
|
((memq 'backtrace (debug-options-interface))
|
||||||
|
@ -93,43 +86,42 @@
|
||||||
|
|
||||||
(define (call-with-backtrace thunk)
|
(define (call-with-backtrace thunk)
|
||||||
(catch #t
|
(catch #t
|
||||||
thunk
|
(lambda () (%start-stack #t thunk))
|
||||||
default-catch-handler
|
default-catch-handler
|
||||||
default-pre-unwind-handler))
|
pre-unwind-handler-dispatch))
|
||||||
|
|
||||||
|
(define-macro (with-backtrace form)
|
||||||
|
`(call-with-backtrace (lambda () ,form)))
|
||||||
|
|
||||||
(define (start-repl lang)
|
(define (start-repl lang)
|
||||||
(let ((repl (make-repl lang))
|
(let ((repl (make-repl lang))
|
||||||
(status #f))
|
(status #f))
|
||||||
(repl-welcome repl)
|
(repl-welcome repl)
|
||||||
(let prompt-loop ()
|
(let prompt-loop ()
|
||||||
(let ((exp (call-with-backtrace
|
(let ((exp (with-backtrace (prompting-meta-read repl))))
|
||||||
(lambda () (prompting-meta-read repl)))))
|
|
||||||
(cond
|
(cond
|
||||||
((eqv? exp (if #f #f))) ; read error, pass
|
((eqv? exp (if #f #f))) ; read error, pass
|
||||||
((eq? exp meta-command-token)
|
((eq? exp meta-command-token)
|
||||||
(call-with-backtrace
|
(with-backtrace (meta-command repl (read-line))))
|
||||||
(lambda ()
|
|
||||||
(meta-command repl (read-line)))))
|
|
||||||
((eof-object? exp)
|
((eof-object? exp)
|
||||||
(newline)
|
(newline)
|
||||||
(set! status '()))
|
(set! status '()))
|
||||||
(else
|
(else
|
||||||
(call-with-backtrace
|
(with-backtrace
|
||||||
(lambda ()
|
(catch 'quit
|
||||||
(catch 'quit
|
(lambda ()
|
||||||
(lambda ()
|
(call-with-values
|
||||||
(call-with-values (lambda ()
|
(lambda ()
|
||||||
(run-hook before-eval-hook exp)
|
(run-hook before-eval-hook exp)
|
||||||
(start-stack repl-eval
|
(start-stack #t
|
||||||
(repl-eval repl
|
(repl-eval repl (repl-parse repl exp))))
|
||||||
(repl-parse repl exp))))
|
(lambda l
|
||||||
(lambda l
|
(for-each (lambda (v)
|
||||||
(for-each (lambda (v)
|
(run-hook before-print-hook v)
|
||||||
(run-hook before-print-hook v)
|
(repl-print repl v))
|
||||||
(repl-print repl v))
|
l))))
|
||||||
l))))
|
(lambda (k . args)
|
||||||
(lambda (k . args)
|
(set! status args))))))
|
||||||
(set! status args)))))))
|
|
||||||
(or status
|
(or status
|
||||||
(begin
|
(begin
|
||||||
(next-char #f) ;; consume trailing whitespace
|
(next-char #f) ;; consume trailing whitespace
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue