racket/serialize: serialize fxvectors and flvectors
This commit is contained in:
parent
9cf821b301
commit
9e8477dd45
|
@ -2,6 +2,8 @@
|
|||
(require syntax/modcollapse
|
||||
unstable/struct
|
||||
racket/list
|
||||
racket/flonum
|
||||
racket/fixnum
|
||||
"serialize-structs.rkt")
|
||||
|
||||
;; This module implements the core serializer. The syntactic
|
||||
|
@ -43,6 +45,8 @@
|
|||
(path-for-some-system? v)
|
||||
(bytes? v)
|
||||
(vector? v)
|
||||
(flvector? v)
|
||||
(fxvector? v)
|
||||
(pair? v)
|
||||
(mpair? v)
|
||||
(hash? v)
|
||||
|
@ -137,6 +141,8 @@
|
|||
(hash? o))
|
||||
(not (immutable? o)))
|
||||
(serializable-struct? o)
|
||||
(flvector? o)
|
||||
(fxvector? o)
|
||||
(let ([k (prefab-struct-key o)])
|
||||
(and k
|
||||
;; Check whether all fields are mutable:
|
||||
|
@ -226,6 +232,8 @@
|
|||
(void)]
|
||||
[(vector? v)
|
||||
(for-each loop (vector->list v))]
|
||||
[(flvector? v) (void)]
|
||||
[(fxvector? v) (void)]
|
||||
[(pair? v)
|
||||
(loop (car v))
|
||||
(loop (cdr v))]
|
||||
|
@ -313,6 +321,10 @@
|
|||
(andmap quotable? elems))
|
||||
(cons 'q v)
|
||||
(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)
|
||||
(let ([loop (serial #t)])
|
||||
(let ([a (loop (car v))]
|
||||
|
@ -493,6 +505,8 @@
|
|||
[(m) (mcons (loop (cadr v)) (loop (cddr v)))]
|
||||
[(v) (apply vector-immutable (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 (loop (cdr v)))]
|
||||
[(h) (let ([al (map (lambda (p)
|
||||
|
|
|
@ -45,7 +45,8 @@ The following kinds of values are serializable:
|
|||
@tech{unreadable symbols}, @tech{strings}, @tech{byte strings}, @tech{paths} (for a
|
||||
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}
|
||||
|
||||
|
@ -264,6 +265,14 @@ elements:
|
|||
@racket[cdr] is a list of serials; it represents a
|
||||
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
|
||||
@racket[cdr] is a serial; it represents an immutable
|
||||
box.}
|
||||
|
|
|
@ -4,7 +4,9 @@
|
|||
(Section 'serialization)
|
||||
|
||||
(require racket/serialize
|
||||
racket/file)
|
||||
racket/file
|
||||
racket/flonum
|
||||
racket/fixnum)
|
||||
|
||||
;; ----------------------------------------
|
||||
|
||||
|
@ -136,6 +138,8 @@
|
|||
(test-ser (mk-ht make-weak-hash))
|
||||
(test-ser #s(a 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 (seteqv 'seteqv 0 1 2))
|
||||
|
|
|
@ -3,6 +3,7 @@ Changed case to use equal? instead of eqv?
|
|||
r5rs, r6rs: fixed case and cond to disallow internal definitions
|
||||
in clauses
|
||||
Add #fx() and #fl() reader forms for flvectors and fxvectors
|
||||
racket/serialize: fxvectors and flvectors are serializable
|
||||
|
||||
Version 5.3.1.8
|
||||
file/untar: added
|
||||
|
|
Loading…
Reference in New Issue
Block a user