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
26 X(assign_call,1, ARG_UINT, 0) \
27 X(bool, 1, ARG_INT, 0) \
29 X(call, 1, ARG_UINT, ARG_UINT) \
30 X(call_member,1, ARG_UINT, ARG_UINT) \
31 X(carray, 1, ARG_UINT, 0) \
32 X(carray_set, 1, ARG_UINT, 0) \
33 X(case, 0, ARG_ADDR, 0) \
34 X(cnd_nz, 0, ARG_ADDR, 0) \
35 X(cnd_z, 0, ARG_ADDR, 0) \
37 X(delete_ident,1,ARG_BSTR, 0) \
39 X(double, 1, ARG_DBL, 0) \
40 X(end_finally,0, 0,0) \
41 X(enter_catch,1, ARG_BSTR, 0) \
44 X(forin, 0, ARG_ADDR, 0) \
45 X(func, 1, ARG_UINT, 0) \
48 X(ident, 1, ARG_BSTR, 0) \
49 X(identid, 1, ARG_BSTR, ARG_INT) \
51 X(instanceof, 1, 0,0) \
52 X(int, 1, ARG_INT, 0) \
53 X(jmp, 0, ARG_ADDR, 0) \
54 X(jmp_z, 0, ARG_ADDR, 0) \
55 X(local, 1, ARG_INT, 0) \
56 X(local_ref, 1, ARG_INT, ARG_UINT) \
60 X(member, 1, ARG_BSTR, 0) \
61 X(memberid, 1, ARG_UINT, 0) \
68 X(new, 1, ARG_UINT, 0) \
71 X(obj_prop, 1, ARG_BSTR, ARG_UINT) \
73 X(pop, 1, ARG_UINT, 0) \
74 X(pop_except, 0, ARG_ADDR, 0) \
75 X(pop_scope, 1, 0,0) \
76 X(postinc, 1, ARG_INT, 0) \
77 X(preinc, 1, ARG_INT, 0) \
79 X(push_except,1, ARG_ADDR, ARG_UINT) \
80 X(push_scope, 1, 0,0) \
81 X(regexp, 1, ARG_STR, ARG_UINT) \
84 X(str, 1, ARG_STR, 0) \
87 X(throw_ref, 0, ARG_UINT, 0) \
88 X(throw_type, 0, ARG_UINT, ARG_STR) \
92 X(typeofident,1, 0,0) \
94 X(ret, 0, ARG_UINT, 0) \
97 X(undefined, 1, 0,0) \
102 #define X(x,a,b,c) OP_##x,
135 PROPERTY_DEFINITION_VALUE
,
136 PROPERTY_DEFINITION_GETTER
,
137 PROPERTY_DEFINITION_SETTER
138 } property_definition_type_t
;
145 typedef struct _function_code_t
{
155 struct _function_code_t
*funcs
;
160 int func_id
; /* -1 if not a function */
170 local_ref_t
*lookup_local(const function_code_t
*,const WCHAR
*) DECLSPEC_HIDDEN
;
172 typedef struct _bytecode_t
{
178 function_code_t global_code
;
183 unsigned bstr_pool_size
;
187 unsigned str_pool_size
;
190 struct _bytecode_t
*next
;
193 HRESULT
compile_script(script_ctx_t
*,const WCHAR
*,const WCHAR
*,const WCHAR
*,BOOL
,BOOL
,bytecode_t
**) DECLSPEC_HIDDEN
;
194 void release_bytecode(bytecode_t
*) DECLSPEC_HIDDEN
;
196 static inline bytecode_t
*bytecode_addref(bytecode_t
*code
)
202 typedef struct _scope_chain_t
{
206 struct _call_frame_t
*frame
;
207 struct _scope_chain_t
*next
;
210 void scope_release(scope_chain_t
*) DECLSPEC_HIDDEN
;
212 static inline scope_chain_t
*scope_addref(scope_chain_t
*scope
)
218 typedef struct _except_frame_t except_frame_t
;
219 struct _parser_ctx_t
;
221 typedef struct _call_frame_t
{
223 except_frame_t
*except_frame
;
225 scope_chain_t
*scope
;
226 scope_chain_t
*base_scope
;
231 jsdisp_t
*function_instance
;
232 jsdisp_t
*variable_obj
;
233 jsdisp_t
*arguments_obj
;
238 unsigned arguments_off
;
239 unsigned variables_off
;
240 unsigned pop_variables
;
242 bytecode_t
*bytecode
;
243 function_code_t
*function
;
245 struct _call_frame_t
*prev_frame
;
248 #define EXEC_GLOBAL 0x0001
249 #define EXEC_CONSTRUCTOR 0x0002
250 #define EXEC_RETURN_TO_INTERP 0x0004
251 #define EXEC_EVAL 0x0008
253 HRESULT
exec_source(script_ctx_t
*,DWORD
,bytecode_t
*,function_code_t
*,scope_chain_t
*,IDispatch
*,
254 jsdisp_t
*,jsdisp_t
*,unsigned,jsval_t
*,jsval_t
*) DECLSPEC_HIDDEN
;
256 HRESULT
create_source_function(script_ctx_t
*,bytecode_t
*,function_code_t
*,scope_chain_t
*,jsdisp_t
**) DECLSPEC_HIDDEN
;
257 HRESULT
setup_arguments_object(script_ctx_t
*,call_frame_t
*) DECLSPEC_HIDDEN
;
258 void detach_arguments_object(jsdisp_t
*) DECLSPEC_HIDDEN
;