Reformating

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

View File

@ -26,64 +26,59 @@
(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)
(begin (begin
(hash-set! shared v (add1 (hash-count shared))) (hash-set! shared v (add1 (hash-count shared)))
#f) #f)
(begin (begin
(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
(map (lambda (v) (map (lambda (v)
(let ([v (cdr v)]) (let ([v (cdr v)])
(begin0 (begin0
(file-position s) (file-position s)
(out-anything v (make-out (out-anything v (make-out
s s
(let ([skip? #t]) (let ([skip? #t])
(lambda (v2) (lambda (v2)
(if (and skip? (eq? v v2)) (if (and skip? (eq? v v2))
(begin (begin
(set! skip? #f) (set! skip? #f)
#f) #f)
(hash-ref shared v2 #f)))) (hash-ref shared v2 #f))))
wrapped))))) wrapped)))))
(sort (hash-map shared (lambda (k v) (cons v k))) (sort (hash-map shared (lambda (k v) (cons v k)))
< <
#: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) [version-bs (string->bytes/latin-1 (version))])
(let ([res (get-output-bytes s)] (out-data (list* max-let-depth prefix (protect-quote form)) out)
[version-bs (string->bytes/latin-1 (version))]) (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 (for ([o (in-list offsets)])
0)) outp) (write-bytes (integer->integer-bytes o (if all-short? 2 4) #f #f) outp))
(for ([o (in-list offsets)]) (write-bytes (int->bytes post-shared) outp)
(write-bytes (integer->integer-bytes o (write-bytes (int->bytes (bytes-length res)) outp)
(if all-short? 2 4) (write-bytes res outp)))]))
#f
#f) outp))
(write-bytes (int->bytes post-shared) outp)
(write-bytes (int->bytes (bytes-length res)) outp)
(write-bytes res outp))))]))
;; ---------------------------------------- ;; ----------------------------------------