From 60fe2ea32ee4ca05ca45fabc3fa79870b72d4e70 Mon Sep 17 00:00:00 2001 From: djsrv Date: Thu, 20 Aug 2020 15:34:13 -0400 Subject: [PATCH] DIRECTOR: LINGO: Eliminate lazy vars Now normal var refs are evaluated on pop. To get the reference itself, use pop(false) --- engines/director/lingo/lingo-bytecode.cpp | 5 ++--- engines/director/lingo/lingo-code.cpp | 14 +++++++------- engines/director/lingo/lingo.cpp | 11 ----------- engines/director/lingo/lingo.h | 1 - 4 files changed, 9 insertions(+), 22 deletions(-) diff --git a/engines/director/lingo/lingo-bytecode.cpp b/engines/director/lingo/lingo-bytecode.cpp index d62df57a70b..d66d4302920 100644 --- a/engines/director/lingo/lingo-bytecode.cpp +++ b/engines/director/lingo/lingo-bytecode.cpp @@ -405,7 +405,7 @@ void LC::cb_localcall() { void LC::cb_objectcall() { int varType = g_lingo->readInt(); - Datum varId = g_lingo->pop(); + Datum varId = g_lingo->pop(false); Datum nargs = g_lingo->pop(); Datum var = g_lingo->findVarV4(varType, varId); @@ -424,7 +424,6 @@ void LC::cb_objectcall() { // The first arg could be either a method name or a variable name if (firstArg.type == SYMBOL) { firstArg.type = VAR; - firstArg.lazy = true; // var will be evaluated on pop } } @@ -436,7 +435,7 @@ void LC::cb_v4assign() { int arg = g_lingo->readInt(); int op = (arg >> 4) & 0xF; int varType = arg & 0xF; - Datum varId = g_lingo->pop(); + Datum varId = g_lingo->pop(false); Datum var = g_lingo->findVarV4(varType, varId); g_lingo->push(var); diff --git a/engines/director/lingo/lingo-code.cpp b/engines/director/lingo/lingo-code.cpp index b91e2a6819f..48d09e0d72c 100644 --- a/engines/director/lingo/lingo-code.cpp +++ b/engines/director/lingo/lingo-code.cpp @@ -197,7 +197,7 @@ Datum Lingo::pop(bool eval) { Datum ret = _stack.back(); _stack.pop_back(); - if (eval && ret.lazy) { + if (eval && ret.type == VAR) { ret = ret.eval(); } @@ -208,9 +208,10 @@ Datum Lingo::peek(uint offset, bool eval) { assert (_stack.size() > offset); Datum ret = _stack[_stack.size() - 1 - offset]; - if (eval && ret.lazy) { + if (eval && ret.type == VAR) { ret = ret.eval(); } + return ret; } @@ -489,7 +490,7 @@ void LC::c_setImmediate() { void LC::c_assign() { Datum d1, d2; - d1 = g_lingo->pop(); + d1 = g_lingo->pop(false); d2 = g_lingo->pop(); g_lingo->varAssign(d1, d2); @@ -516,7 +517,6 @@ void LC::c_lazyeval() { Datum d; d = g_lingo->pop(); - d.lazy = true; g_lingo->push(d); } @@ -790,7 +790,7 @@ void LC::c_ampersand() { } void LC::c_putbefore() { - Datum var = g_lingo->pop(); + Datum var = g_lingo->pop(false); Datum a = g_lingo->pop(); Datum b = g_lingo->varFetch(var); @@ -799,7 +799,7 @@ void LC::c_putbefore() { } void LC::c_putafter() { - Datum var = g_lingo->pop(); + Datum var = g_lingo->pop(false); Datum a = g_lingo->pop(); Datum b = g_lingo->varFetch(var); @@ -1458,7 +1458,7 @@ void LC::call(const Common::String &name, int nargs, bool allowRetVal) { Datum firstArg = g_lingo->_stack[g_lingo->_stack.size() - nargs]; // Factory/XObject method call - if (firstArg.lazy) { // first arg could be method name + if (firstArg.type == VAR) { // first arg could be method name Datum objName(name); objName.type = VAR; Datum obj = g_lingo->varFetch(objName, false, nullptr, true); diff --git a/engines/director/lingo/lingo.cpp b/engines/director/lingo/lingo.cpp index 6fb1244d02c..02598787cd3 100644 --- a/engines/director/lingo/lingo.cpp +++ b/engines/director/lingo/lingo.cpp @@ -736,14 +736,12 @@ int Lingo::getAlignedType(const Datum &d1, const Datum &d2, bool numsOnly) { Datum::Datum() { u.s = nullptr; type = VOID; - lazy = false; refCount = new int; *refCount = 1; } Datum::Datum(const Datum &d) { type = d.type; - lazy = d.lazy; u = d.u; refCount = d.refCount; *refCount += 1; @@ -763,7 +761,6 @@ Datum& Datum::operator=(const Datum &d) { Datum::Datum(int val) { u.i = val; type = INT; - lazy = false; refCount = new int; *refCount = 1; } @@ -771,7 +768,6 @@ Datum::Datum(int val) { Datum::Datum(double val) { u.f = val; type = FLOAT; - lazy = false; refCount = new int; *refCount = 1; } @@ -779,14 +775,12 @@ Datum::Datum(double val) { Datum::Datum(const Common::String &val) { u.s = new Common::String(val); type = STRING; - lazy = false; refCount = new int; *refCount = 1; } Datum::Datum(AbstractObject *val) { u.obj = val; - lazy = false; if (val) { type = OBJECT; refCount = val->getRefCount(); @@ -841,7 +835,6 @@ void Datum::reset() { Datum Datum::eval() { if (type != VAR) { // It could be cast ref - lazy = false; return *this; } @@ -1015,10 +1008,6 @@ Common::String Datum::asString(bool printonly) const { warning("Incorrect operation asString() for type: %s", type2str()); } - if (printonly && lazy) { - s += " (lazy)"; - } - return s; } diff --git a/engines/director/lingo/lingo.h b/engines/director/lingo/lingo.h index d5c1289f530..524a0502b41 100644 --- a/engines/director/lingo/lingo.h +++ b/engines/director/lingo/lingo.h @@ -109,7 +109,6 @@ struct Symbol { /* symbol table entry */ struct Datum { /* interpreter stack type */ int type; - bool lazy; // evaluate when popped off stack union { int i; /* INT, ARGC, ARGCNORET */