Module: wine Branch: master Commit: f8deed7c2fd5912ad819259ba76fc3f23f920017 URL: http://source.winehq.org/git/wine.git/?a=commit;h=f8deed7c2fd5912ad819259ba7...
Author: Jacek Caban jacek@codeweavers.com Date: Tue Jul 3 19:17:47 2012 +0200
vbscript: Fixed function return crossing for loop.
---
dlls/vbscript/compile.c | 25 ++++++++++++++++++++++--- dlls/vbscript/tests/lang.vbs | 18 ++++++++++++++++++ 2 files changed, 40 insertions(+), 3 deletions(-)
diff --git a/dlls/vbscript/compile.c b/dlls/vbscript/compile.c index 68e0a70..de29777 100644 --- a/dlls/vbscript/compile.c +++ b/dlls/vbscript/compile.c @@ -946,6 +946,25 @@ static HRESULT compile_exitfor_statement(compile_ctx_t *ctx) return push_instr_addr(ctx, OP_jmp, iter->for_end_label); }
+static HRESULT exit_label(compile_ctx_t *ctx, unsigned jmp_label) +{ + statement_ctx_t *iter; + unsigned pop_cnt = 0; + + for(iter = ctx->stat_ctx; iter; iter = iter->next) + pop_cnt += iter->stack_use; + + if(pop_cnt) { + HRESULT hres; + + hres = push_instr_uint(ctx, OP_pop, pop_cnt); + if(FAILED(hres)) + return hres; + } + + return push_instr_addr(ctx, OP_jmp, jmp_label); +} + static HRESULT compile_exitsub_statement(compile_ctx_t *ctx) { if(!ctx->sub_end_label) { @@ -953,7 +972,7 @@ static HRESULT compile_exitsub_statement(compile_ctx_t *ctx) return E_FAIL; }
- return push_instr_addr(ctx, OP_jmp, ctx->sub_end_label); + return exit_label(ctx, ctx->sub_end_label); }
static HRESULT compile_exitfunc_statement(compile_ctx_t *ctx) @@ -963,7 +982,7 @@ static HRESULT compile_exitfunc_statement(compile_ctx_t *ctx) return E_FAIL; }
- return push_instr_addr(ctx, OP_jmp, ctx->func_end_label); + return exit_label(ctx, ctx->func_end_label); }
static HRESULT compile_exitprop_statement(compile_ctx_t *ctx) @@ -973,7 +992,7 @@ static HRESULT compile_exitprop_statement(compile_ctx_t *ctx) return E_FAIL; }
- return push_instr_addr(ctx, OP_jmp, ctx->prop_end_label); + return exit_label(ctx, ctx->prop_end_label); }
static HRESULT compile_onerror_statement(compile_ctx_t *ctx, onerror_statement_t *stat) diff --git a/dlls/vbscript/tests/lang.vbs b/dlls/vbscript/tests/lang.vbs index f203e83..c03fa8f 100644 --- a/dlls/vbscript/tests/lang.vbs +++ b/dlls/vbscript/tests/lang.vbs @@ -489,6 +489,13 @@ End Sub
Call TestSubExit(true)
+Sub TestSubExit2 + for x = 1 to 100 + Exit Sub + next +End Sub +Call TestSubExit2 + TestSubMultiArgs 1, 2, 3, 4, 5 Call TestSubMultiArgs(1, 2, 3, 4, 5)
@@ -584,6 +591,17 @@ End Function
Call TestFuncExit(true)
+Function TestFuncExit2(ByRef a) + For x = 1 to 100 + For y = 1 to 100 + Exit Function + Next + Next + Call ok(false, "Exit Function not called?") +End Function + +Call TestFuncExit2(true) + Sub SubParseTest End Sub : x = false Call SubParseTest