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