2011-09-07 14:07:24 +02:00
|
|
|
/*
|
|
|
|
* Copyright 2011 Jacek Caban for CodeWeavers
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
#include "vbscript.h"
|
|
|
|
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(vbscript);
|
|
|
|
|
2012-07-03 17:05:32 +02:00
|
|
|
static DISPID propput_dispid = DISPID_PROPERTYPUT;
|
|
|
|
|
2011-09-07 14:07:24 +02:00
|
|
|
typedef struct {
|
|
|
|
vbscode_t *code;
|
|
|
|
instr_t *instr;
|
2011-09-08 14:54:37 +02:00
|
|
|
script_ctx_t *script;
|
2011-09-09 14:47:00 +02:00
|
|
|
function_t *func;
|
2011-09-15 14:21:58 +02:00
|
|
|
IDispatch *this_obj;
|
2014-03-07 14:27:35 +01:00
|
|
|
vbdisp_t *vbthis;
|
2011-09-08 14:57:45 +02:00
|
|
|
|
2011-09-14 12:56:45 +02:00
|
|
|
VARIANT *args;
|
2011-09-14 12:57:37 +02:00
|
|
|
VARIANT *vars;
|
2013-11-13 16:29:29 +01:00
|
|
|
SAFEARRAY **arrays;
|
2011-09-14 12:56:45 +02:00
|
|
|
|
2011-09-20 14:59:53 +02:00
|
|
|
dynamic_var_t *dynamic_vars;
|
2013-02-15 15:11:13 +01:00
|
|
|
heap_pool_t heap;
|
2011-09-20 14:59:53 +02:00
|
|
|
|
2011-09-22 14:26:25 +02:00
|
|
|
BOOL resume_next;
|
|
|
|
|
2011-09-08 14:57:45 +02:00
|
|
|
unsigned stack_size;
|
|
|
|
unsigned top;
|
|
|
|
VARIANT *stack;
|
2011-09-14 12:58:30 +02:00
|
|
|
|
|
|
|
VARIANT ret_val;
|
2011-09-07 14:07:24 +02:00
|
|
|
} exec_ctx_t;
|
|
|
|
|
|
|
|
typedef HRESULT (*instr_func_t)(exec_ctx_t*);
|
|
|
|
|
2011-09-08 14:54:37 +02:00
|
|
|
typedef enum {
|
|
|
|
REF_NONE,
|
2011-09-13 11:37:08 +02:00
|
|
|
REF_DISP,
|
2011-09-14 12:55:42 +02:00
|
|
|
REF_VAR,
|
2011-09-19 14:09:21 +02:00
|
|
|
REF_OBJ,
|
2011-09-21 14:04:16 +02:00
|
|
|
REF_CONST,
|
2011-09-14 12:55:42 +02:00
|
|
|
REF_FUNC
|
2011-09-08 14:54:37 +02:00
|
|
|
} ref_type_t;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
ref_type_t type;
|
|
|
|
union {
|
|
|
|
struct {
|
|
|
|
IDispatch *disp;
|
|
|
|
DISPID id;
|
|
|
|
} d;
|
2011-09-13 11:37:08 +02:00
|
|
|
VARIANT *v;
|
2011-09-14 12:55:42 +02:00
|
|
|
function_t *f;
|
2011-09-19 14:09:21 +02:00
|
|
|
IDispatch *obj;
|
2011-09-08 14:54:37 +02:00
|
|
|
} u;
|
|
|
|
} ref_t;
|
|
|
|
|
2011-09-09 14:47:55 +02:00
|
|
|
typedef struct {
|
|
|
|
VARIANT *v;
|
|
|
|
VARIANT store;
|
|
|
|
BOOL owned;
|
|
|
|
} variant_val_t;
|
|
|
|
|
2011-09-13 11:37:08 +02:00
|
|
|
static BOOL lookup_dynamic_vars(dynamic_var_t *var, const WCHAR *name, ref_t *ref)
|
|
|
|
{
|
|
|
|
while(var) {
|
2019-06-25 08:38:01 +02:00
|
|
|
if(!wcsicmp(var->name, name)) {
|
2011-09-21 14:04:16 +02:00
|
|
|
ref->type = var->is_const ? REF_CONST : REF_VAR;
|
2011-09-13 11:37:08 +02:00
|
|
|
ref->u.v = &var->v;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
var = var->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2011-09-14 12:58:30 +02:00
|
|
|
static HRESULT lookup_identifier(exec_ctx_t *ctx, BSTR name, vbdisp_invoke_type_t invoke_type, ref_t *ref)
|
2011-09-08 14:54:37 +02:00
|
|
|
{
|
|
|
|
named_item_t *item;
|
2011-09-14 12:55:42 +02:00
|
|
|
function_t *func;
|
2018-03-16 23:34:41 +01:00
|
|
|
IDispatch *disp;
|
2011-09-14 12:56:45 +02:00
|
|
|
unsigned i;
|
2011-09-08 14:54:37 +02:00
|
|
|
DISPID id;
|
|
|
|
HRESULT hres;
|
|
|
|
|
2011-09-19 14:09:21 +02:00
|
|
|
static const WCHAR errW[] = {'e','r','r',0};
|
|
|
|
|
2011-09-16 13:28:52 +02:00
|
|
|
if(invoke_type == VBDISP_LET
|
|
|
|
&& (ctx->func->type == FUNC_FUNCTION || ctx->func->type == FUNC_PROPGET || ctx->func->type == FUNC_DEFGET)
|
2019-06-25 08:38:01 +02:00
|
|
|
&& !wcsicmp(name, ctx->func->name)) {
|
2011-09-14 12:58:30 +02:00
|
|
|
ref->type = REF_VAR;
|
|
|
|
ref->u.v = &ctx->ret_val;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2011-09-14 12:57:37 +02:00
|
|
|
for(i=0; i < ctx->func->var_cnt; i++) {
|
2019-06-25 08:38:01 +02:00
|
|
|
if(!wcsicmp(ctx->func->vars[i].name, name)) {
|
2011-09-14 12:57:37 +02:00
|
|
|
ref->type = REF_VAR;
|
|
|
|
ref->u.v = ctx->vars+i;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-14 12:56:45 +02:00
|
|
|
for(i=0; i < ctx->func->arg_cnt; i++) {
|
2019-06-25 08:38:01 +02:00
|
|
|
if(!wcsicmp(ctx->func->args[i].name, name)) {
|
2011-09-14 12:56:45 +02:00
|
|
|
ref->type = REF_VAR;
|
|
|
|
ref->u.v = ctx->args+i;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-20 14:59:53 +02:00
|
|
|
if(lookup_dynamic_vars(ctx->func->type == FUNC_GLOBAL ? ctx->script->global_vars : ctx->dynamic_vars, name, ref))
|
|
|
|
return S_OK;
|
|
|
|
|
2011-09-22 14:25:15 +02:00
|
|
|
if(ctx->func->type != FUNC_GLOBAL) {
|
2014-03-07 14:27:35 +01:00
|
|
|
if(ctx->vbthis) {
|
|
|
|
/* FIXME: Bind such identifier while generating bytecode. */
|
|
|
|
for(i=0; i < ctx->vbthis->desc->prop_cnt; i++) {
|
2019-06-25 08:38:01 +02:00
|
|
|
if(!wcsicmp(ctx->vbthis->desc->props[i].name, name)) {
|
2014-03-07 14:27:35 +01:00
|
|
|
ref->type = REF_VAR;
|
|
|
|
ref->u.v = ctx->vbthis->props+i;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-22 14:25:15 +02:00
|
|
|
hres = disp_get_id(ctx->this_obj, name, invoke_type, TRUE, &id);
|
|
|
|
if(SUCCEEDED(hres)) {
|
|
|
|
ref->type = REF_DISP;
|
|
|
|
ref->u.d.disp = ctx->this_obj;
|
|
|
|
ref->u.d.id = id;
|
2018-03-16 23:34:52 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(ctx->func->code_ctx->context) {
|
|
|
|
hres = disp_get_id(ctx->func->code_ctx->context, name, invoke_type, TRUE, &id);
|
|
|
|
if(SUCCEEDED(hres)) {
|
|
|
|
ref->type = REF_DISP;
|
|
|
|
ref->u.d.disp = ctx->func->code_ctx->context;
|
|
|
|
ref->u.d.id = id;
|
2011-09-22 14:25:15 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
2011-09-15 14:21:58 +02:00
|
|
|
}
|
|
|
|
|
2011-09-20 14:59:53 +02:00
|
|
|
if(ctx->func->type != FUNC_GLOBAL && lookup_dynamic_vars(ctx->script->global_vars, name, ref))
|
2011-09-13 11:37:08 +02:00
|
|
|
return S_OK;
|
|
|
|
|
2011-09-14 12:55:42 +02:00
|
|
|
for(func = ctx->script->global_funcs; func; func = func->next) {
|
2019-06-25 08:38:01 +02:00
|
|
|
if(!wcsicmp(func->name, name)) {
|
2011-09-14 12:55:42 +02:00
|
|
|
ref->type = REF_FUNC;
|
|
|
|
ref->u.f = func;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-25 08:38:01 +02:00
|
|
|
if(!wcsicmp(name, errW)) {
|
2011-09-22 14:25:15 +02:00
|
|
|
ref->type = REF_OBJ;
|
|
|
|
ref->u.obj = (IDispatch*)&ctx->script->err_obj->IDispatchEx_iface;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
hres = vbdisp_get_id(ctx->script->global_obj, name, invoke_type, TRUE, &id);
|
|
|
|
if(SUCCEEDED(hres)) {
|
|
|
|
ref->type = REF_DISP;
|
|
|
|
ref->u.d.disp = (IDispatch*)&ctx->script->global_obj->IDispatchEx_iface;
|
|
|
|
ref->u.d.id = id;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2018-03-16 23:34:41 +01:00
|
|
|
disp = lookup_named_item(ctx->script, name, SCRIPTITEM_ISVISIBLE);
|
|
|
|
if(disp) {
|
|
|
|
ref->type = REF_OBJ;
|
|
|
|
ref->u.obj = disp;
|
|
|
|
return S_OK;
|
2011-09-08 14:54:37 +02:00
|
|
|
}
|
|
|
|
|
2012-03-26 11:52:33 +02:00
|
|
|
LIST_FOR_EACH_ENTRY(item, &ctx->script->named_items, named_item_t, entry) {
|
|
|
|
if((item->flags & SCRIPTITEM_GLOBALMEMBERS)) {
|
|
|
|
hres = disp_get_id(item->disp, name, invoke_type, FALSE, &id);
|
|
|
|
if(SUCCEEDED(hres)) {
|
|
|
|
ref->type = REF_DISP;
|
|
|
|
ref->u.d.disp = item->disp;
|
|
|
|
ref->u.d.id = id;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-08 14:54:37 +02:00
|
|
|
ref->type = REF_NONE;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2012-10-10 17:16:27 +02:00
|
|
|
static HRESULT add_dynamic_var(exec_ctx_t *ctx, const WCHAR *name,
|
2015-03-03 14:41:17 +01:00
|
|
|
BOOL is_const, VARIANT **out_var)
|
2011-09-21 14:03:50 +02:00
|
|
|
{
|
|
|
|
dynamic_var_t *new_var;
|
2013-02-15 15:11:13 +01:00
|
|
|
heap_pool_t *heap;
|
2011-09-21 14:03:50 +02:00
|
|
|
WCHAR *str;
|
|
|
|
unsigned size;
|
|
|
|
|
|
|
|
heap = ctx->func->type == FUNC_GLOBAL ? &ctx->script->heap : &ctx->heap;
|
|
|
|
|
2013-02-15 15:11:13 +01:00
|
|
|
new_var = heap_pool_alloc(heap, sizeof(*new_var));
|
2011-09-21 14:03:50 +02:00
|
|
|
if(!new_var)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
2019-06-25 08:38:01 +02:00
|
|
|
size = (lstrlenW(name)+1)*sizeof(WCHAR);
|
2013-02-15 15:11:13 +01:00
|
|
|
str = heap_pool_alloc(heap, size);
|
2011-09-21 14:03:50 +02:00
|
|
|
if(!str)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
memcpy(str, name, size);
|
|
|
|
new_var->name = str;
|
2011-09-21 14:04:16 +02:00
|
|
|
new_var->is_const = is_const;
|
2015-03-03 14:41:17 +01:00
|
|
|
V_VT(&new_var->v) = VT_EMPTY;
|
2011-09-21 14:03:50 +02:00
|
|
|
|
|
|
|
if(ctx->func->type == FUNC_GLOBAL) {
|
|
|
|
new_var->next = ctx->script->global_vars;
|
|
|
|
ctx->script->global_vars = new_var;
|
|
|
|
}else {
|
|
|
|
new_var->next = ctx->dynamic_vars;
|
|
|
|
ctx->dynamic_vars = new_var;
|
|
|
|
}
|
|
|
|
|
2015-03-03 14:41:17 +01:00
|
|
|
*out_var = &new_var->v;
|
2011-09-21 14:03:50 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2011-09-08 14:57:45 +02:00
|
|
|
static inline VARIANT *stack_pop(exec_ctx_t *ctx)
|
|
|
|
{
|
|
|
|
assert(ctx->top);
|
|
|
|
return ctx->stack + --ctx->top;
|
|
|
|
}
|
|
|
|
|
2011-09-22 14:23:51 +02:00
|
|
|
static inline VARIANT *stack_top(exec_ctx_t *ctx, unsigned n)
|
|
|
|
{
|
|
|
|
assert(ctx->top >= n);
|
|
|
|
return ctx->stack + (ctx->top-n-1);
|
|
|
|
}
|
|
|
|
|
2011-09-08 14:57:45 +02:00
|
|
|
static HRESULT stack_push(exec_ctx_t *ctx, VARIANT *v)
|
|
|
|
{
|
|
|
|
if(ctx->stack_size == ctx->top) {
|
|
|
|
VARIANT *new_stack;
|
|
|
|
|
2012-01-16 12:41:00 +01:00
|
|
|
new_stack = heap_realloc(ctx->stack, ctx->stack_size*2*sizeof(*ctx->stack));
|
2011-09-08 14:57:45 +02:00
|
|
|
if(!new_stack) {
|
|
|
|
VariantClear(v);
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx->stack = new_stack;
|
|
|
|
ctx->stack_size *= 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx->stack[ctx->top++] = *v;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2012-09-10 10:35:17 +02:00
|
|
|
static inline HRESULT stack_push_null(exec_ctx_t *ctx)
|
|
|
|
{
|
|
|
|
VARIANT v;
|
|
|
|
V_VT(&v) = VT_NULL;
|
|
|
|
return stack_push(ctx, &v);
|
|
|
|
}
|
|
|
|
|
2011-09-08 14:57:45 +02:00
|
|
|
static void stack_popn(exec_ctx_t *ctx, unsigned n)
|
|
|
|
{
|
|
|
|
while(n--)
|
|
|
|
VariantClear(stack_pop(ctx));
|
|
|
|
}
|
|
|
|
|
2014-03-08 14:53:10 +01:00
|
|
|
static void stack_pop_deref(exec_ctx_t *ctx, variant_val_t *r)
|
2011-09-09 14:47:55 +02:00
|
|
|
{
|
2014-03-08 14:53:10 +01:00
|
|
|
VARIANT *v;
|
2011-09-09 14:47:55 +02:00
|
|
|
|
2014-03-08 14:53:10 +01:00
|
|
|
v = stack_pop(ctx);
|
|
|
|
if(V_VT(v) == (VT_BYREF|VT_VARIANT)) {
|
|
|
|
r->owned = FALSE;
|
|
|
|
r->v = V_VARIANTREF(v);
|
2011-09-09 14:47:55 +02:00
|
|
|
}else {
|
2014-03-08 14:53:10 +01:00
|
|
|
r->owned = TRUE;
|
|
|
|
r->v = v;
|
2011-09-09 14:47:55 +02:00
|
|
|
}
|
2014-03-08 14:53:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void release_val(variant_val_t *v)
|
|
|
|
{
|
|
|
|
if(v->owned)
|
|
|
|
VariantClear(v->v);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT stack_pop_val(exec_ctx_t *ctx, variant_val_t *r)
|
|
|
|
{
|
|
|
|
stack_pop_deref(ctx, r);
|
2011-09-09 14:47:55 +02:00
|
|
|
|
2014-03-08 14:53:10 +01:00
|
|
|
if(V_VT(r->v) == VT_DISPATCH) {
|
2011-09-16 13:29:02 +02:00
|
|
|
HRESULT hres;
|
|
|
|
|
2015-03-05 15:49:02 +01:00
|
|
|
hres = get_disp_value(ctx->script, V_DISPATCH(r->v), &r->store);
|
2014-03-08 14:53:10 +01:00
|
|
|
if(r->owned)
|
|
|
|
IDispatch_Release(V_DISPATCH(r->v));
|
2011-09-16 13:29:02 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2014-03-08 14:53:10 +01:00
|
|
|
r->owned = TRUE;
|
|
|
|
r->v = &r->store;
|
2011-09-09 14:47:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2012-03-26 11:53:41 +02:00
|
|
|
static HRESULT stack_assume_val(exec_ctx_t *ctx, unsigned n)
|
|
|
|
{
|
|
|
|
VARIANT *v = stack_top(ctx, n);
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
if(V_VT(v) == (VT_BYREF|VT_VARIANT)) {
|
|
|
|
VARIANT *ref = V_VARIANTREF(v);
|
|
|
|
|
|
|
|
V_VT(v) = VT_EMPTY;
|
|
|
|
hres = VariantCopy(v, ref);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(V_VT(v) == VT_DISPATCH) {
|
|
|
|
IDispatch *disp;
|
|
|
|
|
|
|
|
disp = V_DISPATCH(v);
|
2015-03-05 15:49:02 +01:00
|
|
|
hres = get_disp_value(ctx->script, disp, v);
|
2012-03-26 11:53:41 +02:00
|
|
|
IDispatch_Release(disp);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2012-05-23 15:36:04 +02:00
|
|
|
static int stack_pop_bool(exec_ctx_t *ctx, BOOL *b)
|
|
|
|
{
|
|
|
|
variant_val_t val;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
hres = stack_pop_val(ctx, &val);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
switch (V_VT(val.v))
|
|
|
|
{
|
|
|
|
case VT_BOOL:
|
|
|
|
*b = V_BOOL(val.v);
|
|
|
|
break;
|
2012-09-10 10:35:29 +02:00
|
|
|
case VT_NULL:
|
|
|
|
*b = FALSE;
|
|
|
|
break;
|
2012-05-23 15:36:04 +02:00
|
|
|
case VT_I2:
|
|
|
|
*b = V_I2(val.v);
|
|
|
|
break;
|
|
|
|
case VT_I4:
|
|
|
|
*b = V_I4(val.v);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
FIXME("unsupported for %s\n", debugstr_variant(val.v));
|
|
|
|
release_val(&val);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2011-09-13 11:35:50 +02:00
|
|
|
static HRESULT stack_pop_disp(exec_ctx_t *ctx, IDispatch **ret)
|
|
|
|
{
|
|
|
|
VARIANT *v = stack_pop(ctx);
|
|
|
|
|
|
|
|
if(V_VT(v) == VT_DISPATCH) {
|
|
|
|
*ret = V_DISPATCH(v);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(V_VT(v) != (VT_VARIANT|VT_BYREF)) {
|
|
|
|
FIXME("not supported type: %s\n", debugstr_variant(v));
|
|
|
|
VariantClear(v);
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
v = V_BYREF(v);
|
|
|
|
if(V_VT(v) != VT_DISPATCH) {
|
|
|
|
FIXME("not disp %s\n", debugstr_variant(v));
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(V_DISPATCH(v))
|
|
|
|
IDispatch_AddRef(V_DISPATCH(v));
|
|
|
|
*ret = V_DISPATCH(v);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2012-03-26 11:53:08 +02:00
|
|
|
static HRESULT stack_assume_disp(exec_ctx_t *ctx, unsigned n, IDispatch **disp)
|
|
|
|
{
|
|
|
|
VARIANT *v = stack_top(ctx, n), *ref;
|
|
|
|
|
|
|
|
if(V_VT(v) != VT_DISPATCH) {
|
|
|
|
if(V_VT(v) != (VT_VARIANT|VT_BYREF)) {
|
|
|
|
FIXME("not supported type: %s\n", debugstr_variant(v));
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
ref = V_VARIANTREF(v);
|
|
|
|
if(V_VT(ref) != VT_DISPATCH) {
|
|
|
|
FIXME("not disp %s\n", debugstr_variant(ref));
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
V_VT(v) = VT_DISPATCH;
|
|
|
|
V_DISPATCH(v) = V_DISPATCH(ref);
|
|
|
|
if(V_DISPATCH(v))
|
|
|
|
IDispatch_AddRef(V_DISPATCH(v));
|
|
|
|
}
|
|
|
|
|
|
|
|
if(disp)
|
|
|
|
*disp = V_DISPATCH(v);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2011-09-13 11:38:58 +02:00
|
|
|
static inline void instr_jmp(exec_ctx_t *ctx, unsigned addr)
|
|
|
|
{
|
|
|
|
ctx->instr = ctx->code->instrs + addr;
|
|
|
|
}
|
|
|
|
|
2012-03-26 11:53:41 +02:00
|
|
|
static void vbstack_to_dp(exec_ctx_t *ctx, unsigned arg_cnt, BOOL is_propput, DISPPARAMS *dp)
|
2011-09-08 14:58:15 +02:00
|
|
|
{
|
2012-03-26 11:53:41 +02:00
|
|
|
dp->cNamedArgs = is_propput ? 1 : 0;
|
|
|
|
dp->cArgs = arg_cnt + dp->cNamedArgs;
|
|
|
|
dp->rgdispidNamedArgs = is_propput ? &propput_dispid : NULL;
|
2011-09-08 14:58:15 +02:00
|
|
|
|
|
|
|
if(arg_cnt) {
|
|
|
|
VARIANT tmp;
|
|
|
|
unsigned i;
|
|
|
|
|
|
|
|
assert(ctx->top >= arg_cnt);
|
|
|
|
|
|
|
|
for(i=1; i*2 <= arg_cnt; i++) {
|
|
|
|
tmp = ctx->stack[ctx->top-i];
|
|
|
|
ctx->stack[ctx->top-i] = ctx->stack[ctx->top-arg_cnt+i-1];
|
|
|
|
ctx->stack[ctx->top-arg_cnt+i-1] = tmp;
|
|
|
|
}
|
|
|
|
|
2012-03-26 11:53:41 +02:00
|
|
|
dp->rgvarg = ctx->stack + ctx->top-dp->cArgs;
|
2011-09-08 14:58:15 +02:00
|
|
|
}else {
|
2012-03-26 11:53:41 +02:00
|
|
|
dp->rgvarg = is_propput ? ctx->stack+ctx->top-1 : NULL;
|
2011-09-08 14:58:15 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-13 16:29:39 +01:00
|
|
|
static HRESULT array_access(exec_ctx_t *ctx, SAFEARRAY *array, DISPPARAMS *dp, VARIANT **ret)
|
|
|
|
{
|
2017-10-10 17:08:46 +02:00
|
|
|
unsigned i, argc = arg_cnt(dp);
|
|
|
|
LONG *indices;
|
2013-11-13 16:29:39 +01:00
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
if(!array) {
|
|
|
|
FIXME("NULL array\n");
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
2017-10-10 17:08:46 +02:00
|
|
|
hres = SafeArrayLock(array);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2013-11-13 16:29:39 +01:00
|
|
|
if(array->cDims != argc) {
|
|
|
|
FIXME("argc %d does not match cDims %d\n", dp->cArgs, array->cDims);
|
2017-10-10 17:08:46 +02:00
|
|
|
SafeArrayUnlock(array);
|
2013-11-13 16:29:39 +01:00
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
2017-10-10 17:08:46 +02:00
|
|
|
indices = heap_alloc(sizeof(*indices) * argc);
|
|
|
|
if(!indices) {
|
|
|
|
SafeArrayUnlock(array);
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
2013-11-13 16:29:39 +01:00
|
|
|
|
2017-10-10 17:08:46 +02:00
|
|
|
for(i=0; i<argc; i++) {
|
|
|
|
hres = to_int(get_arg(dp, i), indices+i);
|
|
|
|
if(FAILED(hres)) {
|
|
|
|
heap_free(indices);
|
|
|
|
SafeArrayUnlock(array);
|
|
|
|
return hres;
|
2013-11-13 16:29:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-10 17:08:46 +02:00
|
|
|
hres = SafeArrayPtrOfIndex(array, indices, (void**)ret);
|
|
|
|
SafeArrayUnlock(array);
|
|
|
|
heap_free(indices);
|
|
|
|
return hres;
|
2013-11-13 16:29:39 +01:00
|
|
|
}
|
|
|
|
|
2011-09-09 14:49:00 +02:00
|
|
|
static HRESULT do_icall(exec_ctx_t *ctx, VARIANT *res)
|
2011-09-07 14:08:47 +02:00
|
|
|
{
|
2011-09-08 14:54:37 +02:00
|
|
|
BSTR identifier = ctx->instr->arg1.bstr;
|
2011-09-08 14:57:16 +02:00
|
|
|
const unsigned arg_cnt = ctx->instr->arg2.uint;
|
2011-09-08 14:58:15 +02:00
|
|
|
DISPPARAMS dp;
|
2011-09-19 14:09:21 +02:00
|
|
|
ref_t ref;
|
2011-09-08 14:54:37 +02:00
|
|
|
HRESULT hres;
|
|
|
|
|
2011-09-14 12:58:30 +02:00
|
|
|
hres = lookup_identifier(ctx, identifier, VBDISP_CALLGET, &ref);
|
2011-09-08 14:54:37 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
switch(ref.type) {
|
2011-09-13 11:37:08 +02:00
|
|
|
case REF_VAR:
|
2013-11-13 16:29:39 +01:00
|
|
|
case REF_CONST: {
|
|
|
|
VARIANT *v;
|
|
|
|
|
2011-09-13 11:37:08 +02:00
|
|
|
if(!res) {
|
|
|
|
FIXME("REF_VAR no res\n");
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2013-11-13 16:29:39 +01:00
|
|
|
v = V_VT(ref.u.v) == (VT_VARIANT|VT_BYREF) ? V_VARIANTREF(ref.u.v) : ref.u.v;
|
|
|
|
|
2011-09-13 11:37:08 +02:00
|
|
|
if(arg_cnt) {
|
2014-07-21 18:07:40 +02:00
|
|
|
SAFEARRAY *array = NULL;
|
2013-11-13 16:29:39 +01:00
|
|
|
|
|
|
|
switch(V_VT(v)) {
|
|
|
|
case VT_ARRAY|VT_BYREF|VT_VARIANT:
|
|
|
|
array = *V_ARRAYREF(ref.u.v);
|
|
|
|
break;
|
|
|
|
case VT_ARRAY|VT_VARIANT:
|
|
|
|
array = V_ARRAY(ref.u.v);
|
|
|
|
break;
|
2014-07-21 18:07:40 +02:00
|
|
|
case VT_DISPATCH:
|
|
|
|
vbstack_to_dp(ctx, arg_cnt, FALSE, &dp);
|
|
|
|
hres = disp_call(ctx->script, V_DISPATCH(v), DISPID_VALUE, &dp, res);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
break;
|
2013-11-13 16:29:39 +01:00
|
|
|
default:
|
|
|
|
FIXME("arguments not implemented\n");
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2014-07-21 18:07:40 +02:00
|
|
|
if(!array)
|
|
|
|
break;
|
|
|
|
|
2013-11-13 16:29:39 +01:00
|
|
|
vbstack_to_dp(ctx, arg_cnt, FALSE, &dp);
|
|
|
|
hres = array_access(ctx, array, &dp, &v);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
2011-09-13 11:37:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
V_VT(res) = VT_BYREF|VT_VARIANT;
|
2013-11-13 16:29:39 +01:00
|
|
|
V_BYREF(res) = v;
|
2011-09-13 11:37:08 +02:00
|
|
|
break;
|
2013-11-13 16:29:39 +01:00
|
|
|
}
|
2011-09-08 14:54:37 +02:00
|
|
|
case REF_DISP:
|
2013-11-13 16:29:39 +01:00
|
|
|
vbstack_to_dp(ctx, arg_cnt, FALSE, &dp);
|
2011-09-09 14:49:00 +02:00
|
|
|
hres = disp_call(ctx->script, ref.u.d.disp, ref.u.d.id, &dp, res);
|
2011-09-08 14:54:37 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
break;
|
2011-09-14 12:55:42 +02:00
|
|
|
case REF_FUNC:
|
2013-11-13 16:29:39 +01:00
|
|
|
vbstack_to_dp(ctx, arg_cnt, FALSE, &dp);
|
2011-09-15 14:21:58 +02:00
|
|
|
hres = exec_script(ctx->script, ref.u.f, NULL, &dp, res);
|
2011-09-14 12:56:01 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
break;
|
2011-09-19 14:09:21 +02:00
|
|
|
case REF_OBJ:
|
|
|
|
if(arg_cnt) {
|
|
|
|
FIXME("arguments on object\n");
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(res) {
|
|
|
|
IDispatch_AddRef(ref.u.obj);
|
|
|
|
V_VT(res) = VT_DISPATCH;
|
|
|
|
V_DISPATCH(res) = ref.u.obj;
|
|
|
|
}
|
|
|
|
break;
|
2011-09-13 11:37:08 +02:00
|
|
|
case REF_NONE:
|
2012-10-10 17:16:27 +02:00
|
|
|
if(res && !ctx->func->code_ctx->option_explicit && arg_cnt == 0) {
|
2015-03-03 14:41:17 +01:00
|
|
|
VARIANT *new;
|
|
|
|
hres = add_dynamic_var(ctx, identifier, FALSE, &new);
|
2012-10-10 17:16:27 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
V_VT(res) = VT_BYREF|VT_VARIANT;
|
|
|
|
V_BYREF(res) = new;
|
|
|
|
break;
|
|
|
|
}
|
2011-09-08 14:54:37 +02:00
|
|
|
FIXME("%s not found\n", debugstr_w(identifier));
|
|
|
|
return DISP_E_UNKNOWNNAME;
|
|
|
|
}
|
|
|
|
|
2011-09-08 14:58:15 +02:00
|
|
|
stack_popn(ctx, arg_cnt);
|
2011-09-08 14:54:37 +02:00
|
|
|
return S_OK;
|
2011-09-07 14:08:47 +02:00
|
|
|
}
|
|
|
|
|
2011-09-09 14:49:00 +02:00
|
|
|
static HRESULT interp_icall(exec_ctx_t *ctx)
|
|
|
|
{
|
|
|
|
VARIANT v;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
hres = do_icall(ctx, &v);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
return stack_push(ctx, &v);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT interp_icallv(exec_ctx_t *ctx)
|
|
|
|
{
|
|
|
|
TRACE("\n");
|
|
|
|
return do_icall(ctx, NULL);
|
|
|
|
}
|
|
|
|
|
2011-09-15 14:19:41 +02:00
|
|
|
static HRESULT do_mcall(exec_ctx_t *ctx, VARIANT *res)
|
|
|
|
{
|
|
|
|
const BSTR identifier = ctx->instr->arg1.bstr;
|
|
|
|
const unsigned arg_cnt = ctx->instr->arg2.uint;
|
|
|
|
IDispatch *obj;
|
|
|
|
DISPPARAMS dp;
|
|
|
|
DISPID id;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
hres = stack_pop_disp(ctx, &obj);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
if(!obj) {
|
|
|
|
FIXME("NULL obj\n");
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
2012-03-26 11:53:41 +02:00
|
|
|
vbstack_to_dp(ctx, arg_cnt, FALSE, &dp);
|
2011-09-15 14:19:41 +02:00
|
|
|
|
2011-09-16 13:28:18 +02:00
|
|
|
hres = disp_get_id(obj, identifier, VBDISP_CALLGET, FALSE, &id);
|
2011-09-15 14:19:41 +02:00
|
|
|
if(SUCCEEDED(hres))
|
|
|
|
hres = disp_call(ctx->script, obj, id, &dp, res);
|
|
|
|
IDispatch_Release(obj);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
stack_popn(ctx, arg_cnt);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT interp_mcall(exec_ctx_t *ctx)
|
|
|
|
{
|
|
|
|
VARIANT res;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
hres = do_mcall(ctx, &res);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
return stack_push(ctx, &res);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT interp_mcallv(exec_ctx_t *ctx)
|
|
|
|
{
|
2011-09-15 14:21:44 +02:00
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
return do_mcall(ctx, NULL);
|
2011-09-15 14:19:41 +02:00
|
|
|
}
|
|
|
|
|
2015-03-03 14:41:30 +01:00
|
|
|
static HRESULT assign_value(exec_ctx_t *ctx, VARIANT *dst, VARIANT *src, WORD flags)
|
|
|
|
{
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
hres = VariantCopyInd(dst, src);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
if(V_VT(dst) == VT_DISPATCH && !(flags & DISPATCH_PROPERTYPUTREF)) {
|
|
|
|
VARIANT value;
|
|
|
|
|
2015-03-05 15:49:02 +01:00
|
|
|
hres = get_disp_value(ctx->script, V_DISPATCH(dst), &value);
|
2015-03-03 14:41:30 +01:00
|
|
|
IDispatch_Release(V_DISPATCH(dst));
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
*dst = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2015-03-03 14:40:36 +01:00
|
|
|
static HRESULT assign_ident(exec_ctx_t *ctx, BSTR name, WORD flags, DISPPARAMS *dp)
|
2011-09-12 12:33:03 +02:00
|
|
|
{
|
|
|
|
ref_t ref;
|
|
|
|
HRESULT hres;
|
|
|
|
|
2011-09-14 12:58:30 +02:00
|
|
|
hres = lookup_identifier(ctx, name, VBDISP_LET, &ref);
|
2011-09-12 12:33:03 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
switch(ref.type) {
|
2011-09-13 11:37:24 +02:00
|
|
|
case REF_VAR: {
|
|
|
|
VARIANT *v = ref.u.v;
|
|
|
|
|
2013-11-13 16:29:53 +01:00
|
|
|
if(V_VT(v) == (VT_VARIANT|VT_BYREF))
|
|
|
|
v = V_VARIANTREF(v);
|
|
|
|
|
2012-03-26 11:53:41 +02:00
|
|
|
if(arg_cnt(dp)) {
|
2013-11-13 16:29:53 +01:00
|
|
|
SAFEARRAY *array;
|
|
|
|
|
|
|
|
if(!(V_VT(v) & VT_ARRAY)) {
|
|
|
|
FIXME("array assign on type %d\n", V_VT(v));
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch(V_VT(v)) {
|
|
|
|
case VT_ARRAY|VT_BYREF|VT_VARIANT:
|
|
|
|
array = *V_ARRAYREF(v);
|
|
|
|
break;
|
|
|
|
case VT_ARRAY|VT_VARIANT:
|
|
|
|
array = V_ARRAY(v);
|
|
|
|
break;
|
|
|
|
default:
|
2013-11-14 10:02:24 +01:00
|
|
|
FIXME("Unsupported array type %x\n", V_VT(v));
|
2013-11-13 16:29:53 +01:00
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!array) {
|
|
|
|
FIXME("null array\n");
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
hres = array_access(ctx, array, dp, &v);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
}else if(V_VT(v) == (VT_ARRAY|VT_BYREF|VT_VARIANT)) {
|
|
|
|
FIXME("non-array assign\n");
|
2012-03-26 11:53:41 +02:00
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2015-03-03 14:41:30 +01:00
|
|
|
hres = assign_value(ctx, v, dp->rgvarg, flags);
|
2011-09-13 11:37:08 +02:00
|
|
|
break;
|
2011-09-13 11:37:24 +02:00
|
|
|
}
|
2011-09-12 12:33:03 +02:00
|
|
|
case REF_DISP:
|
2015-03-03 14:40:36 +01:00
|
|
|
hres = disp_propput(ctx->script, ref.u.d.disp, ref.u.d.id, flags, dp);
|
2011-09-12 12:33:03 +02:00
|
|
|
break;
|
2011-09-14 12:55:42 +02:00
|
|
|
case REF_FUNC:
|
|
|
|
FIXME("functions not implemented\n");
|
|
|
|
return E_NOTIMPL;
|
2011-09-19 14:09:21 +02:00
|
|
|
case REF_OBJ:
|
|
|
|
FIXME("REF_OBJ\n");
|
|
|
|
return E_NOTIMPL;
|
2011-09-21 14:04:16 +02:00
|
|
|
case REF_CONST:
|
|
|
|
FIXME("REF_CONST\n");
|
|
|
|
return E_NOTIMPL;
|
2011-09-21 14:03:50 +02:00
|
|
|
case REF_NONE:
|
2011-09-20 14:59:53 +02:00
|
|
|
if(ctx->func->code_ctx->option_explicit) {
|
|
|
|
FIXME("throw exception\n");
|
2011-09-21 14:03:50 +02:00
|
|
|
hres = E_FAIL;
|
2011-09-20 14:59:53 +02:00
|
|
|
}else {
|
2015-03-03 14:41:17 +01:00
|
|
|
VARIANT *new_var;
|
|
|
|
|
2012-03-26 11:53:41 +02:00
|
|
|
if(arg_cnt(dp)) {
|
|
|
|
FIXME("arg_cnt %d not supported\n", arg_cnt(dp));
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2011-09-21 14:03:50 +02:00
|
|
|
TRACE("creating variable %s\n", debugstr_w(name));
|
2015-03-03 14:41:17 +01:00
|
|
|
hres = add_dynamic_var(ctx, name, FALSE, &new_var);
|
|
|
|
if(SUCCEEDED(hres))
|
2015-03-03 14:41:30 +01:00
|
|
|
hres = assign_value(ctx, new_var, dp->rgvarg, flags);
|
2011-09-20 14:59:53 +02:00
|
|
|
}
|
2011-09-12 12:33:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
2011-09-12 12:32:50 +02:00
|
|
|
static HRESULT interp_assign_ident(exec_ctx_t *ctx)
|
|
|
|
{
|
2011-09-12 12:33:03 +02:00
|
|
|
const BSTR arg = ctx->instr->arg1.bstr;
|
2011-12-27 16:17:21 +01:00
|
|
|
const unsigned arg_cnt = ctx->instr->arg2.uint;
|
2012-03-26 11:53:41 +02:00
|
|
|
DISPPARAMS dp;
|
2011-09-12 12:33:03 +02:00
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("%s\n", debugstr_w(arg));
|
|
|
|
|
2012-03-26 11:53:41 +02:00
|
|
|
vbstack_to_dp(ctx, arg_cnt, TRUE, &dp);
|
2015-03-03 14:40:36 +01:00
|
|
|
hres = assign_ident(ctx, arg, DISPATCH_PROPERTYPUT, &dp);
|
2011-09-12 12:33:03 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2012-03-26 11:53:41 +02:00
|
|
|
stack_popn(ctx, arg_cnt+1);
|
|
|
|
return S_OK;
|
2011-09-12 12:32:50 +02:00
|
|
|
}
|
|
|
|
|
2011-09-15 14:17:38 +02:00
|
|
|
static HRESULT interp_set_ident(exec_ctx_t *ctx)
|
|
|
|
{
|
|
|
|
const BSTR arg = ctx->instr->arg1.bstr;
|
2011-12-27 16:17:21 +01:00
|
|
|
const unsigned arg_cnt = ctx->instr->arg2.uint;
|
2012-03-26 11:53:41 +02:00
|
|
|
DISPPARAMS dp;
|
2011-09-15 14:17:51 +02:00
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("%s\n", debugstr_w(arg));
|
|
|
|
|
2011-12-27 16:17:21 +01:00
|
|
|
if(arg_cnt) {
|
|
|
|
FIXME("arguments not supported\n");
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2012-03-26 11:53:41 +02:00
|
|
|
hres = stack_assume_disp(ctx, 0, NULL);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
vbstack_to_dp(ctx, 0, TRUE, &dp);
|
2015-03-03 14:40:36 +01:00
|
|
|
hres = assign_ident(ctx, ctx->instr->arg1.bstr, DISPATCH_PROPERTYPUTREF, &dp);
|
2011-09-15 14:17:51 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2012-03-26 11:53:41 +02:00
|
|
|
stack_popn(ctx, 1);
|
|
|
|
return S_OK;
|
2011-09-15 14:17:38 +02:00
|
|
|
}
|
|
|
|
|
2011-09-13 11:35:33 +02:00
|
|
|
static HRESULT interp_assign_member(exec_ctx_t *ctx)
|
|
|
|
{
|
2011-09-13 11:35:50 +02:00
|
|
|
BSTR identifier = ctx->instr->arg1.bstr;
|
2011-12-27 16:17:21 +01:00
|
|
|
const unsigned arg_cnt = ctx->instr->arg2.uint;
|
2011-09-13 11:35:50 +02:00
|
|
|
IDispatch *obj;
|
2012-03-26 11:53:41 +02:00
|
|
|
DISPPARAMS dp;
|
2011-09-13 11:35:50 +02:00
|
|
|
DISPID id;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("%s\n", debugstr_w(identifier));
|
|
|
|
|
2012-03-26 11:53:08 +02:00
|
|
|
hres = stack_assume_disp(ctx, arg_cnt+1, &obj);
|
2011-09-13 11:35:50 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
if(!obj) {
|
|
|
|
FIXME("NULL obj\n");
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
2011-09-16 13:28:18 +02:00
|
|
|
hres = disp_get_id(obj, identifier, VBDISP_LET, FALSE, &id);
|
2012-03-26 11:53:41 +02:00
|
|
|
if(SUCCEEDED(hres)) {
|
|
|
|
vbstack_to_dp(ctx, arg_cnt, TRUE, &dp);
|
2015-03-03 14:40:36 +01:00
|
|
|
hres = disp_propput(ctx->script, obj, id, DISPATCH_PROPERTYPUT, &dp);
|
2012-03-26 11:53:41 +02:00
|
|
|
}
|
2012-03-26 11:53:08 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2012-03-26 11:54:54 +02:00
|
|
|
stack_popn(ctx, arg_cnt+2);
|
2012-03-26 11:53:08 +02:00
|
|
|
return S_OK;
|
2011-09-13 11:35:33 +02:00
|
|
|
}
|
|
|
|
|
2011-09-15 14:17:38 +02:00
|
|
|
static HRESULT interp_set_member(exec_ctx_t *ctx)
|
|
|
|
{
|
|
|
|
BSTR identifier = ctx->instr->arg1.bstr;
|
2011-12-27 16:17:21 +01:00
|
|
|
const unsigned arg_cnt = ctx->instr->arg2.uint;
|
2012-03-26 11:53:08 +02:00
|
|
|
IDispatch *obj;
|
2012-03-26 11:53:41 +02:00
|
|
|
DISPPARAMS dp;
|
2011-09-16 13:28:42 +02:00
|
|
|
DISPID id;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("%s\n", debugstr_w(identifier));
|
|
|
|
|
2011-12-27 16:17:21 +01:00
|
|
|
if(arg_cnt) {
|
|
|
|
FIXME("arguments not supported\n");
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2012-03-26 11:53:08 +02:00
|
|
|
hres = stack_assume_disp(ctx, 1, &obj);
|
2011-09-16 13:28:42 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
if(!obj) {
|
|
|
|
FIXME("NULL obj\n");
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
2012-03-26 11:53:08 +02:00
|
|
|
hres = stack_assume_disp(ctx, 0, NULL);
|
|
|
|
if(FAILED(hres))
|
2011-09-16 13:28:42 +02:00
|
|
|
return hres;
|
|
|
|
|
|
|
|
hres = disp_get_id(obj, identifier, VBDISP_SET, FALSE, &id);
|
2012-03-26 11:53:41 +02:00
|
|
|
if(SUCCEEDED(hres)) {
|
|
|
|
vbstack_to_dp(ctx, arg_cnt, TRUE, &dp);
|
2015-03-03 14:40:36 +01:00
|
|
|
hres = disp_propput(ctx->script, obj, id, DISPATCH_PROPERTYPUTREF, &dp);
|
2012-03-26 11:53:41 +02:00
|
|
|
}
|
2012-03-26 11:53:08 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
2011-09-16 13:28:42 +02:00
|
|
|
|
2012-03-26 11:53:08 +02:00
|
|
|
stack_popn(ctx, 2);
|
|
|
|
return S_OK;
|
2011-09-15 14:17:38 +02:00
|
|
|
}
|
|
|
|
|
2011-09-21 14:03:38 +02:00
|
|
|
static HRESULT interp_const(exec_ctx_t *ctx)
|
|
|
|
{
|
|
|
|
BSTR arg = ctx->instr->arg1.bstr;
|
2015-03-03 14:41:17 +01:00
|
|
|
VARIANT *v;
|
2011-09-21 14:04:16 +02:00
|
|
|
ref_t ref;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("%s\n", debugstr_w(arg));
|
|
|
|
|
|
|
|
assert(ctx->func->type == FUNC_GLOBAL);
|
|
|
|
|
|
|
|
hres = lookup_identifier(ctx, arg, VBDISP_CALLGET, &ref);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
if(ref.type != REF_NONE) {
|
|
|
|
FIXME("%s already defined\n", debugstr_w(arg));
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
2015-03-03 14:41:17 +01:00
|
|
|
hres = stack_assume_val(ctx, 0);
|
2011-09-21 14:04:16 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2015-03-03 14:41:17 +01:00
|
|
|
hres = add_dynamic_var(ctx, arg, TRUE, &v);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
*v = *stack_pop(ctx);
|
|
|
|
return S_OK;
|
2011-09-21 14:03:38 +02:00
|
|
|
}
|
|
|
|
|
2011-09-22 14:23:10 +02:00
|
|
|
static HRESULT interp_val(exec_ctx_t *ctx)
|
|
|
|
{
|
2011-09-22 14:23:25 +02:00
|
|
|
variant_val_t val;
|
|
|
|
VARIANT v;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
hres = stack_pop_val(ctx, &val);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
if(!val.owned) {
|
|
|
|
V_VT(&v) = VT_EMPTY;
|
|
|
|
hres = VariantCopy(&v, val.v);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
|
|
|
return stack_push(ctx, val.owned ? val.v : &v);
|
2011-09-22 14:23:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT interp_pop(exec_ctx_t *ctx)
|
|
|
|
{
|
|
|
|
const unsigned n = ctx->instr->arg1.uint;
|
|
|
|
|
|
|
|
TRACE("%u\n", n);
|
|
|
|
|
|
|
|
stack_popn(ctx, n);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2011-09-15 14:18:12 +02:00
|
|
|
static HRESULT interp_new(exec_ctx_t *ctx)
|
|
|
|
{
|
|
|
|
const WCHAR *arg = ctx->instr->arg1.bstr;
|
2011-09-15 14:18:29 +02:00
|
|
|
class_desc_t *class_desc;
|
|
|
|
vbdisp_t *obj;
|
|
|
|
VARIANT v;
|
|
|
|
HRESULT hres;
|
|
|
|
|
2014-03-18 15:52:13 +01:00
|
|
|
static const WCHAR regexpW[] = {'r','e','g','e','x','p',0};
|
|
|
|
|
2011-09-15 14:18:29 +02:00
|
|
|
TRACE("%s\n", debugstr_w(arg));
|
|
|
|
|
2019-06-25 08:38:01 +02:00
|
|
|
if(!wcsicmp(arg, regexpW)) {
|
2014-03-18 15:52:13 +01:00
|
|
|
V_VT(&v) = VT_DISPATCH;
|
|
|
|
hres = create_regexp(&V_DISPATCH(&v));
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
return stack_push(ctx, &v);
|
|
|
|
}
|
|
|
|
|
2011-09-15 14:18:29 +02:00
|
|
|
for(class_desc = ctx->script->classes; class_desc; class_desc = class_desc->next) {
|
2019-06-25 08:38:01 +02:00
|
|
|
if(!wcsicmp(class_desc->name, arg))
|
2011-09-15 14:18:29 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if(!class_desc) {
|
|
|
|
FIXME("Class %s not found\n", debugstr_w(arg));
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
2011-09-15 14:18:43 +02:00
|
|
|
hres = create_vbdisp(class_desc, &obj);
|
2011-09-15 14:18:29 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
V_VT(&v) = VT_DISPATCH;
|
|
|
|
V_DISPATCH(&v) = (IDispatch*)&obj->IDispatchEx_iface;
|
|
|
|
return stack_push(ctx, &v);
|
2011-09-15 14:18:12 +02:00
|
|
|
}
|
|
|
|
|
2013-11-13 16:29:18 +01:00
|
|
|
static HRESULT interp_dim(exec_ctx_t *ctx)
|
|
|
|
{
|
|
|
|
const BSTR ident = ctx->instr->arg1.bstr;
|
|
|
|
const unsigned array_id = ctx->instr->arg2.uint;
|
2013-11-22 16:48:33 +01:00
|
|
|
const array_desc_t *array_desc;
|
2013-11-13 16:29:29 +01:00
|
|
|
ref_t ref;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("%s\n", debugstr_w(ident));
|
|
|
|
|
|
|
|
assert(array_id < ctx->func->array_cnt);
|
|
|
|
if(!ctx->arrays) {
|
|
|
|
ctx->arrays = heap_alloc_zero(ctx->func->array_cnt * sizeof(SAFEARRAY*));
|
|
|
|
if(!ctx->arrays)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
hres = lookup_identifier(ctx, ident, VBDISP_LET, &ref);
|
|
|
|
if(FAILED(hres)) {
|
|
|
|
FIXME("lookup %s failed: %08x\n", debugstr_w(ident), hres);
|
|
|
|
return hres;
|
|
|
|
}
|
2013-11-13 16:29:18 +01:00
|
|
|
|
2013-11-13 16:29:29 +01:00
|
|
|
if(ref.type != REF_VAR) {
|
|
|
|
FIXME("got ref.type = %d\n", ref.type);
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
2013-11-22 16:48:33 +01:00
|
|
|
if(ctx->arrays[array_id]) {
|
|
|
|
FIXME("Array already initialized\n");
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
2013-11-13 16:29:29 +01:00
|
|
|
|
2013-11-22 16:48:33 +01:00
|
|
|
array_desc = ctx->func->array_descs + array_id;
|
|
|
|
if(array_desc->dim_cnt) {
|
|
|
|
ctx->arrays[array_id] = SafeArrayCreate(VT_VARIANT, array_desc->dim_cnt, array_desc->bounds);
|
|
|
|
if(!ctx->arrays[array_id])
|
|
|
|
return E_OUTOFMEMORY;
|
2013-11-13 16:29:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
V_VT(ref.u.v) = VT_ARRAY|VT_BYREF|VT_VARIANT;
|
|
|
|
V_ARRAYREF(ref.u.v) = ctx->arrays+array_id;
|
|
|
|
return S_OK;
|
2013-11-13 16:29:18 +01:00
|
|
|
}
|
|
|
|
|
2011-09-22 14:23:10 +02:00
|
|
|
static HRESULT interp_step(exec_ctx_t *ctx)
|
|
|
|
{
|
|
|
|
const BSTR ident = ctx->instr->arg2.bstr;
|
2011-09-22 14:23:51 +02:00
|
|
|
BOOL gteq_zero;
|
|
|
|
VARIANT zero;
|
|
|
|
ref_t ref;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("%s\n", debugstr_w(ident));
|
|
|
|
|
|
|
|
V_VT(&zero) = VT_I2;
|
|
|
|
V_I2(&zero) = 0;
|
|
|
|
hres = VarCmp(stack_top(ctx, 0), &zero, ctx->script->lcid, 0);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
gteq_zero = hres == VARCMP_GT || hres == VARCMP_EQ;
|
|
|
|
|
|
|
|
hres = lookup_identifier(ctx, ident, VBDISP_ANY, &ref);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
if(ref.type != REF_VAR) {
|
|
|
|
FIXME("%s is not REF_VAR\n", debugstr_w(ident));
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
hres = VarCmp(ref.u.v, stack_top(ctx, 1), ctx->script->lcid, 0);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2012-07-03 19:17:23 +02:00
|
|
|
if(hres == VARCMP_EQ || hres == (gteq_zero ? VARCMP_LT : VARCMP_GT)) {
|
2011-09-22 14:23:51 +02:00
|
|
|
ctx->instr++;
|
2012-07-03 19:17:23 +02:00
|
|
|
}else {
|
|
|
|
stack_popn(ctx, 2);
|
2011-09-22 14:23:51 +02:00
|
|
|
instr_jmp(ctx, ctx->instr->arg1.uint);
|
2012-07-03 19:17:23 +02:00
|
|
|
}
|
2011-09-22 14:23:51 +02:00
|
|
|
return S_OK;
|
2011-09-22 14:23:10 +02:00
|
|
|
}
|
|
|
|
|
2012-07-03 17:05:32 +02:00
|
|
|
static HRESULT interp_newenum(exec_ctx_t *ctx)
|
|
|
|
{
|
2014-03-08 14:53:10 +01:00
|
|
|
variant_val_t v;
|
2014-03-21 14:37:39 +01:00
|
|
|
VARIANT *r;
|
2012-07-03 17:05:32 +02:00
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
2014-03-08 14:53:10 +01:00
|
|
|
stack_pop_deref(ctx, &v);
|
2014-03-21 14:37:39 +01:00
|
|
|
assert(V_VT(stack_top(ctx, 0)) == VT_EMPTY);
|
|
|
|
r = stack_top(ctx, 0);
|
2014-03-08 14:53:10 +01:00
|
|
|
|
|
|
|
switch(V_VT(v.v)) {
|
2014-02-05 06:05:17 +01:00
|
|
|
case VT_DISPATCH|VT_BYREF:
|
2012-07-03 17:05:32 +02:00
|
|
|
case VT_DISPATCH: {
|
|
|
|
IEnumVARIANT *iter;
|
|
|
|
DISPPARAMS dp = {0};
|
|
|
|
VARIANT iterv;
|
|
|
|
|
2014-03-08 14:53:10 +01:00
|
|
|
hres = disp_call(ctx->script, V_ISBYREF(v.v) ? *V_DISPATCHREF(v.v) : V_DISPATCH(v.v), DISPID_NEWENUM, &dp, &iterv);
|
|
|
|
release_val(&v);
|
2012-07-03 17:05:32 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
if(V_VT(&iterv) != VT_UNKNOWN && V_VT(&iterv) != VT_DISPATCH) {
|
|
|
|
FIXME("Unsupported iterv %s\n", debugstr_variant(&iterv));
|
|
|
|
VariantClear(&iterv);
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
|
|
|
hres = IUnknown_QueryInterface(V_UNKNOWN(&iterv), &IID_IEnumVARIANT, (void**)&iter);
|
|
|
|
IUnknown_Release(V_UNKNOWN(&iterv));
|
|
|
|
if(FAILED(hres)) {
|
|
|
|
FIXME("Could not get IEnumVARIANT iface: %08x\n", hres);
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
2014-03-21 14:37:39 +01:00
|
|
|
V_VT(r) = VT_UNKNOWN;
|
|
|
|
V_UNKNOWN(r) = (IUnknown*)iter;
|
2012-07-03 17:05:32 +02:00
|
|
|
break;
|
|
|
|
}
|
2017-11-08 15:05:01 +01:00
|
|
|
case VT_VARIANT|VT_ARRAY:
|
|
|
|
case VT_VARIANT|VT_ARRAY|VT_BYREF: {
|
|
|
|
IEnumVARIANT *iter;
|
|
|
|
|
|
|
|
hres = create_safearray_iter(V_ISBYREF(v.v) ? *V_ARRAYREF(v.v) : V_ARRAY(v.v), &iter);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
V_VT(r) = VT_UNKNOWN;
|
|
|
|
V_UNKNOWN(r) = (IUnknown*)iter;
|
|
|
|
break;
|
|
|
|
}
|
2012-07-03 17:05:32 +02:00
|
|
|
default:
|
2014-03-08 14:53:10 +01:00
|
|
|
FIXME("Unsupported for %s\n", debugstr_variant(v.v));
|
|
|
|
release_val(&v);
|
2012-07-03 17:05:32 +02:00
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2014-03-21 14:37:39 +01:00
|
|
|
return S_OK;
|
2012-07-03 17:05:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT interp_enumnext(exec_ctx_t *ctx)
|
|
|
|
{
|
|
|
|
const unsigned loop_end = ctx->instr->arg1.uint;
|
|
|
|
const BSTR ident = ctx->instr->arg2.bstr;
|
|
|
|
VARIANT v;
|
|
|
|
DISPPARAMS dp = {&v, &propput_dispid, 1, 1};
|
|
|
|
IEnumVARIANT *iter;
|
|
|
|
BOOL do_continue;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
2014-03-21 14:37:39 +01:00
|
|
|
if(V_VT(stack_top(ctx, 0)) == VT_EMPTY) {
|
|
|
|
FIXME("uninitialized\n");
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
2012-07-03 17:05:32 +02:00
|
|
|
assert(V_VT(stack_top(ctx, 0)) == VT_UNKNOWN);
|
|
|
|
iter = (IEnumVARIANT*)V_UNKNOWN(stack_top(ctx, 0));
|
|
|
|
|
|
|
|
V_VT(&v) = VT_EMPTY;
|
|
|
|
hres = IEnumVARIANT_Next(iter, 1, &v, NULL);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
do_continue = hres == S_OK;
|
2015-03-03 14:40:36 +01:00
|
|
|
hres = assign_ident(ctx, ident, DISPATCH_PROPERTYPUT|DISPATCH_PROPERTYPUTREF, &dp);
|
2012-07-03 17:05:32 +02:00
|
|
|
VariantClear(&v);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
if(do_continue) {
|
|
|
|
ctx->instr++;
|
|
|
|
}else {
|
2017-11-08 18:11:56 +01:00
|
|
|
stack_popn(ctx, 1);
|
2012-07-03 17:05:32 +02:00
|
|
|
instr_jmp(ctx, loop_end);
|
|
|
|
}
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2011-09-13 11:38:38 +02:00
|
|
|
static HRESULT interp_jmp(exec_ctx_t *ctx)
|
|
|
|
{
|
2011-09-13 11:38:58 +02:00
|
|
|
const unsigned arg = ctx->instr->arg1.uint;
|
|
|
|
|
|
|
|
TRACE("%u\n", arg);
|
|
|
|
|
|
|
|
instr_jmp(ctx, arg);
|
|
|
|
return S_OK;
|
2011-09-13 11:38:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT interp_jmp_false(exec_ctx_t *ctx)
|
|
|
|
{
|
2011-09-13 11:39:13 +02:00
|
|
|
const unsigned arg = ctx->instr->arg1.uint;
|
|
|
|
HRESULT hres;
|
2012-05-23 15:36:04 +02:00
|
|
|
BOOL b;
|
2011-09-13 11:39:13 +02:00
|
|
|
|
|
|
|
TRACE("%u\n", arg);
|
|
|
|
|
2012-05-23 15:36:04 +02:00
|
|
|
hres = stack_pop_bool(ctx, &b);
|
2011-09-13 23:45:23 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2012-05-23 15:36:04 +02:00
|
|
|
if(b)
|
2011-09-13 11:39:13 +02:00
|
|
|
ctx->instr++;
|
|
|
|
else
|
|
|
|
instr_jmp(ctx, ctx->instr->arg1.uint);
|
|
|
|
return S_OK;
|
2011-09-13 11:38:38 +02:00
|
|
|
}
|
|
|
|
|
2011-09-16 13:30:31 +02:00
|
|
|
static HRESULT interp_jmp_true(exec_ctx_t *ctx)
|
|
|
|
{
|
|
|
|
const unsigned arg = ctx->instr->arg1.uint;
|
|
|
|
HRESULT hres;
|
2012-05-23 15:36:04 +02:00
|
|
|
BOOL b;
|
2011-09-16 13:30:31 +02:00
|
|
|
|
|
|
|
TRACE("%u\n", arg);
|
|
|
|
|
2012-05-23 15:36:04 +02:00
|
|
|
hres = stack_pop_bool(ctx, &b);
|
2011-09-16 13:30:31 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2012-05-23 15:36:04 +02:00
|
|
|
if(b)
|
2011-09-16 13:30:31 +02:00
|
|
|
instr_jmp(ctx, ctx->instr->arg1.uint);
|
|
|
|
else
|
|
|
|
ctx->instr++;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2011-09-07 14:07:24 +02:00
|
|
|
static HRESULT interp_ret(exec_ctx_t *ctx)
|
|
|
|
{
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
ctx->instr = NULL;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2019-09-17 14:54:31 +02:00
|
|
|
static HRESULT interp_retval(exec_ctx_t *ctx)
|
|
|
|
{
|
|
|
|
variant_val_t val;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
hres = stack_pop_val(ctx, &val);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
if(val.owned) {
|
|
|
|
VariantClear(&ctx->ret_val);
|
|
|
|
ctx->ret_val = *val.v;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
hres = VariantCopy(&ctx->ret_val, val.v);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2011-09-15 14:22:27 +02:00
|
|
|
static HRESULT interp_stop(exec_ctx_t *ctx)
|
|
|
|
{
|
|
|
|
WARN("\n");
|
|
|
|
|
|
|
|
/* NOTE: this should have effect in debugging mode (that we don't support yet) */
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2011-09-19 14:09:57 +02:00
|
|
|
static HRESULT interp_me(exec_ctx_t *ctx)
|
|
|
|
{
|
2011-09-19 14:10:08 +02:00
|
|
|
VARIANT v;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
IDispatch_AddRef(ctx->this_obj);
|
|
|
|
V_VT(&v) = VT_DISPATCH;
|
|
|
|
V_DISPATCH(&v) = ctx->this_obj;
|
|
|
|
return stack_push(ctx, &v);
|
2011-09-19 14:09:57 +02:00
|
|
|
}
|
|
|
|
|
2011-09-08 14:57:16 +02:00
|
|
|
static HRESULT interp_bool(exec_ctx_t *ctx)
|
|
|
|
{
|
2011-09-08 14:57:45 +02:00
|
|
|
const VARIANT_BOOL arg = ctx->instr->arg1.lng;
|
|
|
|
VARIANT v;
|
|
|
|
|
|
|
|
TRACE("%s\n", arg ? "true" : "false");
|
|
|
|
|
|
|
|
V_VT(&v) = VT_BOOL;
|
|
|
|
V_BOOL(&v) = arg;
|
|
|
|
return stack_push(ctx, &v);
|
2011-09-08 14:57:16 +02:00
|
|
|
}
|
|
|
|
|
2011-09-19 14:10:19 +02:00
|
|
|
static HRESULT interp_errmode(exec_ctx_t *ctx)
|
|
|
|
{
|
|
|
|
const int err_mode = ctx->instr->arg1.uint;
|
2011-09-22 14:26:25 +02:00
|
|
|
|
|
|
|
TRACE("%d\n", err_mode);
|
|
|
|
|
|
|
|
ctx->resume_next = err_mode;
|
2014-06-13 17:27:44 +02:00
|
|
|
ctx->script->err_number = S_OK;
|
2011-09-22 14:26:25 +02:00
|
|
|
return S_OK;
|
2011-09-19 14:10:19 +02:00
|
|
|
}
|
|
|
|
|
2011-09-08 14:57:31 +02:00
|
|
|
static HRESULT interp_string(exec_ctx_t *ctx)
|
|
|
|
{
|
2011-09-08 14:57:56 +02:00
|
|
|
VARIANT v;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
V_VT(&v) = VT_BSTR;
|
|
|
|
V_BSTR(&v) = SysAllocString(ctx->instr->arg1.str);
|
|
|
|
if(!V_BSTR(&v))
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
return stack_push(ctx, &v);
|
2011-09-08 14:57:31 +02:00
|
|
|
}
|
|
|
|
|
2019-08-22 19:31:49 +02:00
|
|
|
static HRESULT interp_int(exec_ctx_t *ctx)
|
2011-09-12 12:30:11 +02:00
|
|
|
{
|
2011-09-12 12:30:21 +02:00
|
|
|
const LONG arg = ctx->instr->arg1.lng;
|
|
|
|
VARIANT v;
|
|
|
|
|
|
|
|
TRACE("%d\n", arg);
|
|
|
|
|
2019-08-22 19:31:41 +02:00
|
|
|
if(arg == (INT16)arg) {
|
|
|
|
V_VT(&v) = VT_I2;
|
|
|
|
V_I2(&v) = arg;
|
|
|
|
}else {
|
|
|
|
V_VT(&v) = VT_I4;
|
|
|
|
V_I4(&v) = arg;
|
|
|
|
}
|
2011-09-12 12:30:21 +02:00
|
|
|
return stack_push(ctx, &v);
|
2011-09-12 12:30:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT interp_double(exec_ctx_t *ctx)
|
|
|
|
{
|
2011-09-12 12:30:21 +02:00
|
|
|
const DOUBLE *arg = ctx->instr->arg1.dbl;
|
|
|
|
VARIANT v;
|
|
|
|
|
|
|
|
TRACE("%lf\n", *arg);
|
|
|
|
|
|
|
|
V_VT(&v) = VT_R8;
|
|
|
|
V_R8(&v) = *arg;
|
|
|
|
return stack_push(ctx, &v);
|
2011-09-12 12:30:11 +02:00
|
|
|
}
|
|
|
|
|
2011-09-09 14:49:26 +02:00
|
|
|
static HRESULT interp_empty(exec_ctx_t *ctx)
|
|
|
|
{
|
|
|
|
VARIANT v;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
V_VT(&v) = VT_EMPTY;
|
|
|
|
return stack_push(ctx, &v);
|
|
|
|
}
|
|
|
|
|
2011-09-09 14:49:36 +02:00
|
|
|
static HRESULT interp_null(exec_ctx_t *ctx)
|
|
|
|
{
|
|
|
|
TRACE("\n");
|
2012-09-10 10:35:17 +02:00
|
|
|
return stack_push_null(ctx);
|
2011-09-09 14:49:36 +02:00
|
|
|
}
|
|
|
|
|
2011-09-15 14:18:56 +02:00
|
|
|
static HRESULT interp_nothing(exec_ctx_t *ctx)
|
|
|
|
{
|
2011-09-15 14:19:19 +02:00
|
|
|
VARIANT v;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
V_VT(&v) = VT_DISPATCH;
|
|
|
|
V_DISPATCH(&v) = NULL;
|
|
|
|
return stack_push(ctx, &v);
|
2011-09-15 14:18:56 +02:00
|
|
|
}
|
|
|
|
|
2015-01-28 19:28:17 +01:00
|
|
|
static HRESULT interp_hres(exec_ctx_t *ctx)
|
|
|
|
{
|
|
|
|
const unsigned arg = ctx->instr->arg1.uint;
|
|
|
|
VARIANT v;
|
|
|
|
|
|
|
|
TRACE("%d\n", arg);
|
|
|
|
|
|
|
|
V_VT(&v) = VT_ERROR;
|
|
|
|
V_ERROR(&v) = arg;
|
|
|
|
return stack_push(ctx, &v);
|
|
|
|
}
|
|
|
|
|
2011-09-09 14:47:45 +02:00
|
|
|
static HRESULT interp_not(exec_ctx_t *ctx)
|
|
|
|
{
|
2011-09-09 14:47:55 +02:00
|
|
|
variant_val_t val;
|
|
|
|
VARIANT v;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
hres = stack_pop_val(ctx, &val);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
hres = VarNot(val.v, &v);
|
|
|
|
release_val(&val);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
return stack_push(ctx, &v);
|
2011-09-09 14:47:45 +02:00
|
|
|
}
|
|
|
|
|
2011-09-14 12:59:02 +02:00
|
|
|
static HRESULT interp_and(exec_ctx_t *ctx)
|
|
|
|
{
|
2011-09-14 12:59:14 +02:00
|
|
|
variant_val_t r, l;
|
|
|
|
VARIANT v;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
hres = stack_pop_val(ctx, &r);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
hres = stack_pop_val(ctx, &l);
|
|
|
|
if(SUCCEEDED(hres)) {
|
|
|
|
hres = VarAnd(l.v, r.v, &v);
|
|
|
|
release_val(&l);
|
|
|
|
}
|
|
|
|
release_val(&r);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
return stack_push(ctx, &v);
|
2011-09-14 12:59:02 +02:00
|
|
|
}
|
|
|
|
|
2011-09-14 12:59:26 +02:00
|
|
|
static HRESULT interp_or(exec_ctx_t *ctx)
|
|
|
|
{
|
2011-09-14 12:59:37 +02:00
|
|
|
variant_val_t r, l;
|
|
|
|
VARIANT v;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
hres = stack_pop_val(ctx, &r);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
hres = stack_pop_val(ctx, &l);
|
|
|
|
if(SUCCEEDED(hres)) {
|
|
|
|
hres = VarOr(l.v, r.v, &v);
|
|
|
|
release_val(&l);
|
|
|
|
}
|
|
|
|
release_val(&r);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
return stack_push(ctx, &v);
|
2011-09-14 12:59:26 +02:00
|
|
|
}
|
|
|
|
|
2011-09-14 12:59:49 +02:00
|
|
|
static HRESULT interp_xor(exec_ctx_t *ctx)
|
|
|
|
{
|
2011-09-14 13:00:02 +02:00
|
|
|
variant_val_t r, l;
|
|
|
|
VARIANT v;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
hres = stack_pop_val(ctx, &r);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
hres = stack_pop_val(ctx, &l);
|
|
|
|
if(SUCCEEDED(hres)) {
|
|
|
|
hres = VarXor(l.v, r.v, &v);
|
|
|
|
release_val(&l);
|
|
|
|
}
|
|
|
|
release_val(&r);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
return stack_push(ctx, &v);
|
2011-09-14 12:59:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT interp_eqv(exec_ctx_t *ctx)
|
|
|
|
{
|
2011-09-14 13:00:12 +02:00
|
|
|
variant_val_t r, l;
|
|
|
|
VARIANT v;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
hres = stack_pop_val(ctx, &r);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
hres = stack_pop_val(ctx, &l);
|
|
|
|
if(SUCCEEDED(hres)) {
|
|
|
|
hres = VarEqv(l.v, r.v, &v);
|
|
|
|
release_val(&l);
|
|
|
|
}
|
|
|
|
release_val(&r);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
return stack_push(ctx, &v);
|
2011-09-14 12:59:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT interp_imp(exec_ctx_t *ctx)
|
|
|
|
{
|
2011-09-14 13:00:23 +02:00
|
|
|
variant_val_t r, l;
|
|
|
|
VARIANT v;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
hres = stack_pop_val(ctx, &r);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
hres = stack_pop_val(ctx, &l);
|
|
|
|
if(SUCCEEDED(hres)) {
|
|
|
|
hres = VarImp(l.v, r.v, &v);
|
|
|
|
release_val(&l);
|
|
|
|
}
|
|
|
|
release_val(&r);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
return stack_push(ctx, &v);
|
2011-09-14 12:59:49 +02:00
|
|
|
}
|
|
|
|
|
2012-07-20 16:29:00 +02:00
|
|
|
static HRESULT var_cmp(exec_ctx_t *ctx, VARIANT *l, VARIANT *r)
|
|
|
|
{
|
|
|
|
TRACE("%s %s\n", debugstr_variant(l), debugstr_variant(r));
|
|
|
|
|
|
|
|
/* FIXME: Fix comparing string to number */
|
|
|
|
|
|
|
|
return VarCmp(l, r, ctx->script->lcid, 0);
|
|
|
|
}
|
|
|
|
|
2011-09-09 14:48:35 +02:00
|
|
|
static HRESULT cmp_oper(exec_ctx_t *ctx)
|
|
|
|
{
|
|
|
|
variant_val_t l, r;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
hres = stack_pop_val(ctx, &r);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
hres = stack_pop_val(ctx, &l);
|
2011-09-09 14:49:36 +02:00
|
|
|
if(SUCCEEDED(hres)) {
|
2012-07-20 16:29:00 +02:00
|
|
|
hres = var_cmp(ctx, l.v, r.v);
|
|
|
|
release_val(&l);
|
2011-09-09 14:49:36 +02:00
|
|
|
}
|
2011-09-09 14:48:35 +02:00
|
|
|
|
|
|
|
release_val(&r);
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
2011-09-09 14:48:25 +02:00
|
|
|
static HRESULT interp_equal(exec_ctx_t *ctx)
|
|
|
|
{
|
2011-09-09 14:48:35 +02:00
|
|
|
VARIANT v;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
hres = cmp_oper(ctx);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
2012-09-10 10:35:17 +02:00
|
|
|
if(hres == VARCMP_NULL)
|
|
|
|
return stack_push_null(ctx);
|
2011-09-09 14:48:35 +02:00
|
|
|
|
|
|
|
V_VT(&v) = VT_BOOL;
|
|
|
|
V_BOOL(&v) = hres == VARCMP_EQ ? VARIANT_TRUE : VARIANT_FALSE;
|
|
|
|
return stack_push(ctx, &v);
|
2011-09-09 14:48:25 +02:00
|
|
|
}
|
|
|
|
|
2011-09-12 12:32:27 +02:00
|
|
|
static HRESULT interp_nequal(exec_ctx_t *ctx)
|
|
|
|
{
|
|
|
|
VARIANT v;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
hres = cmp_oper(ctx);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
2012-09-10 10:35:17 +02:00
|
|
|
if(hres == VARCMP_NULL)
|
|
|
|
return stack_push_null(ctx);
|
2011-09-12 12:32:27 +02:00
|
|
|
|
|
|
|
V_VT(&v) = VT_BOOL;
|
|
|
|
V_BOOL(&v) = hres != VARCMP_EQ ? VARIANT_TRUE : VARIANT_FALSE;
|
|
|
|
return stack_push(ctx, &v);
|
|
|
|
}
|
|
|
|
|
2011-09-19 14:07:12 +02:00
|
|
|
static HRESULT interp_gt(exec_ctx_t *ctx)
|
|
|
|
{
|
2011-09-19 14:07:31 +02:00
|
|
|
VARIANT v;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
hres = cmp_oper(ctx);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
2012-09-10 10:35:17 +02:00
|
|
|
if(hres == VARCMP_NULL)
|
|
|
|
return stack_push_null(ctx);
|
2011-09-19 14:07:31 +02:00
|
|
|
|
|
|
|
V_VT(&v) = VT_BOOL;
|
|
|
|
V_BOOL(&v) = hres == VARCMP_GT ? VARIANT_TRUE : VARIANT_FALSE;
|
|
|
|
return stack_push(ctx, &v);
|
2011-09-19 14:07:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT interp_gteq(exec_ctx_t *ctx)
|
|
|
|
{
|
2011-09-19 14:07:22 +02:00
|
|
|
VARIANT v;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
hres = cmp_oper(ctx);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
2012-09-10 10:35:17 +02:00
|
|
|
if(hres == VARCMP_NULL)
|
|
|
|
return stack_push_null(ctx);
|
2011-09-19 14:07:22 +02:00
|
|
|
|
|
|
|
V_VT(&v) = VT_BOOL;
|
|
|
|
V_BOOL(&v) = hres == VARCMP_GT || hres == VARCMP_EQ ? VARIANT_TRUE : VARIANT_FALSE;
|
|
|
|
return stack_push(ctx, &v);
|
2011-09-19 14:07:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT interp_lt(exec_ctx_t *ctx)
|
|
|
|
{
|
2011-09-19 14:07:39 +02:00
|
|
|
VARIANT v;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
hres = cmp_oper(ctx);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
2012-09-10 10:35:17 +02:00
|
|
|
if(hres == VARCMP_NULL)
|
|
|
|
return stack_push_null(ctx);
|
2011-09-19 14:07:39 +02:00
|
|
|
|
|
|
|
V_VT(&v) = VT_BOOL;
|
|
|
|
V_BOOL(&v) = hres == VARCMP_LT ? VARIANT_TRUE : VARIANT_FALSE;
|
|
|
|
return stack_push(ctx, &v);
|
2011-09-19 14:07:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT interp_lteq(exec_ctx_t *ctx)
|
|
|
|
{
|
2011-09-19 14:07:51 +02:00
|
|
|
VARIANT v;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
hres = cmp_oper(ctx);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
2012-09-10 10:35:17 +02:00
|
|
|
if(hres == VARCMP_NULL)
|
|
|
|
return stack_push_null(ctx);
|
2011-09-19 14:07:51 +02:00
|
|
|
|
|
|
|
V_VT(&v) = VT_BOOL;
|
|
|
|
V_BOOL(&v) = hres == VARCMP_LT || hres == VARCMP_EQ ? VARIANT_TRUE : VARIANT_FALSE;
|
|
|
|
return stack_push(ctx, &v);
|
2011-09-19 14:07:12 +02:00
|
|
|
}
|
|
|
|
|
2012-07-20 16:28:45 +02:00
|
|
|
static HRESULT interp_case(exec_ctx_t *ctx)
|
|
|
|
{
|
2012-07-20 16:29:00 +02:00
|
|
|
const unsigned arg = ctx->instr->arg1.uint;
|
|
|
|
variant_val_t v;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("%d\n", arg);
|
|
|
|
|
|
|
|
hres = stack_pop_val(ctx, &v);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
hres = var_cmp(ctx, stack_top(ctx, 0), v.v);
|
|
|
|
release_val(&v);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
if(hres == VARCMP_EQ) {
|
|
|
|
stack_popn(ctx, 1);
|
|
|
|
instr_jmp(ctx, arg);
|
|
|
|
}else {
|
|
|
|
ctx->instr++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
2012-07-20 16:28:45 +02:00
|
|
|
}
|
|
|
|
|
2011-09-19 14:08:02 +02:00
|
|
|
static HRESULT disp_cmp(IDispatch *disp1, IDispatch *disp2, VARIANT_BOOL *ret)
|
|
|
|
{
|
|
|
|
IObjectIdentity *identity;
|
|
|
|
IUnknown *unk1, *unk2;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
if(disp1 == disp2) {
|
|
|
|
*ret = VARIANT_TRUE;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!disp1 || !disp2) {
|
|
|
|
*ret = VARIANT_FALSE;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
hres = IDispatch_QueryInterface(disp1, &IID_IUnknown, (void**)&unk1);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
hres = IDispatch_QueryInterface(disp2, &IID_IUnknown, (void**)&unk2);
|
|
|
|
if(FAILED(hres)) {
|
|
|
|
IUnknown_Release(unk1);
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(unk1 == unk2) {
|
|
|
|
*ret = VARIANT_TRUE;
|
|
|
|
}else {
|
|
|
|
hres = IUnknown_QueryInterface(unk1, &IID_IObjectIdentity, (void**)&identity);
|
|
|
|
if(SUCCEEDED(hres)) {
|
|
|
|
hres = IObjectIdentity_IsEqualObject(identity, unk2);
|
|
|
|
IObjectIdentity_Release(identity);
|
|
|
|
*ret = hres == S_OK ? VARIANT_TRUE : VARIANT_FALSE;
|
|
|
|
}else {
|
|
|
|
*ret = VARIANT_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
IUnknown_Release(unk1);
|
|
|
|
IUnknown_Release(unk2);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT interp_is(exec_ctx_t *ctx)
|
|
|
|
{
|
|
|
|
IDispatch *l, *r;
|
|
|
|
VARIANT v;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
hres = stack_pop_disp(ctx, &r);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
hres = stack_pop_disp(ctx, &l);
|
|
|
|
if(SUCCEEDED(hres)) {
|
|
|
|
V_VT(&v) = VT_BOOL;
|
|
|
|
hres = disp_cmp(l, r, &V_BOOL(&v));
|
|
|
|
if(l)
|
|
|
|
IDispatch_Release(l);
|
|
|
|
}
|
|
|
|
if(r)
|
|
|
|
IDispatch_Release(r);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
return stack_push(ctx, &v);
|
|
|
|
}
|
|
|
|
|
2011-09-12 12:30:47 +02:00
|
|
|
static HRESULT interp_concat(exec_ctx_t *ctx)
|
|
|
|
{
|
2011-09-12 12:30:57 +02:00
|
|
|
variant_val_t r, l;
|
|
|
|
VARIANT v;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
hres = stack_pop_val(ctx, &r);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
hres = stack_pop_val(ctx, &l);
|
|
|
|
if(SUCCEEDED(hres)) {
|
|
|
|
hres = VarCat(l.v, r.v, &v);
|
|
|
|
release_val(&l);
|
|
|
|
}
|
|
|
|
release_val(&r);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
return stack_push(ctx, &v);
|
2011-09-12 12:30:47 +02:00
|
|
|
}
|
|
|
|
|
2011-09-12 12:31:58 +02:00
|
|
|
static HRESULT interp_add(exec_ctx_t *ctx)
|
|
|
|
{
|
2011-09-12 12:32:07 +02:00
|
|
|
variant_val_t r, l;
|
|
|
|
VARIANT v;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
hres = stack_pop_val(ctx, &r);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
hres = stack_pop_val(ctx, &l);
|
|
|
|
if(SUCCEEDED(hres)) {
|
|
|
|
hres = VarAdd(l.v, r.v, &v);
|
|
|
|
release_val(&l);
|
|
|
|
}
|
|
|
|
release_val(&r);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
return stack_push(ctx, &v);
|
2011-09-12 12:31:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT interp_sub(exec_ctx_t *ctx)
|
|
|
|
{
|
2011-09-12 12:32:18 +02:00
|
|
|
variant_val_t r, l;
|
|
|
|
VARIANT v;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
hres = stack_pop_val(ctx, &r);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
hres = stack_pop_val(ctx, &l);
|
|
|
|
if(SUCCEEDED(hres)) {
|
|
|
|
hres = VarSub(l.v, r.v, &v);
|
|
|
|
release_val(&l);
|
|
|
|
}
|
|
|
|
release_val(&r);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
return stack_push(ctx, &v);
|
2011-09-12 12:31:58 +02:00
|
|
|
}
|
|
|
|
|
2011-09-13 11:39:53 +02:00
|
|
|
static HRESULT interp_mod(exec_ctx_t *ctx)
|
|
|
|
{
|
2011-09-13 11:40:02 +02:00
|
|
|
variant_val_t r, l;
|
|
|
|
VARIANT v;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
hres = stack_pop_val(ctx, &r);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
hres = stack_pop_val(ctx, &l);
|
|
|
|
if(SUCCEEDED(hres)) {
|
|
|
|
hres = VarMod(l.v, r.v, &v);
|
|
|
|
release_val(&l);
|
|
|
|
}
|
|
|
|
release_val(&r);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
return stack_push(ctx, &v);
|
2011-09-13 11:39:53 +02:00
|
|
|
}
|
|
|
|
|
2011-09-13 11:40:14 +02:00
|
|
|
static HRESULT interp_idiv(exec_ctx_t *ctx)
|
|
|
|
{
|
2011-09-13 11:40:28 +02:00
|
|
|
variant_val_t r, l;
|
|
|
|
VARIANT v;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
hres = stack_pop_val(ctx, &r);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
hres = stack_pop_val(ctx, &l);
|
|
|
|
if(SUCCEEDED(hres)) {
|
|
|
|
hres = VarIdiv(l.v, r.v, &v);
|
|
|
|
release_val(&l);
|
|
|
|
}
|
|
|
|
release_val(&r);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
return stack_push(ctx, &v);
|
2011-09-13 11:40:14 +02:00
|
|
|
}
|
|
|
|
|
2011-09-13 11:40:39 +02:00
|
|
|
static HRESULT interp_div(exec_ctx_t *ctx)
|
|
|
|
{
|
2011-09-13 11:41:03 +02:00
|
|
|
variant_val_t r, l;
|
|
|
|
VARIANT v;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
hres = stack_pop_val(ctx, &r);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
hres = stack_pop_val(ctx, &l);
|
|
|
|
if(SUCCEEDED(hres)) {
|
|
|
|
hres = VarDiv(l.v, r.v, &v);
|
|
|
|
release_val(&l);
|
|
|
|
}
|
|
|
|
release_val(&r);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
return stack_push(ctx, &v);
|
2011-09-13 11:40:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT interp_mul(exec_ctx_t *ctx)
|
|
|
|
{
|
2011-09-13 11:40:50 +02:00
|
|
|
variant_val_t r, l;
|
|
|
|
VARIANT v;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
hres = stack_pop_val(ctx, &r);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
hres = stack_pop_val(ctx, &l);
|
|
|
|
if(SUCCEEDED(hres)) {
|
|
|
|
hres = VarMul(l.v, r.v, &v);
|
|
|
|
release_val(&l);
|
|
|
|
}
|
|
|
|
release_val(&r);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
return stack_push(ctx, &v);
|
2011-09-13 11:40:39 +02:00
|
|
|
}
|
|
|
|
|
2011-09-13 11:41:15 +02:00
|
|
|
static HRESULT interp_exp(exec_ctx_t *ctx)
|
|
|
|
{
|
2011-09-13 11:41:34 +02:00
|
|
|
variant_val_t r, l;
|
|
|
|
VARIANT v;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
hres = stack_pop_val(ctx, &r);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
hres = stack_pop_val(ctx, &l);
|
|
|
|
if(SUCCEEDED(hres)) {
|
|
|
|
hres = VarPow(l.v, r.v, &v);
|
|
|
|
release_val(&l);
|
|
|
|
}
|
|
|
|
release_val(&r);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
return stack_push(ctx, &v);
|
2011-09-13 11:41:15 +02:00
|
|
|
}
|
|
|
|
|
2011-09-12 12:31:37 +02:00
|
|
|
static HRESULT interp_neg(exec_ctx_t *ctx)
|
|
|
|
{
|
2011-09-12 12:31:47 +02:00
|
|
|
variant_val_t val;
|
|
|
|
VARIANT v;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
hres = stack_pop_val(ctx, &val);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
hres = VarNeg(val.v, &v);
|
|
|
|
release_val(&val);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
return stack_push(ctx, &v);
|
2011-09-12 12:31:37 +02:00
|
|
|
}
|
|
|
|
|
2011-09-22 14:23:10 +02:00
|
|
|
static HRESULT interp_incc(exec_ctx_t *ctx)
|
|
|
|
{
|
|
|
|
const BSTR ident = ctx->instr->arg1.bstr;
|
2011-09-22 14:24:05 +02:00
|
|
|
VARIANT v;
|
|
|
|
ref_t ref;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
hres = lookup_identifier(ctx, ident, VBDISP_LET, &ref);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
if(ref.type != REF_VAR) {
|
|
|
|
FIXME("ref.type is not REF_VAR\n");
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
hres = VarAdd(stack_top(ctx, 0), ref.u.v, &v);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
VariantClear(ref.u.v);
|
|
|
|
*ref.u.v = v;
|
|
|
|
return S_OK;
|
2011-09-22 14:23:10 +02:00
|
|
|
}
|
|
|
|
|
2014-03-21 14:37:39 +01:00
|
|
|
static HRESULT interp_catch(exec_ctx_t *ctx)
|
|
|
|
{
|
|
|
|
/* Nothing to do here, the OP is for unwinding only. */
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2011-09-07 14:07:24 +02:00
|
|
|
static const instr_func_t op_funcs[] = {
|
2011-09-07 14:08:47 +02:00
|
|
|
#define X(x,n,a,b) interp_ ## x,
|
2011-09-07 14:07:24 +02:00
|
|
|
OP_LIST
|
|
|
|
#undef X
|
|
|
|
};
|
|
|
|
|
|
|
|
static const unsigned op_move[] = {
|
2011-09-07 14:08:47 +02:00
|
|
|
#define X(x,n,a,b) n,
|
2011-09-07 14:07:24 +02:00
|
|
|
OP_LIST
|
|
|
|
#undef X
|
|
|
|
};
|
|
|
|
|
2011-10-14 16:22:18 +02:00
|
|
|
void release_dynamic_vars(dynamic_var_t *var)
|
|
|
|
{
|
|
|
|
while(var) {
|
|
|
|
VariantClear(&var->v);
|
|
|
|
var = var->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-14 12:56:45 +02:00
|
|
|
static void release_exec(exec_ctx_t *ctx)
|
|
|
|
{
|
2011-09-14 12:57:37 +02:00
|
|
|
unsigned i;
|
2011-09-14 12:56:45 +02:00
|
|
|
|
2011-09-14 12:58:30 +02:00
|
|
|
VariantClear(&ctx->ret_val);
|
2011-10-14 16:22:18 +02:00
|
|
|
release_dynamic_vars(ctx->dynamic_vars);
|
2011-09-14 12:58:30 +02:00
|
|
|
|
2011-09-15 14:21:58 +02:00
|
|
|
if(ctx->this_obj)
|
|
|
|
IDispatch_Release(ctx->this_obj);
|
|
|
|
|
2011-09-14 12:57:37 +02:00
|
|
|
if(ctx->args) {
|
2011-09-14 12:56:45 +02:00
|
|
|
for(i=0; i < ctx->func->arg_cnt; i++)
|
|
|
|
VariantClear(ctx->args+i);
|
|
|
|
}
|
|
|
|
|
2011-09-14 12:57:37 +02:00
|
|
|
if(ctx->vars) {
|
|
|
|
for(i=0; i < ctx->func->var_cnt; i++)
|
|
|
|
VariantClear(ctx->vars+i);
|
|
|
|
}
|
|
|
|
|
2013-11-13 16:29:29 +01:00
|
|
|
if(ctx->arrays) {
|
|
|
|
for(i=0; i < ctx->func->var_cnt; i++) {
|
|
|
|
if(ctx->arrays[i])
|
|
|
|
SafeArrayDestroy(ctx->arrays[i]);
|
|
|
|
}
|
|
|
|
heap_free(ctx->arrays);
|
|
|
|
}
|
|
|
|
|
2013-02-15 15:11:13 +01:00
|
|
|
heap_pool_free(&ctx->heap);
|
2011-09-14 12:56:45 +02:00
|
|
|
heap_free(ctx->args);
|
2011-09-14 12:57:37 +02:00
|
|
|
heap_free(ctx->vars);
|
2011-09-14 12:56:45 +02:00
|
|
|
heap_free(ctx->stack);
|
|
|
|
}
|
|
|
|
|
2014-03-07 14:27:35 +01:00
|
|
|
HRESULT exec_script(script_ctx_t *ctx, function_t *func, vbdisp_t *vbthis, DISPPARAMS *dp, VARIANT *res)
|
2011-09-07 14:07:24 +02:00
|
|
|
{
|
2011-09-14 12:56:45 +02:00
|
|
|
exec_ctx_t exec = {func->code_ctx};
|
2011-09-07 14:07:24 +02:00
|
|
|
vbsop_t op;
|
|
|
|
HRESULT hres = S_OK;
|
|
|
|
|
2011-09-14 12:56:45 +02:00
|
|
|
exec.code = func->code_ctx;
|
|
|
|
|
|
|
|
if(dp ? func->arg_cnt != arg_cnt(dp) : func->arg_cnt) {
|
|
|
|
FIXME("wrong arg_cnt %d, expected %d\n", dp ? arg_cnt(dp) : 0, func->arg_cnt);
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
2013-02-15 15:11:13 +01:00
|
|
|
heap_pool_init(&exec.heap);
|
2011-09-20 14:59:53 +02:00
|
|
|
|
2011-09-14 12:56:45 +02:00
|
|
|
if(func->arg_cnt) {
|
|
|
|
VARIANT *v;
|
|
|
|
unsigned i;
|
|
|
|
|
|
|
|
exec.args = heap_alloc_zero(func->arg_cnt * sizeof(VARIANT));
|
|
|
|
if(!exec.args) {
|
|
|
|
release_exec(&exec);
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
for(i=0; i < func->arg_cnt; i++) {
|
|
|
|
v = get_arg(dp, i);
|
|
|
|
if(V_VT(v) == (VT_VARIANT|VT_BYREF)) {
|
|
|
|
if(func->args[i].by_ref)
|
|
|
|
exec.args[i] = *v;
|
|
|
|
else
|
2014-03-08 14:52:35 +01:00
|
|
|
hres = VariantCopyInd(exec.args+i, V_VARIANTREF(v));
|
2011-09-14 12:56:45 +02:00
|
|
|
}else {
|
2014-03-08 14:52:35 +01:00
|
|
|
hres = VariantCopyInd(exec.args+i, v);
|
2011-09-14 12:56:45 +02:00
|
|
|
}
|
|
|
|
if(FAILED(hres)) {
|
|
|
|
release_exec(&exec);
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}else {
|
|
|
|
exec.args = NULL;
|
2011-09-14 12:56:01 +02:00
|
|
|
}
|
|
|
|
|
2011-09-14 12:57:37 +02:00
|
|
|
if(func->var_cnt) {
|
|
|
|
exec.vars = heap_alloc_zero(func->var_cnt * sizeof(VARIANT));
|
|
|
|
if(!exec.vars) {
|
|
|
|
release_exec(&exec);
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
}else {
|
|
|
|
exec.vars = NULL;
|
|
|
|
}
|
|
|
|
|
2011-09-08 14:57:45 +02:00
|
|
|
exec.stack_size = 16;
|
|
|
|
exec.top = 0;
|
|
|
|
exec.stack = heap_alloc(exec.stack_size * sizeof(VARIANT));
|
2011-09-14 12:56:45 +02:00
|
|
|
if(!exec.stack) {
|
|
|
|
release_exec(&exec);
|
2011-09-08 14:57:45 +02:00
|
|
|
return E_OUTOFMEMORY;
|
2011-09-14 12:56:45 +02:00
|
|
|
}
|
2011-09-08 14:57:45 +02:00
|
|
|
|
2014-03-07 14:27:35 +01:00
|
|
|
if(vbthis) {
|
|
|
|
exec.this_obj = (IDispatch*)&vbthis->IDispatchEx_iface;
|
|
|
|
exec.vbthis = vbthis;
|
|
|
|
}else if (ctx->host_global) {
|
2011-09-15 14:21:58 +02:00
|
|
|
exec.this_obj = ctx->host_global;
|
2014-03-07 14:27:35 +01:00
|
|
|
}else {
|
2011-09-15 14:21:58 +02:00
|
|
|
exec.this_obj = (IDispatch*)&ctx->script_obj->IDispatchEx_iface;
|
2014-03-07 14:27:35 +01:00
|
|
|
}
|
2011-09-15 14:21:58 +02:00
|
|
|
IDispatch_AddRef(exec.this_obj);
|
|
|
|
|
2011-09-07 14:07:24 +02:00
|
|
|
exec.instr = exec.code->instrs + func->code_off;
|
2011-09-08 14:54:37 +02:00
|
|
|
exec.script = ctx;
|
2011-09-09 14:47:00 +02:00
|
|
|
exec.func = func;
|
2011-09-07 14:07:24 +02:00
|
|
|
|
|
|
|
while(exec.instr) {
|
|
|
|
op = exec.instr->op;
|
|
|
|
hres = op_funcs[op](&exec);
|
|
|
|
if(FAILED(hres)) {
|
2014-03-27 14:44:12 +01:00
|
|
|
ctx->err_number = hres = map_hres(hres);
|
2014-03-21 14:37:39 +01:00
|
|
|
|
|
|
|
if(exec.resume_next) {
|
|
|
|
unsigned stack_off;
|
|
|
|
|
|
|
|
WARN("Failed %08x in resume next mode\n", hres);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Unwinding here is simple. We need to find the next OP_catch, which contains
|
|
|
|
* information about expected stack size and jump offset on error. Generated
|
|
|
|
* bytecode needs to guarantee, that simple jump and stack adjustment will
|
|
|
|
* guarantee proper execution continuation.
|
|
|
|
*/
|
|
|
|
while((++exec.instr)->op != OP_catch);
|
|
|
|
|
|
|
|
TRACE("unwind jmp %d stack_off %d\n", exec.instr->arg1.uint, exec.instr->arg2.uint);
|
|
|
|
|
|
|
|
stack_off = exec.instr->arg2.uint;
|
2014-03-25 14:58:41 +01:00
|
|
|
instr_jmp(&exec, exec.instr->arg1.uint);
|
2014-03-21 14:37:39 +01:00
|
|
|
|
|
|
|
if(exec.top > stack_off) {
|
|
|
|
stack_popn(&exec, exec.top-stack_off);
|
|
|
|
}else if(exec.top < stack_off) {
|
|
|
|
VARIANT v;
|
|
|
|
|
|
|
|
V_VT(&v) = VT_EMPTY;
|
|
|
|
while(exec.top < stack_off) {
|
|
|
|
hres = stack_push(&exec, &v);
|
|
|
|
if(FAILED(hres))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}else {
|
2011-09-22 14:26:25 +02:00
|
|
|
WARN("Failed %08x\n", hres);
|
2014-03-21 14:37:39 +01:00
|
|
|
stack_popn(&exec, exec.top);
|
|
|
|
break;
|
|
|
|
}
|
2011-09-07 14:07:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
exec.instr += op_move[op];
|
|
|
|
}
|
|
|
|
|
2011-09-08 14:57:45 +02:00
|
|
|
assert(!exec.top);
|
2011-09-14 12:58:30 +02:00
|
|
|
|
|
|
|
if(SUCCEEDED(hres) && res) {
|
|
|
|
*res = exec.ret_val;
|
|
|
|
V_VT(&exec.ret_val) = VT_EMPTY;
|
|
|
|
}
|
|
|
|
|
2011-09-14 12:56:45 +02:00
|
|
|
release_exec(&exec);
|
2011-09-07 14:07:24 +02:00
|
|
|
return hres;
|
|
|
|
}
|