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

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