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

SCM Repository

[diderot] Annotation of /branches/vis12/src/compiler/simplify/simple.sml
ViewVC logotype

Annotation of /branches/vis12/src/compiler/simplify/simple.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 227 - (view) (download)
Original Path: trunk/src/compiler/simplify/simple.sml

1 : jhr 171 (* simple.sml
2 :     *
3 :     * COPYRIGHT (c) 2010 The Diderot Project (http://diderot.cs.uchicago.edu)
4 :     * All rights reserved.
5 :     *
6 :     * A simplified AST representation of a Diderot program
7 :     *)
8 :    
9 :     structure Simple =
10 :     struct
11 :    
12 :     datatype var_kind = datatype AST.var_kind
13 :    
14 :     datatype var = datatype AST.var
15 :    
16 : jhr 175 datatype program = Program of {
17 : jhr 171 globals : var list,
18 : jhr 227 staticInit : block, (* initialization code that gets run at compile time *)
19 : jhr 192 globalInit : block,
20 : jhr 171 actors : actor list
21 :     (* initialization *)
22 :     }
23 :    
24 :     and actor = Actor of {
25 : jhr 173 name : Atom.atom,
26 : jhr 171 params : var list,
27 :     state : var list,
28 : jhr 192 stateInit : block,
29 : jhr 171 methods : method list
30 :     }
31 :    
32 : jhr 192 and method = Method of Atom.atom * block
33 : jhr 171
34 : jhr 192 and block = Block of stmt list
35 :    
36 : jhr 171 and stmt
37 : jhr 192 = S_Assign of var * exp
38 :     | S_IfThenElse of var * block * block
39 : jhr 171 | S_New of Atom.atom * var list
40 :     | S_Die
41 :     | S_Stabilize
42 :    
43 :     and exp
44 :     = E_Var of var
45 :     | E_Lit of Literal.literal
46 :     | E_Tuple of var list
47 :     | E_Apply of var * Types.meta_var list * var list * Types.ty
48 :     | E_Cons of var list
49 : jhr 221 | E_Input of string * var option
50 :     | E_Field of FieldDef.field_def
51 : jhr 226 | E_LoadImage of ImageInfo.info
52 : jhr 171
53 :     and create = C_Create of {
54 : jhr 192 argInit : block,
55 : jhr 171 name : Atom.atom,
56 :     args : var list
57 :     }
58 :    
59 :     and iter = I_Range of {
60 : jhr 192 rangeInit : block,
61 : jhr 171 param : var,
62 :     lo : var,
63 :     hi : var
64 :     }
65 :    
66 :     fun typeOf (E_Var x) = Var.monoTypeOf x
67 :     | typeOf (E_Lit lit) = (case lit
68 :     of (Literal.Int _) => Types.T_Int
69 :     | (Literal.Float _) => Types.realTy
70 :     | (Literal.String s) => Types.T_String
71 :     | (Literal.Bool _) => Types.T_Bool
72 :     (* end case *))
73 :     | typeOf (E_Tuple _) = raise Fail "E_Tuple"
74 :     | typeOf (E_Apply(_, _, _, ty)) = ty
75 :     | typeOf (E_Cons(x::xs)) = let
76 :     val d = List.length xs + 1
77 :     val ty = Var.monoTypeOf x
78 :     in
79 :     case ty
80 :     of Types.T_Tensor shape => Types.T_Tensor(Types.shapeExt(shape, Types.DimConst d))
81 :     | _ => raise Fail "element of tensor construction not tensor"
82 :     (* end case *)
83 :     end
84 :     | typeOf (E_Cons[]) = raise Fail "impossible empty E_Cons"
85 :    
86 :     end

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