Jacek Caban : vbscript: Added bytecode support for arrays.

Alexandre Julliard julliard at winehq.org
Wed Nov 13 13:34:41 CST 2013


Module: wine
Branch: master
Commit: fc713bfc1233a0c11f0441569281fd2efd0b6d5d
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=fc713bfc1233a0c11f0441569281fd2efd0b6d5d

Author: Jacek Caban <jacek at codeweavers.com>
Date:   Wed Nov 13 16:29:18 2013 +0100

vbscript: Added bytecode support for arrays.

---

 dlls/vbscript/compile.c  |   42 ++++++++++++++++++++++++++++++++++++++++--
 dlls/vbscript/interp.c   |    9 +++++++++
 dlls/vbscript/vbscript.h |    8 ++++++++
 3 files changed, 57 insertions(+), 2 deletions(-)

diff --git a/dlls/vbscript/compile.c b/dlls/vbscript/compile.c
index 7353c22..ea22787 100644
--- a/dlls/vbscript/compile.c
+++ b/dlls/vbscript/compile.c
@@ -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;
 
diff --git a/dlls/vbscript/interp.c b/dlls/vbscript/interp.c
index b3f4244..7d2cd65 100644
--- a/dlls/vbscript/interp.c
+++ b/dlls/vbscript/interp.c
@@ -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;
diff --git a/dlls/vbscript/vbscript.h b/dlls/vbscript/vbscript.h
index e25b524..47fa4c0 100644
--- a/dlls/vbscript/vbscript.h
+++ b/dlls/vbscript/vbscript.h
@@ -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;




More information about the wine-cvs mailing list