[Scummvm-git-logs] scummvm master -> 728fe97d97d089e7c7006fcc4323a5be370e0821

moralrecordings code at moral.net.au
Tue Jun 9 13:15:44 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:
728fe97d97 DIRECTOR: LINGO: Move non-compiler methods out of lingo-codegen.cpp


Commit: 728fe97d97d089e7c7006fcc4323a5be370e0821
    https://github.com/scummvm/scummvm/commit/728fe97d97d089e7c7006fcc4323a5be370e0821
Author: Scott Percival (code at moral.net.au)
Date: 2020-06-09T21:13:40+08:00

Commit Message:
DIRECTOR: LINGO: Move non-compiler methods out of lingo-codegen.cpp

Changed paths:
    engines/director/lingo/lingo-codegen.cpp
    engines/director/lingo/lingo.cpp
    engines/director/lingo/lingo.h


diff --git a/engines/director/lingo/lingo-codegen.cpp b/engines/director/lingo/lingo-codegen.cpp
index 65bda39db2..0f29aceb2d 100644
--- a/engines/director/lingo/lingo-codegen.cpp
+++ b/engines/director/lingo/lingo-codegen.cpp
@@ -54,168 +54,6 @@
 
 namespace Director {
 
-void Lingo::execute(uint pc) {
-	int counter = 0;
-
-	for (_pc = pc; !_abort && (*_currentScript)[_pc] != STOP && !_nextRepeat;) {
-		Common::String instr = decodeInstruction(_currentScript, _pc);
-		uint current = _pc;
-
-		if (debugChannelSet(5, kDebugLingoExec))
-			printStack("Stack before: ", current);
-
-		if (debugChannelSet(9, kDebugLingoExec)) {
-			debug("Vars before");
-			printAllVars();
-			if (_currentMeObj)
-				debug("me: %s", _currentMeObj->name->c_str());
-		}
-
-		debugC(1, kDebugLingoExec, "[%3d]: %s", current, instr.c_str());
-
-		_pc++;
-		(*((*_currentScript)[_pc - 1]))();
-
-		if (debugChannelSet(5, kDebugLingoExec))
-			printStack("Stack after: ", current);
-
-		if (debugChannelSet(9, kDebugLingoExec)) {
-			debug("Vars after");
-			printAllVars();
-		}
-
-		if (_pc >= (*_currentScript).size()) {
-			warning("Lingo::execute(): Bad PC (%d)", _pc);
-			break;
-		}
-
-		if (++counter > 1000 && debugChannelSet(-1, kDebugFewFramesOnly)) {
-			warning("Lingo::execute(): Stopping due to debug few frames only");
-			break;
-		}
-	}
-
-	_abort = false;
-}
-
-void Lingo::printStack(const char *s, uint pc) {
-	Common::String stack(s);
-
-	for (uint i = 0; i < _stack.size(); i++) {
-		Datum d = _stack[i];
-		stack += Common::String::format("<%s> ", d.asString(true).c_str());
-	}
-	debugC(5, kDebugLingoExec, "[%3d]: %s", pc, stack.c_str());
-}
-
-void Lingo::printCallStack(uint pc) {
-	debugC(5, kDebugLingoExec, "Call stack:");
-	for (int i = 0; i < (int)g_lingo->_callstack.size(); i++) {
-		CFrame *frame = g_lingo->_callstack[i];
-		uint framePc = pc;
-		if (i < (int)g_lingo->_callstack.size() - 1)
-			framePc = g_lingo->_callstack[i + 1]->retpc;
-
-		if (frame->sp.type != VOID) {
-			debugC(5, kDebugLingoExec, "#%d %s:%d", i + 1,
-				g_lingo->_callstack[i]->sp.name->c_str(),
-				framePc
-			);
-		} else {
-			debugC(5, kDebugLingoExec, "#%d [unknown]:%d", i + 1,
-				framePc
-			);
-		}
-	}
-}
-
-Common::String Lingo::decodeInstruction(ScriptData *sd, uint pc, uint *newPc) {
-	Symbol sym;
-	Common::String res;
-
-	sym.u.func = (*sd)[pc++];
-	if (_functions.contains((void *)sym.u.s)) {
-		res = _functions[(void *)sym.u.s]->name;
-		const char *pars = _functions[(void *)sym.u.s]->proto;
-		inst i;
-		uint start = pc;
-
-		while (*pars) {
-			switch (*pars++) {
-			case 'i':
-				{
-					i = (*sd)[pc++];
-					int v = READ_UINT32(&i);
-
-					res += Common::String::format(" %d", v);
-					break;
-				}
-			case 'f':
-				{
-					Datum d;
-					i = (*sd)[pc++];
-					d.u.f = *(double *)(&i);
-
-					res += Common::String::format(" %f", d.u.f);
-					break;
-				}
-			case 'o':
-				{
-					i = (*sd)[pc++];
-					int v = READ_UINT32(&i);
-
-					res += Common::String::format(" [%5d]", v + start - 1);
-					break;
-				}
-			case 's':
-				{
-					char *s = (char *)&(*sd)[pc];
-					pc += calcStringAlignment(s);
-
-					res += Common::String::format(" \"%s\"", s);
-					break;
-				}
-			case 'E':
-				{
-					i = (*sd)[pc++];
-					int v = READ_UINT32(&i);
-
-					res += Common::String::format(" %s", entity2str(v));
-					break;
-				}
-			case 'F':
-				{
-					i = (*sd)[pc++];
-					int v = READ_UINT32(&i);
-
-					res += Common::String::format(" %s", field2str(v));
-					break;
-				}
-			case 'N':
-				{
-					i = (*sd)[pc++];
-					int v = READ_UINT32(&i);
-
-					res += Common::String::format(" \"%s\"", getName(v).c_str());
-					break;
-				}
-			default:
-				warning("decodeInstruction: Unknown parameter type: %c", pars[-1]);
-			}
-
-			if (*pars)
-				res += ',';
-		}
-	} else {
-		res = "<unknown>";
-	}
-
-	if (newPc)
-		*newPc = pc;
-
-	return res;
-}
-
 void Lingo::cleanLocalVars() {
 	// Clean up current scope local variables and clean up memory
 	debugC(3, kDebugLingoExec, "cleanLocalVars: have %d vars", _localvars->size());
@@ -412,35 +250,6 @@ void Lingo::processIf(int toplabel, int endlabel) {
 	}
 }
 
-int Lingo::castIdFetch(Datum &var) {
-	Score *score = _vm->getCurrentScore();
-	if (!score) {
-		warning("castIdFetch: Score is empty");
-		return 0;
-	}
-
-	int id = 0;
-	if (var.type == STRING) {
-		if (score->_castsNames.contains(*var.u.s))
-			id = score->_castsNames[*var.u.s];
-		else
-			warning("castIdFetch: reference to non-existent cast member: %s", var.u.s->c_str());
-	} else if (var.type == INT || var.type == FLOAT) {
-		int castId = var.asInt();
-		if (!_vm->getCastMember(castId))
-			warning("castIdFetch: reference to non-existent cast ID: %d", castId);
-		else
-			id = castId;
-	} else if (var.type == VOID) {
-		warning("castIdFetch: reference to VOID cast ID");
-		return 0;
-	} else {
-		error("castIdFetch: was expecting STRING or INT, got %s", var.type2str());
-	}
-
-	return id;
-}
-
 void Lingo::varCreate(const Common::String &name, bool global, SymbolHash *localvars) {
 	if (localvars == nullptr) {
 		localvars = _localvars;
@@ -469,177 +278,6 @@ void Lingo::varCreate(const Common::String &name, bool global, SymbolHash *local
 	}
 }
 
-void Lingo::varAssign(Datum &var, Datum &value, bool global, SymbolHash *localvars) {
-	if (localvars == nullptr) {
-		localvars = _localvars;
-	}
-
-	if (var.type != VAR && var.type != REFERENCE) {
-		warning("varAssign: assignment to non-variable");
-		return;
-	}
-
-	if (var.type == VAR) {
-		Symbol *sym = nullptr;
-		Common::String name = *var.u.s;
-
-		if (localvars && localvars->contains(name)) {
-			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);
-			if (global)
-				warning("varAssign: variable %s is instance or property, not global", sym->name->c_str());
-		} else if (_globalvars.contains(name)) {
-			sym = &_globalvars[name];
-			if (!global)
-				warning("varAssign: variable %s is global, not local", name.c_str());
-		}
-
-		if (!sym) {
-			warning("varAssign: variable %s not defined", name.c_str());
-			return;
-		}
-
-		if (sym->type != INT && sym->type != VOID &&
-				sym->type != FLOAT && sym->type != STRING &&
-				sym->type != ARRAY && sym->type != PARRAY) {
-			warning("varAssign: assignment to non-variable '%s'", sym->name->c_str());
-			return;
-		}
-
-		sym->reset();
-		sym->refCount = value.refCount;
-		*sym->refCount += 1;
-		sym->name = new Common::String(name);
-		sym->type = value.type;
-		if (value.type == INT) {
-			sym->u.i = value.u.i;
-		} else if (value.type == FLOAT) {
-			sym->u.f = value.u.f;
-		} else if (value.type == STRING || value.type == SYMBOL) {
-			sym->u.s = value.u.s;
-		} else if (value.type == POINT || value.type == ARRAY) {
-			sym->u.farr = value.u.farr;
-		} else if (value.type == PARRAY) {
-			sym->u.parr = value.u.parr;
-		} else if (value.type == OBJECT) {
-			sym->u.obj = value.u.obj;
-		} else if (value.type == VOID) {
-			sym->u.i = 0;
-		} else {
-			warning("varAssign: unhandled type: %s", value.type2str());
-			sym->u.s = value.u.s;
-		}
-	} else if (var.type == REFERENCE) {
-		Score *score = g_director->getCurrentScore();
-		if (!score) {
-			warning("varAssign: Assigning to a reference to an empty score");
-			return;
-		}
-		int referenceId = var.u.i;
-		Cast *member = g_director->getCastMember(referenceId);
-		if (!member) {
-			warning("varAssign: Unknown cast id %d", referenceId);
-			return;
-		}
-		switch (member->_type) {
-		case kCastText:
-			((TextCast *)member)->setText(value.asString().c_str());
-			break;
-		default:
-			warning("varAssign: Unhandled cast type %s", tag2str(member->_type));
-			break;
-		}
-	}
-}
-
-Datum Lingo::varFetch(Datum &var, bool global, SymbolHash *localvars) {
-	if (localvars == nullptr) {
-		localvars = _localvars;
-	}
-
-	Datum result;
-	result.type = VOID;
-	if (var.type != VAR && var.type != REFERENCE) {
-		warning("varFetch: fetch from non-variable");
-		return result;
-	}
-
-	if (var.type == VAR) {
-		Symbol *sym = nullptr;
-		Common::String name = *var.u.s;
-
-		if (_currentMeObj != nullptr && name.equalsIgnoreCase("me")) {
-			result.type = OBJECT;
-			result.u.obj = _currentMeObj;
-			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);
-			if (global)
-				warning("varFetch: variable %s is instance or property, not global", sym->name->c_str());
-		} else if (_globalvars.contains(name)) {
-			sym = &_globalvars[name];
-			if (!global)
-				warning("varFetch: variable %s is global, not local", sym->name->c_str());
-		}
-
-		if (!sym) {
-			warning("varFetch: variable %s not found", name.c_str());
-			return result;
-		}
-
-		result.type = sym->type;
-		delete result.refCount;
-		result.refCount = sym->refCount;
-		*result.refCount += 1;
-
-		if (sym->type == INT)
-			result.u.i = sym->u.i;
-		else if (sym->type == FLOAT)
-			result.u.f = sym->u.f;
-		else if (sym->type == STRING || sym->type == SYMBOL)
-			result.u.s = sym->u.s;
-		else if (sym->type == POINT || sym->type == ARRAY)
-			result.u.farr = sym->u.farr;
-		else if (sym->type == PARRAY)
-			result.u.parr = sym->u.parr;
-		else if (sym->type == OBJECT)
-			result.u.obj = sym->u.obj;
-		else if (sym->type == VOID)
-			result.u.i = 0;
-		else {
-			warning("varFetch: unhandled type: %s", var.type2str());
-			result.type = VOID;
-		}
-
-	} else if (var.type == REFERENCE) {
-		Cast *cast = _vm->getCastMember(var.u.i);
-		if (cast) {
-			switch (cast->_type) {
-			case kCastText:
-				result.type = STRING;
-				result.u.s = new Common::String(((TextCast *)cast)->getText());
-				break;
-			default:
-				warning("varFetch: Unhandled cast type %s", tag2str(cast->_type));
-				break;
-			}
-		} else {
-			warning("varFetch: Unknown cast id %d", var.u.i);
-		}
-
-	}
-
-	return result;
-}
-
 void Lingo::codeFactory(Common::String &name) {
 	Object *obj = new Object;
 	obj->name = new Common::String(name);
diff --git a/engines/director/lingo/lingo.cpp b/engines/director/lingo/lingo.cpp
index ed3ec281c5..08d3cb4e73 100644
--- a/engines/director/lingo/lingo.cpp
+++ b/engines/director/lingo/lingo.cpp
@@ -412,6 +412,168 @@ void Lingo::addCode(const char *code, ScriptType type, uint16 id) {
 	_currentScriptContext->functions.push_back(currentFunc);
 }
 
+void Lingo::printStack(const char *s, uint pc) {
+	Common::String stack(s);
+
+	for (uint i = 0; i < _stack.size(); i++) {
+		Datum d = _stack[i];
+		stack += Common::String::format("<%s> ", d.asString(true).c_str());
+	}
+	debugC(5, kDebugLingoExec, "[%3d]: %s", pc, stack.c_str());
+}
+
+void Lingo::printCallStack(uint pc) {
+	debugC(5, kDebugLingoExec, "Call stack:");
+	for (int i = 0; i < (int)g_lingo->_callstack.size(); i++) {
+		CFrame *frame = g_lingo->_callstack[i];
+		uint framePc = pc;
+		if (i < (int)g_lingo->_callstack.size() - 1)
+			framePc = g_lingo->_callstack[i + 1]->retpc;
+
+		if (frame->sp.type != VOID) {
+			debugC(5, kDebugLingoExec, "#%d %s:%d", i + 1,
+				g_lingo->_callstack[i]->sp.name->c_str(),
+				framePc
+			);
+		} else {
+			debugC(5, kDebugLingoExec, "#%d [unknown]:%d", i + 1,
+				framePc
+			);
+		}
+	}
+}
+
+Common::String Lingo::decodeInstruction(ScriptData *sd, uint pc, uint *newPc) {
+	Symbol sym;
+	Common::String res;
+
+	sym.u.func = (*sd)[pc++];
+	if (_functions.contains((void *)sym.u.s)) {
+		res = _functions[(void *)sym.u.s]->name;
+		const char *pars = _functions[(void *)sym.u.s]->proto;
+		inst i;
+		uint start = pc;
+
+		while (*pars) {
+			switch (*pars++) {
+			case 'i':
+				{
+					i = (*sd)[pc++];
+					int v = READ_UINT32(&i);
+
+					res += Common::String::format(" %d", v);
+					break;
+				}
+			case 'f':
+				{
+					Datum d;
+					i = (*sd)[pc++];
+					d.u.f = *(double *)(&i);
+
+					res += Common::String::format(" %f", d.u.f);
+					break;
+				}
+			case 'o':
+				{
+					i = (*sd)[pc++];
+					int v = READ_UINT32(&i);
+
+					res += Common::String::format(" [%5d]", v + start - 1);
+					break;
+				}
+			case 's':
+				{
+					char *s = (char *)&(*sd)[pc];
+					pc += calcStringAlignment(s);
+
+					res += Common::String::format(" \"%s\"", s);
+					break;
+				}
+			case 'E':
+				{
+					i = (*sd)[pc++];
+					int v = READ_UINT32(&i);
+
+					res += Common::String::format(" %s", entity2str(v));
+					break;
+				}
+			case 'F':
+				{
+					i = (*sd)[pc++];
+					int v = READ_UINT32(&i);
+
+					res += Common::String::format(" %s", field2str(v));
+					break;
+				}
+			case 'N':
+				{
+					i = (*sd)[pc++];
+					int v = READ_UINT32(&i);
+
+					res += Common::String::format(" \"%s\"", getName(v).c_str());
+					break;
+				}
+			default:
+				warning("decodeInstruction: Unknown parameter type: %c", pars[-1]);
+			}
+
+			if (*pars)
+				res += ',';
+		}
+	} else {
+		res = "<unknown>";
+	}
+
+	if (newPc)
+		*newPc = pc;
+
+	return res;
+}
+
+void Lingo::execute(uint pc) {
+	int counter = 0;
+
+	for (_pc = pc; !_abort && (*_currentScript)[_pc] != STOP && !_nextRepeat;) {
+		Common::String instr = decodeInstruction(_currentScript, _pc);
+		uint current = _pc;
+
+		if (debugChannelSet(5, kDebugLingoExec))
+			printStack("Stack before: ", current);
+
+		if (debugChannelSet(9, kDebugLingoExec)) {
+			debug("Vars before");
+			printAllVars();
+			if (_currentMeObj)
+				debug("me: %s", _currentMeObj->name->c_str());
+		}
+
+		debugC(1, kDebugLingoExec, "[%3d]: %s", current, instr.c_str());
+
+		_pc++;
+		(*((*_currentScript)[_pc - 1]))();
+
+		if (debugChannelSet(5, kDebugLingoExec))
+			printStack("Stack after: ", current);
+
+		if (debugChannelSet(9, kDebugLingoExec)) {
+			debug("Vars after");
+			printAllVars();
+		}
+
+		if (_pc >= (*_currentScript).size()) {
+			warning("Lingo::execute(): Bad PC (%d)", _pc);
+			break;
+		}
+
+		if (++counter > 1000 && debugChannelSet(-1, kDebugFewFramesOnly)) {
+			warning("Lingo::execute(): Stopping due to debug few frames only");
+			break;
+		}
+	}
+
+	_abort = false;
+}
+
 void Lingo::executeScript(ScriptType type, uint16 id, uint16 function) {
 	ScriptContext *sc = getScriptContext(type, id);
 	if (!sc) {
@@ -865,4 +1027,204 @@ void Lingo::printAllVars() {
 	debugN("\n");
 }
 
+int Lingo::castIdFetch(Datum &var) {
+	Score *score = _vm->getCurrentScore();
+	if (!score) {
+		warning("castIdFetch: Score is empty");
+		return 0;
+	}
+
+	int id = 0;
+	if (var.type == STRING) {
+		if (score->_castsNames.contains(*var.u.s))
+			id = score->_castsNames[*var.u.s];
+		else
+			warning("castIdFetch: reference to non-existent cast member: %s", var.u.s->c_str());
+	} else if (var.type == INT || var.type == FLOAT) {
+		int castId = var.asInt();
+		if (!_vm->getCastMember(castId))
+			warning("castIdFetch: reference to non-existent cast ID: %d", castId);
+		else
+			id = castId;
+	} else if (var.type == VOID) {
+		warning("castIdFetch: reference to VOID cast ID");
+		return 0;
+	} else {
+		error("castIdFetch: was expecting STRING or INT, got %s", var.type2str());
+	}
+
+	return id;
+}
+
+void Lingo::varAssign(Datum &var, Datum &value, bool global, SymbolHash *localvars) {
+	if (localvars == nullptr) {
+		localvars = _localvars;
+	}
+
+	if (var.type != VAR && var.type != REFERENCE) {
+		warning("varAssign: assignment to non-variable");
+		return;
+	}
+
+	if (var.type == VAR) {
+		Symbol *sym = nullptr;
+		Common::String name = *var.u.s;
+
+		if (localvars && localvars->contains(name)) {
+			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);
+			if (global)
+				warning("varAssign: variable %s is instance or property, not global", sym->name->c_str());
+		} else if (_globalvars.contains(name)) {
+			sym = &_globalvars[name];
+			if (!global)
+				warning("varAssign: variable %s is global, not local", name.c_str());
+		}
+
+		if (!sym) {
+			warning("varAssign: variable %s not defined", name.c_str());
+			return;
+		}
+
+		if (sym->type != INT && sym->type != VOID &&
+				sym->type != FLOAT && sym->type != STRING &&
+				sym->type != ARRAY && sym->type != PARRAY) {
+			warning("varAssign: assignment to non-variable '%s'", sym->name->c_str());
+			return;
+		}
+
+		sym->reset();
+		sym->refCount = value.refCount;
+		*sym->refCount += 1;
+		sym->name = new Common::String(name);
+		sym->type = value.type;
+		if (value.type == INT) {
+			sym->u.i = value.u.i;
+		} else if (value.type == FLOAT) {
+			sym->u.f = value.u.f;
+		} else if (value.type == STRING || value.type == SYMBOL) {
+			sym->u.s = value.u.s;
+		} else if (value.type == POINT || value.type == ARRAY) {
+			sym->u.farr = value.u.farr;
+		} else if (value.type == PARRAY) {
+			sym->u.parr = value.u.parr;
+		} else if (value.type == OBJECT) {
+			sym->u.obj = value.u.obj;
+		} else if (value.type == VOID) {
+			sym->u.i = 0;
+		} else {
+			warning("varAssign: unhandled type: %s", value.type2str());
+			sym->u.s = value.u.s;
+		}
+	} else if (var.type == REFERENCE) {
+		Score *score = g_director->getCurrentScore();
+		if (!score) {
+			warning("varAssign: Assigning to a reference to an empty score");
+			return;
+		}
+		int referenceId = var.u.i;
+		Cast *member = g_director->getCastMember(referenceId);
+		if (!member) {
+			warning("varAssign: Unknown cast id %d", referenceId);
+			return;
+		}
+		switch (member->_type) {
+		case kCastText:
+			((TextCast *)member)->setText(value.asString().c_str());
+			break;
+		default:
+			warning("varAssign: Unhandled cast type %s", tag2str(member->_type));
+			break;
+		}
+	}
+}
+
+Datum Lingo::varFetch(Datum &var, bool global, SymbolHash *localvars) {
+	if (localvars == nullptr) {
+		localvars = _localvars;
+	}
+
+	Datum result;
+	result.type = VOID;
+	if (var.type != VAR && var.type != REFERENCE) {
+		warning("varFetch: fetch from non-variable");
+		return result;
+	}
+
+	if (var.type == VAR) {
+		Symbol *sym = nullptr;
+		Common::String name = *var.u.s;
+
+		if (_currentMeObj != nullptr && name.equalsIgnoreCase("me")) {
+			result.type = OBJECT;
+			result.u.obj = _currentMeObj;
+			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);
+			if (global)
+				warning("varFetch: variable %s is instance or property, not global", sym->name->c_str());
+		} else if (_globalvars.contains(name)) {
+			sym = &_globalvars[name];
+			if (!global)
+				warning("varFetch: variable %s is global, not local", sym->name->c_str());
+		}
+
+		if (!sym) {
+			warning("varFetch: variable %s not found", name.c_str());
+			return result;
+		}
+
+		result.type = sym->type;
+		delete result.refCount;
+		result.refCount = sym->refCount;
+		*result.refCount += 1;
+
+		if (sym->type == INT)
+			result.u.i = sym->u.i;
+		else if (sym->type == FLOAT)
+			result.u.f = sym->u.f;
+		else if (sym->type == STRING || sym->type == SYMBOL)
+			result.u.s = sym->u.s;
+		else if (sym->type == POINT || sym->type == ARRAY)
+			result.u.farr = sym->u.farr;
+		else if (sym->type == PARRAY)
+			result.u.parr = sym->u.parr;
+		else if (sym->type == OBJECT)
+			result.u.obj = sym->u.obj;
+		else if (sym->type == VOID)
+			result.u.i = 0;
+		else {
+			warning("varFetch: unhandled type: %s", var.type2str());
+			result.type = VOID;
+		}
+
+	} else if (var.type == REFERENCE) {
+		Cast *cast = _vm->getCastMember(var.u.i);
+		if (cast) {
+			switch (cast->_type) {
+			case kCastText:
+				result.type = STRING;
+				result.u.s = new Common::String(((TextCast *)cast)->getText());
+				break;
+			default:
+				warning("varFetch: Unhandled cast type %s", tag2str(cast->_type));
+				break;
+			}
+		} else {
+			warning("varFetch: Unknown cast id %d", var.u.i);
+		}
+
+	}
+
+	return result;
+}
+
 } // End of namespace Director
