Fixes handling of pattern variables that look like metafunctions

This commit is contained in:
Casey Klein 2011-08-31 11:09:38 -05:00
parent d8c04a7d57
commit 145828527f
4 changed files with 45 additions and 6 deletions

View File

@ -1895,15 +1895,18 @@
(loop (cdr rest-modes) rest-terms rest-ctcs (+ 1 pos))))))) (loop (cdr rest-modes) rest-terms rest-ctcs (+ 1 pos)))))))
(define-for-syntax (mode-check mode clauses nts syn-err-name) (define-for-syntax (mode-check mode clauses nts syn-err-name)
(define ((check-template named-vars) temp bound) (define ((check-template bound-anywhere) temp bound)
(let check ([t temp]) (let check ([t temp])
(syntax-case t (unquote) (syntax-case t (unquote)
[(unquote . _) [(unquote . _)
(raise-syntax-error syn-err-name "unquote unsupported" t)] (raise-syntax-error syn-err-name "unquote unsupported" t)]
[x [x
(identifier? #'x) (identifier? #'x)
(when (and (or (id-binds? nts #t #'x) (free-id-table-ref named-vars #'x #f)) (unless (cond [(free-id-table-ref bound-anywhere #'x #f)
(not (free-id-table-ref bound #'x #f))) (free-id-table-ref bound #'x #f)]
[(id-binds? nts #t #'x)
(term-fn? (syntax-local-value #'x (λ () #f)))]
[else #t])
(raise-syntax-error syn-err-name "unbound pattern variable" #'x))] (raise-syntax-error syn-err-name "unbound pattern variable" #'x))]
[(u ...) [(u ...)
(for-each check (syntax->list #'(u ...)))] (for-each check (syntax->list #'(u ...)))]
@ -1956,7 +1959,7 @@
(for ([clause clauses]) (for ([clause clauses])
(define do-tmpl (define do-tmpl
(check-template (check-template
(fold-clause (bind 'name-only) void (make-immutable-free-id-table) clause))) (fold-clause (bind 'rhs-only) void (make-immutable-free-id-table) clause)))
(fold-clause (bind 'rhs-only) do-tmpl (make-immutable-free-id-table) clause))) (fold-clause (bind 'rhs-only) do-tmpl (make-immutable-free-id-table) clause)))
;; Defined as a macro instead of an ordinary phase 1 function so that the ;; Defined as a macro instead of an ordinary phase 1 function so that the

View File

@ -161,8 +161,7 @@
(and (identifier? (syntax x)) (and (identifier? (syntax x))
((case mode ((case mode
[(rhs-only) binds-in-right-hand-side?] [(rhs-only) binds-in-right-hand-side?]
[(binds-anywhere) binds?] [(binds-anywhere) binds?])
[(name-only) (λ (_1 _2 _3) #f)])
all-nts bind-names? (syntax x))) all-nts bind-names? (syntax x)))
(cons (make-id/depth (syntax x) depth) names)] (cons (make-id/depth (syntax x) depth) names)]
[else names]))] [else names]))]

View File

@ -183,3 +183,27 @@
[(name binder) [(name binder)
premise ellipsis]) premise ellipsis])
(void))) (void)))
(#rx"unbound pattern variable"
([x f_7])
(let ()
(define-language L
(f any))
(define-judgment-form L
#:mode (J1 O)
[(J1 x)])
(void)))
(#rx"unbound pattern variable"
([use f_2]) ([outer-def f_2] [inner-def f_2])
(let ()
(define-language L
(f any))
(define-metafunction L
[(outer-def) ()])
(define-judgment-form L
#:mode (K I I O)
[(K a any_1 x)
(K b (use) (name inner-def any))]
[(K b any K-b-out)])
(void)))

View File

@ -1823,6 +1823,19 @@
'a) 'a)
'(a b))) '(a b)))
; a call to a metafunction that looks like a pattern variable
(let ()
(define result 'result)
(define-language L
(f any))
(define-judgment-form L
#:mode (J O)
[(J (f_2))])
(define-metafunction L
[(f_2) ,result])
(test (judgment-holds (J any) any)
(list result)))
; ;
; ;
; ;; ;; ; ;; ;;