26#include "wine/rbtree.h"
81#define X(n,a,b,c) {#n,b,c},
100 TRACE_(jscript_disas)(
"\t%u",
arg->uint);
113 for(instr =
ctx->code->instrs+off; instr < ctx->
code->instrs+
ctx->code_off; instr++) {
121 TRACE_(jscript_disas)(
"\n");
137 if(!
ctx->code->str_pool_size) {
139 if(!
ctx->code->str_pool)
141 ctx->code->str_pool_size = 8;
142 }
else if(
ctx->code->str_pool_size ==
ctx->code->str_cnt) {
149 ctx->code->str_pool = new_pool;
150 ctx->code->str_pool_size *= 2;
157 ctx->code->str_pool[
ctx->code->str_cnt++] = new_str;
168 if(!
ctx->code->bstr_pool_size) {
170 if(!
ctx->code->bstr_pool)
172 ctx->code->bstr_pool_size = 8;
173 }
else if(
ctx->code->bstr_pool_size ==
ctx->code->bstr_cnt) {
180 ctx->code->bstr_pool = new_pool;
181 ctx->code->bstr_pool_size *= 2;
193 if(!
ctx->code->bstr_pool[
ctx->code->bstr_cnt])
196 return ctx->code->bstr_pool[
ctx->code->bstr_cnt++];
205 if(!
ctx->code->bstr_pool[
ctx->code->bstr_cnt])
208 return ctx->code->bstr_pool[
ctx->code->bstr_cnt++];
215 if(
ctx->code_size ==
ctx->code_off) {
222 ctx->code->instrs = new_instrs;
226 ctx->code->instrs[
ctx->code_off].op =
op;
227 return ctx->code_off++;
232 assert(off < ctx->code_off);
233 return ctx->code->instrs + off;
393#define LABEL_FLAG 0x80000000
397 if(!
ctx->labels_size) {
401 ctx->labels_size = 8;
402 }
else if(
ctx->labels_size ==
ctx->labels_cnt) {
403 unsigned *new_labels;
409 ctx->labels = new_labels;
410 ctx->labels_size *= 2;
432 for(iter =
ctx->stat_ctx; iter; iter = iter->
next) {
568 unsigned jmp_false, jmp_end;
630 unsigned arg_cnt = 0, extra_args;
714 static const WCHAR fixmeW[] = {
'F',
'I',
'X',
'M',
'E',0};
716 WARN(
"invalid delete, unimplemented exception message\n");
768 use_throw_path =
TRUE;
777 use_throw_path =
TRUE;
835 switch(literal->
type) {
853 switch(literal->
type) {
869 unsigned array_instr;
874 for(iter =
expr->element_list; iter; iter = iter->
next) {
901 for(iter =
expr->property_list; iter; iter = iter->
next) {
1136 for(iter =
list; iter; iter = iter->
next) {
1195 if(
stat->else_stat) {
1231 jmp_off =
ctx->code_off;
1233 if(!
stat->do_while) {
1248 if(
stat->do_while) {
1274 if(
stat->variable_list) {
1278 }
else if(
stat->begin_expr) {
1292 expr_off =
ctx->code_off;
1310 if(
stat->end_expr) {
1330 if(
stat->variable) {
1348 if(
stat->variable) {
1392 for(iter =
ctx->stat_ctx; iter != stat_ctx; iter = iter->
next) {
1424 if(
stat->identifier) {
1430 for(iter =
ctx->stat_ctx; iter; iter = iter->
next) {
1438 WARN(
"Label not found\n");
1447 WARN(
"Label is not a loop\n");
1453 for(pop_ctx =
ctx->stat_ctx; pop_ctx; pop_ctx = pop_ctx->
next) {
1459 WARN(
"continue outside loop\n");
1477 if(
stat->identifier) {
1478 for(pop_ctx =
ctx->stat_ctx; pop_ctx; pop_ctx = pop_ctx->
next) {
1486 WARN(
"Label not found\n");
1490 for(pop_ctx =
ctx->stat_ctx; pop_ctx; pop_ctx = pop_ctx->
next) {
1496 WARN(
"Break outside loop\n");
1513 if(
ctx->from_eval) {
1514 WARN(
"misplaced return statement\n");
1562 for(iter =
ctx->stat_ctx; iter; iter = iter->next) {
1563 if(iter->labelled_stat && !
wcscmp(iter->labelled_stat->identifier,
stat->identifier)) {
1586 unsigned case_cnt = 0, *case_jmps,
i, default_jmp;
1600 for(iter =
stat->case_list; iter; iter = iter->
next) {
1605 case_jmps =
heap_alloc(case_cnt *
sizeof(*case_jmps));
1610 for(iter =
stat->case_list; iter; iter = iter->
next) {
1612 have_default =
TRUE;
1643 for(iter =
stat->case_list; iter; iter = iter->
next) {
1651 for(stat_iter = iter->
stat; stat_iter && (!iter->
next || iter->
next->stat != stat_iter);
1652 stat_iter = stat_iter->
next) {
1693 unsigned push_except, finally_off = 0, catch_off = 0, pop_except, catch_pop_except = 0;
1701 if(
stat->catch_block) {
1717 if(
stat->catch_block) {
1720 if(
stat->finally_statement)
1723 catch_off =
ctx->code_off;
1736 if(
stat->finally_statement) {
1738 if(!catch_pop_except)
1743 if(
stat->finally_statement) {
1749 finally_off =
ctx->code_off;
1759 if(catch_pop_except)
1771 stat_ctx->
next =
ctx->stat_ctx;
1772 ctx->stat_ctx = stat_ctx;
1775 switch(
stat->type) {
1830 ctx->stat_ctx = stat_ctx->
next;
1879 expr->func_id =
ctx->func->func_cnt++;
2021 for(iter =
list; iter; iter = iter->
next) {
2056 switch(
stat->type) {
2082 if(for_stat->
expr) {
2109 if(forin_stat->
expr) {
2145 for(iter = switch_stat->
case_list; iter; iter = iter->
next) {
2153 for(iter = switch_stat->
case_list; iter; iter = iter->
next) {
2156 for(stat_iter = iter->
stat; stat_iter && (!iter->
next || iter->
next->stat != stat_iter);
2157 stat_iter = stat_iter->
next) {
2215 for(instr =
ctx->code->instrs+off; instr < ctx->
code->instrs+
ctx->code_off; instr++) {
2223 ctx->labels_cnt = 0;
2233 for(
i=0;
i <
code->bstr_cnt;
i++)
2235 for(
i=0;
i <
code->str_cnt;
i++)
2283 ctx->from_eval = from_eval;
2285 ctx->locals_cnt = 0;
2299 if(!
func->event_target)
2306 for(param_iter = func_expr->
parameter_list; param_iter; param_iter = param_iter->
next)
2313 for(param_iter = func_expr->
parameter_list,
i=0; param_iter; param_iter = param_iter->
next,
i++) {
2315 if(!
func->params[
i])
2320 for(
i = 0;
i <
func->param_cnt;
i++) {
2332 func->locals_cnt =
ctx->locals_cnt;
2335 if(!
func->variables)
2342 if(
local->ref >= 0) {
2344 func->variables[
local->ref].func_id = -1;
2355 off =
ctx->code_off;
2369 func->instr_off = off;
2371 for(iter =
ctx->func_head,
i=0; iter; iter = iter->
next,
i++) {
2377 if(
func->funcs[
i].name && !
func->funcs[
i].event_target) {
2379 func->funcs[
i].local_ref = local_ref->
ref;
2381 if(local_ref->
ref >= 0)
2382 func->variables[local_ref->
ref].func_id =
i;
2454 ctx->code->global_code.param_cnt *
sizeof(*
ctx->code->global_code.params));
2455 if(!
ctx->code->global_code.params)
2480 WARN(
"Decoding failed\n");
static void * heap_alloc(size_t len)
static BOOL heap_free(void *mem)
static void * heap_realloc(void *mem, size_t len)
#define WINE_DEFAULT_DEBUG_CHANNEL(t)
static WCHAR * heap_strdupW(const WCHAR *str)
#define WINE_DECLARE_DEBUG_CHANNEL(x)
void parser_release(parser_ctx_t *) DECLSPEC_HIDDEN
HRESULT script_parse(script_ctx_t *, struct _compiler_ctx_t *, const WCHAR *, const WCHAR *, BOOL, parser_ctx_t **) DECLSPEC_HIDDEN
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
static jsval_t stack_pop(script_ctx_t *ctx)
local_ref_t * lookup_local(const function_code_t *function, const WCHAR *identifier)
GLuint GLuint GLsizei GLenum type
GLuint GLuint GLuint GLuint arg1
GLuint GLuint GLuint GLuint GLuint GLuint GLuint arg2
GLuint GLsizei GLsizei * length
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 const GLfloat const GLdouble const GLfloat GLint i
static HRESULT push_instr_bstr(compiler_ctx_t *ctx, jsop_t op, const WCHAR *arg)
static HRESULT compile_for_statement(compiler_ctx_t *ctx, for_statement_t *stat)
static HRESULT compile_forin_statement(compiler_ctx_t *ctx, forin_statement_t *stat)
static void dump_code(compiler_ctx_t *ctx, unsigned off)
static HRESULT compile_continue_statement(compiler_ctx_t *ctx, branch_statement_t *stat)
void release_bytecode(bytecode_t *code)
static HRESULT compile_arguments(compiler_ctx_t *ctx, const WCHAR *args)
static HRESULT compile_comma_expression(compiler_ctx_t *ctx, binary_expression_t *expr, BOOL emit_ret)
static BSTR compiler_alloc_bstr(compiler_ctx_t *ctx, const WCHAR *str)
static BSTR compiler_alloc_bstr_len(compiler_ctx_t *ctx, const WCHAR *str, size_t len)
static HRESULT compile_expression(compiler_ctx_t *, expression_t *, BOOL)
static HRESULT compile_new_expression(compiler_ctx_t *ctx, call_expression_t *expr)
static HRESULT compile_return_statement(compiler_ctx_t *ctx, expression_statement_t *stat)
static HRESULT parse_arguments(compiler_ctx_t *ctx, const WCHAR *args, BSTR *arg_array, unsigned *args_size)
static HRESULT push_instr_uint_str(compiler_ctx_t *ctx, jsop_t op, unsigned arg1, const WCHAR *arg2)
static BOOL ensure_bstr_slot(compiler_ctx_t *ctx)
static HRESULT compile_conditional_expression(compiler_ctx_t *ctx, conditional_expression_t *expr)
static HRESULT compile_while_statement(compiler_ctx_t *ctx, while_statement_t *stat)
static void * compiler_alloc(bytecode_t *code, size_t size)
static HRESULT compile_member_expression(compiler_ctx_t *ctx, member_expression_t *expr)
instr_arg_type_t arg2_type
static HRESULT compile_statement(compiler_ctx_t *, statement_ctx_t *, statement_t *)
static unsigned push_instr(compiler_ctx_t *ctx, jsop_t op)
static HRESULT compile_logical_expression(compiler_ctx_t *ctx, binary_expression_t *expr, jsop_t op)
static void resolve_labels(compiler_ctx_t *ctx, unsigned off)
static BOOL is_loop_statement(statement_type_t type)
static HRESULT literal_as_string(compiler_ctx_t *ctx, literal_t *literal, jsstr_t **str)
static HRESULT compile_block_statement(compiler_ctx_t *ctx, statement_t *iter)
static unsigned alloc_label(compiler_ctx_t *ctx)
static HRESULT compile_binary_expression(compiler_ctx_t *ctx, binary_expression_t *expr, jsop_t op)
static HRESULT init_code(compiler_ctx_t *compiler, const WCHAR *source)
static HRESULT compile_labelled_statement(compiler_ctx_t *ctx, labelled_statement_t *stat)
static void dump_instr_arg(instr_arg_type_t type, instr_arg_t *arg)
instr_arg_type_t arg1_type
static HRESULT visit_statement(compiler_ctx_t *, statement_t *)
static HRESULT compile_typeof_expression(compiler_ctx_t *ctx, unary_expression_t *expr)
static BOOL alloc_local(compiler_ctx_t *ctx, BSTR name, int ref)
static HRESULT compile_throw_statement(compiler_ctx_t *ctx, expression_statement_t *stat)
static HRESULT compile_literal(compiler_ctx_t *ctx, literal_t *literal)
static HRESULT compile_variable_list(compiler_ctx_t *ctx, variable_declaration_t *list)
static BOOL bind_local(compiler_ctx_t *ctx, const WCHAR *identifier, int *ret_ref)
static HRESULT compile_function(compiler_ctx_t *ctx, source_elements_t *source, function_expression_t *func_expr, BOOL from_eval, function_code_t *func)
static HRESULT compile_if_statement(compiler_ctx_t *ctx, if_statement_t *stat)
static HRESULT visit_variable_list(compiler_ctx_t *ctx, variable_declaration_t *list)
static HRESULT compile_array_literal(compiler_ctx_t *ctx, array_literal_expression_t *expr)
static HRESULT pop_to_stat(compiler_ctx_t *ctx, statement_ctx_t *stat_ctx)
static HRESULT visit_function_expression(compiler_ctx_t *ctx, function_expression_t *expr)
static HRESULT visit_block_statement(compiler_ctx_t *ctx, statement_t *iter)
static HRESULT push_instr_str_uint(compiler_ctx_t *ctx, jsop_t op, jsstr_t *str, unsigned arg2)
static HRESULT push_instr_double(compiler_ctx_t *ctx, jsop_t op, double arg)
static HRESULT compile_var_statement(compiler_ctx_t *ctx, var_statement_t *stat)
static HRESULT compile_expression_statement(compiler_ctx_t *ctx, expression_statement_t *stat)
static HRESULT compile_unary_expression(compiler_ctx_t *ctx, unary_expression_t *expr, jsop_t op)
static HRESULT compile_function_expression(compiler_ctx_t *ctx, function_expression_t *expr, BOOL emit_ret)
static jsstr_t * compiler_alloc_string(compiler_ctx_t *ctx, const WCHAR *str)
static BOOL is_memberid_expr(expression_type_t type)
static HRESULT compile_break_statement(compiler_ctx_t *ctx, branch_statement_t *stat)
static HRESULT compile_assign_expression(compiler_ctx_t *ctx, binary_expression_t *expr, jsop_t op)
static HRESULT emit_identifier(compiler_ctx_t *ctx, const WCHAR *identifier)
static HRESULT compile_switch_statement(compiler_ctx_t *ctx, switch_statement_t *stat)
static HRESULT compile_increment_expression(compiler_ctx_t *ctx, unary_expression_t *expr, jsop_t op, int n)
jsstr_t * compiler_alloc_string_len(compiler_ctx_t *ctx, const WCHAR *str, unsigned len)
static void label_set_addr(compiler_ctx_t *ctx, unsigned label)
static void set_arg_uint(compiler_ctx_t *ctx, unsigned instr, unsigned arg)
static HRESULT push_instr_uint(compiler_ctx_t *ctx, jsop_t op, unsigned arg)
static HRESULT visit_expression(compiler_ctx_t *ctx, expression_t *expr)
static BOOL alloc_variable(compiler_ctx_t *ctx, const WCHAR *name)
static HRESULT push_instr_bstr_uint(compiler_ctx_t *ctx, jsop_t op, const WCHAR *arg1, unsigned arg2)
static instr_t * instr_ptr(compiler_ctx_t *ctx, unsigned off)
static int function_local_cmp(const void *key, const struct wine_rb_entry *entry)
static HRESULT compile_object_literal(compiler_ctx_t *ctx, property_value_expression_t *expr)
static HRESULT compile_call_expression(compiler_ctx_t *ctx, call_expression_t *expr, BOOL emit_ret)
static HRESULT emit_identifier_ref(compiler_ctx_t *ctx, const WCHAR *identifier, unsigned flags)
struct _statement_ctx_t statement_ctx_t
static HRESULT compile_memberid_expression(compiler_ctx_t *ctx, expression_t *expr, unsigned flags)
static HRESULT push_instr_int(compiler_ctx_t *ctx, jsop_t op, LONG arg)
static HRESULT compile_try_statement(compiler_ctx_t *ctx, try_statement_t *stat)
static HRESULT push_instr_str(compiler_ctx_t *ctx, jsop_t op, jsstr_t *str)
static HRESULT compile_with_statement(compiler_ctx_t *ctx, with_statement_t *stat)
static HRESULT compile_delete_expression(compiler_ctx_t *ctx, unary_expression_t *expr)
struct _compiler_ctx_t compiler_ctx_t
static function_local_t * find_local(compiler_ctx_t *ctx, const WCHAR *name)
HRESULT compile_script(script_ctx_t *ctx, const WCHAR *code, const WCHAR *args, const WCHAR *delimiter, BOOL from_eval, BOOL use_decode, bytecode_t **ret)
HRESULT decode_source(WCHAR *code)
void * heap_pool_alloc(heap_pool_t *, DWORD) __WINE_ALLOC_SIZE(2) DECLSPEC_HIDDEN
void heap_pool_free(heap_pool_t *) DECLSPEC_HIDDEN
#define JS_E_ILLEGAL_ASSIGN
#define JS_E_INVALID_BREAK
#define JS_E_MISPLACED_RETURN
#define JS_E_LABEL_REDEFINED
#define JS_E_LABEL_NOT_FOUND
#define JS_E_INVALID_CONTINUE
HRESULT double_to_string(double, jsstr_t **) DECLSPEC_HIDDEN
void heap_pool_init(heap_pool_t *) DECLSPEC_HIDDEN
#define JS_E_INVALID_DELETE
jsstr_t * jsstr_alloc_len(const WCHAR *buf, unsigned len)
const char * debugstr_jsstr(jsstr_t *str)
static void jsstr_release(jsstr_t *str)
static const WCHAR label[]
#define DEFAULT_UNREACHABLE
BSTR WINAPI SysAllocString(LPCOLESTR str)
UINT WINAPI SysStringLen(BSTR str)
void WINAPI DECLSPEC_HOTPATCH SysFreeString(BSTR str)
BSTR WINAPI SysAllocStringLen(const OLECHAR *str, unsigned int len)
_Check_return_ _CRTIMP int __cdecl wcscmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
#define WINE_RB_ENTRY_VALUE(element, type, field)
static struct wine_rb_entry * wine_rb_get(const struct wine_rb_tree *tree, const void *key)
#define WINE_RB_FOR_EACH_ENTRY(elem, tree, type, field)
static void wine_rb_init(struct wine_rb_tree *tree, wine_rb_compare_func_t compare)
static int wine_rb_put(struct wine_rb_tree *tree, const void *key, struct wine_rb_entry *entry)
struct _array_element_t * next
function_code_t global_code
struct _case_clausule_t * next
function_expression_t * func_head
function_expression_t * func_tail
struct wine_rb_tree locals
statement_ctx_t * stat_ctx
const WCHAR * event_target
parameter_t * parameter_list
struct _function_expression_t * next
source_elements_t * source_elements
struct _parameter_t * next
struct _property_definition_t * next
const labelled_statement_t * labelled_stat
struct _statement_ctx_t * next
struct _variable_declaration_t * next
array_element_t * element_list
expression_t * expression1
expression_t * expression2
expression_t * expression
argument_t * argument_list
expression_t * true_expression
expression_t * expression
expression_t * false_expression
expression_t * begin_expr
variable_declaration_t * variable_list
variable_declaration_t * variable
struct literal_t::@447::@448 regexp
expression_t * expression
case_clausule_t * case_list
catch_block_t * catch_block
statement_t * try_statement
statement_t * finally_statement
static unsigned arg_cnt(const DISPPARAMS *dp)
_In_ ULONG _In_ ULONG_PTR ident