diff --git a/engines/director/lingo/lingo.h b/engines/director/lingo/lingo.h
index 5fd03b58fa..64e2e3a508 100644
--- a/engines/director/lingo/lingo.h
+++ b/engines/director/lingo/lingo.h
@@ -369,11 +369,7 @@ public:
 	void pushContext(const Symbol *funcSym = nullptr);
 	void popContext();
 	void cleanLocalVars();
-	Symbol define(Common::String &s, int nargs, ScriptData *code, Common::Array<Common::String> *argNames = nullptr, Common::Array<Common::String> *varNames = nullptr, Object *obj = nullptr);
-	Symbol codeDefine(Common::String &s, int start, int nargs, Object *obj = nullptr, int end = -1, bool removeCode = true);
-	void processIf(int toplabel, int endlabel);
 	int castIdFetch(Datum &var);
-	void varCreate(const Common::String &name, bool global, SymbolHash *localvars = nullptr);
 	void varAssign(Datum &var, Datum &value, bool global = false, SymbolHash *localvars = nullptr);
 	Datum varFetch(Datum &var, bool global = false, SymbolHash *localvars = nullptr);
 
@@ -381,14 +377,6 @@ public:
 
 	void printAllVars();
 
-	int code1(inst code) { _currentScript->push_back(code); return _currentScript->size() - 1; }
-	int code2(inst code_1, inst code_2) { int o = code1(code_1); code1(code_2); return o; }
-	int code3(inst code_1, inst code_2, inst code_3) { int o = code1(code_1); code1(code_2); code1(code_3); return o; }
-	int code4(inst code_1, inst code_2, inst code_3, inst code_4) { int o = code1(code_1); code1(code_2); code1(code_3); code1(code_4); return o; }
-	int codeString(const char *s);
-	void codeLabel(int label);
-	int codeInt(int val);
-
 	int calcStringAlignment(const char *s) {
 		return calcCodeAlignment(strlen(s) + 1);
 	}
