]> gitweb.factorcode.org Git - factor.git/commitdiff
pack uses endian library now
authorDoug Coleman <doug.coleman@gmail.com>
Sat, 7 Feb 2009 05:37:38 +0000 (23:37 -0600)
committerDoug Coleman <doug.coleman@gmail.com>
Sat, 7 Feb 2009 05:37:38 +0000 (23:37 -0600)
basis/pack/pack.factor

index 3cf7dbab4c9fc534876940b5ec42044106e59a90..9078817206c54f9e961c71f2e52ab0117a77d8f3 100755 (executable)
@@ -5,33 +5,9 @@ io.binary io.streams.string kernel math math.parser namespaces
 make parser prettyprint quotations sequences strings vectors
 words macros math.functions math.bitwise fry generalizations
 combinators.smart io.streams.byte-array io.encodings.binary
-math.vectors combinators multiline ;
+math.vectors combinators multiline endian ;
 IN: pack
 
-SYMBOL: big-endian
-
-: big-endian? ( -- ? )
-    1 <int> *char zero? ;
-
-<PRIVATE
-
-: set-big-endian ( -- )
-    big-endian? big-endian set ; inline
-
-PRIVATE>
-
-: >signed ( x n -- y )
-    2dup neg 1+ shift 1 = [ 2^ - ] [ drop ] if ;
-
-: >endian ( obj n -- str )
-    big-endian get [ >be ] [ >le ] if ; inline
-
-: unsigned-endian> ( obj -- str )
-    big-endian get [ be> ] [ le> ] if ; inline
-
-: signed-endian> ( obj n -- str )
-    [ unsigned-endian> ] dip >signed ;
-
 GENERIC: >n-byte-array ( obj n -- byte-array )
 
 M: integer >n-byte-array ( m n -- byte-array ) >endian ;
@@ -124,13 +100,13 @@ PRIVATE>
     [ ch>packed-length ] sigma ;
  
 : pack-native ( seq str -- seq )
-    [ set-big-endian pack ] with-scope ; inline
+    '[ _ _ pack ] with-native-endian ; inline
 
 : pack-be ( seq str -- seq )
-    [ big-endian on pack ] with-scope ; inline
+    '[ _ _ pack ] with-big-endian ; inline
 
 : pack-le ( seq str -- seq )
-    [ big-endian off pack ] with-scope ; inline
+    '[ _ _ pack ] with-little-endian ; inline
 
 <PRIVATE
 
@@ -146,13 +122,13 @@ MACRO: unpack ( str -- quot )
 PRIVATE>
 
 : unpack-native ( seq str -- seq )
-    [ set-big-endian unpack ] with-scope ; inline
+    '[ _ _ unpack ] with-native-endian ; inline
 
 : unpack-be ( seq str -- seq )
-    [ big-endian on unpack ] with-scope ; inline
+    '[ _ _ unpack ] with-big-endian ; inline
 
 : unpack-le ( seq str -- seq )
-    [ big-endian off unpack ] with-scope ; inline
+    '[ _ _ unpack ] with-little-endian ; inline
 
 ERROR: packed-read-fail str bytes ;