vbscript: Added compiler support for numeric literals.

This commit is contained in:
Jacek Caban 2011-09-12 12:30:11 +02:00 committed by Alexandre Julliard
parent 7f835c969e
commit 880d706636
3 changed files with 48 additions and 1 deletions

View File

@ -107,6 +107,24 @@ static HRESULT push_instr_str(compile_ctx_t *ctx, vbsop_t op, const WCHAR *arg)
return S_OK; return S_OK;
} }
static HRESULT push_instr_double(compile_ctx_t *ctx, vbsop_t op, double arg)
{
unsigned instr;
double *d;
d = compiler_alloc(ctx->code, sizeof(double));
if(!d)
return E_OUTOFMEMORY;
instr = push_instr(ctx, op);
if(instr == -1)
return E_OUTOFMEMORY;
*d = arg;
instr_ptr(ctx, instr)->arg1.dbl = d;
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) {
@ -218,6 +236,8 @@ static HRESULT compile_expression(compile_ctx_t *ctx, expression_t *expr)
switch(expr->type) { switch(expr->type) {
case EXPR_BOOL: case EXPR_BOOL:
return push_instr_int(ctx, OP_bool, ((bool_expression_t*)expr)->value); return push_instr_int(ctx, OP_bool, ((bool_expression_t*)expr)->value);
case EXPR_DOUBLE:
return push_instr_double(ctx, OP_double, ((double_expression_t*)expr)->value);
case EXPR_EMPTY: case EXPR_EMPTY:
return push_instr(ctx, OP_empty) != -1 ? S_OK : E_OUTOFMEMORY; return push_instr(ctx, OP_empty) != -1 ? S_OK : E_OUTOFMEMORY;
case EXPR_EQUAL: case EXPR_EQUAL:
@ -230,6 +250,10 @@ static HRESULT compile_expression(compile_ctx_t *ctx, expression_t *expr)
return push_instr(ctx, OP_null) != -1 ? S_OK : E_OUTOFMEMORY; return push_instr(ctx, OP_null) != -1 ? S_OK : E_OUTOFMEMORY;
case EXPR_STRING: case EXPR_STRING:
return push_instr_str(ctx, OP_string, ((string_expression_t*)expr)->value); return push_instr_str(ctx, OP_string, ((string_expression_t*)expr)->value);
case EXPR_USHORT:
return push_instr_int(ctx, OP_short, ((int_expression_t*)expr)->value);
case EXPR_ULONG:
return push_instr_int(ctx, OP_long, ((int_expression_t*)expr)->value);
default: default:
FIXME("Unimplemented expression type %d\n", expr->type); FIXME("Unimplemented expression type %d\n", expr->type);
return E_NOTIMPL; return E_NOTIMPL;

View File

@ -251,6 +251,24 @@ static HRESULT interp_string(exec_ctx_t *ctx)
return stack_push(ctx, &v); return stack_push(ctx, &v);
} }
static HRESULT interp_long(exec_ctx_t *ctx)
{
FIXME("\n");
return E_NOTIMPL;
}
static HRESULT interp_short(exec_ctx_t *ctx)
{
FIXME("\n");
return E_NOTIMPL;
}
static HRESULT interp_double(exec_ctx_t *ctx)
{
FIXME("\n");
return E_NOTIMPL;
}
static HRESULT interp_empty(exec_ctx_t *ctx) static HRESULT interp_empty(exec_ctx_t *ctx)
{ {
VARIANT v; VARIANT v;

View File

@ -83,18 +83,22 @@ typedef enum {
ARG_STR, ARG_STR,
ARG_BSTR, ARG_BSTR,
ARG_INT, ARG_INT,
ARG_UINT ARG_UINT,
ARG_DOUBLE
} instr_arg_type_t; } instr_arg_type_t;
#define OP_LIST \ #define OP_LIST \
X(bool, 1, ARG_INT, 0) \ X(bool, 1, ARG_INT, 0) \
X(double, 1, ARG_DOUBLE, 0) \
X(empty, 1, 0, 0) \ X(empty, 1, 0, 0) \
X(equal, 1, 0, 0) \ X(equal, 1, 0, 0) \
X(icall, 1, ARG_BSTR, ARG_UINT) \ X(icall, 1, ARG_BSTR, ARG_UINT) \
X(icallv, 1, ARG_BSTR, ARG_UINT) \ X(icallv, 1, ARG_BSTR, ARG_UINT) \
X(long, 1, ARG_INT, 0) \
X(not, 1, 0, 0) \ X(not, 1, 0, 0) \
X(null, 1, 0, 0) \ X(null, 1, 0, 0) \
X(ret, 0, 0, 0) \ X(ret, 0, 0, 0) \
X(short, 1, ARG_INT, 0) \
X(string, 1, ARG_STR, 0) X(string, 1, ARG_STR, 0)
typedef enum { typedef enum {
@ -109,6 +113,7 @@ typedef union {
BSTR bstr; BSTR bstr;
unsigned uint; unsigned uint;
LONG lng; LONG lng;
double *dbl;
} instr_arg_t; } instr_arg_t;
typedef struct { typedef struct {