Reformating

This commit is contained in:
Jay McCarthy 2010-05-24 11:55:49 -06:00
parent b892c276ff
commit 63f546a080

View File

@ -26,10 +26,10 @@
(define (zo-marshal-to top outp) (define (zo-marshal-to top outp)
(match top (match top
[(struct compilation-top (max-let-depth prefix form)) [(struct compilation-top (max-let-depth prefix form))
(let ([encountered (make-hasheq)] (define encountered (make-hasheq))
[shared (make-hasheq)] (define shared (make-hasheq))
[wrapped (make-hasheq)]) (define wrapped (make-hasheq))
(let ([visit (lambda (v) (define (visit v)
(if (hash-ref shared v #f) (if (hash-ref shared v #f)
#f #f
(if (hash-ref encountered v #f) (if (hash-ref encountered v #f)
@ -40,10 +40,10 @@
(hash-set! encountered v #t) (hash-set! encountered v #t)
(when (closure? v) (when (closure? v)
(hash-set! shared v (add1 (hash-count shared)))) (hash-set! shared v (add1 (hash-count shared))))
#t))))]) #t))))
(parameterize ([current-wrapped-ht wrapped]) (parameterize ([current-wrapped-ht wrapped])
(traverse-prefix prefix visit) (traverse-prefix prefix visit)
(traverse-form form visit))) (traverse-form form visit))
(let* ([s (open-output-bytes)] (let* ([s (open-output-bytes)]
[out (make-out s (lambda (v) (hash-ref shared v #f)) wrapped)] [out (make-out s (lambda (v) (hash-ref shared v #f)) wrapped)]
[offsets [offsets
@ -65,25 +65,20 @@
< <
#:key car))] #:key car))]
[post-shared (file-position s)] [post-shared (file-position s)]
[all-short? (post-shared . < . #xFFFF)]) [all-short? (post-shared . < . #xFFFF)]
(out-data (list* max-let-depth prefix (protect-quote form)) out)
(let ([res (get-output-bytes s)]
[version-bs (string->bytes/latin-1 (version))]) [version-bs (string->bytes/latin-1 (version))])
(out-data (list* max-let-depth prefix (protect-quote form)) out)
(let ([res (get-output-bytes s)])
(write-bytes #"#~" outp) (write-bytes #"#~" outp)
(write-bytes (bytes (bytes-length version-bs)) outp) (write-bytes (bytes (bytes-length version-bs)) outp)
(write-bytes version-bs outp) (write-bytes version-bs outp)
(write-bytes (int->bytes (add1 (hash-count shared))) outp) (write-bytes (int->bytes (add1 (hash-count shared))) outp)
(write-bytes (bytes (if all-short? (write-bytes (bytes (if all-short? 1 0)) outp)
1
0)) outp)
(for ([o (in-list offsets)]) (for ([o (in-list offsets)])
(write-bytes (integer->integer-bytes o (write-bytes (integer->integer-bytes o (if all-short? 2 4) #f #f) outp))
(if all-short? 2 4)
#f
#f) outp))
(write-bytes (int->bytes post-shared) outp) (write-bytes (int->bytes post-shared) outp)
(write-bytes (int->bytes (bytes-length res)) outp) (write-bytes (int->bytes (bytes-length res)) outp)
(write-bytes res outp))))])) (write-bytes res outp)))]))
;; ---------------------------------------- ;; ----------------------------------------