vbscript: Added compiler support for boolean literals.
This commit is contained in:
parent
dc73a7c4bb
commit
23c1fea07e
@ -34,6 +34,8 @@ typedef struct {
|
|||||||
vbscode_t *code;
|
vbscode_t *code;
|
||||||
} compile_ctx_t;
|
} compile_ctx_t;
|
||||||
|
|
||||||
|
static HRESULT compile_expression(compile_ctx_t*,expression_t*);
|
||||||
|
|
||||||
static inline instr_t *instr_ptr(compile_ctx_t *ctx, unsigned id)
|
static inline instr_t *instr_ptr(compile_ctx_t *ctx, unsigned id)
|
||||||
{
|
{
|
||||||
assert(id < ctx->instr_cnt);
|
assert(id < ctx->instr_cnt);
|
||||||
@ -59,6 +61,18 @@ static unsigned push_instr(compile_ctx_t *ctx, vbsop_t op)
|
|||||||
return ctx->instr_cnt++;
|
return ctx->instr_cnt++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static HRESULT push_instr_int(compile_ctx_t *ctx, vbsop_t op, LONG arg)
|
||||||
|
{
|
||||||
|
unsigned ret;
|
||||||
|
|
||||||
|
ret = push_instr(ctx, op);
|
||||||
|
if(ret == -1)
|
||||||
|
return E_OUTOFMEMORY;
|
||||||
|
|
||||||
|
instr_ptr(ctx, ret)->arg1.lng = arg;
|
||||||
|
return S_OK;
|
||||||
|
}
|
||||||
|
|
||||||
static BSTR alloc_bstr_arg(compile_ctx_t *ctx, const WCHAR *str)
|
static BSTR alloc_bstr_arg(compile_ctx_t *ctx, const WCHAR *str)
|
||||||
{
|
{
|
||||||
if(!ctx->code->bstr_pool_size) {
|
if(!ctx->code->bstr_pool_size) {
|
||||||
@ -84,12 +98,12 @@ static BSTR alloc_bstr_arg(compile_ctx_t *ctx, const WCHAR *str)
|
|||||||
return ctx->code->bstr_pool[ctx->code->bstr_cnt++];
|
return ctx->code->bstr_pool[ctx->code->bstr_cnt++];
|
||||||
}
|
}
|
||||||
|
|
||||||
static HRESULT push_instr_bstr(compile_ctx_t *ctx, vbsop_t op, const WCHAR *arg)
|
static HRESULT push_instr_bstr_uint(compile_ctx_t *ctx, vbsop_t op, const WCHAR *arg1, unsigned arg2)
|
||||||
{
|
{
|
||||||
unsigned instr;
|
unsigned instr;
|
||||||
BSTR bstr;
|
BSTR bstr;
|
||||||
|
|
||||||
bstr = alloc_bstr_arg(ctx, arg);
|
bstr = alloc_bstr_arg(ctx, arg1);
|
||||||
if(!bstr)
|
if(!bstr)
|
||||||
return E_OUTOFMEMORY;
|
return E_OUTOFMEMORY;
|
||||||
|
|
||||||
@ -98,28 +112,60 @@ static HRESULT push_instr_bstr(compile_ctx_t *ctx, vbsop_t op, const WCHAR *arg)
|
|||||||
return E_OUTOFMEMORY;
|
return E_OUTOFMEMORY;
|
||||||
|
|
||||||
instr_ptr(ctx, instr)->arg1.bstr = bstr;
|
instr_ptr(ctx, instr)->arg1.bstr = bstr;
|
||||||
|
instr_ptr(ctx, instr)->arg2.uint = arg2;
|
||||||
|
return S_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
static HRESULT compile_args(compile_ctx_t *ctx, expression_t *args, unsigned *ret)
|
||||||
|
{
|
||||||
|
unsigned arg_cnt = 0;
|
||||||
|
HRESULT hres;
|
||||||
|
|
||||||
|
while(args) {
|
||||||
|
hres = compile_expression(ctx, args);
|
||||||
|
if(FAILED(hres))
|
||||||
|
return hres;
|
||||||
|
|
||||||
|
arg_cnt++;
|
||||||
|
args = args->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
*ret = arg_cnt;
|
||||||
return S_OK;
|
return S_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static HRESULT compile_member_expression(compile_ctx_t *ctx, member_expression_t *expr)
|
static HRESULT compile_member_expression(compile_ctx_t *ctx, member_expression_t *expr)
|
||||||
{
|
{
|
||||||
|
unsigned arg_cnt = 0;
|
||||||
HRESULT hres;
|
HRESULT hres;
|
||||||
|
|
||||||
if(expr->args) {
|
hres = compile_args(ctx, expr->args, &arg_cnt);
|
||||||
FIXME("arguments not implemented\n");
|
if(FAILED(hres))
|
||||||
return E_NOTIMPL;
|
return hres;
|
||||||
}
|
|
||||||
|
|
||||||
if(expr->obj_expr) {
|
if(expr->obj_expr) {
|
||||||
FIXME("obj_expr not implemented\n");
|
FIXME("obj_expr not implemented\n");
|
||||||
hres = E_NOTIMPL;
|
hres = E_NOTIMPL;
|
||||||
}else {
|
}else {
|
||||||
hres = push_instr_bstr(ctx, OP_icallv, expr->identifier);
|
hres = push_instr_bstr_uint(ctx, OP_icallv, expr->identifier, arg_cnt);
|
||||||
}
|
}
|
||||||
|
|
||||||
return hres;
|
return hres;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static HRESULT compile_expression(compile_ctx_t *ctx, expression_t *expr)
|
||||||
|
{
|
||||||
|
switch(expr->type) {
|
||||||
|
case EXPR_BOOL:
|
||||||
|
return push_instr_int(ctx, OP_bool, ((bool_expression_t*)expr)->value);
|
||||||
|
default:
|
||||||
|
FIXME("Unimplemented expression type %d\n", expr->type);
|
||||||
|
return E_NOTIMPL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return S_OK;
|
||||||
|
}
|
||||||
|
|
||||||
static HRESULT compile_statement(compile_ctx_t *ctx, statement_t *stat)
|
static HRESULT compile_statement(compile_ctx_t *ctx, statement_t *stat)
|
||||||
{
|
{
|
||||||
HRESULT hres;
|
HRESULT hres;
|
||||||
|
@ -75,12 +75,18 @@ static HRESULT lookup_identifier(exec_ctx_t *ctx, BSTR name, ref_t *ref)
|
|||||||
static HRESULT interp_icallv(exec_ctx_t *ctx)
|
static HRESULT interp_icallv(exec_ctx_t *ctx)
|
||||||
{
|
{
|
||||||
BSTR identifier = ctx->instr->arg1.bstr;
|
BSTR identifier = ctx->instr->arg1.bstr;
|
||||||
|
const unsigned arg_cnt = ctx->instr->arg2.uint;
|
||||||
DISPPARAMS dp = {0};
|
DISPPARAMS dp = {0};
|
||||||
ref_t ref;
|
ref_t ref;
|
||||||
HRESULT hres;
|
HRESULT hres;
|
||||||
|
|
||||||
TRACE("\n");
|
TRACE("\n");
|
||||||
|
|
||||||
|
if(arg_cnt) {
|
||||||
|
FIXME("arguments not implemented\n");
|
||||||
|
return E_NOTIMPL;
|
||||||
|
}
|
||||||
|
|
||||||
hres = lookup_identifier(ctx, identifier, &ref);
|
hres = lookup_identifier(ctx, identifier, &ref);
|
||||||
if(FAILED(hres))
|
if(FAILED(hres))
|
||||||
return hres;
|
return hres;
|
||||||
@ -107,6 +113,12 @@ static HRESULT interp_ret(exec_ctx_t *ctx)
|
|||||||
return S_OK;
|
return S_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static HRESULT interp_bool(exec_ctx_t *ctx)
|
||||||
|
{
|
||||||
|
FIXME("\n");
|
||||||
|
return E_NOTIMPL;
|
||||||
|
}
|
||||||
|
|
||||||
static const instr_func_t op_funcs[] = {
|
static const instr_func_t op_funcs[] = {
|
||||||
#define X(x,n,a,b) interp_ ## x,
|
#define X(x,n,a,b) interp_ ## x,
|
||||||
OP_LIST
|
OP_LIST
|
||||||
|
@ -69,11 +69,14 @@ HRESULT init_global(script_ctx_t*);
|
|||||||
typedef enum {
|
typedef enum {
|
||||||
ARG_NONE = 0,
|
ARG_NONE = 0,
|
||||||
ARG_STR,
|
ARG_STR,
|
||||||
ARG_BSTR
|
ARG_BSTR,
|
||||||
|
ARG_INT,
|
||||||
|
ARG_UINT
|
||||||
} instr_arg_type_t;
|
} instr_arg_type_t;
|
||||||
|
|
||||||
#define OP_LIST \
|
#define OP_LIST \
|
||||||
X(icallv, 1, ARG_BSTR, 0) \
|
X(bool, 1, ARG_INT, 0) \
|
||||||
|
X(icallv, 1, ARG_BSTR, ARG_UINT) \
|
||||||
X(ret, 0, 0, 0)
|
X(ret, 0, 0, 0)
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
@ -86,6 +89,8 @@ OP_LIST
|
|||||||
typedef union {
|
typedef union {
|
||||||
const WCHAR *str;
|
const WCHAR *str;
|
||||||
BSTR bstr;
|
BSTR bstr;
|
||||||
|
unsigned uint;
|
||||||
|
LONG lng;
|
||||||
} instr_arg_t;
|
} instr_arg_t;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user