From aa01d2568dcecf5a12ce2d8f04e969658ea46c89 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Fri, 30 Jun 2000 11:29:35 -0300 Subject: [PATCH] symbolic execution must handle return and tailcall --- ldebug.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/ldebug.c b/ldebug.c index 050cc6c8..6ab85434 100644 --- a/ldebug.c +++ b/ldebug.c @@ -1,5 +1,5 @@ /* -** $Id: ldebug.c,v 1.24 2000/06/26 19:28:31 roberto Exp roberto $ +** $Id: ldebug.c,v 1.25 2000/06/28 20:20:36 roberto Exp roberto $ ** Debug Interface ** See Copyright Notice in lua.h */ @@ -245,15 +245,27 @@ static Instruction luaG_symbexec (const Proto *pt, int lastpc, int stackpos) { top++; /* `arg' */ while (pc < lastpc) { const Instruction i = code[pc++]; + LUA_ASSERT(NULL, top <= pt->maxstacksize, "wrong stack"); switch (GET_OPCODE(i)) { + case OP_RETURN: { + LUA_ASSERT(NULL, top >= GETARG_U(i), "wrong stack"); + top = GETARG_U(i); + break; + } case OP_CALL: { int nresults = GETARG_B(i); if (nresults == MULT_RET) nresults = 1; + LUA_ASSERT(NULL, top >= GETARG_A(i), "wrong stack"); top = GETARG_A(i); while (nresults--) stack[top++] = pc-1; break; } + case OP_TAILCALL: { + LUA_ASSERT(NULL, top >= GETARG_A(i), "wrong stack"); + top = GETARG_B(i); + break; + } case OP_PUSHNIL: { int n; for (n=0; n= lastpc) { + if (lastpc < newpc) + top--; /* original code did not jump; condition was false */ + else { stack[top-1] = pc-1; /* value generated by or-and */ pc = newpc; /* do the jump */ } - else - top--; /* original code did not jump; condition was false */ break; } case OP_PUSHNILJMP: { @@ -302,6 +314,7 @@ static Instruction luaG_symbexec (const Proto *pt, int lastpc, int stackpos) { LUA_ASSERT(NULL, luaK_opproperties[GET_OPCODE(i)].push != VD, "invalid opcode for default"); top -= luaK_opproperties[GET_OPCODE(i)].pop; + LUA_ASSERT(NULL, top >= 0, "wrong stack"); for (n=0; n