Import Upstream version 20180207
[hcoop/debian/mlton.git] / regression / generate / all-overloads.sml
1 structure List =
2 struct
3 fun foreach (l, f) = List.app f l
4 fun map (l, f) = List.map f l
5 val tabulate = List.tabulate
6 end
7
8 val int =
9 List.map (["Int", "IntInf", "LargeInt", "FixedInt", "Position"]
10 @ List.map (List.tabulate (31, fn i => i + 2) @ [64],
11 fn i => concat ["Int", Int.toString i]),
12 fn s => concat [s, ".int"])
13
14 val real =
15 List.map (["Real", "Real32", "Real64", "LargeReal"],
16 fn s => concat [s, ".real"])
17
18 val word =
19 List.map (["Word", "LargeWord", "SysWord"]
20 @ List.map (List.tabulate (31, fn i => i + 2) @ [64],
21 fn i => concat ["Word", Int.toString i]),
22 fn s => concat [s, ".word"])
23
24 val text = ["Char.char", "String.string"]
25
26 val num = int @ word @ real
27 val numtext = num @ text
28 val realint = int @ real
29 val wordint = int @ word
30
31 datatype ty = Binary | Compare | Unary
32 val binary = Binary
33 val compare = Compare
34 val unary = Unary
35
36 val () = print "(* This file is automatically generated. Do not edit. *)\n"
37
38 val () =
39 List.foreach
40 ([(2, "~", unary, num),
41 (2, "+", binary, num),
42 (2, "-", binary, num),
43 (2, "*", binary, num),
44 (4, "/", binary, real),
45 (3, "div", binary, wordint),
46 (3, "mod", binary, wordint),
47 (3, "abs", unary, realint),
48 (1, "<", compare, numtext),
49 (1, "<=", compare, numtext),
50 (1, ">", compare, numtext),
51 (1, ">=", compare, numtext)],
52 fn (prec, f, ty, class) =>
53 List.foreach
54 (class, fn c =>
55 print (concat ["fun f (x: ", c, ") = ",
56 case ty of
57 Binary => concat ["x ", f, " x"]
58 | Compare => concat ["x ", f, " x"]
59 | Unary => concat [f, " x"],
60 "\n"])))