fixed PR 10684 and fixed up some old, broken tests and fiddled with the test suite infrastructure

svn: r17536
This commit is contained in:
Robby Findler 2010-01-07 18:10:28 +00:00
parent dc9f3227c5
commit 52eee4547b
49 changed files with 531 additions and 534 deletions

View File

@ -1,171 +1,161 @@
(module bitmap-test-util mzscheme #lang scheme/gui
(require (lib "mred.ss" "mred") (require framework
(lib "mrpict.ss" "texpict") slideshow
(lib "framework.ss" "framework") "../pict.ss"
(lib "class.ss") "../reduction-semantics.ss"
"../pict.ss" "config.ss")
"../reduction-semantics.ss")
(provide test done)
(provide test done)
(define tests 0)
(define-struct failed-test (panel)) (define failed '())
(define (done)
(define show-diffs?-env "PLT_REDEX_TEST_NOSHOW_DIFFS") (printf "~a tests" tests)
(define show-diffs? (not (getenv show-diffs?-env))) (if (null? failed)
(printf ", all passed\n")
(define tests 0) (printf ", ~a failed\n" (length failed))))
(define failed '())
(define (done) (define-syntax (test stx)
(printf "~a tests" tests) (syntax-case stx ()
(if (null? failed) [(_ test-exp bitmap-filename)
(printf ", all passed\n") #`(test/proc
(printf ", ~a failed\n" (length failed)))) #,(syntax-line stx)
test-exp
(define-syntax (test stx) bitmap-filename)]))
(syntax-case stx ()
[(_ test-exp bitmap-filename) (define (test/proc line-number pict raw-bitmap-filename)
#`(test/proc (set! tests (+ tests 1))
#,(syntax-line stx) (let* ([bitmap-filename
test-exp (build-path (format "bmps-~a" (system-type))
bitmap-filename)])) (case (system-type)
[(unix) (string-append "unix-" raw-bitmap-filename)]
(define (test/proc line-number pict raw-bitmap-filename) [else raw-bitmap-filename]))]
(set! tests (+ tests 1)) [old-bitmap (if (file-exists? bitmap-filename)
(let* ([bitmap-filename (make-object bitmap% bitmap-filename)
(build-path "bmps" (let* ([bm (make-object bitmap% 100 20)]
(case (system-type) [bdc (make-object bitmap-dc% bm)])
[(unix) (string-append "unix-" raw-bitmap-filename)] (send bdc clear)
[else raw-bitmap-filename]))] (send bdc draw-text "does not exist" 0 0)
[old-bitmap (if (file-exists? bitmap-filename) (send bdc set-bitmap #f)
(make-object bitmap% bitmap-filename) bm))]
(let* ([bm (make-object bitmap% 100 20)] [new-bitmap (make-object bitmap%
[bdc (make-object bitmap-dc% bm)]) (inexact->exact (pict-width pict))
(send bdc clear) (inexact->exact (pict-height pict)))]
(send bdc draw-text "does not exist" 0 0) [bdc (make-object bitmap-dc% new-bitmap)])
(send bdc set-bitmap #f) (send bdc clear)
bm))] (draw-pict pict bdc 0 0)
[new-bitmap (make-object bitmap% (send bdc set-bitmap #f)
(inexact->exact (pict-width pict)) (let ([diff-bitmap (compute-diffs old-bitmap new-bitmap)])
(inexact->exact (pict-height pict)))] (when diff-bitmap
[bdc (make-object bitmap-dc% new-bitmap)]) (let ([failed-panel (make-failed-panel line-number bitmap-filename old-bitmap new-bitmap diff-bitmap)])
(send bdc clear) (set! failed (append failed (list failed-panel))))))))
(draw-pict pict bdc 0 0)
(send bdc set-bitmap #f) (define (compute-diffs old-bitmap new-bitmap)
(let ([diff-bitmap (compute-diffs old-bitmap new-bitmap)]) (let* ([w (max (send old-bitmap get-width)
(when diff-bitmap (send new-bitmap get-width))]
(if show-diffs? [h (max (send old-bitmap get-height)
(let ([failed-panel (make-failed-panel line-number bitmap-filename old-bitmap new-bitmap diff-bitmap)]) (send new-bitmap get-height))]
(set! failed (append failed (list (make-failed-test failed-panel))))) [diff-bitmap (make-object bitmap% w h)]
(set! failed (append failed (list #f)))))))) [new (make-object bitmap-dc% new-bitmap)]
[old (make-object bitmap-dc% old-bitmap)]
(define (compute-diffs old-bitmap new-bitmap) [diff (make-object bitmap-dc% diff-bitmap)]
(let* ([w (max (send old-bitmap get-width) [new-c (make-object color%)]
(send new-bitmap get-width))] [old-c (make-object color%)]
[h (max (send old-bitmap get-height) [any-different? #f])
(send new-bitmap get-height))] (let loop ([x 0])
[diff-bitmap (make-object bitmap% w h)] (unless (= x w)
[new (make-object bitmap-dc% new-bitmap)] (let loop ([y 0])
[old (make-object bitmap-dc% old-bitmap)] (unless (= y h)
[diff (make-object bitmap-dc% diff-bitmap)] (cond
[new-c (make-object color%)] [(and (<= x (send new-bitmap get-width))
[old-c (make-object color%)] (<= y (send new-bitmap get-height))
[any-different? #f]) (<= x (send old-bitmap get-width))
(let loop ([x 0]) (<= y (send old-bitmap get-height)))
(unless (= x w) (send new get-pixel x y new-c)
(let loop ([y 0]) (send old get-pixel x y old-c)
(unless (= y h) (cond
(cond [(and (= (send new-c red) (send old-c red))
[(and (<= x (send new-bitmap get-width)) (= (send new-c green) (send old-c green))
(<= y (send new-bitmap get-height)) (= (send new-c blue) (send old-c blue)))
(<= x (send old-bitmap get-width)) (send diff set-pixel x y new-c)]
(<= y (send old-bitmap get-height))) [else
(send new get-pixel x y new-c) (set! any-different? #t)
(send old get-pixel x y old-c) (send new-c set 255 0 0)
(cond (send diff set-pixel x y new-c)])]
[(and (= (send new-c red) (send old-c red)) [else
(= (send new-c green) (send old-c green)) (set! any-different? #t)
(= (send new-c blue) (send old-c blue))) (send new-c set 255 0 0)
(send diff set-pixel x y new-c)] (send diff set-pixel x y new-c)])
[else (loop (+ y 1))))
(set! any-different? #t) (loop (+ x 1))))
(send new-c set 255 0 0) (send diff set-bitmap #f)
(send diff set-pixel x y new-c)])] (send old set-bitmap #f)
[else (send new set-bitmap #f)
(set! any-different? #t) (and any-different? diff-bitmap)))
(send new-c set 255 0 0)
(send diff set-pixel x y new-c)]) (define test-result-single-panel #f)
(loop (+ y 1)))) (define (get-test-result-single-panel)
(loop (+ x 1)))) (cond
(send diff set-bitmap #f) [test-result-single-panel
(send old set-bitmap #f) test-result-single-panel]
(send new set-bitmap #f) [else
(and any-different? diff-bitmap))) (let ()
(define f (new frame% [label "bitmap-test.ss failures"]))
(define test-result-single-panel #f) (define lined (new vertical-panel% [parent f] [style '(border)]))
(define (get-test-result-single-panel) (define sp (new panel:single% [parent lined]))
(cond (define current-index 0)
[test-result-single-panel (define hp (new horizontal-panel% [parent f]))
test-result-single-panel] (define prev
[else (new button%
(let () [label "Prev"]
(define f (new frame% [label "bitmap-test.ss failures"])) [parent hp]
(define lined (new vertical-panel% [parent f] [style '(border)])) [callback
(define sp (new panel:single% [parent lined])) (λ (x y)
(define current-index 0) (set! current-index (modulo (- current-index 1) (length failed)))
(define hp (new horizontal-panel% [parent f])) (update-gui))]))
(define prev (define next (new button%
(new button% [label "Next"]
[label "Prev"] [parent hp]
[parent hp] [callback
[callback (λ (x y)
(λ (x y) (set! current-index (modulo (+ current-index 1) (length failed)))
(set! current-index (modulo (- current-index 1) (length failed))) (update-gui))]))
(update-gui))])) (define (update-gui)
(define next (new button% (send sp active-child (list-ref failed current-index)))
[label "Next"] (set! test-result-single-panel sp)
[parent hp] (when (get-show-bitmaps?) (send f show #t))
[callback sp)]))
(λ (x y)
(set! current-index (modulo (+ current-index 1) (length failed))) (define (make-failed-panel line-number filename old-bitmap new-bitmap diff-bitmap)
(update-gui))])) (define f (new vertical-panel% [parent (get-test-result-single-panel)]))
(define (update-gui) (define msg (new message% [label (format "line ~a" line-number)] [parent f]))
(send sp active-child (failed-test-panel (list-ref failed current-index)))) (define hp (new horizontal-panel% [parent f]))
(set! test-result-single-panel sp) (define vp1 (new vertical-panel% [parent hp]))
(send f show #t) (define vp2 (new vertical-panel% [parent hp]))
sp)])) (define chk (new check-box%
[label "Show diff"]
(define (make-failed-panel line-number filename old-bitmap new-bitmap diff-bitmap) [parent f]
(define f (new vertical-panel% [parent (get-test-result-single-panel)])) [callback
(define msg (new message% [label (format "line ~a" line-number)] [parent f])) (λ (_1 _2)
(define hp (new horizontal-panel% [parent f])) (cond
(define vp1 (new vertical-panel% [parent hp])) [(send chk get-value)
(define vp2 (new vertical-panel% [parent hp])) (send right-hand set-label diff-bitmap)]
(define chk (new check-box% [else
[label "Show diff"] (send right-hand set-label new-bitmap)]))]))
[parent f] (define btn (new button%
[callback [parent f]
(λ (_1 _2) [label "Save"]
(cond [callback
[(send chk get-value) (λ (x y)
(send chk set-label "Hide diff") (send new-bitmap save-file filename 'png))]))
(send right-hand set-label diff-bitmap)] (define left-label (new message% [parent vp1] [label "Old"]))
[else (define left-hand (new message%
(send chk set-label "Show diff") [parent vp1]
(send right-hand set-label new-bitmap)]))])) [label diff-bitmap]))
(define btn (new button% (define right-label (new message% [parent vp2] [label "New"]))
[parent f] (define right-hand (new message%
[label "Save"] [parent vp2]
[callback [label diff-bitmap]))
(λ (x y) (send left-hand set-label old-bitmap)
(send new-bitmap save-file filename 'png))])) (send right-hand set-label new-bitmap)
(define left-label (new message% [parent vp1] [label "Old"])) f)
(define left-hand (new message%
[parent vp1]
[label diff-bitmap]))
(define right-label (new message% [parent vp2] [label "New"]))
(define right-hand (new message%
[parent vp2]
[label diff-bitmap]))
(send left-hand set-label old-bitmap)
(send right-hand set-label new-bitmap)
f))

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 394 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

View File

Before

Width:  |  Height:  |  Size: 2.1 KiB

After

Width:  |  Height:  |  Size: 2.1 KiB

View File

Before

Width:  |  Height:  |  Size: 3.1 KiB

After

Width:  |  Height:  |  Size: 3.1 KiB

View File

Before

Width:  |  Height:  |  Size: 5.5 KiB

After

Width:  |  Height:  |  Size: 5.5 KiB

View File

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

View File

Before

Width:  |  Height:  |  Size: 4.4 KiB

After

Width:  |  Height:  |  Size: 4.4 KiB

View File

Before

Width:  |  Height:  |  Size: 3.7 KiB

After

Width:  |  Height:  |  Size: 3.7 KiB

View File

Before

Width:  |  Height:  |  Size: 3.9 KiB

After

Width:  |  Height:  |  Size: 3.9 KiB

View File

Before

Width:  |  Height:  |  Size: 4.4 KiB

After

Width:  |  Height:  |  Size: 4.4 KiB

View File

Before

Width:  |  Height:  |  Size: 7.0 KiB

After

Width:  |  Height:  |  Size: 7.0 KiB

View File

Before

Width:  |  Height:  |  Size: 5.2 KiB

After

Width:  |  Height:  |  Size: 5.2 KiB

View File

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 10 KiB

View File

Before

Width:  |  Height:  |  Size: 1.9 KiB

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 398 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.7 KiB

View File

@ -0,0 +1,5 @@
#lang scheme
(provide set-show-bitmaps? get-show-bitmaps?)
(define show-bitmaps? #t)
(define (set-show-bitmaps? sb?) (set! show-bitmaps? sb?))
(define (get-show-bitmaps?) show-bitmaps?)

View File

@ -220,76 +220,73 @@
;; the withs, freshs, and side-conditions come in backwards order ;; the withs, freshs, and side-conditions come in backwards order
(define-for-syntax (bind-withs orig-name main lang lang-nts stx where-mode body) (define-for-syntax (bind-withs orig-name main lang lang-nts stx where-mode body)
(let loop ([stx stx] (let* ([bindings '()]
[body body] [body
[bindings '()]) (let loop ([stx stx]
(syntax-case stx (side-condition where fresh) [to-not-be-in main])
[() (values body bindings)] (syntax-case stx (side-condition where fresh)
[((where x e) y ...) [() body]
(let-values ([(names names/ellipses) (extract-names lang-nts 'reduction-relation #t #'x)]) [((where x e) y ...)
(with-syntax ([(cpat) (generate-temporaries '(compiled-pattern))] (let-values ([(names names/ellipses) (extract-names lang-nts 'reduction-relation #t #'x)])
[side-conditions-rewritten (rewrite-side-conditions/check-errs (with-syntax ([(cpat) (generate-temporaries '(compiled-pattern))]
lang-nts [side-conditions-rewritten (rewrite-side-conditions/check-errs
'reduction-relation lang-nts
#f 'reduction-relation
#'x)] #f
[(names ...) names] #'x)]
[(names/ellipses ...) names/ellipses]) [(names ...) names]
(loop #'(y ...) [(names/ellipses ...) names/ellipses])
#`(let ([mtchs (match-pattern cpat (term e))]) (with-syntax ([(x ...) (generate-temporaries #'(names ...))])
(if mtchs (set! bindings (cons #`[cpat (compile-pattern #,lang `side-conditions-rewritten #t)] bindings))
#, (let ([rest-body (loop #'(y ...) #`(list x ... #,to-not-be-in))])
(case where-mode #`(let ([mtchs (match-pattern cpat (term e))])
[(flatten) (if mtchs
#`(apply #,
append (case where-mode
(map (λ (mtch) [(flatten)
(let ([bindings (mtch-bindings mtch)]) #`(apply
(term-let ([names/ellipses (lookup-binding bindings 'names)] ...) append
#,body))) (map (λ (mtch)
mtchs))] (let ([bindings (mtch-bindings mtch)])
[(predicate) (let ([x (lookup-binding bindings 'names)] ...)
#`(andmap (λ (mtch) (term-let ([names/ellipses x] ...)
(let ([bindings (mtch-bindings mtch)]) #,rest-body))))
(term-let ([names/ellipses (lookup-binding bindings 'names)] ...) mtchs))]
#,body))) [(predicate)
mtchs)] #`(andmap (λ (mtch)
[else (error 'unknown-where-mode "~s" where-mode)]) (let ([bindings (mtch-bindings mtch)])
#f)) (let ([x (lookup-binding bindings 'names)] ...)
(cons #`[cpat (compile-pattern #,lang `side-conditions-rewritten #t)] (term-let ([names/ellipses x] ...)
bindings))))] #,rest-body))))
[((side-condition s ...) y ...) mtchs)]
(loop #'(y ...) #`(and s ... #,body) bindings)] [else (error 'unknown-where-mode "~s" where-mode)])
[((fresh x) y ...) #f))))))]
(identifier? #'x) [((side-condition s ...) y ...)
(loop #'(y ...) #`(and s ... #,(loop #'(y ...) to-not-be-in))]
#`(term-let ([x (variable-not-in #,main 'x)]) #,body) [((fresh x) y ...)
bindings)] (identifier? #'x)
[((fresh x name) y ...) #`(term-let ([x (variable-not-in #,to-not-be-in 'x)])
(identifier? #'x) #,(loop #'(y ...) #`(list (term x) #,to-not-be-in)))]
(loop #'(y ...) [((fresh x name) y ...)
#`(term-let ([x (let ([the-name (term name)]) (identifier? #'x)
(verify-name-ok '#,orig-name the-name) #`(term-let ([x (let ([the-name (term name)])
(variable-not-in #,main the-name))]) (verify-name-ok '#,orig-name the-name)
#,body) (variable-not-in #,to-not-be-in the-name))])
bindings)] #,(loop #'(y ...) #`(list (term x) #,to-not-be-in)))]
[((fresh (y) (x ...)) z ...) [((fresh (y) (x ...)) z ...)
(loop #'(z ...) #`(term-let ([(y #,'...)
#`(term-let ([(y #,'...) (variables-not-in #,to-not-be-in
(variables-not-in #,main (map (λ (_ignore_) 'y)
(map (λ (_ignore_) 'y) (term (x ...))))])
(term (x ...))))]) #,(loop #'(z ...) #`(list (term (y #,'...)) #,to-not-be-in)))]
#,body) [((fresh (y) (x ...) names) z ...)
bindings)] #`(term-let ([(y #,'...)
[((fresh (y) (x ...) names) z ...) (let ([the-names (term names)]
(loop #'(z ...) [len-counter (term (x ...))])
#`(term-let ([(y #,'...) (verify-names-ok '#,orig-name the-names len-counter)
(let ([the-names (term names)] (variables-not-in #,to-not-be-in the-names))])
[len-counter (term (x ...))]) #,(loop #'(z ...) #`(list (term (y #,'...)) #,to-not-be-in)))]))])
(verify-names-ok '#,orig-name the-names len-counter) (values body bindings)))
(variables-not-in #,main the-names))])
#,body)
bindings)])))
(define-syntax-set (do-reduction-relation) (define-syntax-set (do-reduction-relation)
(define (do-reduction-relation/proc stx) (define (do-reduction-relation/proc stx)
@ -746,84 +743,76 @@
case-id))))))) case-id)))))))
(define (process-extras stx orig-name name-table extras) (define (process-extras stx orig-name name-table extras)
(let ([the-name #f] (let* ([the-name #f]
[the-name-stx #f] [the-name-stx #f]
[sides/withs/freshs '()]) [sides/withs/freshs
(let loop ([extras extras]) (let loop ([extras extras])
(cond (cond
[(null? extras) (values the-name sides/withs/freshs)] [(null? extras) '()]
[else [else
(syntax-case (car extras) (side-condition fresh where) (syntax-case (car extras) (side-condition fresh where)
[name [name
(or (identifier? (car extras)) (or (identifier? (car extras))
(string? (syntax-e (car extras)))) (string? (syntax-e (car extras))))
(begin (begin
(let* ([raw-name (syntax-e (car extras))] (let* ([raw-name (syntax-e (car extras))]
[name-sym [name-sym
(if (symbol? raw-name) (if (symbol? raw-name)
raw-name raw-name
(string->symbol raw-name))]) (string->symbol raw-name))])
(when (hash-ref name-table name-sym #f) (when (hash-ref name-table name-sym #f)
(raise-syntax-errors orig-name (raise-syntax-errors orig-name
"same name on multiple rules" "same name on multiple rules"
stx stx
(list (car (hash-ref name-table name-sym)) (list (car (hash-ref name-table name-sym))
(syntax name)))) (syntax name))))
(let ([num (hash-ref name-table #f)]) (let ([num (hash-ref name-table #f)])
(hash-set! name-table #f (+ num 1)) (hash-set! name-table #f (+ num 1))
(hash-set! name-table name-sym (list (syntax name) num))) (hash-set! name-table name-sym (list (syntax name) num)))
(when the-name (when the-name
(raise-syntax-errors orig-name (raise-syntax-errors orig-name
"expected only a single name" "expected only a single name"
stx stx
(list the-name-stx (car extras)))) (list the-name-stx (car extras))))
(set! the-name (if (symbol? raw-name) (set! the-name (if (symbol? raw-name)
(symbol->string raw-name) (symbol->string raw-name)
raw-name)) raw-name))
(set! the-name-stx (car extras)) (set! the-name-stx (car extras))
(loop (cdr extras))))] (loop (cdr extras))))]
[(fresh var ...) [(fresh var ...)
(begin (append (map (λ (x)
(set! sides/withs/freshs (syntax-case x ()
(append [x
(reverse (identifier? #'x)
(map (λ (x) #'(fresh x)]
(syntax-case x () [(x name)
[x (identifier? #'x)
(identifier? #'x) #'(fresh x name)]
#'(fresh x)] [((ys dots2) (xs dots1))
[(x name) (and (eq? (syntax-e #'dots1) (string->symbol "..."))
(identifier? #'x) (eq? (syntax-e #'dots2) (string->symbol "...")))
#'(fresh x name)] #'(fresh (ys) (xs dots1))]
[((ys dots2) (xs dots1)) [((ys dots2) (xs dots1) names)
(and (eq? (syntax-e #'dots1) (string->symbol "...")) (and (eq? (syntax-e #'dots1) (string->symbol "..."))
(eq? (syntax-e #'dots2) (string->symbol "..."))) (eq? (syntax-e #'dots2) (string->symbol "...")))
#'(fresh (ys) (xs dots1))] #'(fresh (ys) (xs dots1) names)]
[((ys dots2) (xs dots1) names) [x
(and (eq? (syntax-e #'dots1) (string->symbol "...")) (raise-syntax-error orig-name
(eq? (syntax-e #'dots2) (string->symbol "..."))) "malformed fresh variable clause"
#'(fresh (ys) (xs dots1) names)] stx
[x #'x)]))
(raise-syntax-error orig-name (syntax->list #'(var ...)))
"malformed fresh variable clause" (loop (cdr extras)))]
stx [(side-condition exp ...)
#'x)])) (cons (car extras) (loop (cdr extras)))]
(syntax->list #'(var ...)))) [(where x e)
sides/withs/freshs)) (cons (car extras) (loop (cdr extras)))]
(loop (cdr extras)))] [(where . x)
[(side-condition exp ...) (raise-syntax-error orig-name "malformed where clause" stx (car extras))]
(begin [_
(set! sides/withs/freshs (cons (car extras) sides/withs/freshs)) (raise-syntax-error orig-name "unknown extra" stx (car extras))])]))])
(loop (cdr extras)))] (values the-name sides/withs/freshs)))
[(where x e)
(begin
(set! sides/withs/freshs (cons (car extras) sides/withs/freshs))
(loop (cdr extras)))]
[(where . x)
(raise-syntax-error orig-name "malformed where clause" stx (car extras))]
[_
(raise-syntax-error orig-name "unknown extra" stx (car extras))])]))))
@ -1125,182 +1114,178 @@
(list name (list name
(car names))))) (car names)))))
(loop name (cdr names))]))]) (loop name (cdr names))]))])
(parse-extras #'((stuff ...) ...))
(with-syntax ([(((tl-side-conds ...) ...) (with-syntax ([(((cp-let-bindings ...) rhs/wheres) ...)
(tl-bindings ...) (map (λ (sc/b rhs)
(tl-side-cond/binds ...)) (let-values ([(body-code cp-let-bindings)
(parse-extras #'((stuff ...) ...))]) (bind-withs
(with-syntax ([(((cp-let-bindings ...) rhs/wheres) ...) syn-error-name '()
(map (λ (sc/b rhs) #'lang lang-nts
(let-values ([(body-code cp-let-bindings) sc/b 'flatten
(bind-withs #`(list (term #,rhs)))])
syn-error-name '() (list cp-let-bindings body-code)))
#'lang lang-nts (syntax->list #'((stuff ...) ...))
sc/b 'flatten (syntax->list #'(rhs ...)))]
#`(list (term #,rhs)))]) [(((rg-cp-let-bindings ...) rg-rhs/wheres) ...)
(list cp-let-bindings body-code))) (map (λ (sc/b rhs)
(syntax->list #'(tl-side-cond/binds ...)) (let-values ([(body-code cp-let-bindings)
(syntax->list #'(rhs ...)))] (bind-withs
[(((rg-cp-let-bindings ...) rg-rhs/wheres) ...) syn-error-name '()
(map (λ (sc/b rhs) #'lang lang-nts
(let-values ([(body-code cp-let-bindings) sc/b 'predicate
(bind-withs #`#t)])
syn-error-name '() (list cp-let-bindings body-code)))
#'lang lang-nts (syntax->list #'((stuff ...) ...))
sc/b 'predicate (syntax->list #'(rhs ...)))])
#`#t)]) (with-syntax ([(side-conditions-rewritten ...)
(list cp-let-bindings body-code))) (map (λ (x) (rewrite-side-conditions/check-errs
(syntax->list #'(tl-side-cond/binds ...)) lang-nts
(syntax->list #'(rhs ...)))]) syn-error-name
(with-syntax ([(side-conditions-rewritten ...) #t
(map (λ (x) (rewrite-side-conditions/check-errs x))
lang-nts (syntax->list (syntax (lhs ...))))]
syn-error-name [(rg-side-conditions-rewritten ...)
#t (map (λ (x) (rewrite-side-conditions/check-errs
x)) lang-nts
(syntax->list (syntax (lhs ...))))] syn-error-name
[(rg-side-conditions-rewritten ...) #t
(map (λ (x) (rewrite-side-conditions/check-errs x))
lang-nts (syntax->list (syntax ((side-condition lhs rg-rhs/wheres) ...))))]
syn-error-name [(clause-src ...)
#t (map (λ (lhs)
x)) (format "~a:~a:~a"
(syntax->list (syntax ((side-condition lhs rg-rhs/wheres) ...))))] (syntax-source lhs)
[(clause-src ...) (syntax-line lhs)
(map (λ (lhs) (syntax-column lhs)))
(format "~a:~a:~a" pats)]
(syntax-source lhs) [dom-side-conditions-rewritten
(syntax-line lhs) (and dom-ctcs
(syntax-column lhs))) (rewrite-side-conditions/check-errs
pats)] lang-nts
[dom-side-conditions-rewritten syn-error-name
(and dom-ctcs #f
(rewrite-side-conditions/check-errs dom-ctcs))]
lang-nts [codom-side-conditions-rewritten
syn-error-name (rewrite-side-conditions/check-errs
#f lang-nts
dom-ctcs))] syn-error-name
[codom-side-conditions-rewritten #f
(rewrite-side-conditions/check-errs codom-contract)]
lang-nts [(rhs-fns ...)
syn-error-name (map (λ (lhs rhs/where)
#f (let-values ([(names names/ellipses)
codom-contract)] (extract-names lang-nts syn-error-name #t lhs)])
[(rhs-fns ...) (with-syntax ([(names ...) names]
(map (λ (lhs rhs/where) [(names/ellipses ...) names/ellipses]
(let-values ([(names names/ellipses) [rhs/where rhs/where])
(extract-names lang-nts syn-error-name #t lhs)]) (syntax
(with-syntax ([(names ...) names] (λ (name bindings)
[(names/ellipses ...) names/ellipses] (term-let-fn ((name name))
[rhs/where rhs/where]) (term-let ([names/ellipses (lookup-binding bindings 'names)] ...)
(syntax rhs/where)))))))
(λ (name bindings) (syntax->list (syntax (lhs ...)))
(term-let-fn ((name name)) (syntax->list (syntax (rhs/wheres ...))))]
(term-let ([names/ellipses (lookup-binding bindings 'names)] ...) [(name2 name-predicate) (generate-temporaries (syntax (name name)))]
rhs/where)))))))
(syntax->list (syntax (lhs ...))) ;; See "!!" below for information on the `seq-' bindings:
(syntax->list (syntax (rhs/wheres ...))))] [seq-of-rhs #'(rhs ...)]
[(name2 name-predicate) (generate-temporaries (syntax (name name)))] [seq-of-lhs #'(lhs ...)]
[seq-of-tl-side-cond/binds #'((stuff ...) ...)]
;; See "!!" below for information on the `seq-' bindings: [seq-of-lhs-for-lw #'(lhs-for-lw ...)])
[seq-of-rhs #'(rhs ...)] (with-syntax ([defs #`(begin
[seq-of-lhs #'(lhs ...)] (define-values (name2 name-predicate)
[seq-of-tl-side-cond/binds #'(tl-side-cond/binds ...)] (let ([sc `(side-conditions-rewritten ...)]
[seq-of-lhs-for-lw #'(lhs-for-lw ...)]) [dsc `dom-side-conditions-rewritten]
(with-syntax ([defs #`(begin cp-let-bindings ... ...
(define-values (name2 name-predicate) rg-cp-let-bindings ... ...)
(let ([sc `(side-conditions-rewritten ...)] (let ([cases (map (λ (pat rhs-fn rg-lhs src)
[dsc `dom-side-conditions-rewritten] (make-metafunc-case
cp-let-bindings ... ... (compile-pattern lang pat #t) rhs-fn rg-lhs src (gensym)))
rg-cp-let-bindings ... ...) sc
(let ([cases (map (λ (pat rhs-fn rg-lhs src) (list rhs-fns ...)
(make-metafunc-case `(rg-side-conditions-rewritten ...)
(compile-pattern lang pat #t) rhs-fn rg-lhs src (gensym))) `(clause-src ...))]
sc [parent-cases
(list rhs-fns ...) #,(if prev-metafunction
`(rg-side-conditions-rewritten ...) #`(metafunc-proc-cases #,(term-fn-get-id (syntax-local-value prev-metafunction)))
`(clause-src ...))] #'null)])
[parent-cases (build-metafunction
#,(if prev-metafunction lang
#`(metafunc-proc-cases #,(term-fn-get-id (syntax-local-value prev-metafunction))) cases
#'null)]) parent-cases
(build-metafunction (λ (f/dom)
lang (make-metafunc-proc
cases (let ([name (lambda (x) (f/dom x))]) name)
parent-cases ;; !! This code goes back to phase 1 to call `to-lw', but it's delayed
(λ (f/dom) ;; through `let-syntax' instead of `unsyntax' so that `to-lw' isn't called
(make-metafunc-proc ;; until all metafunction definitions have been processed.
(let ([name (lambda (x) (f/dom x))]) name) ;; It gets a little complicated because we want to use sequences from the
;; !! This code goes back to phase 1 to call `to-lw', but it's delayed ;; original `define-metafunction' (step 1) and sequences that are generated within
;; through `let-syntax' instead of `unsyntax' so that `to-lw' isn't called ;; `let-syntax' (step 2). So we quote all the `...' in the `let-syntax' form ---
;; until all metafunction definitions have been processed. ;; and also have to quote all uses step-1 pattern variables in case they produce
;; It gets a little complicated because we want to use sequences from the ;; `...', which should be treated as literals at step 2. Hece the `seq-' bindings
;; original `define-metafunction' (step 1) and sequences that are generated within ;; above and a quoting `...' on each use of a `seq-' binding.
;; `let-syntax' (step 2). So we quote all the `...' in the `let-syntax' form --- (...
;; and also have to quote all uses step-1 pattern variables in case they produce (let-syntax
;; `...', which should be treated as literals at step 2. Hece the `seq-' bindings ([generate-lws
;; above and a quoting `...' on each use of a `seq-' binding. (lambda (stx)
(... (with-syntax
(let-syntax ([(rhs/lw ...) (map to-lw/proc (syntax->list #'(... seq-of-rhs)))]
([generate-lws [(((bind-id/lw . bind-pat/lw) ...) ...)
(lambda (stx) ;; Also for pict, extract pattern bindings
(with-syntax (map (λ (x) (map (λ (x) (cons (to-lw/proc (car x)) (to-lw/proc (cdr x))))
([(rhs/lw ...) (map to-lw/proc (syntax->list #'(... seq-of-rhs)))] (extract-pattern-binds x)))
[(((bind-id/lw . bind-pat/lw) ...) ...) (syntax->list #'(... seq-of-lhs)))]
;; Also for pict, extract pattern bindings
(map (λ (x) (map (λ (x) (cons (to-lw/proc (car x)) (to-lw/proc (cdr x)))) [((where/sc/lw ...) ...)
(extract-pattern-binds x))) ;; Also for pict, extract where bindings
(syntax->list #'(... seq-of-lhs)))] (map (λ (hm)
(map
[((where/sc/lw ...) ...) (λ (lst)
;; Also for pict, extract where bindings (syntax-case lst (side-condition where)
(map (λ (hm) [(where pat exp)
(map #`(cons #,(to-lw/proc #'pat) #,(to-lw/proc #'exp))]
(λ (lst) [(side-condition x)
(syntax-case lst (side-condition where) (to-lw/uq/proc #'x)]))
[(where pat exp) (reverse (syntax->list hm))))
#`(cons #,(to-lw/proc #'pat) #,(to-lw/proc #'exp))] (syntax->list #'(... seq-of-tl-side-cond/binds)))]
[(side-condition x)
(to-lw/uq/proc #'x)])) [(((rhs-bind-id/lw . rhs-bind-pat/lw/uq) ...) ...)
(reverse (syntax->list hm)))) ;; Also for pict, extract pattern bindings
(syntax->list #'(... seq-of-tl-side-cond/binds)))] (map (λ (x) (map (λ (x) (cons (to-lw/proc (car x)) (to-lw/uq/proc (cdr x))))
(extract-term-let-binds x)))
[(((rhs-bind-id/lw . rhs-bind-pat/lw/uq) ...) ...) (syntax->list #'(... seq-of-rhs)))]
;; Also for pict, extract pattern bindings
(map (λ (x) (map (λ (x) (cons (to-lw/proc (car x)) (to-lw/uq/proc (cdr x)))) [(x-lhs-for-lw ...) #'(... seq-of-lhs-for-lw)])
(extract-term-let-binds x))) #'(list (list x-lhs-for-lw
(syntax->list #'(... seq-of-rhs)))] (list (cons bind-id/lw bind-pat/lw) ...
(cons rhs-bind-id/lw rhs-bind-pat/lw/uq) ...
[(x-lhs-for-lw ...) #'(... seq-of-lhs-for-lw)]) where/sc/lw ...)
#'(list (list x-lhs-for-lw rhs/lw)
(list (cons bind-id/lw bind-pat/lw) ... ...)))])
(cons rhs-bind-id/lw rhs-bind-pat/lw/uq) ... (generate-lws)))
where/sc/lw ...) lang
rhs/lw) #t ;; multi-args?
...)))]) 'name
(generate-lws))) (let ([name (lambda (x) (name-predicate x))]) name)
lang dsc
#t ;; multi-args? (append cases parent-cases)))
'name dsc
(let ([name (lambda (x) (name-predicate x))]) name) `codom-side-conditions-rewritten
dsc 'name
(append cases parent-cases))) #,relation?))))
dsc (term-define-fn name name2))])
`codom-side-conditions-rewritten (syntax-property
'name (if (eq? 'top-level (syntax-local-context))
#,relation?)))) ; Introduce the names before using them, to allow
(term-define-fn name name2))]) ; metafunction definition at the top-level.
(syntax-property (syntax
(if (eq? 'top-level (syntax-local-context)) (begin
; Introduce the names before using them, to allow (define-syntaxes (name2 name-predicate) (values))
; metafunction definition at the top-level. defs))
(syntax (syntax defs))
(begin 'disappeared-use
(define-syntaxes (name2 name-predicate) (values)) (map syntax-local-introduce (syntax->list #'(original-names ...)))))))))))))))]
defs))
(syntax defs))
'disappeared-use
(map syntax-local-introduce (syntax->list #'(original-names ...))))))))))))))))]
[(_ prev-metafunction name lang clauses ...) [(_ prev-metafunction name lang clauses ...)
(begin (begin
(unless (identifier? #'name) (unless (identifier? #'name)
@ -1383,41 +1368,25 @@
(raise-syntax-error syn-error-name "error checking failed.2" stx))])) (raise-syntax-error syn-error-name "error checking failed.2" stx))]))
(define (parse-extras extras) (define (parse-extras extras)
(let loop ([stuffs (syntax->list extras)] (for-each
[side-conditionss '()] (λ (stuffs)
[bindingss '()] (for-each
[bothss '()]) (λ (stuff)
(cond (syntax-case stuff (where side-condition)
[(null? stuffs) (list (reverse side-conditionss) [(side-condition tl-side-conds ...)
(reverse bindingss) (void)]
(reverse bothss))] [(where x e)
[else (void)]
(let s-loop ([stuff (syntax->list (car stuffs))] [(where . args)
[side-conditions '()] (raise-syntax-error 'define-metafunction
[bindings '()] "malformed where clause"
[boths '()]) stuff)]
(cond [_
[(null? stuff) (loop (cdr stuffs) (raise-syntax-error 'define-metafunction
(cons (reverse side-conditions) side-conditionss) "expected a side-condition or where clause"
(cons (reverse bindings) bindingss) stuff)]))
; Want these in reverse order. (syntax->list stuffs)))
(cons boths bothss))] (syntax->list extras))))
[else
(syntax-case (car stuff) (where side-condition)
[(side-condition tl-side-conds ...)
(s-loop (cdr stuff)
(append (syntax->list #'(tl-side-conds ...)) side-conditions)
bindings
(cons (car stuff) boths))]
[(where x e)
(s-loop (cdr stuff)
side-conditions
(cons #'(x e) bindings)
(cons (car stuff) boths))]
[_
(raise-syntax-error 'define-metafunction
"expected a side-condition or where clause"
(car stuff))])]))]))))
(define (build-metafunction lang cases parent-cases wrap dom-contract-pat codom-contract-pat name relation?) (define (build-metafunction lang cases parent-cases wrap dom-contract-pat codom-contract-pat name relation?)
(let ([dom-compiled-pattern (and dom-contract-pat (compile-pattern lang dom-contract-pat #f))] (let ([dom-compiled-pattern (and dom-contract-pat (compile-pattern lang dom-contract-pat #f))]

View File

@ -1,7 +1,11 @@
;; require this file to run all of the test suites for redex. ;; require this file to run all of the test suites for redex.
#lang scheme/base #lang scheme/base
(require scheme/runtime-path) (require scheme/runtime-path
"config.ss"
"test-util.ss")
(set-show-bitmaps? #t)
(define test-files (define test-files
'("lw-test.ss" '("lw-test.ss"
@ -17,8 +21,6 @@
(define-runtime-path here ".") (define-runtime-path here ".")
(putenv "PLT_REDEX_TEST_NOSHOW_DIFFS" "yes")
(define (flush) (define (flush)
;; these flushes are here for running under cygwin, ;; these flushes are here for running under cygwin,
;; which somehow makes mzscheme think it isn't using ;; which somehow makes mzscheme think it isn't using

View File

@ -35,7 +35,9 @@
(define tests 0) (define tests 0)
(define failures 0) (define failures 0)
(define (reset-count) (set! tests 0)) (define (reset-count)
(set! tests 0)
(set! failures 0))
(define (print-tests-passed filename) (define (print-tests-passed filename)
(cond (cond

View File

@ -1211,6 +1211,35 @@
(fresh ((x ...) (variable_1 ...) (variable_1 ...))))) (fresh ((x ...) (variable_1 ...) (variable_1 ...)))))
'(x y z)) '(x y z))
(list '(x1 y1 z1 x y z))) (list '(x1 y1 z1 x y z)))
(test (apply-reduction-relation
(reduction-relation
empty-language
(--> any (any_y x)
(where any_y x)
(fresh x)))
(term junk))
(list '(x x1)))
(test (apply-reduction-relation
(reduction-relation
empty-language
(--> any (any_y x)
(fresh x)
(where any_y x)
(fresh x)))
(term junk))
(list '(x x1)))
(test (apply-reduction-relation
(reduction-relation
empty-language
(--> (variable ...) (variable_0 ... variable_1 ...)
(fresh ((variable_0 ...) (variable ...)))
(fresh ((variable_1 ...) (variable ...)))))
(term (x y)))
(list '(variable_0 variable_1 variable_2 variable_3)))
;; test that redex match can be used in a side-condition ;; test that redex match can be used in a side-condition
;; with the same language that is used to define the ;; with the same language that is used to define the