SCM Repository
[diderot] / trunk / src / ast / type-util.sml |
View of /trunk/src/ast/type-util.sml
Parent Directory
|
Revision Log
Revision 63 -
(download)
(annotate)
Thu May 13 00:29:39 2010 UTC (10 years, 11 months ago) by jhr
File size: 2188 byte(s)
Thu May 13 00:29:39 2010 UTC (10 years, 11 months ago) by jhr
File size: 2188 byte(s)
Working on typechecking for Diderot
(* 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 fun listToString fmt sep items = String.concatWith sep (List.map fmt items) fun varToString (Ty.TV{kind, stamp}) = let val prefix = (case kind of Ty.TK_NAT => "'nat" | Ty.TK_SHAPE => "'shp" | Ty.TK_TYPE => "'ty" (* end case *)) in prefix ^ Stamp.toString stamp end fun natToString (Ty.NatConst n) = Int.toString n | natToString (Ty.NatExp(n, i)) = if i < 0 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 fun toString ty = (case ty of Ty.T_Var tv => varToString tv | Ty.T_Bool => "bool" | Ty.T_Int => "int" | Ty.T_String => "string" | Ty.T_Kernel n => "kernel#" ^ natToString n | Ty.T_Tensor[] => "real" | Ty.T_Tensor[Ty.NatConst 2] => "vec2" | Ty.T_Tensor[Ty.NatConst 3] => "vec3" | Ty.T_Tensor[Ty.NatConst 4] => "vec4" | Ty.T_Tensor shape => "tensor" ^ shapeToString shape | Ty.T_Image{dim, shape} => concat[ "image(", natToString dim, ")", shapeToString shape ] | Ty.T_Field{diff, dim, shape} => concat[ "field#", natToString diff, "(", natToString 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
root@smlnj-gforge.cs.uchicago.edu | ViewVC Help |
Powered by ViewVC 1.0.0 |