vbscript: Added call statement compilation implementation.

This commit is contained in:
Jacek Caban 2011-09-07 14:08:47 +02:00 committed by Alexandre Julliard
parent 6c5570297e
commit 5ecf436449
3 changed files with 88 additions and 10 deletions

View File

@ -34,6 +34,12 @@ typedef struct {
vbscode_t *code;
} compile_ctx_t;
static inline instr_t *instr_ptr(compile_ctx_t *ctx, unsigned id)
{
assert(id < ctx->instr_cnt);
return ctx->code->instrs + id;
}
static unsigned push_instr(compile_ctx_t *ctx, vbsop_t op)
{
assert(ctx->instr_size && ctx->instr_size >= ctx->instr_cnt);
@ -53,18 +59,72 @@ static unsigned push_instr(compile_ctx_t *ctx, vbsop_t op)
return ctx->instr_cnt++;
}
static HRESULT push_instr_str(compile_ctx_t *ctx, vbsop_t op, const WCHAR *arg)
{
unsigned instr;
instr = push_instr(ctx, op);
if(instr == -1)
return E_OUTOFMEMORY;
instr_ptr(ctx, instr)->arg1.str = arg;
return S_OK;
}
static HRESULT compile_member_expression(compile_ctx_t *ctx, member_expression_t *expr)
{
HRESULT hres;
if(expr->args) {
FIXME("arguments not implemented\n");
return E_NOTIMPL;
}
if(expr->obj_expr) {
FIXME("obj_expr not implemented\n");
hres = E_NOTIMPL;
}else {
hres = push_instr_str(ctx, OP_icallv, expr->identifier);
}
return hres;
}
static HRESULT compile_statement(compile_ctx_t *ctx, statement_t *stat)
{
HRESULT hres;
while(stat) {
switch(stat->type) {
case STAT_CALL:
hres = compile_member_expression(ctx, ((call_statement_t*)stat)->expr);
break;
default:
FIXME("Unimplemented statement type %d\n", stat->type);
hres = E_NOTIMPL;
}
if(FAILED(hres))
return hres;
stat = stat->next;
}
return S_OK;
}
static HRESULT compile_func(compile_ctx_t *ctx, statement_t *stat, function_t *func)
{
HRESULT hres;
func->code_off = ctx->instr_cnt;
hres = compile_statement(ctx, stat);
if(FAILED(hres))
return hres;
if(push_instr(ctx, OP_ret) == -1)
return E_OUTOFMEMORY;
if(stat) {
FIXME("statements compilation not implemented\n");
return E_NOTIMPL;
}
return S_OK;
}

View File

@ -33,6 +33,12 @@ typedef struct {
typedef HRESULT (*instr_func_t)(exec_ctx_t*);
static HRESULT interp_icallv(exec_ctx_t *ctx)
{
FIXME("\n");
return E_NOTIMPL;
}
static HRESULT interp_ret(exec_ctx_t *ctx)
{
TRACE("\n");
@ -42,13 +48,13 @@ static HRESULT interp_ret(exec_ctx_t *ctx)
}
static const instr_func_t op_funcs[] = {
#define X(x,n) interp_ ## x,
#define X(x,n,a,b) interp_ ## x,
OP_LIST
#undef X
};
static const unsigned op_move[] = {
#define X(x,n) n,
#define X(x,n,a,b) n,
OP_LIST
#undef X
};

View File

@ -62,18 +62,30 @@ typedef struct {
HRESULT init_global(script_ctx_t*);
#define OP_LIST \
X(ret, 0)
typedef enum {
ARG_NONE = 0,
ARG_STR
} instr_arg_type_t;
#define OP_LIST \
X(icallv, 1, ARG_STR, 0) \
X(ret, 0, 0, 0)
typedef enum {
#define X(x,n) OP_##x,
#define X(x,n,a,b) OP_##x,
OP_LIST
#undef X
OP_LAST
} vbsop_t;
typedef union {
const WCHAR *str;
} instr_arg_t;
typedef struct {
vbsop_t op;
instr_arg_t arg1;
instr_arg_t arg2;
} instr_t;
struct _function_t {