Skip to content

Commit

Permalink
DIRECTOR: Lingo: Fix 'else if' statement execution
Browse files Browse the repository at this point in the history
  • Loading branch information
sev- committed Aug 3, 2016
1 parent b4670f6 commit 207609a
Show file tree
Hide file tree
Showing 5 changed files with 230 additions and 213 deletions.
17 changes: 12 additions & 5 deletions engines/director/lingo/lingo-code.cpp
Expand Up @@ -400,22 +400,29 @@ void Lingo::c_ifcode() {
Datum d;
int savepc = g_lingo->_pc; /* then part */

int then = READ_UINT32(&(*g_lingo->_currentScript)[savepc]);
int elsep = READ_UINT32(&(*g_lingo->_currentScript)[savepc + 1]);
int end = READ_UINT32(&(*g_lingo->_currentScript)[savepc + 2]);
int then = READ_UINT32(&(*g_lingo->_currentScript)[savepc]);
int elsep = READ_UINT32(&(*g_lingo->_currentScript)[savepc + 1]);
int end = READ_UINT32(&(*g_lingo->_currentScript)[savepc + 2]);
int skipEnd = READ_UINT32(&(*g_lingo->_currentScript)[savepc + 3]);

g_lingo->execute(savepc + 3); /* condition */
debug(8, "executing cond (have to %s end)", skipEnd ? "skip" : "execute");
g_lingo->execute(savepc + 4); /* condition */

d = g_lingo->pop();

if (d.toInt()) {
debug(8, "executing then");
g_lingo->execute(then);
} else if (elsep) { /* else part? */
debug(8, "executing else");
g_lingo->execute(elsep);
}

if (!g_lingo->_returning)
if (!g_lingo->_returning && !skipEnd) {
g_lingo->_pc = end; /* next stmt */
debug(8, "executing end");
} else
debug(8, "Skipped end");
}

//************************
Expand Down
4 changes: 2 additions & 2 deletions engines/director/lingo/lingo-codegen.cpp
Expand Up @@ -222,9 +222,9 @@ void Lingo::codeLabel(int label) {
_labelstack.push_back(label);
}

void Lingo::processIf(int endlabel) {
void Lingo::processIf(int elselabel, int endlabel) {
inst ielse1, iend;
int else1 = endlabel;
int else1 = elselabel;

WRITE_UINT32(&iend, endlabel);

Expand Down

0 comments on commit 207609a

Please sign in to comment.