From f430e3318aa491ba1c126aea570fcf65bf9e5ec6 Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Sun, 1 Dec 2019 14:24:05 +0100 Subject: DIRECTOR: LINGO: Fix compilation of the mixed code, and add relevant test --- engines/director/lingo/lingo-codegen.cpp | 8 ++++++++ engines/director/lingo/lingo.cpp | 21 ++++----------------- engines/director/lingo/tests/mixed-code.lingo | 14 ++++++++++++++ 3 files changed, 26 insertions(+), 17 deletions(-) create mode 100644 engines/director/lingo/tests/mixed-code.lingo diff --git a/engines/director/lingo/lingo-codegen.cpp b/engines/director/lingo/lingo-codegen.cpp index 2ba3c0940c..0b974771c9 100644 --- a/engines/director/lingo/lingo-codegen.cpp +++ b/engines/director/lingo/lingo-codegen.cpp @@ -250,6 +250,14 @@ Symbol *Lingo::define(Common::String &name, int start, int nargs, Common::String _currentScript->remove_at(i); } + if (debugChannelSet(1, kDebugLingoExec)) { + uint pc = 0; + while (pc < sym->u.defn->size()) { + Common::String instr = g_lingo->decodeInstruction(sym->u.defn, pc, &pc); + debugC(1, kDebugLingoExec, "[%5d] %s", pc, instr.c_str()); + } + } + return sym; } diff --git a/engines/director/lingo/lingo.cpp b/engines/director/lingo/lingo.cpp index 703a5b28c4..d009893747 100644 --- a/engines/director/lingo/lingo.cpp +++ b/engines/director/lingo/lingo.cpp @@ -155,17 +155,11 @@ void Lingo::addCode(const char *code, ScriptType type, uint16 id) { // Strip comments for ease of the parser Common::String codeNorm = stripComments(code); code = codeNorm.c_str(); + begin = code; // macros and factories have conflicting grammar. Thus we ease life for the parser. - if ((begin = findNextDefinition(code))) { - bool first = true; - - while ((end = findNextDefinition(begin + 1))) { - - if (first) { - begin = code; - first = false; - } + if ((end = findNextDefinition(code))) { + do { Common::String chunk(begin, end); if (chunk.hasPrefix("factory") || chunk.hasPrefix("method")) @@ -187,15 +181,8 @@ void Lingo::addCode(const char *code, ScriptType type, uint16 id) { } } - _currentScript->clear(); - begin = end; - } - - // Do not execute event handlers, macros and factories - // A side effect of it is that if you had those in your test script, - // then the whole script will not be executed - _hadError = true; + } while ((end = findNextDefinition(begin + 1))); debugC(1, kDebugLingoCompile, "Code chunk:\n#####\n%s\n#####", begin); parse(begin); diff --git a/engines/director/lingo/tests/mixed-code.lingo b/engines/director/lingo/tests/mixed-code.lingo new file mode 100644 index 0000000000..6f03e0b043 --- /dev/null +++ b/engines/director/lingo/tests/mixed-code.lingo @@ -0,0 +1,14 @@ +put "ONE" + +on two + put "TWO" +end two + +put "THREE" + +on four + put "FOUR" +end FOUR + +four +two -- cgit v1.2.3