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

SCM Repository

[diderot] Diff of /trunk/src/compiler/simplify/simple.sml
ViewVC logotype

Diff of /trunk/src/compiler/simplify/simple.sml

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

revision 2488, Mon Oct 21 19:20:12 2013 UTC revision 2489, Mon Oct 21 19:43:32 2013 UTC
# Line 1  Line 1 
1  (* simple.sml  (* simple.sml
2   *   *
3   * COPYRIGHT (c) 2013 The Diderot Project (http://diderot-language.cs.uchicago.edu)   * COPYRIGHT (c) 2010 The Diderot Project (http://diderot-language.cs.uchicago.edu)
4   * All rights reserved.   * All rights reserved.
5   *   *
6   * A simplified AST representation of a Diderot program.  This representation has the property   * A simplified AST representation of a Diderot program.  This representation has the property
# Line 11  Line 11 
11  structure Simple =  structure Simple =
12    struct    struct
13    
   (* types with the meta variables resolved *)  
     type ty = SimpleTypes.ty  
   
   (* resolved meta-variable arguments to basis functions *)  
     datatype meta_arg = datatype SimpleTypes.meta_arg  
   
14      datatype var_kind = datatype AST.var_kind      datatype var_kind = datatype AST.var_kind
15    
16      datatype var = V of {      datatype var = datatype AST.var
         name : string,          (* print name of variable *)  
         id : Stamp.stamp,       (* unique ID *)  
         kind : var_kind,        (* variable kind *)  
         ty : ty (* type *)  
       }  
17    
18      datatype program = Program of {      datatype program = Program of {
19          globals : var list,          globals : var list,
# Line 90  Line 79 
79        = E_Var of var        = E_Var of var
80        | E_Lit of Literal.literal        | E_Lit of Literal.literal
81        | E_Tuple of var list        | E_Tuple of var list
82        | E_Apply of var * var list * ty                          (* user-defined function *)        | E_Apply of var * Types.meta_var list * var list * Types.ty
       | E_Prim of AST.var * meta_arg list * var list * ty       (* Diderot builtin *)  
83        | E_Cons of var list        | E_Cons of var list
84        | E_Slice of var * var option list * Types.ty     (* tensor slicing *)        | E_Slice of var * var option list * Types.ty     (* tensor slicing *)
85        | E_Coerce of {srcTy : Types.ty, dstTy : Types.ty, x : var}        | E_Coerce of {srcTy : Types.ty, dstTy : Types.ty, x : var}
86        | E_Input of Types.ty * string * string * var option        | E_Input of Types.ty * string * string * var option
87        | E_LoadImage of ImageInfo.info * var        | E_LoadImage of ImageInfo.info * var
88    
89      fun typeOf (E_Var(V{ty, ...})) = ty      fun typeOf (E_Var x) = Var.monoTypeOf x
90        | typeOf (E_Lit lit) = (case lit        | typeOf (E_Lit lit) = (case lit
91             of (Literal.Int _) => SimpleTypes.T_Int             of (Literal.Int _) => Types.T_Int
92              | (Literal.Float _) => SimpleTypes.T_Tensor[]              | (Literal.Float _) => Types.realTy
93              | (Literal.String s) => SimpleTypes.T_String              | (Literal.String s) => Types.T_String
94              | (Literal.Bool _) => SimpleTypes.T_Bool              | (Literal.Bool _) => Types.T_Bool
95            (* end case *))            (* end case *))
96        | typeOf (E_Tuple _) = raise Fail "E_Tuple"        | typeOf (E_Tuple _) = raise Fail "E_Tuple"
97        | typeOf (E_Apply(_, _, ty)) = ty        | typeOf (E_Apply(_, _, _, ty)) = ty
       | typeOf (E_Prim(_, _, _, ty)) = ty  
98        | typeOf (E_Cons[]) = raise Fail "impossible empty E_Cons"        | typeOf (E_Cons[]) = raise Fail "impossible empty E_Cons"
99        | typeOf (E_Cons(V{ty, ...}::xs)) = let        | typeOf (E_Cons(x::xs)) = let
100            val d = List.length xs + 1            val d = List.length xs + 1
101              val ty = Var.monoTypeOf x
102            in            in
103              case ty              case TypeUtil.pruneHead ty
104               of SimpleTypes.T_Tensor shape => SimpleTypes.T_Tensor(shape @ [d])               of Types.T_Tensor shape => Types.T_Tensor(Types.shapeExt(shape, Types.DimConst d))
105                | _ => raise Fail(concat[                | _ => raise Fail(concat[
106                      "element of tensor construction is ", SimpleTypes.toString ty,                      "element of tensor construction is ", TypeUtil.toString ty, ", expected tensor"
                     ", expected tensor"  
107                    ])                    ])
108              (* end case *)              (* end case *)
109            end            end
110        | typeOf (E_Slice(_, _, ty)) = ty        | typeOf (E_Slice(_, _, ty)) = ty
111        | typeOf (E_Input(ty, _, _, _)) = ty        | typeOf (E_Input(ty, _, _, _)) = ty
112        | typeOf (E_LoadImage(ImageInfo.ImgInfo{dim, ty=(dd, _), ...}, _)) =        | typeOf (E_LoadImage(ImageInfo.ImgInfo{dim, ty=(dd, _), ...}, _)) =
113            SimpleTypes.T_Image{dim = dim, shape = dd}            Types.T_Image{
114                  dim = Types.DimConst dim,
115                  shape = Types.Shape(List.map Types.DimConst dd)
116                }
117    
118    end    end

Legend:
Removed from v.2488  
changed lines
  Added in v.2489

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