ReactOS 0.4.17-dev-357-ga8f14ff
engine.h
Go to the documentation of this file.
1/*
2 * Copyright 2008,2011 Jacek Caban for CodeWeavers
3 *
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.
8 *
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.
13 *
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
17 */
18
19#pragma once
20
21#define OP_LIST \
22 X(add, 1, 0,0) \
23 X(and, 1, 0,0) \
24 X(array, 1, 0,0) \
25 X(assign, 1, 0,0) \
26 X(assign_call,1, ARG_UINT, 0) \
27 X(bool, 1, ARG_INT, 0) \
28 X(bneg, 1, 0,0) \
29 X(call, 1, ARG_UINT, ARG_UINT) \
30 X(call_eval, 1, ARG_UINT, ARG_UINT) \
31 X(call_member,1, ARG_UINT, ARG_UINT) \
32 X(carray, 1, ARG_UINT, 0) \
33 X(carray_set, 1, ARG_UINT, 0) \
34 X(case, 0, ARG_ADDR, 0) \
35 X(cnd_nz, 0, ARG_ADDR, 0) \
36 X(cnd_z, 0, ARG_ADDR, 0) \
37 X(delete, 1, 0,0) \
38 X(delete_ident,1,ARG_BSTR, 0) \
39 X(div, 1, 0,0) \
40 X(double, 1, ARG_DBL, 0) \
41 X(end_finally,0, 0,0) \
42 X(enter_catch,1, ARG_BSTR, 0) \
43 X(eq, 1, 0,0) \
44 X(eq2, 1, 0,0) \
45 X(forin, 0, ARG_ADDR, 0) \
46 X(func, 1, ARG_UINT, 0) \
47 X(gt, 1, 0,0) \
48 X(gteq, 1, 0,0) \
49 X(ident, 1, ARG_BSTR, 0) \
50 X(identid, 1, ARG_BSTR, ARG_INT) \
51 X(in, 1, 0,0) \
52 X(instanceof, 1, 0,0) \
53 X(int, 1, ARG_INT, 0) \
54 X(jmp, 0, ARG_ADDR, 0) \
55 X(jmp_z, 0, ARG_ADDR, 0) \
56 X(local, 1, ARG_INT, 0) \
57 X(local_ref, 1, ARG_INT, ARG_UINT) \
58 X(lshift, 1, 0,0) \
59 X(lt, 1, 0,0) \
60 X(lteq, 1, 0,0) \
61 X(member, 1, ARG_BSTR, 0) \
62 X(memberid, 1, ARG_UINT, 0) \
63 X(minus, 1, 0,0) \
64 X(mod, 1, 0,0) \
65 X(mul, 1, 0,0) \
66 X(neg, 1, 0,0) \
67 X(neq, 1, 0,0) \
68 X(neq2, 1, 0,0) \
69 X(new, 1, ARG_UINT, 0) \
70 X(new_obj, 1, 0,0) \
71 X(null, 1, 0,0) \
72 X(obj_prop, 1, ARG_STR, ARG_UINT) \
73 X(or, 1, 0,0) \
74 X(pop, 1, ARG_UINT, 0) \
75 X(pop_except, 0, ARG_ADDR, 0) \
76 X(pop_scope, 1, 0,0) \
77 X(postinc, 1, ARG_INT, 0) \
78 X(preinc, 1, ARG_INT, 0) \
79 X(push_acc, 1, 0,0) \
80 X(push_except,1, ARG_ADDR, ARG_UINT) \
81 X(push_block_scope, 1, ARG_UINT, 0) \
82 X(push_with_scope, 1, 0,0) \
83 X(regexp, 1, ARG_STR, ARG_UINT) \
84 X(rshift, 1, 0,0) \
85 X(rshift2, 1, 0,0) \
86 X(str, 1, ARG_STR, 0) \
87 X(this, 1, 0,0) \
88 X(throw, 0, 0,0) \
89 X(throw_ref, 0, ARG_UINT, 0) \
90 X(throw_type, 0, ARG_UINT, ARG_STR) \
91 X(tonum, 1, 0,0) \
92 X(typeof, 1, 0,0) \
93 X(typeofid, 1, 0,0) \
94 X(typeofident,1, 0,0) \
95 X(refval, 1, 0,0) \
96 X(ret, 0, ARG_UINT, 0) \
97 X(set_member, 1, 0,0) \
98 X(setret, 1, 0,0) \
99 X(sub, 1, 0,0) \
100 X(to_string, 1, 0,0) \
101 X(undefined, 1, 0,0) \
102 X(void, 1, 0,0) \
103 X(xor, 1, 0,0)
104
105typedef enum {
106#define X(x,a,b,c) OP_##x,
108#undef X
109 OP_LAST
111
112typedef struct _bytecode_t bytecode_t;
113
114typedef union {
118 unsigned uint;
120
121typedef enum {
131
132typedef struct {
134 unsigned loc;
135 union {
137 double dbl;
138 } u;
139} instr_t;
140
141typedef enum {
146
147typedef struct {
149 int ref;
151
152#define INVALID_LOCAL_REF 0x7fffffff
153
154typedef struct {
155 unsigned locals_cnt;
158
159typedef struct _function_code_t {
163 unsigned instr_off;
164
165 const WCHAR *source;
166 unsigned source_len;
167
168 unsigned func_cnt;
170
171 unsigned var_cnt;
172 struct {
173 BSTR name;
174 int func_id; /* -1 if not a function */
176
177 unsigned param_cnt;
179
182
183 unsigned int scope_index; /* index of scope in the parent function where the function is defined */
184
187
189local_ref_t *lookup_local(const function_code_t*,const WCHAR*,unsigned int);
190
194
197
200
203 unsigned start_line;
204
207 unsigned bstr_cnt;
208
211 unsigned str_cnt;
212
213 struct list entry;
214};
215
218
219unsigned get_location_line(bytecode_t *code, unsigned loc, unsigned *char_pos);
220
222{
223 code->ref++;
224 return code;
225}
226
229 unsigned argc;
231};
232
233typedef struct _scope_chain_t {
236 unsigned int scope_index;
241
243{
244 jsdisp_addref(&scope->dispex);
245 return scope;
246}
247
248static inline void scope_release(scope_chain_t *scope)
249{
250 jsdisp_release(&scope->dispex);
251}
252
255
258
262
264 unsigned loc;
265
268};
269
272void reset_ei(jsexcept_t*);
273void set_error_location(jsexcept_t*,bytecode_t*,unsigned,unsigned,jsstr_t*);
274
276struct _parser_ctx_t;
277
278typedef struct _call_frame_t {
279 unsigned ip;
281 unsigned stack_base;
284
286
292
293 unsigned argc;
294 unsigned pop_locals;
298
301
304
305#define EXEC_GLOBAL 0x0001
306#define EXEC_CONSTRUCTOR 0x0002
307#define EXEC_RETURN_TO_INTERP 0x0004
308#define EXEC_EVAL 0x0008
309
311 jsdisp_t*,unsigned,jsval_t*,jsval_t*);
312
COMPILER_DEPENDENT_UINT64 UINT64
Definition: actypes.h:131
Definition: list.h:37
OLECHAR * BSTR
Definition: compat.h:2293
HRESULT exec_source(script_ctx_t *, DWORD, bytecode_t *, function_code_t *, scope_chain_t *, IDispatch *, jsdisp_t *, unsigned, jsval_t *, jsval_t *)
Definition: engine.c:3425
void detach_arguments_object(call_frame_t *)
Definition: function.c:293
struct _scope_chain_t scope_chain_t
void release_bytecode(bytecode_t *)
Definition: compile.c:2459
HRESULT leave_script(script_ctx_t *, HRESULT)
Definition: jscript.c:348
void set_error_location(jsexcept_t *, bytecode_t *, unsigned, unsigned, jsstr_t *)
Definition: error.c:426
#define OP_LIST
Definition: engine.h:21
IDispatch * lookup_global_host(script_ctx_t *)
Definition: engine.c:845
static scope_chain_t * scope_addref(scope_chain_t *scope)
Definition: engine.h:242
HRESULT compile_script(script_ctx_t *, const WCHAR *, UINT64, unsigned, const WCHAR *, const WCHAR *, BOOL, BOOL, named_item_t *, bytecode_t **)
Definition: compile.c:2725
property_definition_type_t
Definition: engine.h:141
@ PROPERTY_DEFINITION_GETTER
Definition: engine.h:143
@ PROPERTY_DEFINITION_VALUE
Definition: engine.h:142
@ PROPERTY_DEFINITION_SETTER
Definition: engine.h:144
static void scope_release(scope_chain_t *scope)
Definition: engine.h:248
HRESULT setup_arguments_object(script_ctx_t *, call_frame_t *)
Definition: function.c:259
HRESULT create_source_function(script_ctx_t *, bytecode_t *, function_code_t *, scope_chain_t *, jsdisp_t **)
Definition: function.c:953
void enter_script(script_ctx_t *, jsexcept_t *)
Definition: jscript.c:340
struct _call_frame_t call_frame_t
instr_arg_type_t
Definition: engine.h:121
@ ARG_DBL
Definition: engine.h:125
@ ARG_INT
Definition: engine.h:127
@ ARG_ADDR
Definition: engine.h:123
@ ARG_BSTR
Definition: engine.h:124
@ ARG_NONE
Definition: engine.h:122
@ ARG_FUNC
Definition: engine.h:126
@ ARG_STR
Definition: engine.h:128
@ ARG_UINT
Definition: engine.h:129
void reset_ei(jsexcept_t *)
Definition: jscript.c:314
struct _function_code_t function_code_t
jsop_t
Definition: engine.h:105
@ OP_LAST
Definition: engine.h:109
unsigned get_location_line(bytecode_t *code, unsigned loc, unsigned *char_pos)
Definition: compile.c:2445
local_ref_t * lookup_local(const function_code_t *, const WCHAR *, unsigned int)
Definition: engine.c:865
static bytecode_t * bytecode_addref(bytecode_t *code)
Definition: engine.h:221
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble * u
Definition: glfuncs.h:240
ULONG jsdisp_release(jsdisp_t *obj)
Definition: dispex.c:1911
jsdisp_t * jsdisp_addref(jsdisp_t *obj)
Definition: dispex.c:1902
short WCHAR
Definition: pedump.c:58
long LONG
Definition: pedump.c:60
unsigned str_pool_size
Definition: engine.h:210
instr_t * instrs
Definition: engine.h:195
LONG ref
Definition: engine.h:192
WCHAR * source
Definition: engine.h:201
heap_pool_t heap
Definition: engine.h:196
struct list entry
Definition: engine.h:213
UINT64 source_context
Definition: engine.h:202
BSTR * bstr_pool
Definition: engine.h:205
unsigned bstr_pool_size
Definition: engine.h:206
unsigned str_cnt
Definition: engine.h:211
jsstr_t ** str_pool
Definition: engine.h:209
unsigned start_line
Definition: engine.h:203
unsigned bstr_cnt
Definition: engine.h:207
named_item_t * named_item
Definition: engine.h:199
BOOL is_persistent
Definition: engine.h:193
function_code_t global_code
Definition: engine.h:198
IDispatch * this_obj
Definition: engine.h:287
except_frame_t * except_frame
Definition: engine.h:280
struct _call_frame_t * prev_frame
Definition: engine.h:302
unsigned variables_off
Definition: engine.h:296
unsigned ip
Definition: engine.h:279
unsigned argc
Definition: engine.h:293
unsigned pop_locals
Definition: engine.h:294
jsdisp_t * arguments_obj
Definition: engine.h:290
scope_chain_t * base_scope
Definition: engine.h:283
jsdisp_t * variable_obj
Definition: engine.h:289
function_code_t * function
Definition: engine.h:300
bytecode_t * bytecode
Definition: engine.h:299
unsigned arguments_off
Definition: engine.h:295
DWORD flags
Definition: engine.h:291
scope_chain_t * scope
Definition: engine.h:282
jsval_t ret
Definition: engine.h:285
unsigned pop_variables
Definition: engine.h:297
jsdisp_t * function_instance
Definition: engine.h:288
unsigned stack_base
Definition: engine.h:281
unsigned var_cnt
Definition: engine.h:171
struct _function_code_t::@436 * variables
struct _function_code_t * funcs
Definition: engine.h:169
BSTR event_target
Definition: engine.h:162
unsigned int scope_index
Definition: engine.h:183
unsigned func_cnt
Definition: engine.h:168
BSTR * params
Definition: engine.h:178
bytecode_t * bytecode
Definition: engine.h:185
unsigned source_len
Definition: engine.h:166
unsigned param_cnt
Definition: engine.h:177
const WCHAR * source
Definition: engine.h:165
unsigned instr_off
Definition: engine.h:163
local_ref_scopes_t * local_scopes
Definition: engine.h:180
unsigned local_scope_count
Definition: engine.h:181
unsigned loc
Definition: engine.h:264
BOOL valid_value
Definition: engine.h:256
BOOL enter_notified
Definition: engine.h:266
bytecode_t * code
Definition: engine.h:263
jsstr_t * message
Definition: engine.h:260
jsexcept_t * prev
Definition: engine.h:267
jsstr_t * line
Definition: engine.h:261
HRESULT error
Definition: engine.h:254
jsval_t value
Definition: engine.h:257
jsstr_t * source
Definition: engine.h:259
Definition: jsstr.h:36
Definition: jsval.h:54
IDispatch * obj
Definition: engine.h:235
unsigned int scope_index
Definition: engine.h:236
struct _call_frame_t * frame
Definition: engine.h:238
struct _scope_chain_t * next
Definition: engine.h:239
struct vars_buffer * detached_vars
Definition: engine.h:237
jsdisp_t dispex
Definition: engine.h:234
Definition: inflate.c:139
jsop_t op
Definition: engine.h:133
double dbl
Definition: engine.h:137
unsigned loc
Definition: engine.h:134
local_ref_t * locals
Definition: engine.h:156
unsigned locals_cnt
Definition: engine.h:155
int ref
Definition: engine.h:149
BSTR name
Definition: engine.h:148
unsigned argc
Definition: engine.h:229
jsval_t var[]
Definition: engine.h:230
function_code_t * func_code
Definition: engine.h:228
unsigned uint
Definition: engine.h:118
LONG lng
Definition: engine.h:116
jsstr_t * str
Definition: engine.h:117
BSTR bstr
Definition: engine.h:115