Home My Page Projects Code Snippets Project Openings SML/NJ
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files

SCM Repository

[smlnj] Annotation of /sml/trunk/src/compiler/Semant/basics/persstamps.sml
ViewVC logotype

Annotation of /sml/trunk/src/compiler/Semant/basics/persstamps.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 651 - (view) (download)

1 : monnier 249 (* Copyright 1992 by AT&T Bell Laboratories *)
2 :     (* persstamps.sml *)
3 :    
4 :     (*
5 :     * DBM: was an abstraction, but persstamp needs to be an equality type
6 :     * so that conrep is.
7 :     *)
8 :    
9 :     structure PersStamps : PERSSTAMPS =
10 :     struct
11 :     datatype persstamp = PS of Word8Vector.vector
12 :    
13 :     fun compare (PS v1, PS v2) =
14 :     String.compare(Byte.bytesToString v1, Byte.bytesToString v2)
15 :    
16 :     fun toBytes (PS x) = x
17 :    
18 :     fun fromBytes v =
19 :     if Word8Vector.length v = 16 then PS v
20 :     else ErrorMsg.impossible "PersStamps.stringToStamp"
21 :    
22 :     (* convert the persstamp to a printable representation (hex digits) *)
23 :     fun toHex (PS pid) =
24 :     let fun cvtByte b = StringCvt.padLeft #"0" 2 (Word8.toString b)
25 :     fun f (b, l) = cvtByte b :: l
26 :     in String.concat (Word8Vector.foldr f [] pid)
27 :     end
28 :    
29 : blume 569 fun fromHex s = let
30 :     fun onebyte i = let
31 :     val i2 = 2 * i
32 :     val c1 = String.sub (s, i2)
33 :     val c2 = String.sub (s, i2 + 1)
34 :     in
35 :     valOf (Word8.fromString (implode [c1, c2]))
36 :     end
37 :     in
38 :     SOME (PS (Word8Vector.tabulate (16, onebyte)))
39 :     end handle _ => NONE
40 :    
41 : monnier 249 end (* structure PersStamps *)
42 :    
43 :    
44 :    

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0