assert now gives source information when available.

This commit is contained in:
Abdulaziz Ghuloum 2008-07-29 11:04:52 -07:00
parent 5aa6e1b05e
commit 959082d12d
3 changed files with 28 additions and 13 deletions

View File

@ -1 +1 @@
1560 1561

View File

@ -634,6 +634,7 @@
[apply i r ba se] [apply i r ba se]
[asin i r ba se] [asin i r ba se]
[assert i r ba] [assert i r ba]
[assertion-error ]
[assertion-violation i r ba] [assertion-violation i r ba]
[atan i r ba se] [atan i r ba se]
[boolean=? i r ba] [boolean=? i r ba]

View File

@ -30,7 +30,7 @@
compile-r6rs-top-level boot-library-expand compile-r6rs-top-level boot-library-expand
null-environment scheme-report-environment null-environment scheme-report-environment
interaction-environment interaction-environment
ellipsis-map) ellipsis-map assertion-error)
(import (import
(except (rnrs) (except (rnrs)
environment environment? identifier? environment environment? identifier?
@ -1435,8 +1435,10 @@
(lambda (stx) (lambda (stx)
(syntax-match stx () (syntax-match stx ()
((_ expr) ((_ expr)
(bless `(unless ,expr (let ([pos (or (expression-position stx)
(assertion-violation 'assert "assertion failed" ',expr))))))) (expression-position expr))])
(bless
`(unless ,expr (assertion-error ',expr ',pos))))))))
(define endianness-macro (define endianness-macro
(lambda (stx) (lambda (stx)
@ -3843,21 +3845,33 @@
(assertion-violation 'bound-identifier=? "not an identifier" y)) (assertion-violation 'bound-identifier=? "not an identifier" y))
(assertion-violation 'bound-identifier=? "not an identifier" x)))) (assertion-violation 'bound-identifier=? "not an identifier" x))))
(define (extract-position-condition x) (define (make-source-condition x)
(define-condition-type &source-information &condition (define-condition-type &source-information &condition
make-source-condition source-condition? make-source-condition source-condition?
(file-name source-filename) (file-name source-filename)
(character source-character)) (character source-character))
(if (stx? x) (if (pair? x)
(let ([x (stx-expr x)]) (make-source-condition (car x) (cdr x))
(if (annotation? x)
(let ([src (annotation-source x)])
(if (pair? src)
(make-source-condition (car src) (cdr src))
(condition)))
(condition)))
(condition))) (condition)))
(define (extract-position-condition x)
(make-source-condition (expression-position x)))
(define (expression-position x)
(and (stx? x)
(let ([x (stx-expr x)])
(and (annotation? x)
(annotation-source x)))))
(define (assertion-error expr pos)
(raise
(condition
(make-assertion-violation)
(make-who-condition 'assert)
(make-message-condition "assertion failed")
(make-irritants-condition (list expr))
(make-source-condition pos))))
(define syntax-error (define syntax-error
(lambda (x . args) (lambda (x . args)
(unless (for-all string? args) (unless (for-all string? args)