Import Debian changes 20180207-1
[hcoop/debian/mlton.git] / mlton / backend / objptr-tycon.fun
1 (* Copyright (C) 2009 Matthew Fluet.
2 * Copyright (C) 2004-2007 Henry Cejtin, Matthew Fluet, Suresh
3 * Jagannathan, and Stephen Weeks.
4 *
5 * MLton is released under a BSD-style license.
6 * See the file MLton-LICENSE for details.
7 *)
8
9 functor ObjptrTycon (S: OBJPTR_TYCON_STRUCTS): OBJPTR_TYCON =
10 struct
11
12 open S
13
14 datatype t = T of {index: int ref}
15
16 local
17 fun make f (T r) = f r
18 in
19 val index = ! o (make #index)
20 end
21
22 local
23 val c = Counter.new 0
24 in
25 fun new () = T {index = ref (Counter.next c)}
26 end
27
28 fun setIndex (T {index = r}, i) = r := i
29
30 fun fromIndex i = T {index = ref i}
31
32 fun compare (opt, opt') = Int.compare (index opt, index opt')
33
34 fun equals (opt, opt') = index opt = index opt'
35
36 val op <= = fn (opt, opt') => index opt <= index opt'
37
38 fun toString (opt: t): string =
39 concat ["opt_", Int.toString (index opt)]
40
41 val layout = Layout.str o toString
42
43 val stack = new ()
44 val thread = new ()
45 val weakGone = new ()
46
47 local
48 val word8Vector = new ()
49 val word16Vector = new ()
50 val word32Vector = new ()
51 val word64Vector = new ()
52 in
53 fun wordVector (b: Bits.t): t =
54 case Bits.toInt b of
55 8 => word8Vector
56 | 16 => word16Vector
57 | 32 => word32Vector
58 | 64 => word64Vector
59 | _ => Error.bug "ObjptrTycon.wordVector"
60 end
61
62 end