Backport from sid to buster
[hcoop/debian/mlton.git] / regression / size.sml
CommitLineData
7f918cf1
CE
1fun 'a printSize (name: string, min: int, value: 'a): unit=
2 if MLton.size value >= min
3 then
4 (print "The size of "
5 ; print name
6 ; print " is >= "
7 ; print (Int.toString min)
8 ; print " bytes.\n")
9 else ()
10
11val l = [1, 2, 3, 4]
12
13val _ =
14 (
15 printSize ("a char", 0, #"c")
16 ; printSize ("an int list of length 4", 48, l)
17 ; printSize ("a string of length 10", 24, "0123456789")
18 ; printSize ("an int array of length 10", 52, Array.tabulate (10, fn _ => 0))
19 ; printSize ("a double array of length 10",
20 92, Array.tabulate (10, fn _ => 0.0))
21 ; printSize ("an array of length 10 of 2-ples of ints",
22 92, Array.tabulate (10, fn i => (i, i + 1)))
23 ; printSize ("a useless function", 0, fn _ => 13)
24 )
25
26(* This is here so that the list is "useful".
27 * If it were removed, then the optimizer (remove-unused-constructors)
28 * would remove l entirely.
29 *)
30val _ = if 10 = foldl (op +) 0 l
31 then ()
32 else raise Fail "bug"
33
34local
35 open MLton.Cont
36in
37 val rc: int option t option ref = ref NONE
38 val _ =
39 case callcc (fn k: int option t => (rc := SOME k; throw (k, NONE))) of
40 NONE => ()
41 | SOME i => print (concat [Int.toString i, "\n"])
42end
43
44val _ =
45 (print "The size of a continuation option ref is "
46 ; if MLton.size rc > 1000
47 then print "> 1000.\n"
48 else print "< 1000.\n")
49
50val _ =
51 case !rc of
52 NONE => ()
53 | SOME k => (rc := NONE; MLton.Cont.throw (k, SOME 13))