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