Use DrRacket's program-expansion mechanisms instead of directly calling expand.

This commit is contained in:
Vincent St-Amour 2011-07-21 13:39:00 -04:00
parent 860feb30ae
commit b305ea9c62

View File

@ -38,8 +38,26 @@
(not f)] (not f)]
[else ; different file [else ; different file
#f])) #f]))
(with-intercepted-tr-logging
(lambda (l) ;; expand and capture log messages
(define listener #f)
(define done-chan (make-channel))
(drracket:eval:expand-program
(drracket:language:make-text/pos
this 0 (send this last-position))
(send this get-next-settings) #t
(lambda () (set! listener (start-recording #:level 'warning)))
void ; kill
(lambda (term k)
(if (eof-object? term)
(begin (set! log (stop-recording listener)) ; done, stash the log
(channel-put done-chan 'done))
(k)))) ; not done, keep going
(channel-get done-chan) ; wait for expansion to finish
(define (post-process-log-entry l)
;; make sure the message is indeed from the optimizer
(cond [(log-message-from-tr-opt? l)
(define log-entry-data (cdr (vector-ref l 2))) ; log-entry struct (define log-entry-data (cdr (vector-ref l 2))) ; log-entry struct
(define stx (log-entry-stx log-entry-data)) (define stx (log-entry-stx log-entry-data))
(define path (if (and (syntax-source-directory stx) (define path (if (and (syntax-source-directory stx)
@ -47,13 +65,13 @@
(build-path (syntax-source-directory stx) (build-path (syntax-source-directory stx)
(syntax-source-file-name stx)) (syntax-source-file-name stx))
#f)) #f))
(when (right-file? path) ;; it also needs to come from the right file
(set! log (cons log-entry-data log)))) (if (right-file? path)
(lambda () log-entry-data ; payload
(parameterize ([current-namespace (make-base-namespace)] #f)]
[read-accept-reader #t]) [else #f])) ; drop it
(expand (tr:read-syntax portname input)))))
log) (filter values (map post-process-log-entry log)))
;; converts log-entry structs to report-entry structs for further ;; converts log-entry structs to report-entry structs for further
;; processing ;; processing