diff options
Diffstat (limited to 'engines/director/lingo/lingo-codegen.cpp')
-rw-r--r-- | engines/director/lingo/lingo-codegen.cpp | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/engines/director/lingo/lingo-codegen.cpp b/engines/director/lingo/lingo-codegen.cpp index e1e77c990a..eda6469014 100644 --- a/engines/director/lingo/lingo-codegen.cpp +++ b/engines/director/lingo/lingo-codegen.cpp @@ -386,14 +386,19 @@ int Lingo::codeMe(Common::String *method, int numpar) { void Lingo::codeLabel(int label) { _labelstack.push_back(label); + debugC(4, kDebugLingoCompile, "codeLabel: Added label %d", label); } -void Lingo::processIf(int elselabel, int endlabel) { +void Lingo::processIf(int startlabel, int endlabel, int finalElse) { inst ielse1, iend; - int else1 = elselabel; + int else1 = 0; + + debugC(4, kDebugLingoCompile, "processIf(%d, %d, %d)", startlabel, endlabel, finalElse); WRITE_UINT32(&iend, endlabel); + int finalElsePos = -1; + while (true) { if (_labelstack.empty()) { warning("Label stack underflow"); @@ -410,12 +415,26 @@ void Lingo::processIf(int elselabel, int endlabel) { if (else1) else1 = else1 - label; + // Store position of the last 'if', so we could set reference to the + // 'finalElse' part + if (finalElse && finalElsePos == -1) { + finalElsePos = label; + } + + debugC(4, kDebugLingoCompile, "processIf: %d: %d %d", label, else1 + label, endlabel + label); + WRITE_UINT32(&ielse1, else1); (*_currentScript)[label + 2] = ielse1; /* elsepart */ (*_currentScript)[label + 3] = iend; /* end, if cond fails */ else1 = label; } + + if (finalElsePos != -1) { + debugC(4, kDebugLingoCompile, "processIf: storing %d to %d", finalElse - finalElsePos + startlabel, finalElsePos); + WRITE_UINT32(&ielse1, finalElse - finalElsePos + startlabel); + (*_currentScript)[finalElsePos + 2] = ielse1; + } } void Lingo::codeFactory(Common::String &name) { |