racket/serialize: serialize fxvectors and flvectors

This commit is contained in:
Matthew Flatt 2012-12-02 10:45:44 -07:00
parent 9cf821b301
commit 9e8477dd45
4 changed files with 30 additions and 2 deletions

View File

@ -2,6 +2,8 @@
(require syntax/modcollapse (require syntax/modcollapse
unstable/struct unstable/struct
racket/list racket/list
racket/flonum
racket/fixnum
"serialize-structs.rkt") "serialize-structs.rkt")
;; This module implements the core serializer. The syntactic ;; This module implements the core serializer. The syntactic
@ -43,6 +45,8 @@
(path-for-some-system? v) (path-for-some-system? v)
(bytes? v) (bytes? v)
(vector? v) (vector? v)
(flvector? v)
(fxvector? v)
(pair? v) (pair? v)
(mpair? v) (mpair? v)
(hash? v) (hash? v)
@ -137,6 +141,8 @@
(hash? o)) (hash? o))
(not (immutable? o))) (not (immutable? o)))
(serializable-struct? o) (serializable-struct? o)
(flvector? o)
(fxvector? o)
(let ([k (prefab-struct-key o)]) (let ([k (prefab-struct-key o)])
(and k (and k
;; Check whether all fields are mutable: ;; Check whether all fields are mutable:
@ -226,6 +232,8 @@
(void)] (void)]
[(vector? v) [(vector? v)
(for-each loop (vector->list v))] (for-each loop (vector->list v))]
[(flvector? v) (void)]
[(fxvector? v) (void)]
[(pair? v) [(pair? v)
(loop (car v)) (loop (car v))
(loop (cdr v))] (loop (cdr v))]
@ -313,6 +321,10 @@
(andmap quotable? elems)) (andmap quotable? elems))
(cons 'q v) (cons 'q v)
(cons (if (immutable? v) 'v 'v!) elems))] (cons (if (immutable? v) 'v 'v!) elems))]
[(flvector? v)
(cons 'vl (for/list ([i (in-flvector v)]) i))]
[(fxvector? v)
(cons 'vx (for/list ([i (in-fxvector v)]) i))]
[(pair? v) [(pair? v)
(let ([loop (serial #t)]) (let ([loop (serial #t)])
(let ([a (loop (car v))] (let ([a (loop (car v))]
@ -493,6 +505,8 @@
[(m) (mcons (loop (cadr v)) (loop (cddr v)))] [(m) (mcons (loop (cadr v)) (loop (cddr v)))]
[(v) (apply vector-immutable (map loop (cdr v)))] [(v) (apply vector-immutable (map loop (cdr v)))]
[(v!) (list->vector (map loop (cdr v)))] [(v!) (list->vector (map loop (cdr v)))]
[(vl) (apply flvector (map loop (cdr v)))]
[(vx) (apply fxvector (map loop (cdr v)))]
[(b) (box-immutable (loop (cdr v)))] [(b) (box-immutable (loop (cdr v)))]
[(b!) (box (loop (cdr v)))] [(b!) (box (loop (cdr v)))]
[(h) (let ([al (map (lambda (p) [(h) (let ([al (map (lambda (p)

View File

@ -45,7 +45,8 @@ The following kinds of values are serializable:
@tech{unreadable symbols}, @tech{strings}, @tech{byte strings}, @tech{paths} (for a @tech{unreadable symbols}, @tech{strings}, @tech{byte strings}, @tech{paths} (for a
specific convention), @|void-const|, and the empty list;} specific convention), @|void-const|, and the empty list;}
@item{@tech{pairs}, @tech{mutable pairs}, @tech{vectors}, @tech{box}es, @tech{hash tables}, and @tech{sets};} @item{@tech{pairs}, @tech{mutable pairs}, @tech{vectors}, @tech{flvectors}, @tech{fxvectors},
@tech{box}es, @tech{hash tables}, and @tech{sets};}
@item{@racket[date], @racket[date*], and @racket[arity-at-least] structures; and} @item{@racket[date], @racket[date*], and @racket[arity-at-least] structures; and}
@ -264,6 +265,14 @@ elements:
@racket[cdr] is a list of serials; it represents a @racket[cdr] is a list of serials; it represents a
mutable vector.} mutable vector.}
@item{a pair whose @racket[car] is @racket['vl] and whose
@racket[cdr] is a list of serials; it represents a
@tech{flvector}.}
@item{a pair whose @racket[car] is @racket['vx] and whose
@racket[cdr] is a list of serials; it represents a
@tech{fxvector}.}
@item{a pair whose @racket[car] is @racket['b] and whose @item{a pair whose @racket[car] is @racket['b] and whose
@racket[cdr] is a serial; it represents an immutable @racket[cdr] is a serial; it represents an immutable
box.} box.}

View File

@ -4,7 +4,9 @@
(Section 'serialization) (Section 'serialization)
(require racket/serialize (require racket/serialize
racket/file) racket/file
racket/flonum
racket/fixnum)
;; ---------------------------------------- ;; ----------------------------------------
@ -136,6 +138,8 @@
(test-ser (mk-ht make-weak-hash)) (test-ser (mk-ht make-weak-hash))
(test-ser #s(a 0 1 2)) (test-ser #s(a 0 1 2))
(test-ser #s((a q 2) 0 1 2)) (test-ser #s((a q 2) 0 1 2))
(test-ser (fxvector 1 2 30))
(test-ser (flvector 0.1 2.0 30e3))
(test-ser (set 'set 0 1 2)) (test-ser (set 'set 0 1 2))
(test-ser (seteqv 'seteqv 0 1 2)) (test-ser (seteqv 'seteqv 0 1 2))

View File

@ -3,6 +3,7 @@ Changed case to use equal? instead of eqv?
r5rs, r6rs: fixed case and cond to disallow internal definitions r5rs, r6rs: fixed case and cond to disallow internal definitions
in clauses in clauses
Add #fx() and #fl() reader forms for flvectors and fxvectors Add #fx() and #fl() reader forms for flvectors and fxvectors
racket/serialize: fxvectors and flvectors are serializable
Version 5.3.1.8 Version 5.3.1.8
file/untar: added file/untar: added