[MLton-commit] r6026

Vesa Karvonen vesak at mlton.org
Sat Sep 15 02:36:29 PDT 2007


Fixed bug in the pickling of "sizes" and changed the encoding of tags.

----------------------------------------------------------------------

U   mltonlib/trunk/com/ssh/generic/unstable/detail/value/pickle.sml
U   mltonlib/trunk/com/ssh/generic/unstable/public/value/pickle.sig

----------------------------------------------------------------------

Modified: mltonlib/trunk/com/ssh/generic/unstable/detail/value/pickle.sml
===================================================================
--- mltonlib/trunk/com/ssh/generic/unstable/detail/value/pickle.sml	2007-09-15 09:34:58 UTC (rev 6025)
+++ mltonlib/trunk/com/ssh/generic/unstable/detail/value/pickle.sml	2007-09-15 09:36:28 UTC (rev 6026)
@@ -205,7 +205,7 @@
                 rd word8 >>= (fn b =>
                 if b < 0wx80
                 then return (v + Word8.toInt b * m)
-                else lp (v + Word8.toInt (b - 0wx80) * m, m * 0x80))
+                else lp (v + Word8.toInt (Word8.andb (b, 0wx7F)) * m, m * 0x80))
           in
              lp (0, 1)
           end,
@@ -214,10 +214,10 @@
              fun lp i =
                  if i < 0x80
                  then wr word8 (Word8.fromInt i)
-                 else wr word8 (Word8.andb (0wx7F, Word8.fromInt i)) >>=
+                 else wr word8 (Word8.orb (0wx80, Word8.fromInt i)) >>=
                       (fn () => lp (Int.quot (i, 0x80)))
           in
-             fn i => if i < 0 then fail "Negative size" else return i >>= lp
+             fn i => if i < 0 then fail "Negative size" else lp i
           end,
           sz = SOME 2}
 
@@ -255,15 +255,6 @@
          sz = SOME ((n + 7) div 8 + Bool.toInt sized)}
    end
 
-   val intAs16 = let
-      open Word
-   in
-      bits false
-           {wordSize = 16, orb = op orb, << = op <<, ~>> = op ~>>,
-            isoWord8 = isoWord8}
-           (swap Word.isoInt)
-   end
-
    val word32 = bits false Word32.ops Iso.id
 
    (* Encodes fixed size int as a size followed by little endian bytes. *)
@@ -576,10 +567,9 @@
       fun data aS = let
          val n = Arg.numAlts aS
          val tag =
-             if      n <= 1     then intAs0
-             else if n <= 256   then intAs8
-             else if n <= 65536 then intAs16
-             else fail "Too many tags"
+             if      n <= 1   then intAs0
+             else if n <= 256 then intAs8
+             else                  size
          val S {rd = aR, wr = aW, sz = aS} = getS aS
          val aR = aR 0
          open I

Modified: mltonlib/trunk/com/ssh/generic/unstable/public/value/pickle.sig
===================================================================
--- mltonlib/trunk/com/ssh/generic/unstable/public/value/pickle.sig	2007-09-15 09:34:58 UTC (rev 6025)
+++ mltonlib/trunk/com/ssh/generic/unstable/public/value/pickle.sig	2007-09-15 09:36:28 UTC (rev 6026)
@@ -92,8 +92,8 @@
  * pickling constructors based on the knowledge of how many constructors a
  * datatype has.  If a datatype contains only a single constructor, no tag
  * is written at all (0-bits of storage).  If a datatype contains a
- * maximum of 256 constructors, the tag takes 8-bits.  Otherwise 16-bits
- * are used.
+ * maximum of 256 constructors, the tag takes 8-bits.  Otherwise a
+ * variable length tag is used.
  *
  * For maximal flexibility, the interface allows pickling / unpickling
  * directly to / from an arbitrary stream.




More information about the MLton-commit mailing list