[Scummvm-git-logs] scummvm master -> d3adb6329bc194679ef44ad778edb5b525bcda44
sev-
noreply at scummvm.org
Sun Nov 5 18:00:34 UTC 2023
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:
d3adb6329b SLUDGE: Print out stack during execution
Commit: d3adb6329bc194679ef44ad778edb5b525bcda44
https://github.com/scummvm/scummvm/commit/d3adb6329bc194679ef44ad778edb5b525bcda44
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2023-11-05T19:00:28+01:00
Commit Message:
SLUDGE: Print out stack during execution
Changed paths:
engines/sludge/function.cpp
engines/sludge/variable.cpp
engines/sludge/variable.h
diff --git a/engines/sludge/function.cpp b/engines/sludge/function.cpp
index fa9eefa446b..8fd1d75e1e7 100644
--- a/engines/sludge/function.cpp
+++ b/engines/sludge/function.cpp
@@ -62,6 +62,18 @@ void pauseFunction(LoadedFunction *fun) {
}
}
+void printStack(VariableStack *ptr) {
+ if (ptr == NULL)
+ debugN("<empty stack>");
+
+ while (ptr != NULL) {
+ ptr->thisVar.debugPrint();
+ ptr = ptr->next;
+ }
+
+ debug("");
+}
+
void restartFunction(LoadedFunction *fun) {
fun->next = allRunningFunctions;
allRunningFunctions = fun;
@@ -195,7 +207,11 @@ bool continueFunction(LoadedFunction *fun) {
advanceNow = true;
param = fun->compiledLines[fun->runThisLine].param;
com = fun->compiledLines[fun->runThisLine].theCommand;
- debugC(1, kSludgeDebugStackMachine, "Executing command line %i : %s(%s)", fun->runThisLine, sludgeText[com], getCommandParameter(com, param).c_str());
+
+ debugN("Stack before: ");
+ printStack(fun->stack);
+
+ debugC(1, kSludgeDebugStackMachine, "Executing command line %i: %s(%s)", fun->runThisLine, sludgeText[com], getCommandParameter(com, param).c_str());
if (numBIFNames) {
setFatalInfo((fun->originalNumber < numUserFunc) ? allUserFunc[fun->originalNumber] : "Unknown user function", (com < numSludgeCommands) ? sludgeText[com] : ERROR_UNKNOWN_MCODE);
@@ -621,6 +637,9 @@ bool continueFunction(LoadedFunction *fun) {
return fatal(ERROR_UNKNOWN_CODE);
}
+ debugN("Stack after: ");
+ printStack(fun->stack);
+
if (advanceNow)
fun->runThisLine++;
diff --git a/engines/sludge/variable.cpp b/engines/sludge/variable.cpp
index 83afc753703..70ef93228ac 100644
--- a/engines/sludge/variable.cpp
+++ b/engines/sludge/variable.cpp
@@ -19,6 +19,7 @@
*
*/
+#include "common/debug.h"
#include "common/savefile.h"
#include "common/system.h"
@@ -28,6 +29,7 @@
#include "sludge/objtypes.h"
#include "sludge/people.h"
#include "sludge/sludge.h"
+#include "sludge/sprbanks.h"
#include "sludge/variable.h"
namespace Sludge {
@@ -132,6 +134,50 @@ Persona *Variable::getCostumeFromVar() {
return p;
}
+void Variable::debugPrint() {
+ switch (varType) {
+ case SVT_NULL:
+ debugN("SVT_NULL() ");
+ break;
+ case SVT_INT:
+ debugN("SVT_INT(%d) ", varData.intValue);
+ break;
+ case SVT_STRING:
+ debugN("SVT_STRING(\"%s\") ", Common::toPrintable(varData.theString).c_str());
+ break;
+ case SVT_BUILT:
+ debugN("SVT_BUILT(\"%s\") ", varData.theString);
+ break;
+ case SVT_STACK:
+ debugN("SVT_STACK(");
+ varData.theStack->debugPrint();
+ debugN(") ");
+ break;
+ case SVT_FUNC:
+ debugN("SVT_FUNC(%d) ", varData.intValue);
+ break;
+ case SVT_FILE:
+ debugN("SVT_FILE(\"%s\") ", g_sludge->_resMan->resourceNameFromNum(varData.intValue).c_str());
+ break;
+ case SVT_ANIM:
+ debugN("SVT_ANIM(Frames: %d, ID: %d) ", varData.animHandler->numFrames, varData.animHandler->numFrames ? varData.animHandler->theSprites->ID : -1337);
+ break;
+ case SVT_OBJTYPE:
+ debugN("SVT_OBJTYPE(%d) ", varData.intValue);
+ break;
+ case SVT_COSTUME:
+ debugN("SVT_COSTUME(numDirections: %d) ", varData.costumeHandler->numDirections);
+ break;
+ case SVT_FASTARRAY:
+ debugN("FASTARRAY(");
+ varData.fastArray->debugPrint();
+ debugN(") ");
+ break;
+ default :
+ debugN("<UNK %d> ", varType);
+ }
+}
+
int StackHandler::getStackSize() const {
int r = 0;
VariableStack *a = first;
@@ -167,6 +213,19 @@ bool StackHandler::getSavedGamesStack(const Common::String &ext) {
return true;
}
+void StackHandler::debugPrint() {
+ VariableStack *a = first;
+
+ debugN("{");
+
+ while (a) {
+ a->thisVar.debugPrint();
+ a = a->next;
+ }
+
+ debugN("}");
+}
+
bool Variable::copyStack(const Variable &from) {
varType = SVT_STACK;
varData.theStack = new StackHandler;
@@ -383,6 +442,14 @@ Variable *FastArrayHandler::fastArrayGetByIndex(uint theIndex) {
return &fastVariables[theIndex];
}
+void FastArrayHandler::debugPrint() {
+ debugN("[");
+ for (int i = 0; i < size; i++)
+ fastVariables[i].debugPrint();
+
+ debugN("]");
+}
+
bool Variable::makeFastArraySize(int size) {
if (size < 0)
return fatal("Can't create a fast array with a negative number of elements!");
@@ -425,7 +492,7 @@ bool addVarToStack(const Variable &va, VariableStack *&thisStack) {
return false;
newStack->next = thisStack;
thisStack = newStack;
- //debugC(2, kSludgeDebugStackMachine, "Variable %s was added to stack", getTextFromAnyVar(va));
+ debugC(2, kSludgeDebugStackMachine, "Variable %s was added to stack", va.getTextFromAnyVar().c_str());
return true;
}
@@ -441,7 +508,7 @@ bool addVarToStackQuick(Variable &va, VariableStack *&thisStack) {
newStack->next = thisStack;
thisStack = newStack;
- //debugC(2, kSludgeDebugStackMachine, "Variable %s was added to stack quick", getTextFromAnyVar(va));
+ debugC(2, kSludgeDebugStackMachine, "Variable %s was added to stack quick", va.getTextFromAnyVar().c_str());
return true;
}
@@ -515,7 +582,7 @@ void trimStack(VariableStack *&stack) {
VariableStack *killMe = stack;
stack = stack->next;
- //debugC(2, kSludgeDebugStackMachine, "Variable %s was removed from stack", getTextFromAnyVar(killMe->thisVar));
+ debugC(2, kSludgeDebugStackMachine, "Variable %s was removed from stack", killMe->thisVar.getTextFromAnyVar().c_str());
// When calling this, we've ALWAYS checked that stack != NULL
killMe->thisVar.unlinkVar();
diff --git a/engines/sludge/variable.h b/engines/sludge/variable.h
index ecaec73bdc7..c0d3e65d8e0 100644
--- a/engines/sludge/variable.h
+++ b/engines/sludge/variable.h
@@ -54,6 +54,7 @@ struct FastArrayHandler {
int timesUsed;
Variable *fastArrayGetByIndex(uint theIndex);
+ void debugPrint();
};
struct StackHandler {
@@ -63,6 +64,8 @@ struct StackHandler {
int getStackSize() const;
bool getSavedGamesStack(const Common::String &ext);
+
+ void debugPrint();
};
union VariableData {
@@ -122,6 +125,8 @@ struct Variable {
Common::String getTextFromAnyVar() const;
bool getBoolean() const;
bool getValueType(int &toHere, VariableType vT) const;
+
+ void debugPrint();
};
struct VariableStack {
More information about the Scummvm-git-logs
mailing list