Do expansion inside a sandbox.
This commit is contained in:
parent
ea1ae29e0f
commit
7775779e6a
|
@ -1,9 +1,7 @@
|
||||||
#lang racket/base
|
#lang racket/base
|
||||||
|
|
||||||
(require racket/class racket/gui/base racket/match racket/serialize
|
(require racket/class racket/gui/base racket/match racket/port racket/serialize
|
||||||
unstable/syntax)
|
unstable/syntax unstable/port racket/sandbox
|
||||||
|
|
||||||
(require (prefix-in tr: typed-scheme/typed-reader)
|
|
||||||
typed-scheme/optimizer/logging)
|
typed-scheme/optimizer/logging)
|
||||||
|
|
||||||
(provide (struct-out report-entry)
|
(provide (struct-out report-entry)
|
||||||
|
@ -32,27 +30,11 @@
|
||||||
(define portname (send this get-port-name))
|
(define portname (send this get-port-name))
|
||||||
(define input (open-input-text-editor this))
|
(define input (open-input-text-editor this))
|
||||||
(port-count-lines! input)
|
(port-count-lines! input)
|
||||||
(define log '())
|
|
||||||
(define unsaved-file?
|
(define unsaved-file?
|
||||||
(and (symbol? portname)
|
(and (symbol? portname)
|
||||||
(regexp-match #rx"^unsaved-editor" (symbol->string portname))))
|
(regexp-match #rx"^unsaved-editor" (symbol->string portname))))
|
||||||
(define good-portname-cache #f)
|
(define good-portname-cache #f)
|
||||||
(define (right-file? f) ; does the log-entry refer to the file we're in?
|
(define (right-file? l) ; does the log-entry refer to the file we're in?
|
||||||
(cond [(and good-portname-cache ; cache is populated
|
|
||||||
(equal? f good-portname-cache))
|
|
||||||
#t]
|
|
||||||
;; no cache, ask directly
|
|
||||||
[(send this port-name-matches? f)
|
|
||||||
(set! good-portname-cache f) ; populate cache
|
|
||||||
#t]
|
|
||||||
[unsaved-file?
|
|
||||||
;; we assume that any log entry without a filename comes from
|
|
||||||
;; the unsaved editor
|
|
||||||
(not f)]
|
|
||||||
[else ; different file
|
|
||||||
#f]))
|
|
||||||
(with-intercepted-tr-logging
|
|
||||||
(lambda (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
|
(define path
|
||||||
|
@ -61,13 +43,38 @@
|
||||||
(build-path (deserialize (pseudo-syntax-source-directory stx))
|
(build-path (deserialize (pseudo-syntax-source-directory stx))
|
||||||
(deserialize (pseudo-syntax-source-file-name stx)))
|
(deserialize (pseudo-syntax-source-file-name stx)))
|
||||||
#f))
|
#f))
|
||||||
(when (right-file? path)
|
(cond [(and good-portname-cache ; cache is populated
|
||||||
(set! log (cons log-entry-data log))))
|
(equal? path good-portname-cache))
|
||||||
|
#t]
|
||||||
|
;; no cache, ask directly
|
||||||
|
[(send this port-name-matches? path)
|
||||||
|
(set! good-portname-cache path) ; populate cache
|
||||||
|
#t]
|
||||||
|
[unsaved-file?
|
||||||
|
;; we assume that any log entry without a filename comes from
|
||||||
|
;; the unsaved editor
|
||||||
|
(not path)]
|
||||||
|
[else ; different file
|
||||||
|
#f]))
|
||||||
|
(define sandbox
|
||||||
|
(parameterize ([sandbox-output 'string]
|
||||||
|
[sandbox-input input]
|
||||||
|
[sandbox-make-code-inspector current-code-inspector]
|
||||||
|
[sandbox-eval-limits #f])
|
||||||
|
(make-evaluator 'racket/base
|
||||||
|
'(require (prefix-in tr: typed-scheme/typed-reader)
|
||||||
|
typed-scheme/optimizer/logging)
|
||||||
|
`(define portname ,portname))))
|
||||||
|
(sandbox
|
||||||
|
'(with-intercepted-tr-logging
|
||||||
|
write
|
||||||
(lambda ()
|
(lambda ()
|
||||||
(parameterize ([current-namespace (make-base-namespace)]
|
(parameterize ([current-namespace (make-base-namespace)]
|
||||||
[read-accept-reader #t])
|
[read-accept-reader #t])
|
||||||
(expand (tr:read-syntax portname input)))))
|
(void (expand (tr:read-syntax portname (current-input-port))))))))
|
||||||
log)
|
(for/list ([x (with-input-from-string (get-output sandbox) read-all)]
|
||||||
|
#:when (right-file? x))
|
||||||
|
(cdr (vector-ref x 2)))) ; get the log-entry part
|
||||||
|
|
||||||
;; converts log-entry structs to report-entry structs for further
|
;; converts log-entry structs to report-entry structs for further
|
||||||
;; processing
|
;; processing
|
||||||
|
|
Loading…
Reference in New Issue
Block a user