Home My Page Projects Code Snippets Project Openings diderot
Summary Activity Tracker Tasks SCM

SCM Repository

[diderot] Diff of /trunk/src/ast/type-util.sml
ViewVC logotype

Diff of /trunk/src/ast/type-util.sml

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

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

Legend:
Removed from v.63  
changed lines
  Added in v.95

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0