[Scummvm-git-logs] scummvm master -> a5948cfc37a19e939e938c6579b8a507ff3d8fb0
djsrv
dservilla at gmail.com
Thu Aug 20 19:56:26 UTC 2020
This automated email contains information about 2 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
60fe2ea32e DIRECTOR: LINGO: Eliminate lazy vars
a5948cfc37 DIRECTOR: LINGO: Evaluate field ref on pop
Commit: 60fe2ea32ee4ca05ca45fabc3fa79870b72d4e70
https://github.com/scummvm/scummvm/commit/60fe2ea32ee4ca05ca45fabc3fa79870b72d4e70
Author: djsrv (dservilla at gmail.com)
Date: 2020-08-20T15:34:13-04:00
Commit Message:
DIRECTOR: LINGO: Eliminate lazy vars
Now normal var refs are evaluated on pop. To get the reference itself,
use pop(false)
Changed paths:
engines/director/lingo/lingo-bytecode.cpp
engines/director/lingo/lingo-code.cpp
engines/director/lingo/lingo.cpp
engines/director/lingo/lingo.h
diff --git a/engines/director/lingo/lingo-bytecode.cpp b/engines/director/lingo/lingo-bytecode.cpp
index d62df57a70..d66d430292 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 b91e2a6819..48d09e0d72 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 6fb1244d02..02598787cd 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 d5c1289f53..524a0502b4 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 */
Commit: a5948cfc37a19e939e938c6579b8a507ff3d8fb0
https://github.com/scummvm/scummvm/commit/a5948cfc37a19e939e938c6579b8a507ff3d8fb0
Author: djsrv (dservilla at gmail.com)
Date: 2020-08-20T15:53:31-04:00
Commit Message:
DIRECTOR: LINGO: Evaluate field ref on pop
This simplifies handling of fields, since most of the time it should be
treated as a string. Where we actually need a raw reference, pop(false)
is used.
Changed paths:
engines/director/lingo/lingo-builtins.cpp
engines/director/lingo/lingo-bytecode.cpp
engines/director/lingo/lingo-code.cpp
engines/director/lingo/lingo-the.cpp
engines/director/lingo/lingo.cpp
diff --git a/engines/director/lingo/lingo-builtins.cpp b/engines/director/lingo/lingo-builtins.cpp
index 8b929dba1d..e2ffc1ff64 100644
--- a/engines/director/lingo/lingo-builtins.cpp
+++ b/engines/director/lingo/lingo-builtins.cpp
@@ -455,7 +455,7 @@ void LB::b_chars(int nargs) {
Datum d3 = g_lingo->pop();
Datum d2 = g_lingo->pop();
Datum s = g_lingo->pop();
- TYPECHECK2(s, STRING, FIELDREF);
+ TYPECHECK(s, STRING);
if (g_director->getVersion() < 400 && (d2.type == FLOAT || d3.type == FLOAT)) {
warning("LB::b_chars: Called with a float in Director 2 and 3 mode. chars' can't handle floats");
@@ -516,7 +516,7 @@ void LB::b_hilite(int nargs) {
void LB::b_length(int nargs) {
Datum d = g_lingo->pop();
- TYPECHECK2(d, STRING, FIELDREF);
+ TYPECHECK(d, STRING);
int len = strlen(d.asString().c_str());
@@ -603,8 +603,6 @@ void LB::b_addProp(int nargs) {
Datum list = g_lingo->pop();
TYPECHECK(list, PARRAY);
- if (prop.type == FIELDREF)
- prop = g_lingo->varFetch(prop);
PCell cell = PCell(prop, value);
list.u.parr->push_back(cell);
@@ -1036,8 +1034,6 @@ void LB::b_setProp(int nargs) {
Datum prop = g_lingo->pop();
Datum list = g_lingo->pop();
TYPECHECK(list, PARRAY);
- if (prop.type == FIELDREF)
- prop = g_lingo->varFetch(prop);
int index = LC::compareArrays(LC::eqData, list, prop, true).u.i;
if (index > 0) {
diff --git a/engines/director/lingo/lingo-bytecode.cpp b/engines/director/lingo/lingo-bytecode.cpp
index d66d430292..a7effd83fb 100644
--- a/engines/director/lingo/lingo-bytecode.cpp
+++ b/engines/director/lingo/lingo-bytecode.cpp
@@ -379,9 +379,6 @@ void LC::cb_delete() {
void LC::cb_field() {
LB::b_field(1);
- Datum field = g_lingo->pop();
- Datum result = g_lingo->varFetch(field);
- g_lingo->push(result);
}
diff --git a/engines/director/lingo/lingo-code.cpp b/engines/director/lingo/lingo-code.cpp
index 48d09e0d72..e378501c44 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.type == VAR) {
+ if (eval) {
ret = ret.eval();
}
@@ -208,7 +208,7 @@ Datum Lingo::peek(uint offset, bool eval) {
assert (_stack.size() > offset);
Datum ret = _stack[_stack.size() - 1 - offset];
- if (eval && ret.type == VAR) {
+ if (eval) {
ret = ret.eval();
}
diff --git a/engines/director/lingo/lingo-the.cpp b/engines/director/lingo/lingo-the.cpp
index 2614b66940..ca0adeed24 100644
--- a/engines/director/lingo/lingo-the.cpp
+++ b/engines/director/lingo/lingo-the.cpp
@@ -1591,7 +1591,7 @@ Datum Lingo::getObjectProp(Datum &obj, Common::String &propName) {
d = obj.u.parr->operator[](index - 1).v;
}
return d;
- } else if (obj.type == CASTREF || obj.type == FIELDREF) {
+ } else if (obj.type == CASTREF) {
Movie *movie = _vm->getCurrentMovie();
if (!movie) {
warning("Lingo::getObjectProp(): No movie loaded");
@@ -1608,10 +1608,6 @@ Datum Lingo::getObjectProp(Datum &obj, Common::String &propName) {
}
return d;
}
- if (obj.type == FIELDREF && member->_type != kCastText) {
- warning("Lingo::getObjectProp(): CastMember %d is not a field", id);
- return d;
- }
if (member->hasProp(propName)) {
return member->getProp(propName);
@@ -1639,7 +1635,7 @@ void Lingo::setObjectProp(Datum &obj, Common::String &propName, Datum &val) {
PCell cell = PCell(propName, val);
obj.u.parr->push_back(cell);
}
- } else if (obj.type == CASTREF || obj.type == FIELDREF) {
+ } else if (obj.type == CASTREF) {
Movie *movie = _vm->getCurrentMovie();
if (!movie) {
warning("Lingo::setObjectProp(): No movie loaded");
@@ -1652,10 +1648,6 @@ void Lingo::setObjectProp(Datum &obj, Common::String &propName, Datum &val) {
warning("Lingo::setObjectProp(): CastMember %d not found", id);
return;
}
- if ((obj.type == FIELDREF) && member->_type != kCastText) {
- warning("Lingo::setObjectProp(): CastMember %d is not a field", id);
- return;
- }
if (member->hasProp(propName)) {
member->setProp(propName, val);
diff --git a/engines/director/lingo/lingo.cpp b/engines/director/lingo/lingo.cpp
index 02598787cd..db15d3ebea 100644
--- a/engines/director/lingo/lingo.cpp
+++ b/engines/director/lingo/lingo.cpp
@@ -689,11 +689,6 @@ int Lingo::getAlignedType(const Datum &d1, const Datum &d2, bool numsOnly) {
int d1Type = d1.type;
int d2Type = d2.type;
- if (d1Type == FIELDREF)
- d1Type = STRING;
- if (d2Type == FIELDREF)
- d2Type = STRING;
-
if (d1Type == d2Type && (!numsOnly || d1Type == INT || d1Type == FLOAT))
return d1Type;
@@ -834,11 +829,11 @@ void Datum::reset() {
}
Datum Datum::eval() {
- if (type != VAR) { // It could be cast ref
- return *this;
+ if (type == VAR || type == FIELDREF) {
+ return g_lingo->varFetch(*this);
}
- return g_lingo->varFetch(*this);
+ return *this;
}
int Datum::asInt() const {
@@ -846,7 +841,6 @@ int Datum::asInt() const {
switch (type) {
case STRING:
- case FIELDREF:
{
Common::String src = asString();
char *endPtr = 0;
@@ -882,9 +876,7 @@ double Datum::asFloat() const {
double res = 0.0;
switch (type) {
- case STRING:
- case FIELDREF:
- {
+ case STRING: {
Common::String src = asString();
char *endPtr = 0;
double result = strtod(src.c_str(), &endPtr);
@@ -968,11 +960,7 @@ Common::String Datum::asString(bool printonly) const {
break;
}
- if (!printonly) {
- s = ((TextCastMember *)member)->getText();
- } else {
- s = Common::String::format("field: \"%s\"", ((TextCastMember *)member)->getText().c_str());
- }
+ s = Common::String::format("field: \"%s\"", ((TextCastMember *)member)->getText().c_str());
}
break;
case POINT:
@@ -1032,7 +1020,6 @@ int Datum::asCastId() const {
break;
case INT:
case CASTREF:
- case FIELDREF:
castId = u.i;
break;
case FLOAT:
More information about the Scummvm-git-logs
mailing list