@@ -397,12 +385,8 @@ public:
 		return (l + instLen - 1) / instLen;
 	}
 
-	void codeArg(Common::String *s);
 	int codeSetImmediate(bool state);
-	int codeFunc(Common::String *s, int numpar);
 	// int codeMe(Common::String *method, int numpar);
-	int codeFloat(double f);
-	void codeFactory(Common::String &s);
 
 	inst readInst() { return getInst(_pc++); }
 	inst getInst(uint pc) { return (*_currentScript)[pc]; }
@@ -455,10 +439,43 @@ private:
 	Common::StringArray _entityNames;
 	Common::StringArray _fieldNames;
 
+// compiler resources
 public:
 	bool isInArgStack(Common::String *s);
 	void clearArgStack();
 
+	int code1(inst code) { _currentScript->push_back(code); return _currentScript->size() - 1; }
+	int code2(inst code_1, inst code_2) { int o = code1(code_1); code1(code_2); return o; }
+	int code3(inst code_1, inst code_2, inst code_3) { int o = code1(code_1); code1(code_2); code1(code_3); return o; }
+	int code4(inst code_1, inst code_2, inst code_3, inst code_4) { int o = code1(code_1); code1(code_2); code1(code_3); code1(code_4); return o; }
+	void codeArg(Common::String *s);
+	Symbol codeDefine(Common::String &s, int start, int nargs, Object *obj = nullptr, int end = -1, bool removeCode = true);
+	void codeFactory(Common::String &s);
+	int codeFloat(double f);
+	int codeFunc(Common::String *s, int numpar);
+	int codeInt(int val);
+	void codeLabel(int label);
+	int codeString(const char *s);
+	Symbol define(Common::String &s, int nargs, ScriptData *code, Common::Array<Common::String> *argNames = nullptr, Common::Array<Common::String> *varNames = nullptr, Object *obj = nullptr);
+	void processIf(int toplabel, int endlabel);
+	void varCreate(const Common::String &name, bool global, SymbolHash *localvars = nullptr);
+
+	LexerDefineState _indef;
+	int _linenumber;
+	int _colnumber;
+	int _bytenumber;
+	Common::String _lasttoken;
+	int _lastbytenumber;
+	Common::String _errortoken;
+	int _errorbytenumber;
+	bool _ignoreError;
+	bool _inFactory;
+	Object *_currentFactory;
+
+	Common::Array<Common::String *> _argstack;
+	Common::HashMap<Common::String, VarType, Common::IgnoreCase_Hash, Common::IgnoreCase_EqualTo> *_methodVars;
+	Common::HashMap<Common::String, VarType, Common::IgnoreCase_Hash, Common::IgnoreCase_EqualTo> *_methodVarsStash;
+
 public:
 	ScriptType _currentScriptType;
 	uint16 _currentEntityId;
