(let ((idx (add-trap-at-source-location! file line)))
(format #t "Trap ~a: ~a.~%" idx (trap-name idx)))))
+(define (repl-pop-continuation-resumer msg)
+ ;; Capture the dynamic environment with this prompt thing. The
+ ;; result is a procedure that takes a frame.
+ (% (call-with-values
+ (lambda ()
+ (abort
+ (lambda (k)
+ ;; Call frame->stack-vector before reinstating the
+ ;; continuation, so that we catch the %stacks fluid at
+ ;; the time of capture.
+ (lambda (frame)
+ (k frame
+ (frame->stack-vector
+ (frame-previous frame)))))))
+ (lambda (from stack)
+ (format #t "~a~%" msg)
+ (let ((vals (frame-return-values from)))
+ (if (null? vals)
+ (format #t "No return values.~%" msg)
+ (begin
+ (format #t "Return values:~%" msg)
+ (for-each (lambda (x) (repl-print repl x)) vals))))
+ ((module-ref (resolve-interface '(system repl repl)) 'start-repl)
+ #:debug (make-debug stack 0 msg))))))
+
(define-stack-command (finish repl)
"finish
Run until the current frame finishes.
Resume execution, breaking when the current frame finishes."
- (let ((msg (format #f "Return from ~a" cur)))
- (define resume-repl
- ;; Capture the dynamic environment with this prompt thing. The
- ;; result is a procedure that takes a frame.
- (% (call-with-values
- (lambda ()
- (abort
- (lambda (k)
- ;; Call frame->stack-vector before reinstating the
- ;; continuation, so that we catch the %stacks fluid at
- ;; the time of capture.
- (lambda (frame)
- (k frame
- (frame->stack-vector
- (frame-previous frame)))))))
- (lambda (from stack)
- (format #t "~a~%" msg)
- (let ((vals (frame-return-values from)))
- (if (null? vals)
- (format #t "No return values.~%" msg)
- (begin
- (format #t "Return values:~%" msg)
- (for-each (lambda (x) (repl-print repl x)) vals))))
- ((module-ref (resolve-interface '(system repl repl)) 'start-repl)
- #:debug (make-debug stack 0 msg))))))
- (add-trap-at-frame-finish! cur resume-repl)
+ (let ((handler (repl-pop-continuation-resumer
+ (format #f "Return from ~a" cur))))
+ (add-ephemeral-trap-at-frame-finish! cur handler)
(throw 'quit)))
(define-meta-command (tracepoint repl (form))
add-trap-at-procedure-call!
add-trace-at-procedure-call!
add-trap-at-source-location!
- add-trap-at-frame-finish!))
+ add-ephemeral-trap-at-frame-finish!))
(define %default-trap-handler (make-fluid))
(format #f "Breakpoint at ~a:~a" file user-line)))))
;; handler := frame -> nothing
-(define* (add-trap-at-frame-finish! frame handler
- #:optional (trap-state (the-trap-state)))
+(define* (add-ephemeral-trap-at-frame-finish! frame handler
+ #:optional (trap-state
+ (the-trap-state)))
(let* ((idx (next-ephemeral-index! trap-state))
(trap (trap-frame-finish
frame