winex11: Separate fetching the window icon bits and setting the WM hints.
[wine.git] / dlls / jscript / engine.h
blobf7e03f7b2dbb6037e4b7d377a41e6dd98e195cb9
1 /*
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
19 typedef struct _source_elements_t source_elements_t;
20 typedef struct _expression_t expression_t;
21 typedef struct _statement_t statement_t;
23 typedef struct {
24 const WCHAR *begin;
25 const WCHAR *end;
26 const WCHAR *ptr;
28 script_ctx_t *script;
29 source_elements_t *source;
30 BOOL nl;
31 BOOL implicit_nl_semicolon;
32 BOOL is_html;
33 BOOL lexer_error;
34 HRESULT hres;
36 jsheap_t heap;
37 } parser_ctx_t;
39 #define OP_LIST \
40 X(add, 1, 0,0) \
41 X(and, 1, 0,0) \
42 X(array, 1, 0,0) \
43 X(assign, 1, 0,0) \
44 X(assign_call,1, ARG_UINT, 0) \
45 X(bool, 1, ARG_INT, 0) \
46 X(bneg, 1, 0,0) \
47 X(call, 1, ARG_UINT, ARG_UINT) \
48 X(call_member,1, ARG_UINT, ARG_UINT) \
49 X(carray, 1, ARG_UINT, 0) \
50 X(case, 0, ARG_ADDR, 0) \
51 X(cnd_nz, 0, ARG_ADDR, 0) \
52 X(cnd_z, 0, ARG_ADDR, 0) \
53 X(delete, 1, 0,0) \
54 X(delete_ident,1,ARG_BSTR, 0) \
55 X(div, 1, 0,0) \
56 X(double, 1, ARG_DBL, 0) \
57 X(end_finally,1, 0,0) \
58 X(eq, 1, 0,0) \
59 X(eq2, 1, 0,0) \
60 X(forin, 0, ARG_ADDR, 0) \
61 X(func, 1, ARG_UINT, 0) \
62 X(gt, 1, 0,0) \
63 X(gteq, 1, 0,0) \
64 X(ident, 1, ARG_BSTR, 0) \
65 X(identid, 1, ARG_BSTR, ARG_INT) \
66 X(in, 1, 0,0) \
67 X(instanceof, 1, 0,0) \
68 X(int, 1, ARG_INT, 0) \
69 X(jmp, 0, ARG_ADDR, 0) \
70 X(jmp_z, 0, ARG_ADDR, 0) \
71 X(lshift, 1, 0,0) \
72 X(lt, 1, 0,0) \
73 X(lteq, 1, 0,0) \
74 X(member, 1, ARG_BSTR, 0) \
75 X(memberid, 1, ARG_UINT, 0) \
76 X(minus, 1, 0,0) \
77 X(mod, 1, 0,0) \
78 X(mul, 1, 0,0) \
79 X(neg, 1, 0,0) \
80 X(neq, 1, 0,0) \
81 X(neq2, 1, 0,0) \
82 X(new, 1, ARG_UINT, 0) \
83 X(new_obj, 1, 0,0) \
84 X(null, 1, 0,0) \
85 X(obj_prop, 1, ARG_BSTR, 0) \
86 X(or, 1, 0,0) \
87 X(pop, 1, 0,0) \
88 X(pop_except, 1, 0,0) \
89 X(pop_scope, 1, 0,0) \
90 X(postinc, 1, ARG_INT, 0) \
91 X(preinc, 1, ARG_INT, 0) \
92 X(push_except,1, ARG_ADDR, ARG_BSTR) \
93 X(push_scope, 1, 0,0) \
94 X(regexp, 1, ARG_STR, ARG_UINT) \
95 X(rshift, 1, 0,0) \
96 X(rshift2, 1, 0,0) \
97 X(str, 1, ARG_STR, 0) \
98 X(this, 1, 0,0) \
99 X(throw, 0, 0,0) \
100 X(throw_ref, 0, ARG_UINT, 0) \
101 X(throw_type, 0, ARG_UINT, ARG_STR) \
102 X(tonum, 1, 0,0) \
103 X(typeof, 1, 0,0) \
104 X(typeofid, 1, 0,0) \
105 X(typeofident,1, 0,0) \
106 X(refval, 1, 0,0) \
107 X(ret, 0, 0,0) \
108 X(sub, 1, 0,0) \
109 X(undefined, 1, 0,0) \
110 X(var_set, 1, ARG_BSTR, 0) \
111 X(void, 1, 0,0) \
112 X(xor, 1, 0,0)
114 typedef enum {
115 #define X(x,a,b,c) OP_##x,
116 OP_LIST
117 #undef X
118 OP_LAST
119 } jsop_t;
121 typedef union {
122 BSTR bstr;
123 LONG lng;
124 WCHAR *str;
125 unsigned uint;
126 } instr_arg_t;
128 typedef enum {
129 ARG_NONE = 0,
130 ARG_ADDR,
131 ARG_BSTR,
132 ARG_DBL,
133 ARG_FUNC,
134 ARG_INT,
135 ARG_STR,
136 ARG_UINT
137 } instr_arg_type_t;
139 typedef struct {
140 jsop_t op;
141 union {
142 instr_arg_t arg[2];
143 double dbl;
144 } u;
145 } instr_t;
147 typedef struct _function_code_t {
148 BSTR name;
149 unsigned instr_off;
151 const WCHAR *source;
152 unsigned source_len;
154 unsigned func_cnt;
155 struct _function_code_t *funcs;
157 unsigned var_cnt;
158 BSTR *variables;
160 unsigned param_cnt;
161 BSTR *params;
162 } function_code_t;
164 typedef struct _bytecode_t {
165 LONG ref;
167 instr_t *instrs;
168 jsheap_t heap;
170 function_code_t global_code;
172 WCHAR *source;
174 BSTR *bstr_pool;
175 unsigned bstr_pool_size;
176 unsigned bstr_cnt;
178 struct _bytecode_t *next;
179 } bytecode_t;
181 HRESULT compile_script(script_ctx_t*,const WCHAR*,const WCHAR*,BOOL,BOOL,bytecode_t**) DECLSPEC_HIDDEN;
182 void release_bytecode(bytecode_t*) DECLSPEC_HIDDEN;
184 static inline void bytecode_addref(bytecode_t *code)
186 code->ref++;
189 HRESULT script_parse(script_ctx_t*,const WCHAR*,const WCHAR*,BOOL,parser_ctx_t**) DECLSPEC_HIDDEN;
190 void parser_release(parser_ctx_t*) DECLSPEC_HIDDEN;
192 int parser_lex(void*,parser_ctx_t*) DECLSPEC_HIDDEN;
194 static inline void *parser_alloc(parser_ctx_t *ctx, DWORD size)
196 return jsheap_alloc(&ctx->heap, size);
199 static inline void *parser_alloc_tmp(parser_ctx_t *ctx, DWORD size)
201 return jsheap_alloc(&ctx->script->tmp_heap, size);
204 typedef struct _scope_chain_t {
205 LONG ref;
206 jsdisp_t *jsobj;
207 IDispatch *obj;
208 struct _scope_chain_t *next;
209 } scope_chain_t;
211 HRESULT scope_push(scope_chain_t*,jsdisp_t*,IDispatch*,scope_chain_t**) DECLSPEC_HIDDEN;
212 void scope_release(scope_chain_t*) DECLSPEC_HIDDEN;
214 static inline void scope_addref(scope_chain_t *scope)
216 scope->ref++;
219 typedef struct _except_frame_t except_frame_t;
221 struct _exec_ctx_t {
222 LONG ref;
224 parser_ctx_t *parser;
225 bytecode_t *code;
226 script_ctx_t *script;
227 scope_chain_t *scope_chain;
228 jsdisp_t *var_disp;
229 IDispatch *this_obj;
230 function_code_t *func_code;
231 BOOL is_global;
233 jsval_t *stack;
234 unsigned stack_size;
235 unsigned top;
236 except_frame_t *except_frame;
238 unsigned ip;
241 static inline void exec_addref(exec_ctx_t *ctx)
243 ctx->ref++;
246 void exec_release(exec_ctx_t*) DECLSPEC_HIDDEN;
247 HRESULT create_exec_ctx(script_ctx_t*,IDispatch*,jsdisp_t*,scope_chain_t*,BOOL,exec_ctx_t**) DECLSPEC_HIDDEN;
248 HRESULT exec_source(exec_ctx_t*,bytecode_t*,function_code_t*,BOOL,jsval_t*) DECLSPEC_HIDDEN;
249 HRESULT create_source_function(script_ctx_t*,bytecode_t*,function_code_t*,scope_chain_t*,jsdisp_t**) DECLSPEC_HIDDEN;
251 typedef enum {
252 LT_DOUBLE,
253 LT_STRING,
254 LT_BOOL,
255 LT_NULL,
256 LT_REGEXP
257 }literal_type_t;
259 typedef struct {
260 literal_type_t type;
261 union {
262 double dval;
263 const WCHAR *wstr;
264 BOOL bval;
265 struct {
266 const WCHAR *str;
267 DWORD str_len;
268 DWORD flags;
269 } regexp;
270 } u;
271 } literal_t;
273 literal_t *parse_regexp(parser_ctx_t*) DECLSPEC_HIDDEN;
274 literal_t *new_boolean_literal(parser_ctx_t*,BOOL) DECLSPEC_HIDDEN;
276 typedef struct _variable_declaration_t {
277 const WCHAR *identifier;
278 expression_t *expr;
280 struct _variable_declaration_t *next;
281 struct _variable_declaration_t *global_next; /* for compiler */
282 } variable_declaration_t;
284 typedef enum {
285 STAT_BLOCK,
286 STAT_BREAK,
287 STAT_CONTINUE,
288 STAT_EMPTY,
289 STAT_EXPR,
290 STAT_FOR,
291 STAT_FORIN,
292 STAT_IF,
293 STAT_LABEL,
294 STAT_RETURN,
295 STAT_SWITCH,
296 STAT_THROW,
297 STAT_TRY,
298 STAT_VAR,
299 STAT_WHILE,
300 STAT_WITH
301 } statement_type_t;
303 struct _statement_t {
304 statement_type_t type;
305 statement_t *next;
308 typedef struct {
309 statement_t stat;
310 statement_t *stat_list;
311 } block_statement_t;
313 typedef struct {
314 statement_t stat;
315 variable_declaration_t *variable_list;
316 } var_statement_t;
318 typedef struct {
319 statement_t stat;
320 expression_t *expr;
321 } expression_statement_t;
323 typedef struct {
324 statement_t stat;
325 expression_t *expr;
326 statement_t *if_stat;
327 statement_t *else_stat;
328 } if_statement_t;
330 typedef struct {
331 statement_t stat;
332 BOOL do_while;
333 expression_t *expr;
334 statement_t *statement;
335 } while_statement_t;
337 typedef struct {
338 statement_t stat;
339 variable_declaration_t *variable_list;
340 expression_t *begin_expr;
341 expression_t *expr;
342 expression_t *end_expr;
343 statement_t *statement;
344 } for_statement_t;
346 typedef struct {
347 statement_t stat;
348 variable_declaration_t *variable;
349 expression_t *expr;
350 expression_t *in_expr;
351 statement_t *statement;
352 } forin_statement_t;
354 typedef struct {
355 statement_t stat;
356 const WCHAR *identifier;
357 } branch_statement_t;
359 typedef struct {
360 statement_t stat;
361 expression_t *expr;
362 statement_t *statement;
363 } with_statement_t;
365 typedef struct {
366 statement_t stat;
367 const WCHAR *identifier;
368 statement_t *statement;
369 } labelled_statement_t;
371 typedef struct _case_clausule_t {
372 expression_t *expr;
373 statement_t *stat;
375 struct _case_clausule_t *next;
376 } case_clausule_t;
378 typedef struct {
379 statement_t stat;
380 expression_t *expr;
381 case_clausule_t *case_list;
382 } switch_statement_t;
384 typedef struct {
385 const WCHAR *identifier;
386 statement_t *statement;
387 } catch_block_t;
389 typedef struct {
390 statement_t stat;
391 statement_t *try_statement;
392 catch_block_t *catch_block;
393 statement_t *finally_statement;
394 } try_statement_t;
396 typedef struct {
397 enum {
398 EXPRVAL_JSVAL,
399 EXPRVAL_IDREF,
400 EXPRVAL_INVALID
401 } type;
402 union {
403 jsval_t val;
404 struct {
405 IDispatch *disp;
406 DISPID id;
407 } idref;
408 } u;
409 } exprval_t;
411 typedef enum {
412 EXPR_COMMA,
413 EXPR_OR,
414 EXPR_AND,
415 EXPR_BOR,
416 EXPR_BXOR,
417 EXPR_BAND,
418 EXPR_INSTANCEOF,
419 EXPR_IN,
420 EXPR_ADD,
421 EXPR_SUB,
422 EXPR_MUL,
423 EXPR_DIV,
424 EXPR_MOD,
425 EXPR_DELETE,
426 EXPR_VOID,
427 EXPR_TYPEOF,
428 EXPR_MINUS,
429 EXPR_PLUS,
430 EXPR_POSTINC,
431 EXPR_POSTDEC,
432 EXPR_PREINC,
433 EXPR_PREDEC,
434 EXPR_EQ,
435 EXPR_EQEQ,
436 EXPR_NOTEQ,
437 EXPR_NOTEQEQ,
438 EXPR_LESS,
439 EXPR_LESSEQ,
440 EXPR_GREATER,
441 EXPR_GREATEREQ,
442 EXPR_BITNEG,
443 EXPR_LOGNEG,
444 EXPR_LSHIFT,
445 EXPR_RSHIFT,
446 EXPR_RRSHIFT,
447 EXPR_ASSIGN,
448 EXPR_ASSIGNLSHIFT,
449 EXPR_ASSIGNRSHIFT,
450 EXPR_ASSIGNRRSHIFT,
451 EXPR_ASSIGNADD,
452 EXPR_ASSIGNSUB,
453 EXPR_ASSIGNMUL,
454 EXPR_ASSIGNDIV,
455 EXPR_ASSIGNMOD,
456 EXPR_ASSIGNAND,
457 EXPR_ASSIGNOR,
458 EXPR_ASSIGNXOR,
459 EXPR_COND,
460 EXPR_ARRAY,
461 EXPR_MEMBER,
462 EXPR_NEW,
463 EXPR_CALL,
464 EXPR_THIS,
465 EXPR_FUNC,
466 EXPR_IDENT,
467 EXPR_ARRAYLIT,
468 EXPR_PROPVAL,
469 EXPR_LITERAL
470 } expression_type_t;
472 struct _expression_t {
473 expression_type_t type;
476 typedef struct _parameter_t {
477 const WCHAR *identifier;
478 struct _parameter_t *next;
479 } parameter_t;
481 struct _source_elements_t {
482 statement_t *statement;
483 statement_t *statement_tail;
486 typedef struct _function_expression_t {
487 expression_t expr;
488 const WCHAR *identifier;
489 parameter_t *parameter_list;
490 source_elements_t *source_elements;
491 const WCHAR *src_str;
492 DWORD src_len;
494 struct _function_expression_t *next; /* for compiler */
495 } function_expression_t;
497 typedef struct {
498 expression_t expr;
499 expression_t *expression1;
500 expression_t *expression2;
501 } binary_expression_t;
503 typedef struct {
504 expression_t expr;
505 expression_t *expression;
506 } unary_expression_t;
508 typedef struct {
509 expression_t expr;
510 expression_t *expression;
511 expression_t *true_expression;
512 expression_t *false_expression;
513 } conditional_expression_t;
515 typedef struct {
516 expression_t expr;
517 expression_t *expression;
518 const WCHAR *identifier;
519 } member_expression_t;
521 typedef struct _argument_t {
522 expression_t *expr;
524 struct _argument_t *next;
525 } argument_t;
527 typedef struct {
528 expression_t expr;
529 expression_t *expression;
530 argument_t *argument_list;
531 } call_expression_t;
533 typedef struct {
534 expression_t expr;
535 const WCHAR *identifier;
536 } identifier_expression_t;
538 typedef struct {
539 expression_t expr;
540 literal_t *literal;
541 } literal_expression_t;
543 typedef struct _array_element_t {
544 int elision;
545 expression_t *expr;
547 struct _array_element_t *next;
548 } array_element_t;
550 typedef struct {
551 expression_t expr;
552 array_element_t *element_list;
553 int length;
554 } array_literal_expression_t;
556 typedef struct _prop_val_t {
557 literal_t *name;
558 expression_t *value;
560 struct _prop_val_t *next;
561 } prop_val_t;
563 typedef struct {
564 expression_t expr;
565 prop_val_t *property_list;
566 } property_value_expression_t;