SCM Repository
Annotation of /trunk/src/compiler/simplify/simple.sml
Parent Directory
|
Revision Log
Revision 171 - (view) (download)
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 : | datatype program = Prog of { | ||
17 : | globals : var list, | ||
18 : | globalInit : stmt, | ||
19 : | actors : actor list | ||
20 : | (* initialization *) | ||
21 : | } | ||
22 : | |||
23 : | and actor = Actor of { | ||
24 : | params : var list, | ||
25 : | state : var list, | ||
26 : | stateInit : stmt, | ||
27 : | methods : method list | ||
28 : | } | ||
29 : | |||
30 : | and method | ||
31 : | = M_Method of Atom.atom * stmt | ||
32 : | |||
33 : | and stmt | ||
34 : | = S_Block of stmt list | ||
35 : | | S_Assign of var * exp | ||
36 : | | S_IfThenElse of var * stmt * stmt | ||
37 : | | S_New of Atom.atom * var list | ||
38 : | | S_Die | ||
39 : | | S_Stabilize | ||
40 : | |||
41 : | and exp | ||
42 : | = E_Var of var | ||
43 : | | E_Lit of Literal.literal | ||
44 : | | E_Tuple of var list | ||
45 : | | E_Apply of var * Types.meta_var list * var list * Types.ty | ||
46 : | | E_Cons of var list | ||
47 : | |||
48 : | and create = C_Create of { | ||
49 : | argInit : stmt, | ||
50 : | name : Atom.atom, | ||
51 : | args : var list | ||
52 : | } | ||
53 : | |||
54 : | and iter = I_Range of { | ||
55 : | rangeInit : stmt, | ||
56 : | param : var, | ||
57 : | lo : var, | ||
58 : | hi : var | ||
59 : | } | ||
60 : | |||
61 : | fun typeOf (E_Var x) = Var.monoTypeOf x | ||
62 : | | typeOf (E_Lit lit) = (case lit | ||
63 : | of (Literal.Int _) => Types.T_Int | ||
64 : | | (Literal.Float _) => Types.realTy | ||
65 : | | (Literal.String s) => Types.T_String | ||
66 : | | (Literal.Bool _) => Types.T_Bool | ||
67 : | (* end case *)) | ||
68 : | | typeOf (E_Tuple _) = raise Fail "E_Tuple" | ||
69 : | | typeOf (E_Apply(_, _, _, ty)) = ty | ||
70 : | | typeOf (E_Cons(x::xs)) = let | ||
71 : | val d = List.length xs + 1 | ||
72 : | val ty = Var.monoTypeOf x | ||
73 : | in | ||
74 : | case ty | ||
75 : | of Types.T_Tensor shape => Types.T_Tensor(Types.shapeExt(shape, Types.DimConst d)) | ||
76 : | | _ => raise Fail "element of tensor construction not tensor" | ||
77 : | (* end case *) | ||
78 : | end | ||
79 : | | typeOf (E_Cons[]) = raise Fail "impossible empty E_Cons" | ||
80 : | |||
81 : | end |
root@smlnj-gforge.cs.uchicago.edu | ViewVC Help |
Powered by ViewVC 1.0.0 |