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
;
31 BOOL implicit_nl_semicolon
;
44 X(assign_call,1, ARG_UINT, 0) \
45 X(bool, 1, ARG_INT, 0) \
47 X(call, 1, ARG_UINT, ARG_UINT) \
48 X(call_member,1, ARG_UINT, ARG_UINT) \
49 X(carray, 1, ARG_UINT, 0) \
50 X(case, 0, ARG_ADDR, 0) \
51 X(cnd_nz, 0, ARG_ADDR, 0) \
52 X(cnd_z, 0, ARG_ADDR, 0) \
54 X(delete_ident,1,ARG_BSTR, 0) \
56 X(double, 1, ARG_DBL, 0) \
57 X(end_finally,1, 0,0) \
60 X(forin, 0, ARG_ADDR, 0) \
61 X(func, 1, ARG_UINT, 0) \
64 X(ident, 1, ARG_BSTR, 0) \
65 X(identid, 1, ARG_BSTR, ARG_INT) \
67 X(instanceof, 1, 0,0) \
68 X(int, 1, ARG_INT, 0) \
69 X(jmp, 0, ARG_ADDR, 0) \
70 X(jmp_z, 0, ARG_ADDR, 0) \
74 X(member, 1, ARG_BSTR, 0) \
75 X(memberid, 1, ARG_UINT, 0) \
82 X(new, 1, ARG_UINT, 0) \
85 X(obj_prop, 1, ARG_BSTR, 0) \
87 X(pop, 1, ARG_UINT, 0) \
88 X(pop_except, 1, 0,0) \
89 X(pop_scope, 1, 0,0) \
90 X(postinc, 1, ARG_INT, 0) \
91 X(preinc, 1, ARG_INT, 0) \
92 X(push_except,1, ARG_ADDR, ARG_BSTR) \
93 X(push_scope, 1, 0,0) \
94 X(regexp, 1, ARG_STR, ARG_UINT) \
97 X(str, 1, ARG_STR, 0) \
100 X(throw_ref, 0, ARG_UINT, 0) \
101 X(throw_type, 0, ARG_UINT, ARG_STR) \
104 X(typeofid, 1, 0,0) \
105 X(typeofident,1, 0,0) \
110 X(undefined, 1, 0,0) \
111 X(var_set, 1, ARG_BSTR, 0) \
116 #define X(x,a,b,c) OP_##x,
148 typedef struct _function_code_t
{
156 struct _function_code_t
*funcs
;
165 typedef struct _bytecode_t
{
171 function_code_t global_code
;
176 unsigned bstr_pool_size
;
180 unsigned str_pool_size
;
183 struct _bytecode_t
*next
;
186 HRESULT
compile_script(script_ctx_t
*,const WCHAR
*,const WCHAR
*,const WCHAR
*,BOOL
,BOOL
,bytecode_t
**) DECLSPEC_HIDDEN
;
187 void release_bytecode(bytecode_t
*) DECLSPEC_HIDDEN
;
189 static inline void bytecode_addref(bytecode_t
*code
)
194 HRESULT
script_parse(script_ctx_t
*,const WCHAR
*,const WCHAR
*,BOOL
,parser_ctx_t
**) DECLSPEC_HIDDEN
;
195 void parser_release(parser_ctx_t
*) DECLSPEC_HIDDEN
;
197 int parser_lex(void*,parser_ctx_t
*) DECLSPEC_HIDDEN
;
199 static inline void *parser_alloc(parser_ctx_t
*ctx
, DWORD size
)
201 return heap_pool_alloc(&ctx
->heap
, size
);
204 static inline void *parser_alloc_tmp(parser_ctx_t
*ctx
, DWORD size
)
206 return heap_pool_alloc(&ctx
->script
->tmp_heap
, size
);
209 typedef struct _scope_chain_t
{
213 struct _scope_chain_t
*next
;
216 HRESULT
scope_push(scope_chain_t
*,jsdisp_t
*,IDispatch
*,scope_chain_t
**) DECLSPEC_HIDDEN
;
217 void scope_release(scope_chain_t
*) DECLSPEC_HIDDEN
;
219 static inline void scope_addref(scope_chain_t
*scope
)
224 typedef struct _except_frame_t except_frame_t
;
229 parser_ctx_t
*parser
;
231 script_ctx_t
*script
;
232 scope_chain_t
*scope_chain
;
235 function_code_t
*func_code
;
241 except_frame_t
*except_frame
;
247 static inline void exec_addref(exec_ctx_t
*ctx
)
252 void exec_release(exec_ctx_t
*) DECLSPEC_HIDDEN
;
253 HRESULT
create_exec_ctx(script_ctx_t
*,IDispatch
*,jsdisp_t
*,scope_chain_t
*,BOOL
,exec_ctx_t
**) DECLSPEC_HIDDEN
;
254 HRESULT
exec_source(exec_ctx_t
*,bytecode_t
*,function_code_t
*,BOOL
,jsval_t
*) DECLSPEC_HIDDEN
;
255 HRESULT
create_source_function(script_ctx_t
*,bytecode_t
*,function_code_t
*,scope_chain_t
*,jsdisp_t
**) DECLSPEC_HIDDEN
;
279 literal_t
*parse_regexp(parser_ctx_t
*) DECLSPEC_HIDDEN
;
280 literal_t
*new_boolean_literal(parser_ctx_t
*,BOOL
) DECLSPEC_HIDDEN
;
282 typedef struct _variable_declaration_t
{
283 const WCHAR
*identifier
;
286 struct _variable_declaration_t
*next
;
287 struct _variable_declaration_t
*global_next
; /* for compiler */
288 } variable_declaration_t
;
309 struct _statement_t
{
310 statement_type_t type
;
316 statement_t
*stat_list
;
321 variable_declaration_t
*variable_list
;
327 } expression_statement_t
;
332 statement_t
*if_stat
;
333 statement_t
*else_stat
;
340 statement_t
*statement
;
345 variable_declaration_t
*variable_list
;
346 expression_t
*begin_expr
;
348 expression_t
*end_expr
;
349 statement_t
*statement
;
354 variable_declaration_t
*variable
;
356 expression_t
*in_expr
;
357 statement_t
*statement
;
362 const WCHAR
*identifier
;
363 } branch_statement_t
;
368 statement_t
*statement
;
373 const WCHAR
*identifier
;
374 statement_t
*statement
;
375 } labelled_statement_t
;
377 typedef struct _case_clausule_t
{
381 struct _case_clausule_t
*next
;
387 case_clausule_t
*case_list
;
388 } switch_statement_t
;
391 const WCHAR
*identifier
;
392 statement_t
*statement
;
397 statement_t
*try_statement
;
398 catch_block_t
*catch_block
;
399 statement_t
*finally_statement
;
478 struct _expression_t
{
479 expression_type_t type
;
482 typedef struct _parameter_t
{
483 const WCHAR
*identifier
;
484 struct _parameter_t
*next
;
487 struct _source_elements_t
{
488 statement_t
*statement
;
489 statement_t
*statement_tail
;
492 typedef struct _function_expression_t
{
494 const WCHAR
*identifier
;
495 parameter_t
*parameter_list
;
496 source_elements_t
*source_elements
;
497 const WCHAR
*src_str
;
500 struct _function_expression_t
*next
; /* for compiler */
501 } function_expression_t
;
505 expression_t
*expression1
;
506 expression_t
*expression2
;
507 } binary_expression_t
;
511 expression_t
*expression
;
512 } unary_expression_t
;
516 expression_t
*expression
;
517 expression_t
*true_expression
;
518 expression_t
*false_expression
;
519 } conditional_expression_t
;
523 expression_t
*expression
;
524 const WCHAR
*identifier
;
525 } member_expression_t
;
527 typedef struct _argument_t
{
530 struct _argument_t
*next
;
535 expression_t
*expression
;
536 argument_t
*argument_list
;
541 const WCHAR
*identifier
;
542 } identifier_expression_t
;
547 } literal_expression_t
;
549 typedef struct _array_element_t
{
553 struct _array_element_t
*next
;
558 array_element_t
*element_list
;
560 } array_literal_expression_t
;
562 typedef struct _prop_val_t
{
566 struct _prop_val_t
*next
;
571 prop_val_t
*property_list
;
572 } property_value_expression_t
;