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

SCM Repository

[diderot] Annotation of /branches/vis15/src/compiler/parse-tree/parse-tree.sml
ViewVC logotype

Annotation of /branches/vis15/src/compiler/parse-tree/parse-tree.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3390 - (view) (download)

1 : jhr 3352 (* parse-tree.sml
2 :     *
3 :     * Diderot parse-tree representation.
4 :     *
5 :     * This code is part of the Diderot Project (http://diderot-language.cs.uchicago.edu)
6 :     *
7 :     * COPYRIGHT (c) 2015 The University of Chicago
8 :     * All rights reserved.
9 :     *)
10 :    
11 :     structure ParseTree =
12 :     struct
13 :    
14 :     type 'a mark = 'a Error.mark
15 :    
16 :     type var = Atom.atom
17 :     type field = Atom.atom
18 :     type dim = IntInf.int
19 :    
20 : jhr 3382 datatype program = Program of {
21 :     globals : global_dcl list,
22 : jhr 3390 strand : strand_dcl,
23 :     init : stmt option,
24 :     create : create,
25 : jhr 3382 update : stmt option
26 :     }
27 : jhr 3352
28 : jhr 3390 and global_dcl
29 :     = GD_Mark of global_dcl mark
30 :     | GD_Const of ty * var * expr option (* constant declaration; if the expression is not *)
31 :     (* given, then it must be defined on the command-line. *)
32 :     | GD_Input of ty * var * string option * expr option
33 :     (* input variable declaration with optional *)
34 :     (* description and optional default value *)
35 :     | GD_Var of var_dcl (* global variable declaration *)
36 :     | GD_Func of ty * var * param list * fun_body (* function declaration *)
37 :    
38 :     and strand_dcl
39 :     = SD_Mark of strand_dcl mark
40 :     | SD_Strand of { (* strand declaration *)
41 : jhr 3352 name : var,
42 :     params : param list,
43 : jhr 3390 state : state_var_dcl list,
44 : jhr 3352 methods : method list
45 :     }
46 :    
47 : jhr 3390 and state_var_dcl
48 :     = SVD_Mark of state_var_dcl mark
49 :     | SVD_VarDcl of bool * var_dcl (* first argument = true means an output variable *)
50 :    
51 :     and create
52 :     = CR_Mark of create mark
53 :     | CR_Collection of comprehension
54 :     | CR_Grid of expr * comprehension
55 :     | CR_Deprecated of create (* the deprecated "initially ..." form *)
56 :    
57 : jhr 3352 and param
58 :     = P_Mark of param mark
59 :     | P_Param of ty * var
60 :    
61 :     and ty
62 :     = T_Mark of ty mark
63 :     | T_Bool
64 :     | T_Int
65 :     | T_Real
66 :     | T_String
67 : jhr 3390 | T_Id of Atom.atom (* named type; i.e., strand *)
68 : jhr 3352 | T_Kernel of dim
69 : jhr 3390 | T_Field of {diff : dim, dim : expr, shape : expr list}
70 :     | T_Tensor of expr list
71 :     | T_Image of {dim : expr, shape : expr list}
72 :     | T_Seq of ty * expr
73 : jhr 3352 | T_DynSeq of ty
74 :    
75 :     and fun_body (* function bodies can be expressions or blocks *)
76 :     = FB_Expr of expr
77 :     | FB_Stmt of stmt
78 :    
79 : jhr 3390 and var_dcl
80 :     = VD_Mark of var_dcl mark
81 :     | VD_Decl of ty * var * expr option
82 : jhr 3352
83 :     and method
84 :     = M_Mark of method mark
85 :     | M_Method of StrandUtil.method_name * stmt
86 :    
87 :     and stmt
88 :     = S_Mark of stmt mark
89 :     | S_Block of stmt list
90 :     | S_IfThen of expr * stmt
91 :     | S_IfThenElse of expr * stmt * stmt
92 : jhr 3390 | S_Foreach of iterator * stmt
93 :     | S_Print of expr list
94 : jhr 3352 | S_New of var * expr list
95 : jhr 3390 | S_Stabilize
96 :     | S_Die
97 : jhr 3352 | S_Continue
98 :     | S_Return of expr
99 : jhr 3390 | S_Decl of var_dcl
100 :     | S_Assign of var * expr
101 :     | S_OpAssign of var * var * expr
102 :     | S_Deprecate of string * stmt (* deprecated statement forms; string is message *)
103 : jhr 3352
104 : jhr 3390 and comprehension
105 :     = COMP_Mark of comprehension mark
106 :     | COMP_Comprehension of expr * iterator list
107 :    
108 :     and iterator
109 :     = I_Mark of iterator mark
110 :     | I_Iterator of var * expr (* x 'in' e *)
111 :    
112 : jhr 3352 and expr
113 :     = E_Mark of expr mark
114 : jhr 3390 | E_Cond of expr * expr * expr (* e1 'if' e2 'else' e3 *)
115 :     | E_Range of expr * expr (* e1 '..' e2 *)
116 :     | E_OrElse of expr * expr (* e1 '||' e2 *)
117 :     | E_AndAlso of expr * expr (* e1 '&&' e2 *)
118 :     | E_BinOp of expr * var * expr (* e1 <op> e2 *)
119 :     | E_UnaryOp of var * expr (* <op> e *)
120 :     | E_Apply of expr * expr list (* field/function/reduction application *)
121 :     | E_Subscript of expr * expr option list (* sequence/tensor indexing; NONE for ':' *)
122 :     | E_Select of expr * field (* e '.' <field> *)
123 :     | E_Real of expr (* int to real conversion *)
124 :     | E_Load of expr (* initializer for dynamic sequences *)
125 :     | E_Image of expr (* initializer for images *)
126 : jhr 3352 | E_Var of var
127 : jhr 3390 | E_Kernel of var * dim (* kernel '#' dim *)
128 : jhr 3352 | E_Lit of Literal.t
129 : jhr 3390 | E_Id of expr (* identity matrix *)
130 :     | E_Zero of expr list (* zero tensor *)
131 :     | E_NaN of expr list (* NaN tensor *)
132 : jhr 3352 | E_Sequence of expr list (* sequence construction *)
133 : jhr 3390 | E_SeqComp of comprehension (* sequence comprehension *)
134 : jhr 3352 | E_Cons of expr list (* tensor construction *)
135 : jhr 3390 | E_Deprecate of string * expr (* deprecated expression forms; string is message *)
136 : jhr 3352
137 :     end

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