SCM Repository
View of /trunk/src/common/stamp.sml
Parent Directory
|
Revision Log
Revision 9 -
(download)
(annotate)
Fri Jan 8 22:06:11 2010 UTC (11 years ago) by jhr
File size: 1608 byte(s)
Fri Jan 8 22:06:11 2010 UTC (11 years ago) by jhr
File size: 1608 byte(s)
More work on type system
(* stamp.sml * * COPYRIGHT (c) 2010 The Diderot Project (http://diderot.cs.uchicago.edu) * All rights reserved. * * Stamps are locally unique identifiers used in the compiler to * distinguish different types, variables, etc. For a given compilation, * the stamp assigned to an object is guaranteed to be unique, although * an object may have different stamps assigned to it in different compiles. *) structure Stamp :> sig type stamp val new : unit -> stamp val same : (stamp * stamp) -> bool val compare : (stamp * stamp) -> order val hash : stamp -> word val toString : stamp -> string structure Set : ORD_SET where type Key.ord_key = stamp structure Map : ORD_MAP where type Key.ord_key = stamp structure Tbl : MONO_HASH_TABLE where type Key.hash_key = stamp end = struct structure W = Word datatype stamp = STAMP of { id : Word.word } val cnt = ref 0w0 fun new () = let val w = !cnt in cnt := w+0w1; STAMP{id = w} end fun same (STAMP{id, ...}, STAMP{id=id', ...}) = (id = id') fun compare (STAMP{id, ...}, STAMP{id=id', ...}) = W.compare(id, id') fun hash (STAMP{id, ...}) = id fun toString (STAMP{id, ...}) = concat["<", StringCvt.padLeft #"0" 4 (W.toString id), ">"] structure Key = struct type ord_key = stamp val compare = compare end structure Map = RedBlackMapFn (Key) structure Set = RedBlackSetFn (Key) structure Tbl = HashTableFn (struct type hash_key = stamp fun hashVal (STAMP{id}) = id fun sameKey (STAMP{id=a}, STAMP{id=b}) = (a = b) end) end
root@smlnj-gforge.cs.uchicago.edu | ViewVC Help |
Powered by ViewVC 1.0.0 |