Debian Codegraph @

lib/mlrisc-lib/MLRISC/gc-safety/gc-type.sml

raw
1 (*
2 * Abstract interface for GC types.
3 *)
4 functor GCType(ObjType : OBJ_TYPE) : GC_TYPE =
5 struct
6
7 structure O = ObjType
8
9 type ty = int
10
11 datatype gctype =
12 CONST of int (* integer constant *)
13 | NONREF of O.objtype ref (* non-reference value *)
14 | REF of O.objtype ref (* a reference, pointer to a gc object *)
15 | ADD of ty * gctype * gctype (* address arithmetic + *)
16 | SUB of ty * gctype * gctype (* address arithmetic - *)
17 | BOT
18 | TOP
19
20 type gcmap = gctype Intmap.intmap
21
22 exception GCTYPE
23
24 fun int i = if i >= 0 then Int.toString i else "-"^Int.toString(~i)
25
26 fun toString BOT = "bot"
27 | toString TOP = "top"
28 | toString (CONST i) = int i
29 | toString (NONREF(ref obj)) = "nonref "^O.toString obj
30 | toString (REF(ref obj)) = "ref "^O.toString obj
31 | toString (ADD(ty,a,b)) = "("^toString a^"+"^toString b^")"
32 | toString (SUB(ty,a,b)) = "("^toString a^"-"^toString b^")"
33
34 fun mapToString gcmap =
35 let val lookup = Intmap.map gcmap
36 fun f r = "{"^toString(lookup r)^"}" handle _ => "{?}"
37 in f end
38
39 val GCMAP = Annotations.new NONE : gcmap Annotations.property
40 val GCSAFEPOINT = Annotations.newFlag ""
41
42 end