Move hashtables.identity to basis and update serialize vocab to use them
parent
a74de80bb0
commit
1972351d7f
|
@ -8,11 +8,11 @@
|
||||||
!
|
!
|
||||||
USING: namespaces sequences kernel math io math.functions
|
USING: namespaces sequences kernel math io math.functions
|
||||||
io.binary strings classes words sbufs classes.tuple arrays
|
io.binary strings classes words sbufs classes.tuple arrays
|
||||||
vectors byte-arrays quotations hashtables assocs help.syntax
|
vectors byte-arrays quotations hashtables hashtables.identity
|
||||||
help.markup splitting io.streams.byte-array io.encodings.string
|
assocs help.syntax help.markup splitting io.streams.byte-array
|
||||||
io.encodings.utf8 io.encodings.binary combinators accessors
|
io.encodings.string io.encodings.utf8 io.encodings.binary
|
||||||
locals prettyprint compiler.units sequences.private
|
combinators accessors locals prettyprint compiler.units
|
||||||
classes.tuple.private vocabs.loader ;
|
sequences.private classes.tuple.private vocabs.loader ;
|
||||||
IN: serialize
|
IN: serialize
|
||||||
|
|
||||||
GENERIC: (serialize) ( obj -- )
|
GENERIC: (serialize) ( obj -- )
|
||||||
|
@ -22,22 +22,14 @@ GENERIC: (serialize) ( obj -- )
|
||||||
! Variable holding a assoc of objects already serialized
|
! Variable holding a assoc of objects already serialized
|
||||||
SYMBOL: serialized
|
SYMBOL: serialized
|
||||||
|
|
||||||
TUPLE: id obj ;
|
|
||||||
|
|
||||||
C: <id> id
|
|
||||||
|
|
||||||
M: id hashcode* nip obj>> identity-hashcode ;
|
|
||||||
|
|
||||||
M: id equal? over id? [ [ obj>> ] bi@ eq? ] [ 2drop f ] if ;
|
|
||||||
|
|
||||||
: add-object ( obj -- )
|
: add-object ( obj -- )
|
||||||
#! Add an object to the sequence of already serialized
|
#! Add an object to the sequence of already serialized
|
||||||
#! objects.
|
#! objects.
|
||||||
serialized get [ assoc-size swap <id> ] keep set-at ;
|
serialized get [ assoc-size swap ] keep set-at ;
|
||||||
|
|
||||||
: object-id ( obj -- id )
|
: object-id ( obj -- id )
|
||||||
#! Return the id of an already serialized object
|
#! Return the id of an already serialized object
|
||||||
<id> serialized get at ;
|
serialized get at ;
|
||||||
|
|
||||||
! Numbers are serialized as follows:
|
! Numbers are serialized as follows:
|
||||||
! 0 => B{ 0 }
|
! 0 => B{ 0 }
|
||||||
|
@ -289,7 +281,7 @@ PRIVATE>
|
||||||
[ (deserialize) ] with-variable ;
|
[ (deserialize) ] with-variable ;
|
||||||
|
|
||||||
: serialize ( obj -- )
|
: serialize ( obj -- )
|
||||||
H{ } clone serialized [ (serialize) ] with-variable ;
|
IH{ } clone serialized [ (serialize) ] with-variable ;
|
||||||
|
|
||||||
: bytes>object ( bytes -- obj )
|
: bytes>object ( bytes -- obj )
|
||||||
binary [ deserialize ] with-byte-reader ;
|
binary [ deserialize ] with-byte-reader ;
|
||||||
|
|
Loading…
Reference in New Issue