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
24 X(assign_call,1, ARG_UINT, 0) \
25 X(bool, 1, ARG_INT, 0) \
27 X(call, 1, ARG_UINT, ARG_UINT) \
28 X(call_member,1, ARG_UINT, ARG_UINT) \
29 X(carray, 1, ARG_UINT, 0) \
30 X(carray_set, 1, ARG_UINT, 0) \
31 X(case, 0, ARG_ADDR, 0) \
32 X(cnd_nz, 0, ARG_ADDR, 0) \
33 X(cnd_z, 0, ARG_ADDR, 0) \
35 X(delete_ident,1,ARG_BSTR, 0) \
37 X(double, 1, ARG_DBL, 0) \
38 X(end_finally,0, 0,0) \
39 X(enter_catch,1, ARG_BSTR, 0) \
42 X(forin, 0, ARG_ADDR, 0) \
43 X(func, 1, ARG_UINT, 0) \
46 X(ident, 1, ARG_BSTR, 0) \
47 X(identid, 1, ARG_BSTR, ARG_INT) \
49 X(instanceof, 1, 0,0) \
50 X(int, 1, ARG_INT, 0) \
51 X(jmp, 0, ARG_ADDR, 0) \
52 X(jmp_z, 0, ARG_ADDR, 0) \
53 X(local, 1, ARG_INT, 0) \
54 X(local_ref, 1, ARG_INT, ARG_UINT) \
58 X(member, 1, ARG_BSTR, 0) \
59 X(memberid, 1, ARG_UINT, 0) \
66 X(new, 1, ARG_UINT, 0) \
69 X(obj_prop, 1, ARG_STR, ARG_UINT) \
71 X(pop, 1, ARG_UINT, 0) \
72 X(pop_except, 0, ARG_ADDR, 0) \
73 X(pop_scope, 1, 0,0) \
74 X(postinc, 1, ARG_INT, 0) \
75 X(preinc, 1, ARG_INT, 0) \
77 X(push_except,1, ARG_ADDR, ARG_UINT) \
78 X(push_scope, 1, 0,0) \
79 X(regexp, 1, ARG_STR, ARG_UINT) \
82 X(str, 1, ARG_STR, 0) \
85 X(throw_ref, 0, ARG_UINT, 0) \
86 X(throw_type, 0, ARG_UINT, ARG_STR) \
90 X(typeofident,1, 0,0) \
92 X(ret, 0, ARG_UINT, 0) \
93 X(set_member, 1, 0,0) \
96 X(to_string, 1, 0,0) \
97 X(undefined, 1, 0,0) \
102 #define X(x,a,b,c) OP_##x,
108 typedef struct _bytecode_t bytecode_t
;
138 PROPERTY_DEFINITION_VALUE
,
139 PROPERTY_DEFINITION_GETTER
,
140 PROPERTY_DEFINITION_SETTER
141 } property_definition_type_t
;
148 typedef struct _function_code_t
{
158 struct _function_code_t
*funcs
;
163 int func_id
; /* -1 if not a function */
172 bytecode_t
*bytecode
;
175 IDispatch
*lookup_global_host(script_ctx_t
*) DECLSPEC_HIDDEN
;
176 local_ref_t
*lookup_local(const function_code_t
*,const WCHAR
*) DECLSPEC_HIDDEN
;
185 function_code_t global_code
;
186 named_item_t
*named_item
;
189 UINT64 source_context
;
193 unsigned bstr_pool_size
;
197 unsigned str_pool_size
;
203 HRESULT
compile_script(script_ctx_t
*,const WCHAR
*,UINT64
,unsigned,const WCHAR
*,const WCHAR
*,BOOL
,BOOL
,named_item_t
*,bytecode_t
**) DECLSPEC_HIDDEN
;
204 void release_bytecode(bytecode_t
*) DECLSPEC_HIDDEN
;
206 unsigned get_location_line(bytecode_t
*code
, unsigned loc
, unsigned *char_pos
) DECLSPEC_HIDDEN
;
208 static inline bytecode_t
*bytecode_addref(bytecode_t
*code
)
214 typedef struct _scope_chain_t
{
218 struct _call_frame_t
*frame
;
219 struct _scope_chain_t
*next
;
222 void scope_release(scope_chain_t
*) DECLSPEC_HIDDEN
;
224 static inline scope_chain_t
*scope_addref(scope_chain_t
*scope
)
247 void enter_script(script_ctx_t
*,jsexcept_t
*) DECLSPEC_HIDDEN
;
248 HRESULT
leave_script(script_ctx_t
*,HRESULT
) DECLSPEC_HIDDEN
;
249 void reset_ei(jsexcept_t
*) DECLSPEC_HIDDEN
;
250 void set_error_location(jsexcept_t
*,bytecode_t
*,unsigned,unsigned,jsstr_t
*) DECLSPEC_HIDDEN
;
252 typedef struct _except_frame_t except_frame_t
;
253 struct _parser_ctx_t
;
255 typedef struct _call_frame_t
{
257 except_frame_t
*except_frame
;
259 scope_chain_t
*scope
;
260 scope_chain_t
*base_scope
;
265 jsdisp_t
*function_instance
;
266 jsdisp_t
*variable_obj
;
267 jsdisp_t
*arguments_obj
;
272 unsigned arguments_off
;
273 unsigned variables_off
;
274 unsigned pop_variables
;
276 bytecode_t
*bytecode
;
277 function_code_t
*function
;
279 struct _call_frame_t
*prev_frame
;
282 #define EXEC_GLOBAL 0x0001
283 #define EXEC_CONSTRUCTOR 0x0002
284 #define EXEC_RETURN_TO_INTERP 0x0004
285 #define EXEC_EVAL 0x0008
287 HRESULT
exec_source(script_ctx_t
*,DWORD
,bytecode_t
*,function_code_t
*,scope_chain_t
*,IDispatch
*,
288 jsdisp_t
*,unsigned,jsval_t
*,jsval_t
*) DECLSPEC_HIDDEN
;
290 HRESULT
create_source_function(script_ctx_t
*,bytecode_t
*,function_code_t
*,scope_chain_t
*,jsdisp_t
**) DECLSPEC_HIDDEN
;
291 HRESULT
setup_arguments_object(script_ctx_t
*,call_frame_t
*) DECLSPEC_HIDDEN
;
292 void detach_arguments_object(jsdisp_t
*) DECLSPEC_HIDDEN
;