2 * Copyright 2008 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 _function_expression_t function_expression_t
;
21 typedef struct _expression_t expression_t
;
22 typedef struct _statement_t statement_t
;
24 typedef struct _function_declaration_t
{
25 function_expression_t
*expr
;
27 struct _function_declaration_t
*next
;
28 } function_declaration_t
;
30 typedef struct _var_list_t
{
31 const WCHAR
*identifier
;
33 struct _var_list_t
*next
;
36 typedef struct _func_stack
{
37 function_declaration_t
*func_head
;
38 function_declaration_t
*func_tail
;
42 struct _func_stack
*next
;
50 X(bool, 1, ARG_INT, 0) \
52 X(call, 1, ARG_UINT, ARG_UINT) \
53 X(call_member,1, ARG_UINT, ARG_UINT) \
54 X(carray, 1, ARG_UINT, 0) \
55 X(cnd_nz, 0, ARG_ADDR, 0) \
56 X(cnd_z, 0, ARG_ADDR, 0) \
58 X(delete_ident,1,ARG_BSTR, 0) \
60 X(double, 1, ARG_SBL, 0) \
63 X(func, 1, ARG_FUNC, 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_INT, 0) \
87 X(obj_prop, 1, ARG_BSTR, 0) \
90 X(postinc, 1, ARG_INT, 0) \
91 X(preinc, 1, ARG_INT, 0) \
92 X(regexp, 1, ARG_STR, ARG_INT) \
95 X(str, 1, ARG_STR, 0) \
97 X(throw, 0, ARG_UINT, 0) \
98 X(throw_type, 0, ARG_UINT, ARG_STR) \
100 X(tree, 1, ARG_STAT, 0) \
102 X(typeofid, 1, 0,0) \
103 X(typeofident,1, 0,0) \
107 X(undefined, 1, 0,0) \
108 X(var_set, 1, ARG_BSTR, 0) \
113 #define X(x,a,b,c) OP_##x,
126 function_expression_t
*func
; /* FIXME */
150 unsigned bstr_pool_size
;
154 void release_bytecode(bytecode_t
*);
156 typedef struct _compiler_ctx_t compiler_ctx_t
;
158 void release_compiler(compiler_ctx_t
*);
160 typedef struct _parser_ctx_t
{
167 script_ctx_t
*script
;
168 source_elements_t
*source
;
176 func_stack_t
*func_stack
;
179 compiler_ctx_t
*compiler
;
181 struct _parser_ctx_t
*next
;
184 HRESULT
script_parse(script_ctx_t
*,const WCHAR
*,const WCHAR
*,parser_ctx_t
**) DECLSPEC_HIDDEN
;
185 void parser_release(parser_ctx_t
*) DECLSPEC_HIDDEN
;
187 int parser_lex(void*,parser_ctx_t
*) DECLSPEC_HIDDEN
;
189 static inline void parser_addref(parser_ctx_t
*ctx
)
194 static inline void *parser_alloc(parser_ctx_t
*ctx
, DWORD size
)
196 return jsheap_alloc(&ctx
->heap
, size
);
199 static inline void *parser_alloc_tmp(parser_ctx_t
*ctx
, DWORD size
)
201 return jsheap_alloc(&ctx
->script
->tmp_heap
, size
);
204 typedef struct _scope_chain_t
{
207 struct _scope_chain_t
*next
;
210 HRESULT
scope_push(scope_chain_t
*,jsdisp_t
*,scope_chain_t
**) DECLSPEC_HIDDEN
;
211 void scope_release(scope_chain_t
*) DECLSPEC_HIDDEN
;
213 static inline void scope_addref(scope_chain_t
*scope
)
218 typedef struct _return_type_t return_type_t
;
223 parser_ctx_t
*parser
;
224 scope_chain_t
*scope_chain
;
235 return_type_t
*rt
; /* FIXME */
238 static inline void exec_addref(exec_ctx_t
*ctx
)
243 void exec_release(exec_ctx_t
*) DECLSPEC_HIDDEN
;
244 HRESULT
create_exec_ctx(script_ctx_t
*,IDispatch
*,jsdisp_t
*,scope_chain_t
*,BOOL
,exec_ctx_t
**) DECLSPEC_HIDDEN
;
245 HRESULT
exec_source(exec_ctx_t
*,parser_ctx_t
*,source_elements_t
*,BOOL
,jsexcept_t
*,VARIANT
*) DECLSPEC_HIDDEN
;
247 typedef struct _parameter_t parameter_t
;
249 HRESULT
create_source_function(parser_ctx_t
*,parameter_t
*,source_elements_t
*,scope_chain_t
*,
250 const WCHAR
*,DWORD
,jsdisp_t
**) DECLSPEC_HIDDEN
;
276 literal_t
*parse_regexp(parser_ctx_t
*) DECLSPEC_HIDDEN
;
277 literal_t
*new_boolean_literal(parser_ctx_t
*,VARIANT_BOOL
) DECLSPEC_HIDDEN
;
279 typedef struct _variable_declaration_t
{
280 const WCHAR
*identifier
;
283 struct _variable_declaration_t
*next
;
284 } variable_declaration_t
;
286 typedef HRESULT (*statement_eval_t
)(script_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*);
307 struct _statement_t
{
308 statement_type_t type
;
309 statement_eval_t eval
;
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
;
402 HRESULT
compiled_statement_eval(script_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*) DECLSPEC_HIDDEN
;
403 HRESULT
while_statement_eval(script_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*) DECLSPEC_HIDDEN
;
404 HRESULT
for_statement_eval(script_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*) DECLSPEC_HIDDEN
;
405 HRESULT
forin_statement_eval(script_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*) DECLSPEC_HIDDEN
;
406 HRESULT
continue_statement_eval(script_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*) DECLSPEC_HIDDEN
;
407 HRESULT
break_statement_eval(script_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*) DECLSPEC_HIDDEN
;
408 HRESULT
return_statement_eval(script_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*) DECLSPEC_HIDDEN
;
409 HRESULT
with_statement_eval(script_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*) DECLSPEC_HIDDEN
;
410 HRESULT
labelled_statement_eval(script_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*) DECLSPEC_HIDDEN
;
411 HRESULT
switch_statement_eval(script_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*) DECLSPEC_HIDDEN
;
412 HRESULT
throw_statement_eval(script_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*) DECLSPEC_HIDDEN
;
413 HRESULT
try_statement_eval(script_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*) DECLSPEC_HIDDEN
;
491 struct _expression_t
{
492 expression_type_t type
;
496 struct _parameter_t
{
497 const WCHAR
*identifier
;
499 struct _parameter_t
*next
;
502 struct _source_elements_t
{
503 statement_t
*statement
;
504 statement_t
*statement_tail
;
505 function_declaration_t
*functions
;
506 var_list_t
*variables
;
509 struct _function_expression_t
{
511 const WCHAR
*identifier
;
512 parameter_t
*parameter_list
;
513 source_elements_t
*source_elements
;
514 const WCHAR
*src_str
;
520 expression_t
*expression1
;
521 expression_t
*expression2
;
522 } binary_expression_t
;
526 expression_t
*expression
;
527 } unary_expression_t
;
531 expression_t
*expression
;
532 expression_t
*true_expression
;
533 expression_t
*false_expression
;
534 } conditional_expression_t
;
538 expression_t
*expression
;
539 const WCHAR
*identifier
;
540 } member_expression_t
;
542 typedef struct _argument_t
{
545 struct _argument_t
*next
;
550 expression_t
*expression
;
551 argument_t
*argument_list
;
556 const WCHAR
*identifier
;
557 } identifier_expression_t
;
562 } literal_expression_t
;
564 typedef struct _array_element_t
{
568 struct _array_element_t
*next
;
573 array_element_t
*element_list
;
575 } array_literal_expression_t
;
577 typedef struct _prop_val_t
{
581 struct _prop_val_t
*next
;
586 prop_val_t
*property_list
;
587 } property_value_expression_t
;
589 HRESULT
compile_subscript(parser_ctx_t
*,expression_t
*,unsigned*) DECLSPEC_HIDDEN
;
590 HRESULT
compile_subscript_stat(parser_ctx_t
*,statement_t
*,BOOL
,unsigned*) DECLSPEC_HIDDEN
;