vbscript: Added interp_bool implementation.

This commit is contained in:
Jacek Caban 2011-09-08 14:57:45 +02:00 committed by Alexandre Julliard
parent ded37832fb
commit 01e2bea114
1 changed files with 53 additions and 2 deletions

View File

@ -29,6 +29,10 @@ typedef struct {
vbscode_t *code; vbscode_t *code;
instr_t *instr; instr_t *instr;
script_ctx_t *script; script_ctx_t *script;
unsigned stack_size;
unsigned top;
VARIANT *stack;
} exec_ctx_t; } exec_ctx_t;
typedef HRESULT (*instr_func_t)(exec_ctx_t*); typedef HRESULT (*instr_func_t)(exec_ctx_t*);
@ -72,6 +76,37 @@ static HRESULT lookup_identifier(exec_ctx_t *ctx, BSTR name, ref_t *ref)
return S_OK; return S_OK;
} }
static inline VARIANT *stack_pop(exec_ctx_t *ctx)
{
assert(ctx->top);
return ctx->stack + --ctx->top;
}
static HRESULT stack_push(exec_ctx_t *ctx, VARIANT *v)
{
if(ctx->stack_size == ctx->top) {
VARIANT *new_stack;
new_stack = heap_realloc(ctx->stack, ctx->stack_size*2);
if(!new_stack) {
VariantClear(v);
return E_OUTOFMEMORY;
}
ctx->stack = new_stack;
ctx->stack_size *= 2;
}
ctx->stack[ctx->top++] = *v;
return S_OK;
}
static void stack_popn(exec_ctx_t *ctx, unsigned n)
{
while(n--)
VariantClear(stack_pop(ctx));
}
static HRESULT interp_icallv(exec_ctx_t *ctx) static HRESULT interp_icallv(exec_ctx_t *ctx)
{ {
BSTR identifier = ctx->instr->arg1.bstr; BSTR identifier = ctx->instr->arg1.bstr;
@ -115,8 +150,14 @@ static HRESULT interp_ret(exec_ctx_t *ctx)
static HRESULT interp_bool(exec_ctx_t *ctx) static HRESULT interp_bool(exec_ctx_t *ctx)
{ {
FIXME("\n"); const VARIANT_BOOL arg = ctx->instr->arg1.lng;
return E_NOTIMPL; VARIANT v;
TRACE("%s\n", arg ? "true" : "false");
V_VT(&v) = VT_BOOL;
V_BOOL(&v) = arg;
return stack_push(ctx, &v);
} }
static HRESULT interp_string(exec_ctx_t *ctx) static HRESULT interp_string(exec_ctx_t *ctx)
@ -143,6 +184,12 @@ HRESULT exec_script(script_ctx_t *ctx, function_t *func)
vbsop_t op; vbsop_t op;
HRESULT hres = S_OK; HRESULT hres = S_OK;
exec.stack_size = 16;
exec.top = 0;
exec.stack = heap_alloc(exec.stack_size * sizeof(VARIANT));
if(!exec.stack)
return E_OUTOFMEMORY;
exec.code = func->code_ctx; exec.code = func->code_ctx;
exec.instr = exec.code->instrs + func->code_off; exec.instr = exec.code->instrs + func->code_off;
exec.script = ctx; exec.script = ctx;
@ -152,11 +199,15 @@ HRESULT exec_script(script_ctx_t *ctx, function_t *func)
hres = op_funcs[op](&exec); hres = op_funcs[op](&exec);
if(FAILED(hres)) { if(FAILED(hres)) {
FIXME("Failed %08x\n", hres); FIXME("Failed %08x\n", hres);
stack_popn(&exec, exec.top);
break; break;
} }
exec.instr += op_move[op]; exec.instr += op_move[op];
} }
assert(!exec.top);
heap_free(exec.stack);
return hres; return hres;
} }