@@ -470,13 +487,9 @@ public:
 
 	bool _abort;
 	bool _nextRepeat;
-	LexerDefineState _indef;
 	bool _immediateMode;
-	Common::HashMap<Common::String, VarType, Common::IgnoreCase_Hash, Common::IgnoreCase_EqualTo> *_methodVars;
-	Common::HashMap<Common::String, VarType, Common::IgnoreCase_Hash, Common::IgnoreCase_EqualTo> *_methodVarsStash;
 
 	Common::Array<CFrame *> _callstack;
-	Common::Array<Common::String *> _argstack;
 	TheEntityHash _theEntities;
 	TheEntityFieldHash _theEntityFields;
 
@@ -487,21 +500,10 @@ public:
 	SymbolHash _builtins;
 	SymbolHash _methods;
 
-	int _linenumber;
-	int _colnumber;
-	int _bytenumber;
-	Common::String _lasttoken;
-	int _lastbytenumber;
-	Common::String _errortoken;
-	int _errorbytenumber;
-	bool _ignoreError;
-
 	Common::String _floatPrecisionFormat;
 
 	bool _hadError;
 
-	bool _inFactory;
-	Object *_currentFactory;
 	bool _inCond;
 
 	bool _exitRepeat;




More information about the Scummvm-git-logs mailing list