[Scummvm-git-logs] scummvm master -> 478bea4ea04ce8c263137f7d22425ed14be38f15
djsrv
dservilla at gmail.com
Fri Jun 12 23:19:42 UTC 2020
This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
478bea4ea0 DIRECTOR: LINGO: Wrap _currentMe in Datum
Commit: 478bea4ea04ce8c263137f7d22425ed14be38f15
https://github.com/scummvm/scummvm/commit/478bea4ea04ce8c263137f7d22425ed14be38f15
Author: djsrv (dservilla at gmail.com)
Date: 2020-06-12T19:18:02-04:00
Commit Message:
DIRECTOR: LINGO: Wrap _currentMe in Datum
This makes sure it's included in reference counting, like _perFrameHook
Changed paths:
engines/director/lingo/lingo-builtins.cpp
engines/director/lingo/lingo-code.cpp
engines/director/lingo/lingo-code.h
engines/director/lingo/lingo-codegen.cpp
engines/director/lingo/lingo-object.cpp
engines/director/lingo/lingo.cpp
engines/director/lingo/lingo.h
engines/director/lingo/xlibs/fileio.cpp
diff --git a/engines/director/lingo/lingo-builtins.cpp b/engines/director/lingo/lingo-builtins.cpp
index 5f38f4e1df..0e154e8d28 100644
--- a/engines/director/lingo/lingo-builtins.cpp
+++ b/engines/director/lingo/lingo-builtins.cpp
@@ -1272,7 +1272,7 @@ void LB::b_return(int nargs) {
CFrame *fp = g_lingo->_callstack.back();
// Do not allow a factory's mNew method to return a value
// Otherwise do not touch the top of the stack, it will be returned
- if (g_lingo->_currentMeObj && g_lingo->_currentMeObj->type == kFactoryObj && fp->sp.name->equalsIgnoreCase("mNew")) {
+ if (g_lingo->_currentMe.type == OBJECT && g_lingo->_currentMe.u.obj->type == kFactoryObj && fp->sp.name->equalsIgnoreCase("mNew")) {
g_lingo->pop();
}
LC::c_procret();
diff --git a/engines/director/lingo/lingo-code.cpp b/engines/director/lingo/lingo-code.cpp
index dd5801fc81..0a6ad4844c 100644
--- a/engines/director/lingo/lingo-code.cpp
+++ b/engines/director/lingo/lingo-code.cpp
@@ -216,10 +216,11 @@ void Lingo::pushContext(const Symbol *funcSym, bool newVarFrame) {
fp->retctx = g_lingo->_currentScriptContext;
fp->retarchive = g_lingo->_archiveIndex;
fp->localvars = g_lingo->_localvars;
- fp->retMeObj = g_lingo->_currentMeObj;
+ fp->retMe = g_lingo->_currentMe;
if (funcSym)
fp->sp = *funcSym;
+ g_lingo->_currentMe = Datum();
if (newVarFrame)
g_lingo->_localvars = new SymbolHash;
@@ -239,7 +240,7 @@ void Lingo::popContext() {
g_lingo->_currentScriptContext = fp->retctx;
g_lingo->_archiveIndex = fp->retarchive;
g_lingo->_pc = fp->retpc;
- g_lingo->_currentMeObj = fp->retMeObj;
+ g_lingo->_currentMe = fp->retMe;
// Restore local variables
g_lingo->cleanLocalVars();
@@ -1296,13 +1297,13 @@ void LC::call(const Common::String &name, int nargs) {
Datum d = g_lingo->varFetch(eventName);
if (d.type == OBJECT && (d.u.obj->type & (kFactoryObj | kXObj))) {
debugC(3, kDebugLingoExec, "Dereferencing object reference: %s to <%s>", name.c_str(), d.asString(true).c_str());
- Object *target = d.u.obj;
+ Datum target = d;
Datum methodName = g_lingo->_stack.remove_at(g_lingo->_stack.size() - nargs); // Take method name out of stack
nargs -= 1;
if (methodName.u.s->equalsIgnoreCase("mNew")) {
- target = target->clone();
+ target = Datum(target.u.obj->clone());
}
- funcSym = target->getMethod(*methodName.u.s);
+ funcSym = target.u.obj->getMethod(*methodName.u.s);
call(funcSym, nargs, target);
return;
}
@@ -1310,7 +1311,7 @@ void LC::call(const Common::String &name, int nargs) {
call(funcSym, nargs);
}
-void LC::call(const Symbol &funcSym, int nargs, Object *target) {
+void LC::call(const Symbol &funcSym, int nargs, Datum target) {
bool dropArgs = false;
if (funcSym.type == VOID) {
@@ -1348,13 +1349,13 @@ void LC::call(const Symbol &funcSym, int nargs, Object *target) {
if (funcSym.type == BLTIN || funcSym.type == FBLTIN || funcSym.type == RBLTIN) {
int stackSize = g_lingo->_stack.size() - nargs;
- if (target) {
+ if (target.type == OBJECT) {
// Only need to update the me obj
// Pushing an entire stack frame is not necessary
- Object *retMeObj = g_lingo->_currentMeObj;
- g_lingo->_currentMeObj = target;
+ Datum retMe = g_lingo->_currentMe;
+ g_lingo->_currentMe = target;
(*funcSym.u.bltin)(nargs);
- g_lingo->_currentMeObj = retMeObj;
+ g_lingo->_currentMe = retMe;
} else {
(*funcSym.u.bltin)(nargs);
}
@@ -1422,10 +1423,8 @@ void LC::call(const Symbol &funcSym, int nargs, Object *target) {
}
g_lingo->_localvars = localvars;
- if (target) {
- g_lingo->_currentMeObj = target;
- } else {
- g_lingo->_currentMeObj = nullptr;
+ if (target.type == OBJECT) {
+ g_lingo->_currentMe = target;
}
g_lingo->_currentScript = funcSym.u.defn;
@@ -1445,12 +1444,9 @@ void LC::c_procret() {
}
CFrame *fp = g_lingo->_callstack.back();
- if (g_lingo->_currentMeObj && g_lingo->_currentMeObj->type == kFactoryObj && fp->sp.name->equalsIgnoreCase("mNew")) {
+ if (g_lingo->_currentMe.type == OBJECT && g_lingo->_currentMe.u.obj->type == kFactoryObj && fp->sp.name->equalsIgnoreCase("mNew")) {
// Return the newly created object after executing mNew
- Datum d;
- d.type = OBJECT;
- d.u.obj = g_lingo->_currentMeObj;
- g_lingo->push(d);
+ g_lingo->push(g_lingo->_currentMe);
}
g_lingo->popContext();
diff --git a/engines/director/lingo/lingo-code.h b/engines/director/lingo/lingo-code.h
index 2769351232..50f5c6c37b 100644
--- a/engines/director/lingo/lingo-code.h
+++ b/engines/director/lingo/lingo-code.h
@@ -115,7 +115,7 @@ namespace LC {
void c_jumpifz();
void c_call();
- void call(const Symbol &targetSym, int nargs, Object *target = nullptr);
+ void call(const Symbol &targetSym, int nargs, Datum target = Datum());
void call(const Common::String &name, int nargs);
void c_procret();
diff --git a/engines/director/lingo/lingo-codegen.cpp b/engines/director/lingo/lingo-codegen.cpp
index ec9e9b9cef..1b5a00d527 100644
--- a/engines/director/lingo/lingo-codegen.cpp
+++ b/engines/director/lingo/lingo-codegen.cpp
@@ -273,7 +273,7 @@ void Lingo::varCreate(const Common::String &name, bool global, SymbolHash *local
if (global)
warning("varCreate: variable %s is local, not global", name.c_str());
return;
- } else if (_currentMeObj && _currentMeObj->hasVar(name)) {
+ } else if (_currentMe.type == OBJECT && _currentMe.u.obj->hasVar(name)) {
if (global)
warning("varCreate: variable %s is instance or property, not global", name.c_str());
return;
diff --git a/engines/director/lingo/lingo-object.cpp b/engines/director/lingo/lingo-object.cpp
index bb71cbf84d..0df83c3253 100644
--- a/engines/director/lingo/lingo-object.cpp
+++ b/engines/director/lingo/lingo-object.cpp
@@ -120,11 +120,6 @@ Object *Object::clone() {
return res;
}
-void Object::addProperty(const Common::String &propName) {
- g_lingo->_currentMeObj->properties[propName] = Symbol();
- g_lingo->_currentMeObj->properties[propName].name = new Common::String(propName);
-}
-
Symbol Object::getMethod(const Common::String &methodName) {
if (disposed) {
error("Method '%s' called on disposed object <%s>", methodName.c_str(), Datum(this).asString(true).c_str());
@@ -176,33 +171,32 @@ Symbol &Object::getVar(const Common::String &varName) {
void LM::m_new(int nargs) {
// This is usually overridden by a user-defined mNew
g_lingo->printSTUBWithArglist("m_new", nargs);
- Datum res;
- res.type = OBJECT;
- res.u.obj = g_lingo->_currentMeObj;
- g_lingo->push(res);
+ g_lingo->push(g_lingo->_currentMe);
}
void LM::m_dispose(int nargs) {
- g_lingo->_currentMeObj->disposed = true;
+ g_lingo->_currentMe.u.obj->disposed = true;
}
// Object array
void LM::m_get(int nargs) {
+ Object *me = g_lingo->_currentMe.u.obj;
Datum indexD = g_lingo->pop();
uint index = MAX(0, indexD.asInt());
- if (g_lingo->_currentMeObj->objArray->contains(index)) {
- g_lingo->push((*g_lingo->_currentMeObj->objArray)[index]);
+ if (me->objArray->contains(index)) {
+ g_lingo->push((*me->objArray)[index]);
} else {
g_lingo->push(Datum(0));
}
}
void LM::m_put(int nargs) {
+ Object *me = g_lingo->_currentMe.u.obj;
Datum value = g_lingo->pop();
Datum indexD = g_lingo->pop();
uint index = MAX(0, indexD.asInt());
- (*g_lingo->_currentMeObj->objArray)[index] = value;
+ (*me->objArray)[index] = value;
}
// Other
@@ -210,10 +204,11 @@ void LM::m_put(int nargs) {
void LM::m_perform(int nargs) {
// Lingo doesn't seem to bother cloning the object when
// mNew is called with mPerform
+ Object *me = g_lingo->_currentMe.u.obj;
Datum methodName = g_lingo->_stack.remove_at(g_lingo->_stack.size() - nargs); // Take method name out of stack
nargs -= 1;
- Symbol funcSym = g_lingo->_currentMeObj->getMethod(*methodName.u.s);
- LC::call(funcSym, nargs, g_lingo->_currentMeObj);
+ Symbol funcSym = me->getMethod(*methodName.u.s);
+ LC::call(funcSym, nargs, g_lingo->_currentMe);
}
// XObject
@@ -223,7 +218,7 @@ void LM::m_describe(int nargs) {
}
void LM::m_instanceRespondsTo(int nargs) {
- Object *me = g_lingo->_currentMeObj;
+ Object *me = g_lingo->_currentMe.u.obj;
Datum d = g_lingo->pop();
Common::String methodName = d.asString();
@@ -244,12 +239,12 @@ void LM::m_messageList(int nargs) {
}
void LM::m_name(int nargs) {
- Common::String name = *g_lingo->_currentMeObj->name;
- g_lingo->push(Datum(name));
+ Object *me = g_lingo->_currentMe.u.obj;
+ g_lingo->push(Datum(*me->name));
}
void LM::m_respondsTo(int nargs) {
- Object *me = g_lingo->_currentMeObj;
+ Object *me = g_lingo->_currentMe.u.obj;
Datum d = g_lingo->pop();
Common::String methodName = d.asString();
diff --git a/engines/director/lingo/lingo.cpp b/engines/director/lingo/lingo.cpp
index bd90120855..8df3d0133d 100644
--- a/engines/director/lingo/lingo.cpp
+++ b/engines/director/lingo/lingo.cpp
@@ -155,7 +155,6 @@ Lingo::Lingo(DirectorEngine *vm) : _vm(vm) {
_currentScript = 0;
_currentScriptContext = nullptr;
- _currentMeObj = nullptr;
_currentEntityId = 0;
_currentChannelId = -1;
@@ -567,8 +566,8 @@ void Lingo::execute(uint pc) {
if (debugChannelSet(9, kDebugLingoExec)) {
debug("Vars before");
printAllVars();
- if (_currentMeObj)
- debug("me: %s", _currentMeObj->name->c_str());
+ if (_currentMe.type == OBJECT)
+ debug("me: %s", _currentMe.asString(true).c_str());
}
debugC(1, kDebugLingoExec, "[%3d]: %s", current, instr.c_str());
@@ -1055,7 +1054,7 @@ void Lingo::executePerFrameHook(int frame, int subframe) {
debugC(1, kDebugLingoExec, "Executing perFrameHook : <%s>(mAtFrame, %d, %d)", _perFrameHook.asString(true).c_str(), frame, subframe);
push(Datum(frame));
push(Datum(subframe));
- LC::call(method, 2, _perFrameHook.u.obj);
+ LC::call(method, 2, _perFrameHook);
execute(_pc);
}
}
@@ -1072,9 +1071,9 @@ void Lingo::printAllVars() {
}
debugN("\n");
- if (_currentMeObj) {
+ if (_currentMe.type == OBJECT) {
debugN(" Instance/property vars: ");
- for (SymbolHash::iterator i = _currentMeObj->properties.begin(); i != _currentMeObj->properties.end(); ++i) {
+ for (SymbolHash::iterator i = _currentMe.u.obj->properties.begin(); i != _currentMe.u.obj->properties.end(); ++i) {
debugN("%s, ", (*i)._key.c_str());
}
debugN("\n");
@@ -1134,8 +1133,8 @@ void Lingo::varAssign(Datum &var, Datum &value, bool global, SymbolHash *localva
sym = &(*localvars)[name];
if (global)
warning("varAssign: variable %s is local, not global", name.c_str());
- } else if (_currentMeObj && _currentMeObj->hasVar(name)) {
- sym = &_currentMeObj->getVar(name);
+ } else if (_currentMe.type == OBJECT && _currentMe.u.obj->hasVar(name)) {
+ sym = &_currentMe.u.obj->getVar(name);
if (global)
warning("varAssign: variable %s is instance or property, not global", sym->name->c_str());
} else if (_globalvars.contains(name)) {
@@ -1218,17 +1217,16 @@ Datum Lingo::varFetch(Datum &var, bool global, SymbolHash *localvars) {
Symbol *sym = nullptr;
Common::String name = *var.u.s;
- if (_currentMeObj != nullptr && name.equalsIgnoreCase("me")) {
- result.type = OBJECT;
- result.u.obj = _currentMeObj;
+ if (_currentMe.type == OBJECT && name.equalsIgnoreCase("me")) {
+ result = _currentMe;
return result;
}
if (localvars && localvars->contains(name)) {
sym = &(*localvars)[name];
if (global)
warning("varFetch: variable %s is local, not global", sym->name->c_str());
- } else if (_currentMeObj && _currentMeObj->hasVar(name)) {
- sym = &_currentMeObj->getVar(name);
+ } else if (_currentMe.type == OBJECT && _currentMe.u.obj->hasVar(name)) {
+ sym = &_currentMe.u.obj->getVar(name);
if (global)
warning("varFetch: variable %s is instance or property, not global", sym->name->c_str());
} else if (_globalvars.contains(name)) {
diff --git a/engines/director/lingo/lingo.h b/engines/director/lingo/lingo.h
index 2a0cd950c8..99374a5b5f 100644
--- a/engines/director/lingo/lingo.h
+++ b/engines/director/lingo/lingo.h
@@ -264,7 +264,6 @@ struct Object {
}
virtual Object *clone();
- void addProperty(const Common::String &propName);
Symbol getMethod(const Common::String &methodName);
bool hasVar(const Common::String &varName);
Symbol &getVar(const Common::String &varName);
@@ -277,7 +276,7 @@ struct CFrame { /* proc/func call stack frame */
ScriptContext *retctx; /* which script context to use after return */
int retarchive; /* which archive to use after return */
SymbolHash *localvars;
- Object *retMeObj; /* which me obj to use after return */
+ Datum retMe; /* which me obj to use after return */
};
struct LingoEvent {
@@ -493,7 +492,7 @@ public:
int _currentChannelId;
ScriptContext *_currentScriptContext;
ScriptData *_currentScript;
- Object *_currentMeObj;
+ Datum _currentMe;
bool _abort;
bool _immediateMode;
diff --git a/engines/director/lingo/xlibs/fileio.cpp b/engines/director/lingo/xlibs/fileio.cpp
index 1c6854d341..50cfcf46dc 100644
--- a/engines/director/lingo/xlibs/fileio.cpp
+++ b/engines/director/lingo/xlibs/fileio.cpp
@@ -139,7 +139,7 @@ void FileIO::saveFileError() {
}
void FileIO::m_new(int nargs) {
- FileObject *me = static_cast<FileObject *>(g_lingo->_currentMeObj);
+ FileObject *me = static_cast<FileObject *>(g_lingo->_currentMe.u.obj);
Datum d2 = g_lingo->pop();
Datum d1 = g_lingo->pop();
@@ -204,21 +204,18 @@ void FileIO::m_new(int nargs) {
me->filename = new Common::String(filename);
- Datum res;
- res.type = OBJECT;
- res.u.obj = me;
- g_lingo->push(res);
+ g_lingo->push(g_lingo->_currentMe);
}
void FileIO::m_dispose(int nargs) {
- FileObject *me = static_cast<FileObject *>(g_lingo->_currentMeObj);
+ FileObject *me = static_cast<FileObject *>(g_lingo->_currentMe.u.obj);
me->dispose();
}
// Read
void FileIO::m_readChar(int nargs) {
- FileObject *me = static_cast<FileObject *>(g_lingo->_currentMeObj);
+ FileObject *me = static_cast<FileObject *>(g_lingo->_currentMe.u.obj);
if (!me->inStream || me->inStream->eos() || me->inStream->err()) {
g_lingo->push(Datum(kErrorEOF));
@@ -257,7 +254,7 @@ bool FileIO::charInMatchString(char ch, const Common::String &matchString) {
}
void FileIO::m_readToken(int nargs) {
- FileObject *me = static_cast<FileObject *>(g_lingo->_currentMeObj);
+ FileObject *me = static_cast<FileObject *>(g_lingo->_currentMe.u.obj);
Datum d2 = g_lingo->pop();
Datum d1 = g_lingo->pop();
@@ -303,7 +300,7 @@ void FileIO::m_readToken(int nargs) {
// Write
void FileIO::m_writeChar(int nargs) {
- FileObject *me = static_cast<FileObject *>(g_lingo->_currentMeObj);
+ FileObject *me = static_cast<FileObject *>(g_lingo->_currentMe.u.obj);
Datum d = g_lingo->pop();
if (!me->outStream) {
@@ -316,7 +313,7 @@ void FileIO::m_writeChar(int nargs) {
}
void FileIO::m_writeString(int nargs) {
- FileObject *me = static_cast<FileObject *>(g_lingo->_currentMeObj);
+ FileObject *me = static_cast<FileObject *>(g_lingo->_currentMe.u.obj);
Datum d = g_lingo->pop();
if (!me->outStream) {
@@ -331,7 +328,7 @@ void FileIO::m_writeString(int nargs) {
// Other
void FileIO::m_getPosition(int nargs) {
- FileObject *me = static_cast<FileObject *>(g_lingo->_currentMeObj);
+ FileObject *me = static_cast<FileObject *>(g_lingo->_currentMe.u.obj);
if (me->inStream) {
g_lingo->push(Datum(me->inStream->pos()));
@@ -344,7 +341,7 @@ void FileIO::m_getPosition(int nargs) {
}
void FileIO::m_setPosition(int nargs) {
- FileObject *me = static_cast<FileObject *>(g_lingo->_currentMeObj);
+ FileObject *me = static_cast<FileObject *>(g_lingo->_currentMe.u.obj);
Datum d = g_lingo->pop();
int pos = d.asInt();
@@ -371,7 +368,7 @@ void FileIO::m_setPosition(int nargs) {
}
void FileIO::m_getLength(int nargs) {
- FileObject *me = static_cast<FileObject *>(g_lingo->_currentMeObj);
+ FileObject *me = static_cast<FileObject *>(g_lingo->_currentMe.u.obj);
if (me->inStream) {
g_lingo->push(Datum(me->inStream->size()));
@@ -384,7 +381,7 @@ void FileIO::m_getLength(int nargs) {
}
void FileIO::m_fileName(int nargs) {
- FileObject *me = static_cast<FileObject *>(g_lingo->_currentMeObj);
+ FileObject *me = static_cast<FileObject *>(g_lingo->_currentMe.u.obj);
if (me->filename) {
g_lingo->push(Datum(*me->filename));
@@ -395,7 +392,7 @@ void FileIO::m_fileName(int nargs) {
}
void FileIO::m_delete(int nargs) {
- FileObject *me = static_cast<FileObject *>(g_lingo->_currentMeObj);
+ FileObject *me = static_cast<FileObject *>(g_lingo->_currentMe.u.obj);
if (me->filename) {
Common::String filename = *me->filename;
More information about the Scummvm-git-logs
mailing list