static HRESULT init_compiler(parser_ctx_t *parser) { compiler_ctx_t *compiler; if(parser->compiler) return S_OK; compiler = heap_alloc_zero(sizeof(*compiler)); if(!compiler) return E_OUTOFMEMORY; compiler->code = heap_alloc_zero(sizeof(bytecode_t)); if(!compiler->code) { release_compiler(compiler); return E_OUTOFMEMORY; } jsheap_init(&compiler->code->heap); compiler->code->instrs = heap_alloc(64 * sizeof(instr_t)); if(!compiler->code->instrs) { release_bytecode(compiler->code); release_compiler(compiler); return E_OUTOFMEMORY; } compiler->code_size = 64; compiler->code_off = 1; compiler->parser = parser; parser->code = compiler->code; parser->compiler = compiler; return S_OK; }
static HRESULT WINAPI JScriptParse_InitNew(IActiveScriptParse *iface) { JScript *This = ASPARSE_THIS(iface); script_ctx_t *ctx; TRACE("(%p)\n", This); if(This->ctx) return E_UNEXPECTED; ctx = heap_alloc_zero(sizeof(script_ctx_t)); if(!ctx) return E_OUTOFMEMORY; ctx->ref = 1; ctx->state = SCRIPTSTATE_UNINITIALIZED; ctx->safeopt = This->safeopt; ctx->version = This->version; jsheap_init(&ctx->tmp_heap); ctx = InterlockedCompareExchangePointer((void**)&This->ctx, ctx, NULL); if(ctx) { script_release(ctx); return E_UNEXPECTED; } return This->site ? set_ctx_site(This) : S_OK; }
HRESULT compile_subscript(parser_ctx_t *parser, expression_t *expr, BOOL do_ret, unsigned *ret_off) { BOOL no_ret = FALSE; HRESULT hres; if(!parser->code) { parser->code = heap_alloc_zero(sizeof(bytecode_t)); if(!parser->code) return E_OUTOFMEMORY; jsheap_init(&parser->code->heap); } if(!parser->compiler) { parser->compiler = heap_alloc_zero(sizeof(compiler_ctx_t)); if(!parser->compiler) return E_OUTOFMEMORY; parser->compiler->parser = parser; parser->compiler->code = parser->code; } *ret_off = parser->compiler->code_off; hres = compile_expression_noret(parser->compiler, expr, do_ret ? NULL : &no_ret); if(FAILED(hres)) return hres; return push_instr(parser->compiler, OP_ret) == -1 ? E_OUTOFMEMORY : S_OK; }
void jsheap_free(jsheap_t *heap) { DWORD i; jsheap_clear(heap); for(i=0; i < heap->block_cnt; i++) heap_free(heap->blocks[i]); heap_free(heap->blocks); jsheap_init(heap); }