Commit 8906a4aa authored by Jacek Caban's avatar Jacek Caban Committed by Alexandre Julliard

vbscript: Added beginning interpreter implementation.

parent c674c7a7
......@@ -2,6 +2,7 @@ MODULE = vbscript.dll
C_SRCS = \
compile.c \
interp.c \
lex.c \
vbdisp.c \
vbscript.c \
......
/*
* 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;
}
......@@ -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 = {
......
......@@ -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**);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment