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

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