(* type-util.sml * * COPYRIGHT (c) 2010 The Diderot Project (http://diderot.cs.uchicago.edu) * All rights reserved. *) structure TypeUtil : sig val toString : Types.ty -> string end = struct structure Ty = Types structure MV = MetaVar fun listToString fmt sep items = String.concatWith sep (List.map fmt items) fun diffToString (Ty.DiffConst n) = Int.toString n | diffToString (Ty.DiffVar(dv, 0)) = MV.diffVarToString dv | diffToString (Ty.DiffVar(dv, i)) = if i < 0 then String.concat["(", MV.diffVarToString dv, "-", Int.toString(~i), ")"] else String.concat["(", MV.diffVarToString dv, "+", Int.toString i, ")"] fun shapeToString (Ty.Shape shape) = concat["[", listToString dimToString "," shape, "]"] | shapeToString (Ty.ShapeVar sv) = MV.shapeVarToString sv | shapeToString (Ty.ShapeExt(shape, d)) = let fun toS (Ty.Shape shape) = (listToString dimToString "," shape) ^ "," | toS (Ty.ShapeVar sv) = MV.shapeVarToString sv ^ ";" | toS (Ty.ShapeExt(shape, d)) = concat[toS shape, dimToString d, ","] in toS shape ^ dimToString d end and dimToString (Ty.DimConst n) = Int.toString n | dimToString (Ty.DimVar v) = MV.dimVarToString v fun toString ty = (case ty of Ty.T_Var tv => MV.tyVarToString tv | Ty.T_Bool => "bool" | Ty.T_Int => "int" | Ty.T_String => "string" | Ty.T_Kernel n => "kernel#" ^ diffToString n | Ty.T_Tensor(Ty.Shape[]) => "real" | Ty.T_Tensor(Ty.Shape[Ty.DimConst 2]) => "vec2" | Ty.T_Tensor(Ty.Shape[Ty.DimConst 3]) => "vec3" | Ty.T_Tensor(Ty.Shape[Ty.DimConst 4]) => "vec4" | Ty.T_Tensor shape => "tensor" ^ shapeToString shape | Ty.T_Image{dim, shape} => concat[ "image(", dimToString dim, ")", shapeToString shape ] | Ty.T_Field{diff, dim, shape} => concat[ "field#", diffToString diff, "(", dimToString dim, ")", shapeToString shape ] | Ty.T_Fun(tys1, tys2) => let fun tysToString [] = "()" | tysToString [ty] = toString ty | tysToString tys = String.concat[ "(", listToString toString " * " tys, ")" ] in String.concat[tysToString tys1, " -> ", tysToString tys2] end (* end case *)) end
Click to toggle
does not end with </html> tag
does not end with </body> tag
The output has ended thus: ] in String.concat[tysToString tys1, " -> ", tysToString tys2] end (* end case *)) end