Import Debian changes 20180207-1
[hcoop/debian/mlton.git] / regression / weak.sml
1 structure Weak = MLton.Weak
2
3 val w = Weak.new 13
4 val _ =
5 if isSome (Weak.get w)
6 then raise Fail "bug int"
7 else ()
8
9 fun testIntInf (i: IntInf.int) =
10 let
11 val w = Weak.new i
12 val _ =
13 case Weak.get w of
14 NONE => raise Fail "bug IntInf"
15 | SOME i => print (concat [IntInf.toString i, "\n"])
16 in
17 ()
18 end
19 val _ = testIntInf 13
20 val _ = testIntInf 12345678901234567890
21
22 val r = ref 13
23 val n = 2
24 val rs = Array.tabulate (n, ref)
25 val ws = Array.tabulate (n, fn i => Weak.new (Array.sub (rs, i)))
26 fun isAlive i = isSome (Weak.get (Array.sub (ws, i)))
27 val _ = MLton.GC.collect ()
28 val _ =
29 if isAlive 0 andalso isAlive 1
30 then ()
31 else raise Fail "bug1"
32 fun clear i = Array.update (rs, i, r)
33 fun sub i = ! (Array.sub (rs, i))
34 fun pi x = print (concat [Int.toString x, "\n"])
35 val _ = pi (sub 0 + sub 1)
36 val _ = valOf (Weak.get (Array.sub (ws, 0))) := 12345
37 val _ = clear 1
38 val _ = MLton.GC.collect ()
39 val _ =
40 if isAlive 0 andalso not (isAlive 1)
41 then ()
42 else raise Fail "bug2"
43 val _ = pi (sub 0)
44 val _ = clear 0
45 val _ = MLton.GC.collect ()
46 val _ =
47 if not (isAlive 0) andalso not (isAlive 1)
48 then ()
49 else raise Fail "bug2"
50