Fixed check-reduction-relation's handling of cases with `where' and

`side-condition' clauses.

svn: r12995
This commit is contained in:
Casey Klein 2009-01-03 20:48:19 +00:00
parent b6312ff3ca
commit 7da5ee6029
3 changed files with 44 additions and 26 deletions

View File

@ -510,16 +510,13 @@
p)]))))) p)])))))
(define (do-leaf stx orig-name lang name-table from to extras lang-id) (define (do-leaf stx orig-name lang name-table from to extras lang-id)
(let ([lang-nts (language-id-nts lang-id orig-name)]) (let* ([lang-nts (language-id-nts lang-id orig-name)]
[rw-sc (λ (pat) (rewrite-side-conditions/check-errs lang-nts orig-name #t pat))])
(let-values ([(name fresh-vars side-conditions/withs) (process-extras stx orig-name name-table extras)]) (let-values ([(name fresh-vars side-conditions/withs) (process-extras stx orig-name name-table extras)])
(let-values ([(names names/ellipses) (extract-names lang-nts orig-name #t from)]) (let-values ([(names names/ellipses) (extract-names lang-nts orig-name #t from)])
(with-syntax ([side-conditions-rewritten (with-syntax ([side-conditions-rewritten (rw-sc from)]
(rewrite-side-conditions/check-errs [lhs-w/extras (rw-sc #`(side-condition #,from #,(bind-withs side-conditions/withs #'#t)))]
lang-nts [to to]
orig-name
#t
from)]
[to to #;#`,(begin (printf "~s\n" #,name) (term #,to))]
[name name] [name name]
[lang lang] [lang lang]
[(names ...) names] [(names ...) names]
@ -550,6 +547,7 @@
#`(do-leaf-match #`(do-leaf-match
name name
`side-conditions-rewritten `side-conditions-rewritten
`lhs-w/extras
(λ (main bindings) (λ (main bindings)
;; nested term-let's so that the bindings for the variables ;; nested term-let's so that the bindings for the variables
;; show up in the `fresh' side-conditions, the bindings for the variables ;; show up in the `fresh' side-conditions, the bindings for the variables
@ -756,7 +754,7 @@
(rewrite-proc-name child-make-proc) (rewrite-proc-name child-make-proc)
(subst lhs-frm-id (rewrite-proc-lhs child-make-proc) rhs-from))) (subst lhs-frm-id (rewrite-proc-lhs child-make-proc) rhs-from)))
(define (do-leaf-match name pat proc) (define (do-leaf-match name pat w/extras proc)
(make-rewrite-proc (make-rewrite-proc
(λ (lang) (λ (lang)
(let ([cp (compile-pattern lang pat #t)]) (let ([cp (compile-pattern lang pat #t)])
@ -771,7 +769,7 @@
other-matches) other-matches)
other-matches))))) other-matches)))))
name name
pat)) w/extras))
(define-syntax (test-match stx) (define-syntax (test-match stx)
(syntax-case stx () (syntax-case stx ()

View File

@ -540,16 +540,17 @@
(define-language L (define-language L
(e (+ e ...) number) (e (+ e ...) number)
(E (+ number ... E* e ...)) (E (+ number ... E* e ...))
(E* hole E*)) (E* hole E*)
(define R (n 4))
(reduction-relation
(let ([generated null]
[R (reduction-relation
L L
(==> (+ number ...) whatever) (==> (+ number ...) whatever)
(--> (side-condition number (even? (term number))) whatever) (--> (side-condition number (even? (term number))) whatever)
with with
[(--> (in-hole E a) whatever) [(--> (in-hole E a) whatever)
(==> a b)])) (==> a b)])])
(let ([generated null])
(test (begin (test (begin
(check-reduction-relation (check-reduction-relation
R (λ (term) (set! generated (cons term generated))) R (λ (term) (set! generated (cons term generated)))
@ -558,6 +559,7 @@
#:attempts 1) #:attempts 1)
generated) generated)
(reverse '((+ (+)) 0)))) (reverse '((+ (+)) 0))))
(let ([S (reduction-relation L (--> 1 2 name) (--> 3 4))]) (let ([S (reduction-relation L (--> 1 2 name) (--> 3 4))])
(test (check-reduction-relation S (λ (x) #t) #:attempts 1) #t) (test (check-reduction-relation S (λ (x) #t) #:attempts 1) #t)
(test (current-error-port-output (test (current-error-port-output
@ -565,7 +567,23 @@
"checking name failed after 1 attempts:\n1\n") "checking name failed after 1 attempts:\n1\n")
(test (current-error-port-output (test (current-error-port-output
(λ () (check-reduction-relation S (curry eq? 1)))) (λ () (check-reduction-relation S (curry eq? 1))))
"checking unnamed failed after 1 attempts:\n3\n"))) "checking unnamed failed after 1 attempts:\n3\n"))
(let ([T (reduction-relation
L
(==> number number
(where num number)
(side-condition (eq? (term num) 4))
(where numb num)
(side-condition (eq? (term numb) 4)))
with
[(--> (9 a) b)
(==> a b)])])
(test (check-reduction-relation
T (curry equal? '(9 4))
#:attempts 1
#:decisions (decisions #:num (build-list 5 (λ (x) (λ _ x)))))
#t)))
; check-metafunction ; check-metafunction
(let () (let ()

View File

@ -1156,7 +1156,9 @@
[else #f])) [else #f]))
; test shortcut in terms of shortcut ; test shortcut in terms of shortcut
(test (rewrite-proc-lhs (third (reduction-relation-make-procs r))) (test (match (rewrite-proc-lhs (third (reduction-relation-make-procs r)))
'((5 2) 1))) [`(((side-condition 5 ,(? procedure?)) 2) 1) #t]
[else #f])
#t))
(print-tests-passed 'tl-test.ss)) (print-tests-passed 'tl-test.ss))