PR 10009 and added tracing to metafunctions
svn: r13028
This commit is contained in:
parent
cda64e40da
commit
05160bf931
|
@ -1,3 +1,8 @@
|
||||||
|
- Added tracing to metafunctions (see current-traced-metafunctions)
|
||||||
|
|
||||||
|
- added caching-enabled? parameter (changed how set-cache-size!
|
||||||
|
works)
|
||||||
|
|
||||||
v4.2
|
v4.2
|
||||||
|
|
||||||
- added white-bracket-sizing to control how the brackets
|
- added white-bracket-sizing to control how the brackets
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
"term.ss"
|
"term.ss"
|
||||||
"loc-wrapper.ss"
|
"loc-wrapper.ss"
|
||||||
"error.ss"
|
"error.ss"
|
||||||
|
mzlib/trace
|
||||||
(lib "list.ss")
|
(lib "list.ss")
|
||||||
(lib "etc.ss"))
|
(lib "etc.ss"))
|
||||||
|
|
||||||
|
@ -1164,14 +1165,23 @@
|
||||||
`(,name ,@exp)
|
`(,name ,@exp)
|
||||||
(length mtchs))]
|
(length mtchs))]
|
||||||
[else
|
[else
|
||||||
(let ([ans (rhs metafunc (mtch-bindings (car mtchs)))])
|
(let ([ans (rhs traced-metafunc (mtch-bindings (car mtchs)))])
|
||||||
(unless (match-pattern codom-compiled-pattern ans)
|
(unless (match-pattern codom-compiled-pattern ans)
|
||||||
(redex-error name "codomain test failed for ~s, call was ~s" ans `(,name ,@exp)))
|
(redex-error name "codomain test failed for ~s, call was ~s" ans `(,name ,@exp)))
|
||||||
(hash-set! cache exp ans)
|
(hash-set! cache exp ans)
|
||||||
ans)])))]))]
|
ans)])))]))]
|
||||||
[else
|
[else
|
||||||
cache-ref])))])
|
cache-ref])))]
|
||||||
metafunc)
|
[ot (current-trace-print-args)]
|
||||||
|
[traced-metafunc (lambda (exp)
|
||||||
|
(if (or (eq? (current-traced-metafunctions) 'all)
|
||||||
|
(memq name (current-traced-metafunctions)))
|
||||||
|
(parameterize ([current-trace-print-args
|
||||||
|
(λ (name args kws kw-args level)
|
||||||
|
(ot name (car args) kws kw-args level))])
|
||||||
|
(trace-apply name metafunc '() '() exp))
|
||||||
|
(metafunc exp)))])
|
||||||
|
traced-metafunc)
|
||||||
compiled-patterns
|
compiled-patterns
|
||||||
rhss)
|
rhss)
|
||||||
(if dom-compiled-pattern
|
(if dom-compiled-pattern
|
||||||
|
@ -1179,6 +1189,8 @@
|
||||||
(λ (exp) (and (ormap (λ (pat) (match-pattern pat exp)) compiled-patterns)
|
(λ (exp) (and (ormap (λ (pat) (match-pattern pat exp)) compiled-patterns)
|
||||||
#t))))))
|
#t))))))
|
||||||
|
|
||||||
|
(define current-traced-metafunctions (make-parameter '()))
|
||||||
|
|
||||||
(define-syntax (metafunction-form stx)
|
(define-syntax (metafunction-form stx)
|
||||||
(syntax-case stx ()
|
(syntax-case stx ()
|
||||||
[(_ id)
|
[(_ id)
|
||||||
|
@ -1788,6 +1800,7 @@
|
||||||
(rename-out [metafunction-form metafunction])
|
(rename-out [metafunction-form metafunction])
|
||||||
metafunction? metafunction-proc
|
metafunction? metafunction-proc
|
||||||
in-domain?
|
in-domain?
|
||||||
|
current-traced-metafunctions
|
||||||
metafunc-proc-lang
|
metafunc-proc-lang
|
||||||
metafunc-proc-pict-info
|
metafunc-proc-pict-info
|
||||||
metafunc-proc-name
|
metafunc-proc-name
|
||||||
|
|
|
@ -507,6 +507,29 @@
|
||||||
'no-exn)
|
'no-exn)
|
||||||
'no-exn))
|
'no-exn))
|
||||||
|
|
||||||
|
;; test that tracing works properly
|
||||||
|
;; note that caching comes into play here (which is why we don't see the recursive calls)
|
||||||
|
(let ()
|
||||||
|
(define-metafunction empty-language
|
||||||
|
[(f 0) 0]
|
||||||
|
[(f number) (f ,(- (term number) 1))])
|
||||||
|
|
||||||
|
(let ([sp (open-output-string)])
|
||||||
|
(parameterize ([current-output-port sp])
|
||||||
|
(term (f 1)))
|
||||||
|
(test (get-output-string sp) ""))
|
||||||
|
|
||||||
|
(let ([sp (open-output-string)])
|
||||||
|
(parameterize ([current-output-port sp]
|
||||||
|
[current-traced-metafunctions 'all])
|
||||||
|
(term (f 1)))
|
||||||
|
(test (get-output-string sp) "|(f 1)\n|0\n"))
|
||||||
|
|
||||||
|
(let ([sp (open-output-string)])
|
||||||
|
(parameterize ([current-output-port sp]
|
||||||
|
[current-traced-metafunctions '(f)])
|
||||||
|
(term (f 1)))
|
||||||
|
(test (get-output-string sp) "|(f 1)\n|0\n")))
|
||||||
|
|
||||||
|
|
||||||
;
|
;
|
||||||
|
|
|
@ -149,10 +149,12 @@
|
||||||
;; only changed on the reduction thread
|
;; only changed on the reduction thread
|
||||||
;; frontier : (listof (is-a?/c graph-editor-snip%))
|
;; frontier : (listof (is-a?/c graph-editor-snip%))
|
||||||
(define frontier
|
(define frontier
|
||||||
|
(filter
|
||||||
|
(λ (x) x)
|
||||||
(map (lambda (expr) (build-snip snip-cache #f expr pred pp
|
(map (lambda (expr) (build-snip snip-cache #f expr pred pp
|
||||||
(dark-pen-color) (light-pen-color)
|
(dark-pen-color) (light-pen-color)
|
||||||
(dark-text-color) (light-text-color) #f))
|
(dark-text-color) (light-text-color) #f))
|
||||||
exprs))
|
exprs)))
|
||||||
|
|
||||||
;; set-font-size : number -> void
|
;; set-font-size : number -> void
|
||||||
;; =eventspace main thread=
|
;; =eventspace main thread=
|
||||||
|
@ -516,8 +518,7 @@
|
||||||
(define (build-snip cache parent-snip expr pred pp light-arrow-color dark-arrow-color dark-label-color light-label-color name)
|
(define (build-snip cache parent-snip expr pred pp light-arrow-color dark-arrow-color dark-label-color light-label-color name)
|
||||||
(let-values ([(snip new?)
|
(let-values ([(snip new?)
|
||||||
(let/ec k
|
(let/ec k
|
||||||
(k
|
(values (hash-ref
|
||||||
(hash-ref
|
|
||||||
cache
|
cache
|
||||||
expr
|
expr
|
||||||
(lambda ()
|
(lambda ()
|
||||||
|
|
|
@ -944,6 +944,16 @@ legtimate inputs according to @scheme[metafunction-name]'s contract,
|
||||||
and @scheme[#f] otherwise.
|
and @scheme[#f] otherwise.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@defparam[current-traced-metafunctions traced-metafunctions (or/c 'all (listof symbol?))]{
|
||||||
|
|
||||||
|
Controls which metafunctions are currently being traced. If it is
|
||||||
|
@scheme['all], all of them are. Otherwise, the elements of the list
|
||||||
|
name the metafunctions to trace.
|
||||||
|
|
||||||
|
Defaults to @scheme['()].
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@section{Testing}
|
@section{Testing}
|
||||||
|
|
||||||
All of the exports in this section are provided both by
|
All of the exports in this section are provided both by
|
||||||
|
|
|
@ -30,7 +30,6 @@
|
||||||
define-metafunction/extension
|
define-metafunction/extension
|
||||||
metafunction
|
metafunction
|
||||||
in-domain?
|
in-domain?
|
||||||
|
|
||||||
caching-enabled?)
|
caching-enabled?)
|
||||||
|
|
||||||
(provide (rename-out [test-match redex-match])
|
(provide (rename-out [test-match redex-match])
|
||||||
|
@ -45,6 +44,7 @@
|
||||||
test-results)
|
test-results)
|
||||||
|
|
||||||
(provide/contract
|
(provide/contract
|
||||||
|
[current-traced-metafunctions (parameter/c (or/c 'all (listof symbol?)))]
|
||||||
[reduction-relation->rule-names (-> reduction-relation? (listof symbol?))]
|
[reduction-relation->rule-names (-> reduction-relation? (listof symbol?))]
|
||||||
[language-nts (-> compiled-lang? (listof symbol?))]
|
[language-nts (-> compiled-lang? (listof symbol?))]
|
||||||
[set-cache-size! (-> number? void?)]
|
[set-cache-size! (-> number? void?)]
|
||||||
|
|
Loading…
Reference in New Issue
Block a user