11 |
end = struct |
end = struct |
12 |
|
|
13 |
structure Ty = Types |
structure Ty = Types |
14 |
|
structure MV = MetaVar |
15 |
|
|
16 |
fun listToString fmt sep items = String.concatWith sep (List.map fmt items) |
fun listToString fmt sep items = String.concatWith sep (List.map fmt items) |
17 |
|
|
18 |
fun varToString (Ty.TV{kind, stamp}) = let |
fun diffToString (Ty.DiffConst n) = Int.toString n |
19 |
val prefix = (case kind |
| diffToString (Ty.DiffVar(dv, 0)) = MV.diffVarToString dv |
20 |
of Ty.TK_NAT => "'nat" |
| diffToString (Ty.DiffVar(dv, i)) = if i < 0 |
21 |
| Ty.TK_SHAPE => "'shp" |
then String.concat["(", MV.diffVarToString dv, "-", Int.toString(~i), ")"] |
22 |
| Ty.TK_TYPE => "'ty" |
else String.concat["(", MV.diffVarToString dv, "+", Int.toString i, ")"] |
23 |
(* end case *)) |
|
24 |
|
fun shapeToString (Ty.Shape shape) = |
25 |
|
concat["[", listToString dimToString "," shape, "]"] |
26 |
|
| shapeToString (Ty.ShapeVar sv) = MV.shapeVarToString sv |
27 |
|
| shapeToString (Ty.ShapeExt(shape, d)) = let |
28 |
|
fun toS (Ty.Shape shape) = (listToString dimToString "," shape) ^ "," |
29 |
|
| toS (Ty.ShapeVar sv) = MV.shapeVarToString sv ^ ";" |
30 |
|
| toS (Ty.ShapeExt(shape, d)) = concat[toS shape, dimToString d, ","] |
31 |
in |
in |
32 |
prefix ^ Stamp.toString stamp |
toS shape ^ dimToString d |
33 |
end |
end |
34 |
|
|
35 |
fun natToString (Ty.NatConst n) = Int.toString n |
and dimToString (Ty.DimConst n) = Int.toString n |
36 |
| natToString (Ty.NatExp(n, i)) = if i < 0 |
| dimToString (Ty.DimVar v) = MV.dimVarToString v |
|
then String.concat[natToString n, "-", Int.toString(~i)] |
|
|
else String.concat[natToString n, "+", Int.toString i] |
|
|
| natToString (Ty.NatVar v) = varToString v |
|
|
|
|
|
fun shapeToString (Shape shape) = |
|
|
concat["[", listToString natToString "," shape, "]"] |
|
|
| shapeToString (ShapeVar sv) = varToString sv |
|
|
| shapeToString (ShapeExt(shape, d)) = let |
|
|
fun toS (Shape shape) = (listToString natToString "," shape) ^ "," |
|
|
| toS (ShapeVar sv) = varToString sv ^ ";" |
|
|
| toS (ShapeExt(shape, d)) = concat[toS shape, natToString d, ","] |
|
|
in |
|
|
toS shape ^ natToString d |
|
|
end |
|
37 |
|
|
38 |
fun toString ty = (case ty |
fun toString ty = (case ty |
39 |
of Ty.T_Var tv => varToString tv |
of Ty.T_Var tv => MV.tyVarToString tv |
40 |
| Ty.T_Bool => "bool" |
| Ty.T_Bool => "bool" |
41 |
| Ty.T_Int => "int" |
| Ty.T_Int => "int" |
42 |
| Ty.T_String => "string" |
| Ty.T_String => "string" |
43 |
| Ty.T_Kernel n => "kernel#" ^ natToString n |
| Ty.T_Kernel n => "kernel#" ^ diffToString n |
44 |
| Ty.T_Tensor[] => "real" |
| Ty.T_Tensor(Ty.Shape[]) => "real" |
45 |
| Ty.T_Tensor[Ty.NatConst 2] => "vec2" |
| Ty.T_Tensor(Ty.Shape[Ty.DimConst 2]) => "vec2" |
46 |
| Ty.T_Tensor[Ty.NatConst 3] => "vec3" |
| Ty.T_Tensor(Ty.Shape[Ty.DimConst 3]) => "vec3" |
47 |
| Ty.T_Tensor[Ty.NatConst 4] => "vec4" |
| Ty.T_Tensor(Ty.Shape[Ty.DimConst 4]) => "vec4" |
48 |
| Ty.T_Tensor shape => "tensor" ^ shapeToString shape |
| Ty.T_Tensor shape => "tensor" ^ shapeToString shape |
49 |
| Ty.T_Image{dim, shape} => concat[ |
| Ty.T_Image{dim, shape} => concat[ |
50 |
"image(", natToString dim, ")", shapeToString shape |
"image(", dimToString dim, ")", shapeToString shape |
51 |
] |
] |
52 |
| Ty.T_Field{diff, dim, shape} => concat[ |
| Ty.T_Field{diff, dim, shape} => concat[ |
53 |
"field#", natToString diff, "(", natToString dim, |
"field#", diffToString diff, "(", dimToString dim, |
54 |
")", shapeToString shape |
")", shapeToString shape |
55 |
] |
] |
56 |
| Ty.T_Fun(tys1, tys2) => let |
| Ty.T_Fun(tys1, tys2) => let |
60 |
"(", listToString toString " * " tys, ")" |
"(", listToString toString " * " tys, ")" |
61 |
] |
] |
62 |
in |
in |
63 |
String.concat[tysToString tys1, " -> ", tysToSTring tys2] |
String.concat[tysToString tys1, " -> ", tysToString tys2] |
64 |
end |
end |
65 |
(* end case *)) |
(* end case *)) |
66 |
|
|