*** empty log message ***
[chuck-blob.git] / v1 / chuck_absyn.h
blobd638100de2b0427d7b3597944fc1683e008cdca0
1 /*----------------------------------------------------------------------------
2 ChucK Concurrent, On-the-fly Audio Programming Language
3 Compiler and Virtual Machine
5 Copyright (c) 2004 Ge Wang and Perry R. Cook. All rights reserved.
6 http://chuck.cs.princeton.edu/
7 http://soundlab.cs.princeton.edu/
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
22 U.S.A.
23 -----------------------------------------------------------------------------*/
25 //-----------------------------------------------------------------------------
26 // file: chuck_absyn.h
27 // desc: ...
29 // author: Ge Wang (gewang@cs.princeton.edu)
30 // Perry R. Cook (prc@cs.princeton.edu)
31 // date: Autumn 2002
32 //-----------------------------------------------------------------------------
33 #ifndef __CHUCK_ABSYN_H__
34 #define __CHUCK_ABSYN_H__
36 #include "chuck_symbol.h"
38 #if defined(_cplusplus) || defined(__cplusplus)
39 extern "C" {
40 #endif
42 // pos
43 typedef int a_Pos;
45 // enum oper
46 typedef enum {
47 ae_op_plus, ae_op_minus, ae_op_times, ae_op_divide,
48 ae_op_eq, ae_op_neq, ae_op_lt, ae_op_le, ae_op_gt,
49 ae_op_ge, ae_op_and, ae_op_or, ae_op_s_or, ae_op_s_and,
50 ae_op_shift_left, ae_op_shift_right, ae_op_percent,
51 ae_op_s_xor, ae_op_chuck, ae_op_plus_chuck, ae_op_minus_chuck,
52 ae_op_times_chuck, ae_op_divide_chuck, ae_op_s_and_chuck,
53 ae_op_s_or_chuck, ae_op_s_xor_chuck, ae_op_shift_right_chuck,
54 ae_op_shift_left_chuck, ae_op_percent_chuck, ae_op_s_chuck,
55 ae_op_plusplus, ae_op_minusminus, ae_op_tilda, ae_op_exclamation,
56 ae_op_at_chuck, ae_op_unchuck, ae_op_spork
57 } ae_Operator;
59 const char * op2str( ae_Operator op );
61 // enum key words
62 typedef enum {
63 ae_key_before, ae_key_after, ae_key_at, ae_this, ae_func_func, ae_func_public,
64 ae_func_protected, ae_func_private
65 } ae_Keyword;
70 //-----------------------------------------------------------------------------
71 // pointer types
72 //-----------------------------------------------------------------------------
73 typedef struct a_Program_ * a_Program;
74 typedef struct a_Section_ * a_Section;
75 typedef struct a_Stmt_List_ * a_Stmt_List;
76 typedef struct a_Class_Def_ * a_Class_Def;
77 typedef struct a_Func_Def_ * a_Func_Def;
78 typedef struct a_Code_Segment_ * a_Code_Segment;
79 typedef struct a_Stmt_ * a_Stmt;
80 typedef struct a_Exp_ * a_Exp;
81 typedef struct a_Exp_Chuck_ * a_Exp_Chuck;
82 typedef struct a_Exp_Binary_ * a_Exp_Binary;
83 typedef struct a_Exp_Cast_ * a_Exp_Cast;
84 typedef struct a_Exp_Unary_ * a_Exp_Unary;
85 typedef struct a_Exp_Postfix_ * a_Exp_Postfix;
86 typedef struct a_Exp_Primary_ * a_Exp_Primary;
87 typedef struct a_Exp_Dur_ * a_Exp_Dur;
88 typedef struct a_Exp_Array_ * a_Exp_Array;
89 typedef struct a_Exp_Func_Call_ * a_Exp_Func_Call;
90 typedef struct a_Exp_Dot_Member_ * a_Exp_Dot_Member;
91 typedef struct a_Exp_If_ * a_Exp_If;
92 typedef struct a_Exp_Decl_ * a_Exp_Decl;
93 typedef struct a_Exp_Namespace_ * a_Exp_Namespace;
94 typedef struct a_Stmt_Code_ * a_Stmt_Code;
95 typedef struct a_Stmt_If_ * a_Stmt_If;
96 typedef struct a_Stmt_While_ * a_Stmt_While;
97 typedef struct a_Stmt_Until_ * a_Stmt_Until;
98 typedef struct a_Stmt_For_ * a_Stmt_For;
99 typedef struct a_Stmt_Switch_ * a_Stmt_Switch;
100 typedef struct a_Stmt_Break_ * a_Stmt_Break;
101 typedef struct a_Stmt_Continue_ * a_Stmt_Continue;
102 typedef struct a_Stmt_Return_ * a_Stmt_Return;
103 typedef struct a_Stmt_Case_ * a_Stmt_Case;
104 typedef struct a_Stmt_GotoLabel_ * a_Stmt_GotoLabel;
105 typedef struct a_Decl_ * a_Decl;
106 typedef struct a_Var_Decl_ * a_Var_Decl;
107 typedef struct a_Var_Decl_List_ * a_Var_Decl_List;
108 typedef struct a_Type_Decl_ * a_Type_Decl;
109 typedef struct a_Arg_List_ * a_Arg_List;
110 typedef struct a_Id_List_ * a_Id_List;
111 typedef struct a_Class_Ext_ * a_Class_Ext;
112 typedef struct a_Class_Body_ * a_Class_Body;
114 // forward reference for type
115 typedef struct t_Type_ * t_Type;
120 //------------------------------------------------------------------------------
121 // functions
122 //------------------------------------------------------------------------------
123 a_Program new_program( a_Section section, int pos );
124 a_Program prepend_program( a_Section section, a_Program program, int pos );
125 a_Section new_section_stmt( a_Stmt_List stmt_list, int pos );
126 a_Section new_section_func_def( a_Func_Def func_def, int pos );
127 a_Section new_section_class_def( a_Class_Def class_def, int pos );
128 a_Stmt_List new_stmt_list( a_Stmt stmt, int pos );
129 a_Stmt_List prepend_stmt_list( a_Stmt stmt, a_Stmt_List stmt_list, int pos );
130 a_Stmt new_stmt_from_expression( a_Exp exp, int pos );
131 a_Stmt new_stmt_from_code( a_Stmt_List code, int pos );
132 a_Stmt new_stmt_from_while( a_Exp cond, a_Stmt body, int pos );
133 a_Stmt new_stmt_from_do_while( a_Exp cond, a_Stmt body, int pos );
134 a_Stmt new_stmt_from_until( a_Exp cond, a_Stmt body, int pos );
135 a_Stmt new_stmt_from_do_until( a_Exp cond, a_Stmt body, int pos );
136 a_Stmt new_stmt_from_for( a_Stmt c1, a_Stmt c2, a_Exp c3, a_Stmt body, int pos );
137 a_Stmt new_stmt_from_if( a_Exp cond, a_Stmt if_body, a_Stmt else_body, int pos );
138 a_Stmt new_stmt_from_switch( a_Exp exp, int pos );
139 a_Stmt new_stmt_from_break( int pos );
140 a_Stmt new_stmt_from_continue( int pos );
141 a_Stmt new_stmt_from_return( a_Exp exp, int pos );
142 a_Stmt new_stmt_from_label( c_str id, int pos );
143 a_Stmt new_stmt_from_case( a_Exp exp, int pos );
144 a_Exp prepend_expression( a_Exp exp, a_Exp list, int pos );
145 a_Exp new_exp_from_binary( a_Exp lhs, ae_Operator oper, a_Exp rhs, int pos );
146 a_Exp new_exp_from_unary( ae_Operator oper, a_Exp exp, int pos );
147 a_Exp new_exp_from_cast( c_str type, a_Exp exp, int pos );
148 a_Exp new_exp_from_array( a_Exp base, a_Exp index, int pos );
149 a_Exp new_exp_from_func_call( a_Exp base, a_Exp args, int pos );
150 a_Exp new_exp_from_member_dot( a_Exp base, c_str member, int pos );
151 a_Exp new_exp_from_postfix( a_Exp base, ae_Operator op, int pos );
152 a_Exp new_exp_from_dur( a_Exp base, a_Exp unit, int pos );
153 a_Exp new_exp_from_id( c_str id, int pos );
154 a_Exp new_exp_from_int( long num, int pos );
155 a_Exp new_exp_from_uint( unsigned long num, int pos );
156 a_Exp new_exp_from_float( double num, int pos );
157 a_Exp new_exp_from_str( c_str str, int pos );
158 a_Exp new_exp_from_if( a_Exp cond, a_Exp lhs, a_Exp rhs, int pos );
159 a_Exp new_exp_from_decl( c_str type, a_Var_Decl_List var_decl_list, int pos );
160 a_Exp new_exp_decl( c_str type, a_Var_Decl_List var_decl_list, int pos );
161 a_Exp new_exp_from_namespace( c_str name, int pos );
162 a_Var_Decl_List new_var_decl_list( a_Var_Decl var_decl, int pos );
163 a_Var_Decl_List prepend_var_decl_list( a_Var_Decl var_decl, a_Var_Decl_List list, int pos );
164 a_Var_Decl new_var_decl( c_str id, int pos );
165 a_Var_Decl new_var_decl2( a_Var_Decl, int isarray, a_Exp exp, int pos );
166 a_Type_Decl new_type_decl( c_str type, int pos );
167 a_Type_Decl new_type_decl_array( a_Type_Decl decl, int pos );
168 a_Arg_List new_arg_list( a_Type_Decl type_decl, c_str name, int pos );
169 a_Arg_List prepend_arg_list( a_Type_Decl type_decl, c_str name, a_Arg_List arg_list, int pos );
170 a_Class_Def new_class_def( c_str name, a_Class_Ext ext, a_Class_Body body, int pos );
171 a_Class_Body new_class_body( a_Section section, int pos );
172 a_Class_Body prepend_class_body( a_Section section, a_Class_Body body, int pos );
173 a_Class_Ext new_class_ext( c_str extend_id, a_Id_List impl_list, int pos );
174 a_Id_List new_id_list( c_str id, int pos );
175 a_Id_List prepend_id_list( c_str id, a_Id_List list, int pos );
176 a_Func_Def new_func_def( ae_Keyword func_decl, a_Type_Decl type_decl, c_str name,
177 a_Arg_List arg_list, a_Stmt code, int pos );
182 //------------------------------------------------------------------------------
183 // structs
184 //------------------------------------------------------------------------------
185 struct a_Exp_Binary_ { a_Exp lhs; ae_Operator op; a_Exp rhs; int linepos; };
186 struct a_Exp_Cast_ { S_Symbol type; a_Exp exp; int linepos; };
187 struct a_Exp_Unary_ { ae_Operator op; a_Exp exp; int linepos; };
188 struct a_Exp_Postfix_ { a_Exp exp; ae_Operator op; int linepos; };
189 struct a_Exp_Dur_ { a_Exp base; a_Exp unit; int linepos; };
190 struct a_Exp_Array_ { a_Exp base; a_Exp index; int linepos; };
191 struct a_Exp_Func_Call_ { a_Exp func; a_Exp args; t_Type ret_type; int linepos; };
192 struct a_Exp_Dot_Member_ { a_Exp base; S_Symbol id; unsigned long data;
193 unsigned long data2; unsigned int flag; int linepos; };
194 struct a_Exp_If_ { a_Exp cond; a_Exp if_exp; a_Exp else_exp; int linepos; };
195 struct a_Exp_Decl_ { S_Symbol type; a_Var_Decl_List var_decl_list; int linepos; };
196 struct a_Exp_Namespace_ { S_Symbol name; int linepos; };
197 struct a_Var_Decl_List_ { a_Var_Decl var_decl; a_Var_Decl_List next; int linepos; };
198 struct a_Var_Decl_ { S_Symbol id; a_Var_Decl var_decl; int isarray; a_Exp exp; int linepos; };
199 struct a_Type_Decl_ { S_Symbol id; int array; int linepos; };
200 struct a_Arg_List_ { a_Type_Decl type_decl; t_Type type; S_Symbol id;
201 a_Arg_List next; int linepos; };
203 // enum primary exp type
204 typedef enum { ae_primary_var, ae_primary_num, ae_primary_uint,
205 ae_primary_float, ae_primary_str, ae_primary_exp
206 } ae_Exp_Primary_Type;
208 struct a_Exp_Primary_
210 ae_Exp_Primary_Type s_type;
212 union
214 S_Symbol var;
215 int num;
216 unsigned num2;
217 double fnum;
218 c_str str;
219 a_Exp exp;
222 int linepos;
225 // enum exp type
226 typedef enum { ae_exp_binary = 0, ae_exp_unary, ae_exp_cast, ae_exp_postfix,
227 ae_exp_dur, ae_exp_primary, ae_exp_array, ae_exp_func_call,
228 ae_exp_dot_member, ae_exp_if, ae_exp_decl, ae_exp_namespace
229 } ae_Exp_Type;
231 typedef enum { ae_meta_value = 0, ae_meta_var } ae_Exp_Meta;
233 struct a_Exp_
235 ae_Exp_Type s_type;
236 ae_Exp_Meta s_meta;
237 t_Type type;
238 a_Exp next;
240 union
242 struct a_Exp_Binary_ binary;
243 struct a_Exp_Unary_ unary;
244 struct a_Exp_Cast_ cast;
245 struct a_Exp_Postfix_ postfix;
246 struct a_Exp_Dur_ dur;
247 struct a_Exp_Primary_ primary;
248 struct a_Exp_Array_ array;
249 struct a_Exp_Func_Call_ func_call;
250 struct a_Exp_Dot_Member_ dot_member;
251 struct a_Exp_If_ exp_if;
252 struct a_Exp_Decl_ decl;
253 struct a_Exp_Namespace_ name_space;
256 int linepos;
259 struct a_Stmt_While_ { int is_do; a_Exp cond; a_Stmt body; int linepos; };
260 struct a_Stmt_Until_ { int is_do; a_Exp cond; a_Stmt body; int linepos; };
261 struct a_Stmt_For_ { a_Stmt c1; a_Stmt c2; a_Exp c3; a_Stmt body; int linepos; };
262 struct a_Stmt_Code_ { a_Stmt_List stmt_list; int linepos; };
263 struct a_Stmt_If_ { a_Exp cond; a_Stmt if_body; a_Stmt else_body; int linepos; };
264 struct a_Stmt_Switch_ { a_Exp val; int linepos; };
265 //struct a_Stmt_Break_ { int linepos; };
266 //struct a_Stmt_Continue_ { int linepos; };
267 struct a_Stmt_Return_ { a_Exp val; int linepos; };
268 struct a_Stmt_Case_ { a_Exp exp; int linepos; };
269 struct a_Stmt_GotoLabel_ { S_Symbol name; int linepos; };
271 // enum values for stmt type
272 typedef enum { ae_stmt_exp, ae_stmt_while, ae_stmt_until, ae_stmt_for,
273 ae_stmt_if, ae_stmt_code, ae_stmt_switch, ae_stmt_break,
274 ae_stmt_continue, ae_stmt_return, ae_stmt_case, ae_stmt_gotolabel
275 } ae_Stmt_Type;
277 struct a_Stmt_
279 ae_Stmt_Type s_type;
281 union
283 a_Exp stmt_exp;
284 struct a_Stmt_Code_ stmt_code;
285 struct a_Stmt_While_ stmt_while;
286 struct a_Stmt_Until_ stmt_until;
287 struct a_Stmt_For_ stmt_for;
288 struct a_Stmt_If_ stmt_if;
289 struct a_Stmt_Switch_ stmt_switch;
290 // struct a_Stmt_Break_ stmt_break;
291 // struct a_Stmt_Continue_ stmt_continue;
292 struct a_Stmt_Return_ stmt_return;
293 struct a_Stmt_Case_ stmt_case;
294 struct a_Stmt_GotoLabel_ stmt_gotolabel;
297 int linepos;
300 struct a_Stmt_List_ { a_Stmt stmt; a_Stmt_List next; int linepos; };
301 struct a_Class_Def_ { S_Symbol name; a_Class_Ext ext; a_Class_Body body; int linepos; };
302 struct a_Class_Ext_ { S_Symbol extend_id; a_Id_List impl_list; int linepos; };
303 struct a_Class_Body_ { a_Section section; a_Class_Body next; int linepos; };
304 struct a_Id_List_ { S_Symbol id; a_Id_List next; int linepos; };
306 typedef enum { ae_func_user, ae_func_builtin } ae_Func_Type;
307 struct t_Func_User_ { int linepos; };
308 typedef unsigned int (* builtin_func_ptr)( unsigned int arg );
309 struct t_Func_BuiltIn_ { builtin_func_ptr func_ptr; int linepos; };
310 struct a_Func_Def_ { ae_Keyword func_decl; a_Type_Decl type_decl;
311 t_Type ret_type; S_Symbol name; a_Arg_List arg_list;
312 a_Stmt code; unsigned int global; unsigned int s_type;
313 unsigned int stack_depth;
314 union { struct t_Func_User_ user;
315 builtin_func_ptr builtin; };
316 int linepos; };
318 // enum values for section types
319 typedef enum { ae_section_stmt, ae_section_func, ae_section_class
320 } ae_Section_Type;
322 struct a_Section_
324 ae_Section_Type s_type;
326 union
328 a_Stmt_List stmt_list;
329 a_Class_Def class_def;
330 a_Func_Def func_def;
333 int linepos;
336 struct a_Program_ { a_Section section; a_Program next; int linepos; };
339 #if defined(_cplusplus) || defined(__cplusplus)
341 #endif
345 #endif