Commit e0d02783 authored by Robert Wilhelm's avatar Robert Wilhelm Committed by Alexandre Julliard

vbscript: For for loop bounds coerce string to real.

parent 8e338fbb
...@@ -875,6 +875,8 @@ static HRESULT compile_forto_statement(compile_ctx_t *ctx, forto_statement_t *st ...@@ -875,6 +875,8 @@ static HRESULT compile_forto_statement(compile_ctx_t *ctx, forto_statement_t *st
hres = compile_expression(ctx, stat->from_expr); hres = compile_expression(ctx, stat->from_expr);
if(FAILED(hres)) if(FAILED(hres))
return hres; return hres;
if(!push_instr(ctx, OP_numval))
return E_OUTOFMEMORY;
/* FIXME: Assign should happen after both expressions evaluation. */ /* FIXME: Assign should happen after both expressions evaluation. */
instr = push_instr(ctx, OP_assign_ident); instr = push_instr(ctx, OP_assign_ident);
...@@ -887,7 +889,7 @@ static HRESULT compile_forto_statement(compile_ctx_t *ctx, forto_statement_t *st ...@@ -887,7 +889,7 @@ static HRESULT compile_forto_statement(compile_ctx_t *ctx, forto_statement_t *st
if(FAILED(hres)) if(FAILED(hres))
return hres; return hres;
if(!push_instr(ctx, OP_val)) if(!push_instr(ctx, OP_numval))
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
if(stat->step_expr) { if(stat->step_expr) {
...@@ -895,7 +897,7 @@ static HRESULT compile_forto_statement(compile_ctx_t *ctx, forto_statement_t *st ...@@ -895,7 +897,7 @@ static HRESULT compile_forto_statement(compile_ctx_t *ctx, forto_statement_t *st
if(FAILED(hres)) if(FAILED(hres))
return hres; return hres;
if(!push_instr(ctx, OP_val)) if(!push_instr(ctx, OP_numval))
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
}else { }else {
hres = push_instr_int(ctx, OP_int, 1); hres = push_instr_int(ctx, OP_int, 1);
......
...@@ -1088,6 +1088,37 @@ static HRESULT interp_val(exec_ctx_t *ctx) ...@@ -1088,6 +1088,37 @@ static HRESULT interp_val(exec_ctx_t *ctx)
return stack_push(ctx, val.owned ? val.v : &v); return stack_push(ctx, val.owned ? val.v : &v);
} }
static HRESULT interp_numval(exec_ctx_t *ctx)
{
variant_val_t val;
VARIANT v;
HRESULT hres;
TRACE("\n");
hres = stack_pop_val(ctx, &val);
if(FAILED(hres))
return hres;
if (V_VT(val.v) == VT_BSTR) {
V_VT(&v) = VT_EMPTY;
hres = VariantChangeType(&v, val.v, 0, VT_R8);
if(FAILED(hres))
return hres;
release_val(&val);
return stack_push(ctx, &v);
}
if(!val.owned) {
V_VT(&v) = VT_EMPTY;
hres = VariantCopy(&v, val.v);
if(FAILED(hres))
return hres;
}
return stack_push(ctx, val.owned ? val.v : &v);
}
static HRESULT interp_pop(exec_ctx_t *ctx) static HRESULT interp_pop(exec_ctx_t *ctx)
{ {
const unsigned n = ctx->instr->arg1.uint; const unsigned n = ctx->instr->arg1.uint;
......
...@@ -679,6 +679,33 @@ for x = 5 to 8 ...@@ -679,6 +679,33 @@ for x = 5 to 8
next next
Call ok(y = "for8: 5 7", "y = " & y) Call ok(y = "for8: 5 7", "y = " & y)
function testfor( startvalue, endvalue, stepvalue, steps)
Dim s
s=0
for x=startvalue to endvalue step stepvalue
s = s + 1
Next
Call ok( s = steps, "counted " & s & " steps in for loop, expected " & steps)
end function
Call testfor (1, 2, 1, 2)
Call testfor ("1", 2, 1, 2)
Call testfor (1, "2", 1, 2)
Call testfor (1, 2, "1", 2)
Call testfor ("1", "2", "1", 2)
if (isEnglishLang) then
Call testfor (1, 2, 0.5, 3)
Call testfor (1, 2.5, 0.5, 4)
Call testfor ("1", 2, 0.5, 3)
Call testfor ("1", 2.5, 0.5, 4)
Call testfor (1, "2", 0.5, 3)
Call testfor (1, "2.5", 0.5, 4)
Call testfor (1, 2, "0.5", 3)
Call testfor (1, 2.5, "0.5", 4)
Call testfor ("1", "2", "0.5", 3)
Call testfor ("1", "2.5", "0.5", 4)
end if
for x = 1.5 to 1 for x = 1.5 to 1
Call ok(false, "for..to called when unexpected") Call ok(false, "for..to called when unexpected")
next next
......
...@@ -278,6 +278,7 @@ typedef enum { ...@@ -278,6 +278,7 @@ typedef enum {
X(not, 1, 0, 0) \ X(not, 1, 0, 0) \
X(nothing, 1, 0, 0) \ X(nothing, 1, 0, 0) \
X(null, 1, 0, 0) \ X(null, 1, 0, 0) \
X(numval, 1, 0, 0) \
X(or, 1, 0, 0) \ X(or, 1, 0, 0) \
X(pop, 1, ARG_UINT, 0) \ X(pop, 1, ARG_UINT, 0) \
X(redim, 1, ARG_BSTR, ARG_UINT) \ X(redim, 1, ARG_BSTR, ARG_UINT) \
......
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