continuing to exercise the parser.
This commit is contained in:
parent
b658834626
commit
3a6f525c32
|
@ -1,5 +1,7 @@
|
||||||
#lang racket/base
|
#lang racket/base
|
||||||
(require racket/contract racket/path)
|
(require racket/contract
|
||||||
|
racket/path
|
||||||
|
syntax/modcode)
|
||||||
(provide/contract [get-module-bytecode ((or/c string? path? input-port?) . -> . bytes?)])
|
(provide/contract [get-module-bytecode ((or/c string? path? input-port?) . -> . bytes?)])
|
||||||
|
|
||||||
|
|
||||||
|
@ -9,21 +11,34 @@
|
||||||
(define (get-module-bytecode x)
|
(define (get-module-bytecode x)
|
||||||
(let ([compiled-code
|
(let ([compiled-code
|
||||||
(cond
|
(cond
|
||||||
|
;; Assumed to be a path string
|
||||||
[(string? x)
|
[(string? x)
|
||||||
(call-with-input-file x
|
(get-compiled-code-from-path (normalize-path (build-path x)))]
|
||||||
(lambda (ip)
|
|
||||||
(get-compiled-code-from-port ip)))]
|
|
||||||
[(path? x)
|
[(path? x)
|
||||||
(call-with-input-file x
|
(get-compiled-code-from-path x)]
|
||||||
(lambda (ip)
|
|
||||||
(get-compiled-code-from-port ip)))]
|
;; Input port is assumed to contain the text of a module.
|
||||||
|
[(input-port? x)
|
||||||
|
(get-compiled-code-from-port x)]
|
||||||
|
|
||||||
[else
|
[else
|
||||||
(get-compiled-code-from-port x)])])
|
(error 'get-module-bytecode)])])
|
||||||
(let ([op (open-output-bytes)])
|
(let ([op (open-output-bytes)])
|
||||||
(write compiled-code op)
|
(write compiled-code op)
|
||||||
(get-output-bytes op))))
|
(get-output-bytes op))))
|
||||||
|
|
||||||
|
|
||||||
|
;; Tries to use get-module-code to grab at module bytecode. Sometimes this fails
|
||||||
|
;; because it appears get-module-code tries to write to compiled/.
|
||||||
|
(define (get-compiled-code-from-path p)
|
||||||
|
(with-handlers ([void (lambda (exn)
|
||||||
|
;; Failsafe: try to do it from scratch
|
||||||
|
(call-with-input-file* p
|
||||||
|
(lambda (ip)
|
||||||
|
(get-compiled-code-from-port ip))))])
|
||||||
|
(get-module-code p)))
|
||||||
|
|
||||||
|
|
||||||
(define (get-compiled-code-from-port ip)
|
(define (get-compiled-code-from-port ip)
|
||||||
(parameterize ([read-accept-reader #t]
|
(parameterize ([read-accept-reader #t]
|
||||||
|
|
|
@ -1,5 +1,11 @@
|
||||||
#lang racket/base
|
#lang racket/base
|
||||||
|
|
||||||
|
;; Tries to parse all the files in collects and sees how long it takes.
|
||||||
|
;;
|
||||||
|
;; TODO: figure out why it fails to get the module bytecode for
|
||||||
|
;; collects/tests/matrix-test.rkt. I'm seeing the following:
|
||||||
|
;; read-syntax: cannot load snip-class reader
|
||||||
|
|
||||||
(require "../parse-bytecode.rkt"
|
(require "../parse-bytecode.rkt"
|
||||||
racket/path)
|
racket/path)
|
||||||
|
|
||||||
|
@ -14,9 +20,10 @@
|
||||||
p]))))
|
p]))))
|
||||||
|
|
||||||
|
|
||||||
(for ([path (in-directory)])
|
(for ([path (in-directory collects-dir)])
|
||||||
(when (regexp-match? #rx"[.]rkt$" path)
|
(when (regexp-match? #rx"[.]rkt$" path)
|
||||||
(printf "parsing file: ~a... " path)
|
(printf "parsing file: ~a... " path)
|
||||||
|
(flush-output)
|
||||||
(let ([start-time (current-inexact-milliseconds)])
|
(let ([start-time (current-inexact-milliseconds)])
|
||||||
(void (parse-bytecode path))
|
(void (parse-bytecode path))
|
||||||
(let ([end-time (current-inexact-milliseconds)])
|
(let ([end-time (current-inexact-milliseconds)])
|
||||||
|
|
Loading…
Reference in New Issue
Block a user