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(case, 0, ARG_ADDR, 0) \
56 X(cnd_nz, 0, ARG_ADDR, 0) \
57 X(cnd_z, 0, ARG_ADDR, 0) \
59 X(delete_ident,1,ARG_BSTR, 0) \
61 X(double, 1, ARG_DBL, 0) \
62 X(end_finally,1, 0,0) \
65 X(forin, 0, ARG_ADDR, 0) \
66 X(func, 1, ARG_FUNC, 0) \
69 X(ident, 1, ARG_BSTR, 0) \
70 X(identid, 1, ARG_BSTR, ARG_INT) \
72 X(instanceof, 1, 0,0) \
73 X(int, 1, ARG_INT, 0) \
74 X(jmp, 0, ARG_ADDR, 0) \
75 X(jmp_z, 0, ARG_ADDR, 0) \
80 X(member, 1, ARG_BSTR, 0) \
81 X(memberid, 1, ARG_UINT, 0) \
88 X(new, 1, ARG_INT, 0) \
91 X(obj_prop, 1, ARG_BSTR, 0) \
94 X(pop_except, 1, 0,0) \
95 X(pop_scope, 1, 0,0) \
96 X(postinc, 1, ARG_INT, 0) \
97 X(preinc, 1, ARG_INT, 0) \
98 X(push_except,1, ARG_ADDR, ARG_BSTR) \
99 X(push_scope, 1, 0,0) \
100 X(regexp, 1, ARG_STR, ARG_INT) \
103 X(str, 1, ARG_STR, 0) \
106 X(throw_ref, 0, ARG_UINT, 0) \
107 X(throw_type, 0, ARG_UINT, ARG_STR) \
109 X(tree, 1, ARG_STAT, 0) \
111 X(typeofid, 1, 0,0) \
112 X(typeofident,1, 0,0) \
116 X(undefined, 1, 0,0) \
117 X(var_set, 1, ARG_BSTR, 0) \
122 #define X(x,a,b,c) OP_##x,
135 function_expression_t
*func
; /* FIXME */
161 unsigned bstr_pool_size
;
165 void release_bytecode(bytecode_t
*);
167 typedef struct _compiler_ctx_t compiler_ctx_t
;
169 void release_compiler(compiler_ctx_t
*);
171 typedef struct _parser_ctx_t
{
178 script_ctx_t
*script
;
179 source_elements_t
*source
;
187 func_stack_t
*func_stack
;
190 compiler_ctx_t
*compiler
;
192 struct _parser_ctx_t
*next
;
195 HRESULT
script_parse(script_ctx_t
*,const WCHAR
*,const WCHAR
*,parser_ctx_t
**) DECLSPEC_HIDDEN
;
196 void parser_release(parser_ctx_t
*) DECLSPEC_HIDDEN
;
198 int parser_lex(void*,parser_ctx_t
*) DECLSPEC_HIDDEN
;
200 static inline void parser_addref(parser_ctx_t
*ctx
)
205 static inline void *parser_alloc(parser_ctx_t
*ctx
, DWORD size
)
207 return jsheap_alloc(&ctx
->heap
, size
);
210 static inline void *parser_alloc_tmp(parser_ctx_t
*ctx
, DWORD size
)
212 return jsheap_alloc(&ctx
->script
->tmp_heap
, size
);
215 typedef struct _scope_chain_t
{
218 struct _scope_chain_t
*next
;
221 HRESULT
scope_push(scope_chain_t
*,jsdisp_t
*,scope_chain_t
**) DECLSPEC_HIDDEN
;
222 void scope_release(scope_chain_t
*) DECLSPEC_HIDDEN
;
224 static inline void scope_addref(scope_chain_t
*scope
)
229 typedef struct _return_type_t return_type_t
;
230 typedef struct _except_frame_t except_frame_t
;
235 parser_ctx_t
*parser
;
236 scope_chain_t
*scope_chain
;
244 except_frame_t
*except_frame
;
248 return_type_t
*rt
; /* FIXME */
251 static inline void exec_addref(exec_ctx_t
*ctx
)
256 void exec_release(exec_ctx_t
*) DECLSPEC_HIDDEN
;
257 HRESULT
create_exec_ctx(script_ctx_t
*,IDispatch
*,jsdisp_t
*,scope_chain_t
*,BOOL
,exec_ctx_t
**) DECLSPEC_HIDDEN
;
258 HRESULT
exec_source(exec_ctx_t
*,parser_ctx_t
*,source_elements_t
*,BOOL
,jsexcept_t
*,VARIANT
*) DECLSPEC_HIDDEN
;
260 typedef struct _parameter_t parameter_t
;
262 HRESULT
create_source_function(parser_ctx_t
*,parameter_t
*,source_elements_t
*,scope_chain_t
*,
263 const WCHAR
*,DWORD
,jsdisp_t
**) DECLSPEC_HIDDEN
;
289 literal_t
*parse_regexp(parser_ctx_t
*) DECLSPEC_HIDDEN
;
290 literal_t
*new_boolean_literal(parser_ctx_t
*,VARIANT_BOOL
) DECLSPEC_HIDDEN
;
292 typedef struct _variable_declaration_t
{
293 const WCHAR
*identifier
;
296 struct _variable_declaration_t
*next
;
297 } variable_declaration_t
;
299 typedef HRESULT (*statement_eval_t
)(script_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*);
320 struct _statement_t
{
321 statement_type_t type
;
322 statement_eval_t eval
;
329 statement_t
*stat_list
;
334 variable_declaration_t
*variable_list
;
340 } expression_statement_t
;
345 statement_t
*if_stat
;
346 statement_t
*else_stat
;
353 statement_t
*statement
;
358 variable_declaration_t
*variable_list
;
359 expression_t
*begin_expr
;
361 expression_t
*end_expr
;
362 statement_t
*statement
;
367 variable_declaration_t
*variable
;
369 expression_t
*in_expr
;
370 statement_t
*statement
;
375 const WCHAR
*identifier
;
376 } branch_statement_t
;
381 statement_t
*statement
;
386 const WCHAR
*identifier
;
387 statement_t
*statement
;
388 } labelled_statement_t
;
390 typedef struct _case_clausule_t
{
394 struct _case_clausule_t
*next
;
400 case_clausule_t
*case_list
;
401 } switch_statement_t
;
404 const WCHAR
*identifier
;
405 statement_t
*statement
;
410 statement_t
*try_statement
;
411 catch_block_t
*catch_block
;
412 statement_t
*finally_statement
;
415 HRESULT
compiled_statement_eval(script_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*) DECLSPEC_HIDDEN
;
416 HRESULT
while_statement_eval(script_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*) DECLSPEC_HIDDEN
;
417 HRESULT
for_statement_eval(script_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*) DECLSPEC_HIDDEN
;
418 HRESULT
forin_statement_eval(script_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*) DECLSPEC_HIDDEN
;
419 HRESULT
continue_statement_eval(script_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*) DECLSPEC_HIDDEN
;
420 HRESULT
break_statement_eval(script_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*) DECLSPEC_HIDDEN
;
421 HRESULT
return_statement_eval(script_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*) DECLSPEC_HIDDEN
;
422 HRESULT
switch_statement_eval(script_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*) DECLSPEC_HIDDEN
;
423 HRESULT
try_statement_eval(script_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*) DECLSPEC_HIDDEN
;
501 struct _expression_t
{
502 expression_type_t type
;
506 struct _parameter_t
{
507 const WCHAR
*identifier
;
509 struct _parameter_t
*next
;
512 struct _source_elements_t
{
513 statement_t
*statement
;
514 statement_t
*statement_tail
;
515 function_declaration_t
*functions
;
516 var_list_t
*variables
;
519 struct _function_expression_t
{
521 const WCHAR
*identifier
;
522 parameter_t
*parameter_list
;
523 source_elements_t
*source_elements
;
524 const WCHAR
*src_str
;
530 expression_t
*expression1
;
531 expression_t
*expression2
;
532 } binary_expression_t
;
536 expression_t
*expression
;
537 } unary_expression_t
;
541 expression_t
*expression
;
542 expression_t
*true_expression
;
543 expression_t
*false_expression
;
544 } conditional_expression_t
;
548 expression_t
*expression
;
549 const WCHAR
*identifier
;
550 } member_expression_t
;
552 typedef struct _argument_t
{
555 struct _argument_t
*next
;
560 expression_t
*expression
;
561 argument_t
*argument_list
;
566 const WCHAR
*identifier
;
567 } identifier_expression_t
;
572 } literal_expression_t
;
574 typedef struct _array_element_t
{
578 struct _array_element_t
*next
;
583 array_element_t
*element_list
;
585 } array_literal_expression_t
;
587 typedef struct _prop_val_t
{
591 struct _prop_val_t
*next
;
596 prop_val_t
*property_list
;
597 } property_value_expression_t
;
599 HRESULT
compile_subscript(parser_ctx_t
*,expression_t
*,unsigned*) DECLSPEC_HIDDEN
;
600 HRESULT
compile_subscript_stat(parser_ctx_t
*,statement_t
*,BOOL
,unsigned*) DECLSPEC_HIDDEN
;