Jacek Caban : vbscript: Added beginning interpreter implementation.
Alexandre Julliard
julliard at winehq.org
Wed Sep 7 12:35:30 CDT 2011
Module: wine
Branch: master
Commit: 8906a4aa622ff3de4f6306ce518e10b6f6428b6b
URL: http://source.winehq.org/git/wine.git/?a=commit;h=8906a4aa622ff3de4f6306ce518e10b6f6428b6b
Author: Jacek Caban <jacek at codeweavers.com>
Date: Wed Sep 7 14:07:24 2011 +0200
vbscript: Added beginning interpreter implementation.
---
dlls/vbscript/Makefile.in | 1 +
dlls/vbscript/interp.c | 77 +++++++++++++++++++++++++++++++++++++++++++++
dlls/vbscript/vbscript.c | 34 +++++++++++++++++---
dlls/vbscript/vbscript.h | 1 +
4 files changed, 108 insertions(+), 5 deletions(-)
diff --git a/dlls/vbscript/Makefile.in b/dlls/vbscript/Makefile.in
index 977bcde..9e27dd4 100644
--- a/dlls/vbscript/Makefile.in
+++ b/dlls/vbscript/Makefile.in
@@ -2,6 +2,7 @@ MODULE = vbscript.dll
C_SRCS = \
compile.c \
+ interp.c \
lex.c \
vbdisp.c \
vbscript.c \
diff --git a/dlls/vbscript/interp.c b/dlls/vbscript/interp.c
new file mode 100644
index 0000000..7cee9c7
--- /dev/null
+++ b/dlls/vbscript/interp.c
@@ -0,0 +1,77 @@
+/*
+ * 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);
+
+
+typedef struct {
+ vbscode_t *code;
+ instr_t *instr;
+} exec_ctx_t;
+
+
+typedef HRESULT (*instr_func_t)(exec_ctx_t*);
+
+static HRESULT interp_ret(exec_ctx_t *ctx)
+{
+ TRACE("\n");
+
+ ctx->instr = NULL;
+ return S_OK;
+}
+
+static const instr_func_t op_funcs[] = {
+#define X(x,n) interp_ ## x,
+OP_LIST
+#undef X
+};
+
+static const unsigned op_move[] = {
+#define X(x,n) n,
+OP_LIST
+#undef X
+};
+
+HRESULT exec_script(script_ctx_t *ctx, function_t *func)
+{
+ exec_ctx_t exec;
+ vbsop_t op;
+ HRESULT hres = S_OK;
+
+ exec.code = func->code_ctx;
+ exec.instr = exec.code->instrs + func->code_off;
+
+ while(exec.instr) {
+ op = exec.instr->op;
+ hres = op_funcs[op](&exec);
+ if(FAILED(hres)) {
+ FIXME("Failed %08x\n", hres);
+ break;
+ }
+
+ exec.instr += op_move[op];
+ }
+
+ return hres;
+}
diff --git a/dlls/vbscript/vbscript.c b/dlls/vbscript/vbscript.c
index ff9d2c9..f6891c7 100644
--- a/dlls/vbscript/vbscript.c
+++ b/dlls/vbscript/vbscript.c
@@ -63,9 +63,34 @@ static void change_state(VBScript *This, SCRIPTSTATE state)
IActiveScriptSite_OnStateChange(This->site, state);
}
-static void exec_queued_code(VBScript *This)
+static inline BOOL is_started(VBScript *This)
{
- FIXME("\n");
+ return This->state == SCRIPTSTATE_STARTED
+ || This->state == SCRIPTSTATE_CONNECTED
+ || This->state == SCRIPTSTATE_DISCONNECTED;
+}
+
+static HRESULT exec_global_code(script_ctx_t *ctx, vbscode_t *code)
+{
+ HRESULT hres;
+
+ code->global_executed = TRUE;
+
+ IActiveScriptSite_OnEnterScript(ctx->site);
+ hres = exec_script(ctx, &code->global_code);
+ IActiveScriptSite_OnLeaveScript(ctx->site);
+
+ return hres;
+}
+
+static void exec_queued_code(script_ctx_t *ctx)
+{
+ vbscode_t *iter;
+
+ LIST_FOR_EACH_ENTRY(iter, &ctx->code_list, vbscode_t, entry) {
+ if(!iter->global_executed)
+ exec_global_code(ctx, iter);
+ }
}
static HRESULT set_ctx_site(VBScript *This)
@@ -264,7 +289,7 @@ static HRESULT WINAPI VBScript_SetScriptState(IActiveScript *iface, SCRIPTSTATE
if(This->state == SCRIPTSTATE_CLOSED)
return E_UNEXPECTED;
- exec_queued_code(This);
+ exec_queued_code(This->ctx);
break;
case SCRIPTSTATE_INITIALIZED:
FIXME("unimplemented SCRIPTSTATE_INITIALIZED\n");
@@ -530,8 +555,7 @@ static HRESULT WINAPI VBScriptParse_ParseScriptText(IActiveScriptParse *iface,
if(FAILED(hres))
return hres;
- FIXME("executing script not implemented\n");
- return E_NOTIMPL;
+ return is_started(This) ? exec_global_code(This->ctx, code) : S_OK;
}
static const IActiveScriptParseVtbl VBScriptParseVtbl = {
diff --git a/dlls/vbscript/vbscript.h b/dlls/vbscript/vbscript.h
index 88f7552..99ed4ba 100644
--- a/dlls/vbscript/vbscript.h
+++ b/dlls/vbscript/vbscript.h
@@ -93,6 +93,7 @@ struct _vbscode_t {
void release_vbscode(vbscode_t*) DECLSPEC_HIDDEN;
HRESULT compile_script(script_ctx_t*,const WCHAR*,vbscode_t**) DECLSPEC_HIDDEN;
+HRESULT exec_script(script_ctx_t*,function_t*) DECLSPEC_HIDDEN;
HRESULT WINAPI VBScriptFactory_CreateInstance(IClassFactory*,IUnknown*,REFIID,void**);
More information about the wine-cvs
mailing list