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
21 typedef struct _source_elements_t source_elements_t
;
22 typedef struct _expression_t expression_t
;
23 typedef struct _statement_t statement_t
;
31 source_elements_t
*source
;
33 BOOL implicit_nl_semicolon
;
46 X(assign_call,1, ARG_UINT, 0) \
47 X(bool, 1, ARG_INT, 0) \
49 X(call, 1, ARG_UINT, ARG_UINT) \
50 X(call_member,1, ARG_UINT, ARG_UINT) \
51 X(carray, 1, ARG_UINT, 0) \
52 X(case, 0, ARG_ADDR, 0) \
53 X(cnd_nz, 0, ARG_ADDR, 0) \
54 X(cnd_z, 0, ARG_ADDR, 0) \
56 X(delete_ident,1,ARG_BSTR, 0) \
58 X(double, 1, ARG_DBL, 0) \
59 X(end_finally,1, 0,0) \
62 X(forin, 0, ARG_ADDR, 0) \
63 X(func, 1, ARG_UINT, 0) \
66 X(ident, 1, ARG_BSTR, 0) \
67 X(identid, 1, ARG_BSTR, ARG_INT) \
69 X(instanceof, 1, 0,0) \
70 X(int, 1, ARG_INT, 0) \
71 X(jmp, 0, ARG_ADDR, 0) \
72 X(jmp_z, 0, ARG_ADDR, 0) \
76 X(member, 1, ARG_BSTR, 0) \
77 X(memberid, 1, ARG_UINT, 0) \
84 X(new, 1, ARG_UINT, 0) \
87 X(obj_prop, 1, ARG_BSTR, 0) \
89 X(pop, 1, ARG_UINT, 0) \
90 X(pop_except, 1, 0,0) \
91 X(pop_scope, 1, 0,0) \
92 X(postinc, 1, ARG_INT, 0) \
93 X(preinc, 1, ARG_INT, 0) \
94 X(push_except,1, ARG_ADDR, ARG_BSTR) \
95 X(push_scope, 1, 0,0) \
96 X(regexp, 1, ARG_STR, ARG_UINT) \
99 X(str, 1, ARG_STR, 0) \
102 X(throw_ref, 0, ARG_UINT, 0) \
103 X(throw_type, 0, ARG_UINT, ARG_STR) \
106 X(typeofid, 1, 0,0) \
107 X(typeofident,1, 0,0) \
112 X(undefined, 1, 0,0) \
113 X(var_set, 1, ARG_BSTR, 0) \
118 #define X(x,a,b,c) OP_##x,
150 typedef struct _function_code_t
{
158 struct _function_code_t
*funcs
;
167 typedef struct _bytecode_t
{
173 function_code_t global_code
;
178 unsigned bstr_pool_size
;
182 unsigned str_pool_size
;
185 struct _bytecode_t
*next
;
188 HRESULT
compile_script(script_ctx_t
*,const WCHAR
*,const WCHAR
*,const WCHAR
*,BOOL
,BOOL
,bytecode_t
**) DECLSPEC_HIDDEN
;
189 void release_bytecode(bytecode_t
*) DECLSPEC_HIDDEN
;
191 static inline void bytecode_addref(bytecode_t
*code
)
196 HRESULT
script_parse(script_ctx_t
*,const WCHAR
*,const WCHAR
*,BOOL
,parser_ctx_t
**) DECLSPEC_HIDDEN
;
197 void parser_release(parser_ctx_t
*) DECLSPEC_HIDDEN
;
199 int parser_lex(void*,parser_ctx_t
*) DECLSPEC_HIDDEN
;
201 static inline void *parser_alloc(parser_ctx_t
*ctx
, DWORD size
)
203 return heap_pool_alloc(&ctx
->heap
, size
);
206 static inline void *parser_alloc_tmp(parser_ctx_t
*ctx
, DWORD size
)
208 return heap_pool_alloc(&ctx
->script
->tmp_heap
, size
);
211 typedef struct _scope_chain_t
{
215 struct _scope_chain_t
*next
;
218 HRESULT
scope_push(scope_chain_t
*,jsdisp_t
*,IDispatch
*,scope_chain_t
**) DECLSPEC_HIDDEN
;
219 void scope_release(scope_chain_t
*) DECLSPEC_HIDDEN
;
221 static inline void scope_addref(scope_chain_t
*scope
)
226 typedef struct _except_frame_t except_frame_t
;
231 parser_ctx_t
*parser
;
233 script_ctx_t
*script
;
234 scope_chain_t
*scope_chain
;
237 function_code_t
*func_code
;
243 except_frame_t
*except_frame
;
249 static inline void exec_addref(exec_ctx_t
*ctx
)
254 void exec_release(exec_ctx_t
*) DECLSPEC_HIDDEN
;
255 HRESULT
create_exec_ctx(script_ctx_t
*,IDispatch
*,jsdisp_t
*,scope_chain_t
*,BOOL
,exec_ctx_t
**) DECLSPEC_HIDDEN
;
256 HRESULT
exec_source(exec_ctx_t
*,bytecode_t
*,function_code_t
*,BOOL
,jsval_t
*) DECLSPEC_HIDDEN
;
257 HRESULT
create_source_function(script_ctx_t
*,bytecode_t
*,function_code_t
*,scope_chain_t
*,jsdisp_t
**) DECLSPEC_HIDDEN
;
281 literal_t
*parse_regexp(parser_ctx_t
*) DECLSPEC_HIDDEN
;
282 literal_t
*new_boolean_literal(parser_ctx_t
*,BOOL
) DECLSPEC_HIDDEN
;
284 typedef struct _variable_declaration_t
{
285 const WCHAR
*identifier
;
288 struct _variable_declaration_t
*next
;
289 struct _variable_declaration_t
*global_next
; /* for compiler */
290 } variable_declaration_t
;
311 struct _statement_t
{
312 statement_type_t type
;
318 statement_t
*stat_list
;
323 variable_declaration_t
*variable_list
;
329 } expression_statement_t
;
334 statement_t
*if_stat
;
335 statement_t
*else_stat
;
342 statement_t
*statement
;
347 variable_declaration_t
*variable_list
;
348 expression_t
*begin_expr
;
350 expression_t
*end_expr
;
351 statement_t
*statement
;
356 variable_declaration_t
*variable
;
358 expression_t
*in_expr
;
359 statement_t
*statement
;
364 const WCHAR
*identifier
;
365 } branch_statement_t
;
370 statement_t
*statement
;
375 const WCHAR
*identifier
;
376 statement_t
*statement
;
377 } labelled_statement_t
;
379 typedef struct _case_clausule_t
{
383 struct _case_clausule_t
*next
;
389 case_clausule_t
*case_list
;
390 } switch_statement_t
;
393 const WCHAR
*identifier
;
394 statement_t
*statement
;
399 statement_t
*try_statement
;
400 catch_block_t
*catch_block
;
401 statement_t
*finally_statement
;
480 struct _expression_t
{
481 expression_type_t type
;
484 typedef struct _parameter_t
{
485 const WCHAR
*identifier
;
486 struct _parameter_t
*next
;
489 struct _source_elements_t
{
490 statement_t
*statement
;
491 statement_t
*statement_tail
;
494 typedef struct _function_expression_t
{
496 const WCHAR
*identifier
;
497 parameter_t
*parameter_list
;
498 source_elements_t
*source_elements
;
499 const WCHAR
*src_str
;
502 struct _function_expression_t
*next
; /* for compiler */
503 } function_expression_t
;
507 expression_t
*expression1
;
508 expression_t
*expression2
;
509 } binary_expression_t
;
513 expression_t
*expression
;
514 } unary_expression_t
;
518 expression_t
*expression
;
519 expression_t
*true_expression
;
520 expression_t
*false_expression
;
521 } conditional_expression_t
;
525 expression_t
*expression
;
526 const WCHAR
*identifier
;
527 } member_expression_t
;
529 typedef struct _argument_t
{
532 struct _argument_t
*next
;
537 expression_t
*expression
;
538 argument_t
*argument_list
;
543 const WCHAR
*identifier
;
544 } identifier_expression_t
;
549 } literal_expression_t
;
551 typedef struct _array_element_t
{
555 struct _array_element_t
*next
;
560 array_element_t
*element_list
;
562 } array_literal_expression_t
;
564 typedef struct _prop_val_t
{
568 struct _prop_val_t
*next
;
573 prop_val_t
*property_list
;
574 } property_value_expression_t
;