2 * Copyright 2008,2011 Jacek Caban for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 typedef struct _source_elements_t source_elements_t;
20 typedef struct _expression_t expression_t;
21 typedef struct _statement_t statement_t;
29 source_elements_t *source;
43 X(assign_call,1, ARG_UINT, 0) \
44 X(bool, 1, ARG_INT, 0) \
46 X(call, 1, ARG_UINT, ARG_UINT) \
47 X(call_member,1, ARG_UINT, ARG_UINT) \
48 X(carray, 1, ARG_UINT, 0) \
49 X(case, 0, ARG_ADDR, 0) \
50 X(cnd_nz, 0, ARG_ADDR, 0) \
51 X(cnd_z, 0, ARG_ADDR, 0) \
53 X(delete_ident,1,ARG_BSTR, 0) \
55 X(double, 1, ARG_DBL, 0) \
56 X(end_finally,1, 0,0) \
59 X(forin, 0, ARG_ADDR, 0) \
60 X(func, 1, ARG_UINT, 0) \
63 X(ident, 1, ARG_BSTR, 0) \
64 X(identid, 1, ARG_BSTR, ARG_INT) \
66 X(instanceof, 1, 0,0) \
67 X(int, 1, ARG_INT, 0) \
68 X(jmp, 0, ARG_ADDR, 0) \
69 X(jmp_z, 0, ARG_ADDR, 0) \
73 X(member, 1, ARG_BSTR, 0) \
74 X(memberid, 1, ARG_UINT, 0) \
81 X(new, 1, ARG_UINT, 0) \
84 X(obj_prop, 1, ARG_BSTR, 0) \
87 X(pop_except, 1, 0,0) \
88 X(pop_scope, 1, 0,0) \
89 X(postinc, 1, ARG_INT, 0) \
90 X(preinc, 1, ARG_INT, 0) \
91 X(push_except,1, ARG_ADDR, ARG_BSTR) \
92 X(push_scope, 1, 0,0) \
93 X(regexp, 1, ARG_STR, ARG_UINT) \
96 X(str, 1, ARG_STR, 0) \
99 X(throw_ref, 0, ARG_UINT, 0) \
100 X(throw_type, 0, ARG_UINT, ARG_STR) \
103 X(typeofid, 1, 0,0) \
104 X(typeofident,1, 0,0) \
108 X(undefined, 1, 0,0) \
109 X(var_set, 1, ARG_BSTR, 0) \
114 #define X(x,a,b,c) OP_##x,
146 typedef struct _function_code_t {
154 struct _function_code_t *funcs;
163 typedef struct _bytecode_t {
169 function_code_t global_code;
174 unsigned bstr_pool_size;
177 struct _bytecode_t *next;
180 HRESULT compile_script(script_ctx_t*,const WCHAR*,const WCHAR*,BOOL,BOOL,bytecode_t**) DECLSPEC_HIDDEN;
181 void release_bytecode(bytecode_t*) DECLSPEC_HIDDEN;
183 static inline void bytecode_addref(bytecode_t *code)
188 HRESULT script_parse(script_ctx_t*,const WCHAR*,const WCHAR*,BOOL,parser_ctx_t**) DECLSPEC_HIDDEN;
189 void parser_release(parser_ctx_t*) DECLSPEC_HIDDEN;
191 int parser_lex(void*,parser_ctx_t*) DECLSPEC_HIDDEN;
193 static inline void *parser_alloc(parser_ctx_t *ctx, DWORD size)
195 return jsheap_alloc(&ctx->heap, size);
198 static inline void *parser_alloc_tmp(parser_ctx_t *ctx, DWORD size)
200 return jsheap_alloc(&ctx->script->tmp_heap, size);
203 typedef struct _scope_chain_t {
206 struct _scope_chain_t *next;
209 HRESULT scope_push(scope_chain_t*,jsdisp_t*,scope_chain_t**) DECLSPEC_HIDDEN;
210 void scope_release(scope_chain_t*) DECLSPEC_HIDDEN;
212 static inline void scope_addref(scope_chain_t *scope)
217 typedef struct _except_frame_t except_frame_t;
222 parser_ctx_t *parser;
224 script_ctx_t *script;
225 scope_chain_t *scope_chain;
228 function_code_t *func_code;
234 except_frame_t *except_frame;
240 static inline void exec_addref(exec_ctx_t *ctx)
245 void exec_release(exec_ctx_t*) DECLSPEC_HIDDEN;
246 HRESULT create_exec_ctx(script_ctx_t*,IDispatch*,jsdisp_t*,scope_chain_t*,BOOL,exec_ctx_t**) DECLSPEC_HIDDEN;
247 HRESULT exec_source(exec_ctx_t*,bytecode_t*,function_code_t*,BOOL,jsexcept_t*,VARIANT*) DECLSPEC_HIDDEN;
248 HRESULT create_source_function(script_ctx_t*,bytecode_t*,function_code_t*,scope_chain_t*,jsdisp_t**) DECLSPEC_HIDDEN;
272 literal_t *parse_regexp(parser_ctx_t*) DECLSPEC_HIDDEN;
273 literal_t *new_boolean_literal(parser_ctx_t*,VARIANT_BOOL) DECLSPEC_HIDDEN;
275 typedef struct _variable_declaration_t {
276 const WCHAR *identifier;
279 struct _variable_declaration_t *next;
280 struct _variable_declaration_t *global_next; /* for compiler */
281 } variable_declaration_t;
302 struct _statement_t {
303 statement_type_t type;
309 statement_t *stat_list;
314 variable_declaration_t *variable_list;
320 } expression_statement_t;
325 statement_t *if_stat;
326 statement_t *else_stat;
333 statement_t *statement;
338 variable_declaration_t *variable_list;
339 expression_t *begin_expr;
341 expression_t *end_expr;
342 statement_t *statement;
347 variable_declaration_t *variable;
349 expression_t *in_expr;
350 statement_t *statement;
355 const WCHAR *identifier;
356 } branch_statement_t;
361 statement_t *statement;
366 const WCHAR *identifier;
367 statement_t *statement;
368 } labelled_statement_t;
370 typedef struct _case_clausule_t {
374 struct _case_clausule_t *next;
380 case_clausule_t *case_list;
381 } switch_statement_t;
384 const WCHAR *identifier;
385 statement_t *statement;
390 statement_t *try_statement;
391 catch_block_t *catch_block;
392 statement_t *finally_statement;
471 struct _expression_t {
472 expression_type_t type;
475 typedef struct _parameter_t {
476 const WCHAR *identifier;
477 struct _parameter_t *next;
480 struct _source_elements_t {
481 statement_t *statement;
482 statement_t *statement_tail;
485 typedef struct _function_expression_t {
487 const WCHAR *identifier;
488 parameter_t *parameter_list;
489 source_elements_t *source_elements;
490 const WCHAR *src_str;
493 struct _function_expression_t *next; /* for compiler */
494 } function_expression_t;
498 expression_t *expression1;
499 expression_t *expression2;
500 } binary_expression_t;
504 expression_t *expression;
505 } unary_expression_t;
509 expression_t *expression;
510 expression_t *true_expression;
511 expression_t *false_expression;
512 } conditional_expression_t;
516 expression_t *expression;
517 const WCHAR *identifier;
518 } member_expression_t;
520 typedef struct _argument_t {
523 struct _argument_t *next;
528 expression_t *expression;
529 argument_t *argument_list;
534 const WCHAR *identifier;
535 } identifier_expression_t;
540 } literal_expression_t;
542 typedef struct _array_element_t {
546 struct _array_element_t *next;
551 array_element_t *element_list;
553 } array_literal_expression_t;
555 typedef struct _prop_val_t {
559 struct _prop_val_t *next;
564 prop_val_t *property_list;
565 } property_value_expression_t;