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

SCM Repository

[diderot] Annotation of /branches/vis12/src/compiler/ast/type-util.sml
ViewVC logotype

Annotation of /branches/vis12/src/compiler/ast/type-util.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 81 - (view) (download)
Original Path: trunk/src/ast/type-util.sml

1 : jhr 63 (* type-util.sml
2 :     *
3 :     * COPYRIGHT (c) 2010 The Diderot Project (http://diderot.cs.uchicago.edu)
4 :     * All rights reserved.
5 :     *)
6 :    
7 :     structure TypeUtil : sig
8 :    
9 :     val toString : Types.ty -> string
10 :    
11 :     end = struct
12 :    
13 :     structure Ty = Types
14 : jhr 75 structure MV = MetaVar
15 : jhr 63
16 :     fun listToString fmt sep items = String.concatWith sep (List.map fmt items)
17 :    
18 : jhr 75 fun diffToString (Ty.DiffConst n) = Int.toString n
19 :     | diffToString (Ty.DiffVar(dv, 0)) = MV.diffVarToString dv
20 :     | diffToString (Ty.DiffVar(dv, i)) = if i < 0
21 :     then String.concat["(", MV.diffVarToString dv, "-", Int.toString(~i), ")"]
22 :     else String.concat["(", MV.diffVarToString dv, "+", Int.toString i, ")"]
23 :    
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 : jhr 63 in
32 : jhr 75 toS shape ^ dimToString d
33 : jhr 63 end
34 :    
35 : jhr 75 and dimToString (Ty.DimConst n) = Int.toString n
36 :     | dimToString (Ty.DimVar v) = MV.dimVarToString v
37 : jhr 63
38 :     fun toString ty = (case ty
39 : jhr 75 of Ty.T_Var tv => MV.tyVarToString tv
40 : jhr 63 | Ty.T_Bool => "bool"
41 :     | Ty.T_Int => "int"
42 :     | Ty.T_String => "string"
43 : jhr 75 | Ty.T_Kernel n => "kernel#" ^ diffToString n
44 :     | Ty.T_Tensor(Ty.Shape[]) => "real"
45 :     | Ty.T_Tensor(Ty.Shape[Ty.DimConst 2]) => "vec2"
46 :     | Ty.T_Tensor(Ty.Shape[Ty.DimConst 3]) => "vec3"
47 :     | Ty.T_Tensor(Ty.Shape[Ty.DimConst 4]) => "vec4"
48 : jhr 63 | Ty.T_Tensor shape => "tensor" ^ shapeToString shape
49 :     | Ty.T_Image{dim, shape} => concat[
50 : jhr 75 "image(", dimToString dim, ")", shapeToString shape
51 : jhr 63 ]
52 :     | Ty.T_Field{diff, dim, shape} => concat[
53 : jhr 75 "field#", diffToString diff, "(", dimToString dim,
54 : jhr 63 ")", shapeToString shape
55 :     ]
56 : jhr 81 | Ty.T_Fun(tys1, ty2) => let
57 : jhr 63 fun tysToString [] = "()"
58 :     | tysToString [ty] = toString ty
59 :     | tysToString tys = String.concat[
60 :     "(", listToString toString " * " tys, ")"
61 :     ]
62 :     in
63 : jhr 81 String.concat[tysToString tys1, " -> ", toString ty2]
64 : jhr 63 end
65 :     (* end case *))
66 :    
67 :     end

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