From 8c8790cb9731adb521c06dee7489218fc02029a6 Mon Sep 17 00:00:00 2001 From: Jose Antonio Ortega Ruiz Date: Sat, 21 Feb 2009 02:45:30 +0100 Subject: Capture backtrace. Fix load/compile from Emacs. --- geiser/emacs.scm | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'geiser') diff --git a/geiser/emacs.scm b/geiser/emacs.scm index 382958d..d5e245b 100644 --- a/geiser/emacs.scm +++ b/geiser/emacs.scm @@ -37,16 +37,25 @@ ge:module-children ge:module-location) #:use-module (srfi srfi-1) + #:use-module (system base compile) #:use-module ((geiser introspection) :renamer (symbol-prefix-proc 'ge:))) (define (write-result result output) (write (list (cons 'result result) (cons 'output output))) (newline)) -(define (write-error key . args) - (write (list (cons 'error (apply parse-error (cons key args))))) +(define (write-error key args stack) + (write (list (cons 'error (apply parse-error (cons key args))) + (cons 'stack (parse-stack stack)))) (newline)) +(define (parse-stack stack) + (if stack + (list + (with-output-to-string + (lambda () (display-backtrace stack (current-output-port))))) + '())) + (define (parse-error key . args) (let* ((len (length args)) (subr (and (> len 0) (first args))) @@ -58,10 +67,11 @@ (cons 'msg (if msg (apply format (cons #f (cons msg margs))) '())) (cons 'rest (or rest '()))))) -(define (evaluate form module evaluator) +(define (evaluate form module-name evaluator) (let ((module (or (and (list? module-name) (resolve-module module-name)) - (current-module)))) + (current-module))) + (captured-stack #f)) (catch #t (lambda () (let ((result #f)) @@ -69,7 +79,8 @@ (lambda () (set! result (evaluator form module)))))) (write-result result output)))) - write-error))) + (lambda (key . args) (write-error key args captured-stack)) + (lambda (key . args) (set! captured-stack (make-stack #t)))))) (define (eval-compile form module) (save-module-excursion -- cgit v1.2.3