vbscript: Added bytecode support for arrays.

This commit is contained in:
Jacek Caban 2013-11-13 16:29:18 +01:00 committed by Alexandre Julliard
parent f3e1f7002d
commit fc713bfc12
3 changed files with 57 additions and 2 deletions

View File

@ -937,8 +937,9 @@ static HRESULT compile_dim_statement(compile_ctx_t *ctx, dim_statement_t *stat)
ctx->func->var_cnt++;
if(dim_decl->is_array) {
FIXME("arrays not supported\n");
return E_NOTIMPL;
HRESULT hres = push_instr_bstr_uint(ctx, OP_dim, dim_decl->name, ctx->func->array_cnt++);
if(FAILED(hres))
return hres;
}
if(!dim_decl->next)
@ -1302,6 +1303,41 @@ static HRESULT compile_func(compile_ctx_t *ctx, statement_t *stat, function_t *f
}
}
if(func->array_cnt) {
unsigned dim_cnt, array_id = 0;
dim_decl_t *dim_decl;
dim_list_t *iter;
func->array_descs = compiler_alloc(ctx->code, func->array_cnt * sizeof(array_desc_t));
if(!func->array_descs)
return E_OUTOFMEMORY;
for(dim_decl = ctx->dim_decls; dim_decl; dim_decl = dim_decl->next) {
if(!dim_decl->is_array)
continue;
dim_cnt = 0;
for(iter = dim_decl->dims; iter; iter = iter->next)
dim_cnt++;
func->array_descs[array_id].bounds = compiler_alloc(ctx->code, dim_cnt * sizeof(SAFEARRAYBOUND));
if(!func->array_descs[array_id].bounds)
return E_OUTOFMEMORY;
func->array_descs[array_id].dim_cnt = dim_cnt;
dim_cnt = 0;
for(iter = dim_decl->dims; iter; iter = iter->next) {
func->array_descs[array_id].bounds[dim_cnt].cElements = iter->val+1;
func->array_descs[array_id].bounds[dim_cnt++].lLbound = 0;
}
array_id++;
}
assert(array_id == func->array_cnt);
}
return S_OK;
}
@ -1337,6 +1373,7 @@ static HRESULT create_function(compile_ctx_t *ctx, function_decl_t *decl, functi
func->vars = NULL;
func->var_cnt = 0;
func->array_cnt = 0;
func->code_ctx = ctx->code;
func->type = decl->type;
func->is_public = decl->is_public;
@ -1637,6 +1674,7 @@ static vbscode_t *alloc_vbscode(compile_ctx_t *ctx, const WCHAR *source)
ret->main_code.code_ctx = ret;
ret->main_code.vars = NULL;
ret->main_code.var_cnt = 0;
ret->main_code.array_cnt = 0;
ret->main_code.arg_cnt = 0;
ret->main_code.args = NULL;

View File

@ -887,6 +887,15 @@ static HRESULT interp_new(exec_ctx_t *ctx)
return stack_push(ctx, &v);
}
static HRESULT interp_dim(exec_ctx_t *ctx)
{
const BSTR ident = ctx->instr->arg1.bstr;
const unsigned array_id = ctx->instr->arg2.uint;
FIXME("%s(%d)\n", debugstr_w(ident), array_id);
return E_NOTIMPL;
}
static HRESULT interp_step(exec_ctx_t *ctx)
{
const BSTR ident = ctx->instr->arg2.bstr;

View File

@ -212,6 +212,7 @@ typedef enum {
X(case, 0, ARG_ADDR, 0) \
X(concat, 1, 0, 0) \
X(const, 1, ARG_BSTR, 0) \
X(dim, 1, ARG_BSTR, ARG_UINT) \
X(div, 1, 0, 0) \
X(double, 1, ARG_DOUBLE, 0) \
X(empty, 1, 0, 0) \
@ -299,6 +300,11 @@ typedef struct {
const WCHAR *name;
} var_desc_t;
typedef struct {
unsigned dim_cnt;
SAFEARRAYBOUND *bounds;
} array_desc_t;
struct _function_t {
function_type_t type;
const WCHAR *name;
@ -307,6 +313,8 @@ struct _function_t {
unsigned arg_cnt;
var_desc_t *vars;
unsigned var_cnt;
array_desc_t *array_descs;
unsigned array_cnt;
unsigned code_off;
vbscode_t *code_ctx;
function_t *next;