1 (* Copyright (C
) 2009 Matthew Fluet
.
2 * Copyright (C
) 1999-2005 Henry Cejtin
, Matthew Fluet
, Suresh
3 * Jagannathan
, and Stephen Weeks
.
5 * MLton is released under a BSD
-style license
.
6 * See the file MLton
-LICENSE for details
.
9 (* Use fromLargeWord instead
of fromLarge so we can compile this code
10 * with older MLtons that don
't have fromLarge
.
12 functor FixWord (W
: PERVASIVE_WORD
) =
17 structure LargeWord
= Pervasive
.LargeWord
18 structure Word = Pervasive
.Word
19 structure Word8 = Pervasive
.Word8
21 fun format (w
, f
) = W
.fmt f w
22 val fromChar
= W
.fromLargeWord
o Word8.toLargeWord
o Byte
.charToByte
23 val fromIntInf
= W
.fromLargeInt
24 val fromLarge
= W
.fromLargeWord
o LargeWord
.toLargeWord
25 val fromWord
= W
.fromLargeWord
o Word.toLargeWord
26 val layout
= Layout
.str
o W
.toString
27 fun nthBitIsSet (w
: t
, n
: int): bool =
28 W
.fromInt
1 = W
.andb (W
.fromInt
1, W
.>> (w
, Word.fromInt n
))
29 val toChar
= Byte
.byteToChar
o Word8.fromLargeWord
o W
.toLargeWord
30 val toIntInf
= W
.toLargeInt
31 val toIntInfX
= W
.toLargeIntX
32 val toLarge
= LargeWord
.fromLargeWord
o W
.toLargeWord
33 val toLargeX
= LargeWord
.fromLargeWord
o W
.toLargeWordX
34 val toWord
= Word.fromLargeWord
o W
.toLargeWord
35 val toWordX
= Word.fromLargeWord
o W
.toLargeWordX
43 val stringToVector
: string -> t vector
44 val vectorToString
: t vector
-> string
48 structure Z
= FixWord (Pervasive
.Word8)
51 val equals
: t
* t
-> bool = op =
53 fun vectorToString v
=
54 CharVector
.tabulate (Pervasive
.Vector.length v
, fn i
=>
55 toChar (Pervasive
.Vector.sub (v
, i
)))
57 fun stringToVector s
=
58 Pervasive
.Vector.tabulate (Pervasive
.String.size s
, fn i
=>
59 fromChar (Pervasive
.String.sub (s
, i
)))