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
;
23 typedef struct _function_declaration_t
{
24 function_expression_t
*expr
;
26 struct _function_declaration_t
*next
;
27 } function_declaration_t
;
29 typedef struct _var_list_t
{
30 const WCHAR
*identifier
;
32 struct _var_list_t
*next
;
35 typedef struct _func_stack
{
36 function_declaration_t
*func_head
;
37 function_declaration_t
*func_tail
;
41 struct _func_stack
*next
;
49 X(bool, 1, ARG_INT, 0) \
51 X(call, 1, ARG_UINT, ARG_UINT) \
52 X(call_member,1, ARG_UINT, ARG_UINT) \
53 X(carray, 1, ARG_UINT, 0) \
55 X(delete_ident,1,ARG_BSTR, 0) \
57 X(double, 1, ARG_SBL, 0) \
60 X(func, 1, ARG_FUNC, 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_nz, 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_INT, 0) \
85 X(obj_prop, 1, ARG_BSTR, 0) \
88 X(postinc, 1, ARG_INT, 0) \
89 X(preinc, 1, ARG_INT, 0) \
90 X(regexp, 1, ARG_STR, ARG_INT) \
93 X(str, 1, ARG_STR, 0) \
95 X(throw, 0, ARG_UINT, 0) \
96 X(throw_type, 0, ARG_UINT, ARG_STR) \
98 X(tree, 1, ARG_EXPR, 0) \
100 X(typeofid, 1, 0,0) \
101 X(typeofident,1, 0,0) \
105 X(undefined, 1, 0,0) \
110 #define X(x,a,b,c) OP_##x,
123 function_expression_t
*func
; /* FIXME */
147 unsigned bstr_pool_size
;
151 void release_bytecode(bytecode_t
*);
153 typedef struct _compiler_ctx_t compiler_ctx_t
;
155 void release_compiler(compiler_ctx_t
*);
157 typedef struct _parser_ctx_t
{
164 script_ctx_t
*script
;
165 source_elements_t
*source
;
173 func_stack_t
*func_stack
;
176 compiler_ctx_t
*compiler
;
178 struct _parser_ctx_t
*next
;
181 HRESULT
script_parse(script_ctx_t
*,const WCHAR
*,const WCHAR
*,parser_ctx_t
**) DECLSPEC_HIDDEN
;
182 void parser_release(parser_ctx_t
*) DECLSPEC_HIDDEN
;
184 int parser_lex(void*,parser_ctx_t
*) DECLSPEC_HIDDEN
;
186 static inline void parser_addref(parser_ctx_t
*ctx
)
191 static inline void *parser_alloc(parser_ctx_t
*ctx
, DWORD size
)
193 return jsheap_alloc(&ctx
->heap
, size
);
196 static inline void *parser_alloc_tmp(parser_ctx_t
*ctx
, DWORD size
)
198 return jsheap_alloc(&ctx
->script
->tmp_heap
, size
);
201 typedef struct _scope_chain_t
{
204 struct _scope_chain_t
*next
;
207 HRESULT
scope_push(scope_chain_t
*,jsdisp_t
*,scope_chain_t
**) DECLSPEC_HIDDEN
;
208 void scope_release(scope_chain_t
*) DECLSPEC_HIDDEN
;
210 static inline void scope_addref(scope_chain_t
*scope
)
218 parser_ctx_t
*parser
;
219 scope_chain_t
*scope_chain
;
232 static inline void exec_addref(exec_ctx_t
*ctx
)
237 void exec_release(exec_ctx_t
*) DECLSPEC_HIDDEN
;
238 HRESULT
create_exec_ctx(script_ctx_t
*,IDispatch
*,jsdisp_t
*,scope_chain_t
*,BOOL
,exec_ctx_t
**) DECLSPEC_HIDDEN
;
239 HRESULT
exec_source(exec_ctx_t
*,parser_ctx_t
*,source_elements_t
*,BOOL
,jsexcept_t
*,VARIANT
*) DECLSPEC_HIDDEN
;
241 typedef struct _statement_t statement_t
;
242 typedef struct _parameter_t parameter_t
;
244 HRESULT
create_source_function(parser_ctx_t
*,parameter_t
*,source_elements_t
*,scope_chain_t
*,
245 const WCHAR
*,DWORD
,jsdisp_t
**) DECLSPEC_HIDDEN
;
271 literal_t
*parse_regexp(parser_ctx_t
*) DECLSPEC_HIDDEN
;
272 literal_t
*new_boolean_literal(parser_ctx_t
*,VARIANT_BOOL
) DECLSPEC_HIDDEN
;
274 typedef struct _variable_declaration_t
{
275 const WCHAR
*identifier
;
278 struct _variable_declaration_t
*next
;
279 } variable_declaration_t
;
281 typedef struct _return_type_t return_type_t
;
283 typedef HRESULT (*statement_eval_t
)(script_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*);
285 struct _statement_t
{
286 statement_eval_t eval
;
292 statement_t
*stat_list
;
297 variable_declaration_t
*variable_list
;
303 } expression_statement_t
;
308 statement_t
*if_stat
;
309 statement_t
*else_stat
;
316 statement_t
*statement
;
321 variable_declaration_t
*variable_list
;
322 expression_t
*begin_expr
;
324 expression_t
*end_expr
;
325 statement_t
*statement
;
330 variable_declaration_t
*variable
;
332 expression_t
*in_expr
;
333 statement_t
*statement
;
338 const WCHAR
*identifier
;
339 } branch_statement_t
;
344 statement_t
*statement
;
349 const WCHAR
*identifier
;
350 statement_t
*statement
;
351 } labelled_statement_t
;
353 typedef struct _case_clausule_t
{
357 struct _case_clausule_t
*next
;
363 case_clausule_t
*case_list
;
364 } switch_statement_t
;
367 const WCHAR
*identifier
;
368 statement_t
*statement
;
373 statement_t
*try_statement
;
374 catch_block_t
*catch_block
;
375 statement_t
*finally_statement
;
378 HRESULT
block_statement_eval(script_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*) DECLSPEC_HIDDEN
;
379 HRESULT
var_statement_eval(script_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*) DECLSPEC_HIDDEN
;
380 HRESULT
empty_statement_eval(script_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*) DECLSPEC_HIDDEN
;
381 HRESULT
expression_statement_eval(script_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*) DECLSPEC_HIDDEN
;
382 HRESULT
if_statement_eval(script_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*) DECLSPEC_HIDDEN
;
383 HRESULT
while_statement_eval(script_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*) DECLSPEC_HIDDEN
;
384 HRESULT
for_statement_eval(script_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*) DECLSPEC_HIDDEN
;
385 HRESULT
forin_statement_eval(script_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*) DECLSPEC_HIDDEN
;
386 HRESULT
continue_statement_eval(script_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*) DECLSPEC_HIDDEN
;
387 HRESULT
break_statement_eval(script_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*) DECLSPEC_HIDDEN
;
388 HRESULT
return_statement_eval(script_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*) DECLSPEC_HIDDEN
;
389 HRESULT
with_statement_eval(script_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*) DECLSPEC_HIDDEN
;
390 HRESULT
labelled_statement_eval(script_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*) DECLSPEC_HIDDEN
;
391 HRESULT
switch_statement_eval(script_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*) DECLSPEC_HIDDEN
;
392 HRESULT
throw_statement_eval(script_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*) DECLSPEC_HIDDEN
;
393 HRESULT
try_statement_eval(script_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*) DECLSPEC_HIDDEN
;
472 typedef HRESULT (*expression_eval_t
)(script_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
474 struct _expression_t
{
475 expression_type_t type
;
476 expression_eval_t eval
;
480 struct _parameter_t
{
481 const WCHAR
*identifier
;
483 struct _parameter_t
*next
;
486 struct _source_elements_t
{
487 statement_t
*statement
;
488 statement_t
*statement_tail
;
489 function_declaration_t
*functions
;
490 var_list_t
*variables
;
493 struct _function_expression_t
{
495 const WCHAR
*identifier
;
496 parameter_t
*parameter_list
;
497 source_elements_t
*source_elements
;
498 const WCHAR
*src_str
;
504 expression_t
*expression1
;
505 expression_t
*expression2
;
506 } binary_expression_t
;
510 expression_t
*expression
;
511 } unary_expression_t
;
515 expression_t
*expression
;
516 expression_t
*true_expression
;
517 expression_t
*false_expression
;
518 } conditional_expression_t
;
522 expression_t
*expression
;
523 const WCHAR
*identifier
;
524 } member_expression_t
;
526 typedef struct _argument_t
{
529 struct _argument_t
*next
;
534 expression_t
*expression
;
535 argument_t
*argument_list
;
540 const WCHAR
*identifier
;
541 } identifier_expression_t
;
546 } literal_expression_t
;
548 typedef struct _array_element_t
{
552 struct _array_element_t
*next
;
557 array_element_t
*element_list
;
559 } array_literal_expression_t
;
561 typedef struct _prop_val_t
{
565 struct _prop_val_t
*next
;
570 prop_val_t
*property_list
;
571 } property_value_expression_t
;
573 HRESULT
compiled_expression_eval(script_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*) DECLSPEC_HIDDEN
;
575 HRESULT
compile_subscript(parser_ctx_t
*,expression_t
*,BOOL
,unsigned*) DECLSPEC_HIDDEN
;