mirror of
https://github.com/scummvm/scummvm.git
synced 2026-06-20 05:45:29 +00:00
DIRECTOR: LINGO: Eliminate lazy vars
Now normal var refs are evaluated on pop. To get the reference itself, use pop(false)
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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 */
|
||||
|
||||
Reference in New Issue
Block a user