Skip to content

Commit

Permalink
Move REPL condition printing into the SRFI 35 implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
dpk committed Nov 2, 2024
1 parent 76f35bc commit 2781739
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 52 deletions.
45 changes: 0 additions & 45 deletions lib/chibi/repl.scm
Original file line number Diff line number Diff line change
Expand Up @@ -370,49 +370,6 @@
(display ".\nNote module files must end in \".sld\".\n" out)))))))
)))

(define (repl-print-condition exn out)
(define components (simple-conditions exn))
(define n-components (length components))
(display "CONDITION: " out)
(display n-components out)
(display " component" out)
(if (not (= n-components 1)) (display "s" out))
(display "\n" out)
(for-each
(lambda (component idx)
(define component-type (type-of component))
(display " " out)
(display idx out)
(display ". " out)
(display (type-name component-type) out)
(display "\n" out)
(let loop ((as (reverse
(condition-type-ancestors component-type)))
(idx 0))
(if (not (null? as))
(let ((a (car as)))
(let a-loop ((fields (type-slots a))
(idx idx))
(if (null? fields)
(loop (cdr as) idx)
(begin
(display " " out)
(display (if (pair? (car fields))
(car (cdar fields))
(car fields))
out)
(if (not (eqv? a component-type))
(begin
(display " (" out)
(display (type-name a) out)
(display ")" out)))
(display ": " out)
(write (slot-ref component-type component idx) out)
(display "\n" out)
(a-loop (cdr fields) (+ idx 1)))))))))
components
(iota n-components 1)))

(define undefined-value (if #f #f))

(define $0 undefined-value)
Expand Down Expand Up @@ -463,8 +420,6 @@
(lambda (n) (thread-interrupt! thread))
(lambda ()
(protect (exn
((condition? exn)
(repl-print-condition exn out))
(else
(repl-print-exception exn out)
(repl-advise-exception exn (current-error-port))))
Expand Down
1 change: 0 additions & 1 deletion lib/chibi/repl.sld
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
(srfi 1)
(srfi 9)
(only (srfi 18) current-thread)
(srfi 35 internal)
(srfi 38)
(srfi 95)
(srfi 98))
Expand Down
43 changes: 43 additions & 0 deletions lib/srfi/35/internal.scm
Original file line number Diff line number Diff line change
Expand Up @@ -204,3 +204,46 @@
(define-condition-type/constructor &error &serious
make-error error?)

;; (chibi repl) support
(define-method (repl-print-exception (exn condition?) (out output-port?))
(define components (simple-conditions exn))
(define n-components (length components))
(display "CONDITION: " out)
(display n-components out)
(display " component" out)
(if (not (= n-components 1)) (display "s" out))
(display "\n" out)
(for-each
(lambda (component idx)
(define component-type (record-rtd component))
(display " " out)
(display idx out)
(display ". " out)
(display (rtd-name component-type) out)
(display "\n" out)
(let loop ((as (reverse
(condition-type-ancestors component-type)))
(idx 0))
(if (not (null? as))
(let ((a (car as)))
(let a-loop ((fields (vector->list (rtd-field-names a)))
(idx idx))
(if (null? fields)
(loop (cdr as) idx)
(begin
(display " " out)
(display (if (pair? (car fields))
(car (cdar fields))
(car fields))
out)
(if (not (eqv? a component-type))
(begin
(display " (" out)
(display (rtd-name a) out)
(display ")" out)))
(display ": " out)
(write (slot-ref component-type component idx) out)
(display "\n" out)
(a-loop (cdr fields) (+ idx 1)))))))))
components
(iota n-components 1)))
11 changes: 5 additions & 6 deletions lib/srfi/35/internal.sld
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,27 @@
define-record-type
;; exclude (srfi 1 immutable) duplicate imports:
map cons list append reverse)
(scheme write)
(only (chibi)
er-macro-transformer
slot-ref
is-a?)
(only (chibi repl) repl-print-exception)
(only (chibi generic) define-method)
;; don’t let people go messing with a compound condition
;; components list:
(srfi 1 immutable)
(srfi 99)
(srfi 133))
(export simple-condition?
compound-condition?
make-condition-type
(export make-condition-type
condition?
condition-type?
condition-subtype?
condition-type-ancestors
make-condition
make-compound-condition
condition-has-type?
condition-ref
simple-conditions
extract-condition
compound-condition-components
condition-predicate
condition-accessor
define-condition-type/constructor
Expand Down

0 comments on commit 2781739

Please sign in to comment.