aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Gilbert2019-07-01 20:56:55 -0700
committerPaul Gilbert2019-07-06 15:27:09 -0700
commit5dea66231397c52afc7d2cdeae5989fd5edd0604 (patch)
tree6cd65d939d4051f0d0bade793f4598485547ad47
parent18566feefcb9f4fa4d7395ffa6e6f2a6f0247d0e (diff)
downloadscummvm-rg350-5dea66231397c52afc7d2cdeae5989fd5edd0604.tar.gz
scummvm-rg350-5dea66231397c52afc7d2cdeae5989fd5edd0604.tar.bz2
scummvm-rg350-5dea66231397c52afc7d2cdeae5989fd5edd0604.zip
GLK: ALAN3: Wrapping method calls in longjmp replacement macros
-rw-r--r--engines/glk/alan3/act.cpp36
-rw-r--r--engines/glk/alan3/act.h3
-rw-r--r--engines/glk/alan3/actor.cpp15
-rw-r--r--engines/glk/alan3/actor.h3
-rw-r--r--engines/glk/alan3/alan3.cpp3
-rw-r--r--engines/glk/alan3/alt_info.cpp53
-rw-r--r--engines/glk/alan3/alt_info.h9
-rw-r--r--engines/glk/alan3/checkentry.cpp11
-rw-r--r--engines/glk/alan3/checkentry.h3
-rw-r--r--engines/glk/alan3/container.cpp24
-rw-r--r--engines/glk/alan3/container.h7
-rw-r--r--engines/glk/alan3/debug.cpp140
-rw-r--r--engines/glk/alan3/debug.h5
-rw-r--r--engines/glk/alan3/exe.cpp8
-rw-r--r--engines/glk/alan3/exe.h7
-rw-r--r--engines/glk/alan3/instance.cpp299
-rw-r--r--engines/glk/alan3/instance.h15
-rw-r--r--engines/glk/alan3/inter.cpp38
-rw-r--r--engines/glk/alan3/inter.h5
-rw-r--r--engines/glk/alan3/location.cpp39
-rw-r--r--engines/glk/alan3/location.h5
-rw-r--r--engines/glk/alan3/main.cpp118
-rw-r--r--engines/glk/alan3/msg.cpp14
-rw-r--r--engines/glk/alan3/msg.h7
-rw-r--r--engines/glk/alan3/output.cpp34
-rw-r--r--engines/glk/alan3/parse.cpp336
-rw-r--r--engines/glk/alan3/readline.cpp16
-rw-r--r--engines/glk/alan3/readline.h3
-rw-r--r--engines/glk/alan3/rules.cpp58
-rw-r--r--engines/glk/alan3/rules.h5
-rw-r--r--engines/glk/alan3/save.cpp39
-rw-r--r--engines/glk/alan3/save.h2
-rw-r--r--engines/glk/alan3/scan.cpp32
-rw-r--r--engines/glk/alan3/syntax.cpp6
-rw-r--r--engines/glk/alan3/syntax.h3
-rw-r--r--engines/glk/alan3/term.cpp4
-rw-r--r--engines/glk/alan3/term.h4
37 files changed, 781 insertions, 628 deletions
diff --git a/engines/glk/alan3/act.cpp b/engines/glk/alan3/act.cpp
index 4874cb9663..cdc95f9217 100644
--- a/engines/glk/alan3/act.cpp
+++ b/engines/glk/alan3/act.cpp
@@ -32,9 +32,10 @@ namespace Glk {
namespace Alan3 {
/*----------------------------------------------------------------------*/
-static void executeCommand(int verb, Parameter parameters[]) {
+static void executeCommand(CONTEXT, int verb, Parameter parameters[]) {
static AltInfo *altInfos = NULL; /* Need to survive lots of different exits...*/
int altIndex;
+ bool flag;
/* Did we leave anything behind last time... */
if (altInfos != NULL)
@@ -42,20 +43,22 @@ static void executeCommand(int verb, Parameter parameters[]) {
altInfos = findAllAlternatives(verb, parameters);
- if (anyCheckFailed(altInfos, EXECUTE_CHECK_BODY_ON_FAIL))
+ FUNC2(anyCheckFailed, flag, altInfos, EXECUTE_CHECK_BODY_ON_FAIL)
+ if (flag)
return;
/* Check for anything to execute... */
if (!anythingToExecute(altInfos))
- error(M_CANT0);
+ CALL1(error, M_CANT0)
/* Now perform actions! First try any BEFORE or ONLY from inside out */
for (altIndex = lastAltInfoIndex(altInfos); altIndex >= 0; altIndex--) {
if (altInfos[altIndex].alt != 0) // TODO Can this ever be NULL? Why?
if (altInfos[altIndex].alt->qual == (Aword)Q_BEFORE
|| altInfos[altIndex].alt->qual == (Aword)Q_ONLY) {
- if (!executedOk(&altInfos[altIndex]))
- abortPlayerCommand();
+ FUNC1(executedOk, flag, &altInfos[altIndex])
+ if (!flag)
+ CALL0(abortPlayerCommand)
if (altInfos[altIndex].alt->qual == (Aword)Q_ONLY)
return;
}
@@ -63,17 +66,22 @@ static void executeCommand(int verb, Parameter parameters[]) {
/* Then execute any not declared as AFTER, i.e. the default */
for (altIndex = 0; !altInfos[altIndex].end; altIndex++) {
- if (altInfos[altIndex].alt != 0)
- if (altInfos[altIndex].alt->qual != (Aword)Q_AFTER)
- if (!executedOk(&altInfos[altIndex]))
- abortPlayerCommand();
+ if (altInfos[altIndex].alt != 0) {
+ if (altInfos[altIndex].alt->qual != (Aword)Q_AFTER) {
+ FUNC1(executedOk, flag, &altInfos[altIndex])
+ if (!flag)
+ CALL0(abortPlayerCommand)
+ }
+ }
}
/* Finally, the ones declared as AFTER */
for (altIndex = lastAltInfoIndex(altInfos); altIndex >= 0; altIndex--) {
- if (altInfos[altIndex].alt != 0)
- if (!executedOk(&altInfos[altIndex]))
- abortPlayerCommand();
+ if (altInfos[altIndex].alt != 0) {
+ FUNC1(executedOk, flag, &altInfos[altIndex])
+ if (!flag)
+ CALL0(abortPlayerCommand)
+ }
}
}
@@ -86,7 +94,7 @@ static void executeCommand(int verb, Parameter parameters[]) {
such as ALL, THEM or lists of objects.
*/
-void action(int verb, Parameter parameters[], Parameter multipleMatches[]) {
+void action(CONTEXT, int verb, Parameter parameters[], Parameter multipleMatches[]) {
int multiplePosition;
#ifdef TODO
char marker[10];
@@ -115,7 +123,7 @@ void action(int verb, Parameter parameters[], Parameter multipleMatches[]) {
#endif
} else {
setGlobalParameters(parameters);
- executeCommand(verb, parameters);
+ CALL2(executeCommand, verb, parameters)
}
}
diff --git a/engines/glk/alan3/act.h b/engines/glk/alan3/act.h
index 09f867657e..b2daa25fb8 100644
--- a/engines/glk/alan3/act.h
+++ b/engines/glk/alan3/act.h
@@ -25,12 +25,13 @@
/* Header file for action unit of ARUN Alan System interpreter */
+#include "glk/alan3/jumps.h"
#include "glk/alan3/params.h"
namespace Glk {
namespace Alan3 {
-extern void action(int verb, Parameter *parameters, Parameter *multipleMatches);
+extern void action(CONTEXT, int verb, Parameter *parameters, Parameter *multipleMatches);
} // End of namespace Alan3
} // End of namespace Glk
diff --git a/engines/glk/alan3/actor.cpp b/engines/glk/alan3/actor.cpp
index ff4d89f9a1..337034fcd3 100644
--- a/engines/glk/alan3/actor.cpp
+++ b/engines/glk/alan3/actor.cpp
@@ -61,18 +61,19 @@ StepEntry *stepOf(int actor) {
/*======================================================================*/
-void describeActor(int actor) {
+void describeActor(CONTEXT, int actor) {
ScriptEntry *script = scriptOf(actor);
- if (script != NULL && script->description != 0)
- interpret(script->description);
- else if (hasDescription(actor))
- describeAnything(actor);
- else {
+ if (script != NULL && script->description != 0) {
+ CALL1(interpret, script->description)
+ } else if (hasDescription(actor)) {
+ CALL1(describeAnything, actor)
+ } else {
printMessageWithInstanceParameter(M_SEE_START, actor);
printMessage(M_SEE_END);
+
if (instances[actor].container != 0)
- describeContainer(actor);
+ CALL1(describeContainer, actor)
}
admin[actor].alreadyDescribed = TRUE;
}
diff --git a/engines/glk/alan3/actor.h b/engines/glk/alan3/actor.h
index 8b2c1ad6bf..6ac20b24f7 100644
--- a/engines/glk/alan3/actor.h
+++ b/engines/glk/alan3/actor.h
@@ -24,6 +24,7 @@
#define GLK_ALAN3_ACTOR
#include "glk/alan3/acode.h"
+#include "glk/alan3/jumps.h"
namespace Glk {
namespace Alan3 {
@@ -31,7 +32,7 @@ namespace Alan3 {
/* FUNCTIONS */
extern ScriptEntry *scriptOf(int actor);
extern StepEntry *stepOf(int actor);
-extern void describeActor(int actor);
+extern void describeActor(CONTEXT, int actor);
} // End of namespace Alan3
} // End of namespace Glk
diff --git a/engines/glk/alan3/alan3.cpp b/engines/glk/alan3/alan3.cpp
index 7fc7e8416a..52a6e25739 100644
--- a/engines/glk/alan3/alan3.cpp
+++ b/engines/glk/alan3/alan3.cpp
@@ -132,8 +132,7 @@ void Alan3::deinitialize() {
}
Common::Error Alan3::readSaveData(Common::SeekableReadStream *rs) {
- Glk::Alan3::restoreGame(rs);
- return Common::kNoError;
+ return Glk::Alan3::restoreGame(rs) ? Common::kNoError : Common::kReadingFailed;
}
Common::Error Alan3::writeGameData(Common::WriteStream *ws) {
diff --git a/engines/glk/alan3/alt_info.cpp b/engines/glk/alan3/alt_info.cpp
index 1b2b3feab5..1e5a05c8a1 100644
--- a/engines/glk/alan3/alt_info.cpp
+++ b/engines/glk/alan3/alt_info.cpp
@@ -55,8 +55,8 @@ void primeAltInfo(AltInfo *altInfo, int level, int parameter, int instance, int
/*----------------------------------------------------------------------*/
-static void traceInstanceAndItsClass(Aid instance, Aid cls) {
- traceSay(instance);
+static void traceInstanceAndItsClass(CONTEXT, Aid instance, Aid cls) {
+ CALL1(traceSay, instance)
printf("[%d]", instance);
if (cls != NO_CLASS)
printf(", inherited from %s[%d]", idOfClass(cls), cls);
@@ -64,14 +64,14 @@ static void traceInstanceAndItsClass(Aid instance, Aid cls) {
/*----------------------------------------------------------------------*/
-static void traceAltInfo(AltInfo *alt) {
+static void traceAltInfo(CONTEXT, AltInfo *alt) {
switch (alt->level) {
case GLOBAL_LEVEL:
printf("GLOBAL");
break;
case LOCATION_LEVEL:
printf("in (location) ");
- traceInstanceAndItsClass(current.location, alt->_class);
+ CALL2(traceInstanceAndItsClass, current.location, alt->_class)
break;
case PARAMETER_LEVEL: {
char *parameterName = parameterNameInSyntax(current.verb, alt->parameter);
@@ -79,7 +79,7 @@ static void traceAltInfo(AltInfo *alt) {
printf("in parameter %s(#%d)=", parameterName, alt->parameter);
else
printf("in parameter #%d=", alt->parameter);
- traceInstanceAndItsClass(globalParameters[alt->parameter - 1].instance, alt->_class);
+ CALL2(traceInstanceAndItsClass, globalParameters[alt->parameter - 1].instance, alt->_class)
break;
}
}
@@ -87,35 +87,36 @@ static void traceAltInfo(AltInfo *alt) {
/*----------------------------------------------------------------------*/
-static void traceVerbCheck(AltInfo *alt, bool execute) {
+static void traceVerbCheck(CONTEXT, AltInfo *alt, bool execute) {
if (traceSectionOption && execute) {
printf("\n<VERB %d, ", current.verb);
- traceAltInfo(alt);
+ CALL1(traceAltInfo, alt)
printf(", CHECK:>\n");
}
}
/*======================================================================*/
-bool checkFailed(AltInfo *altInfo, bool execute) {
+bool checkFailed(CONTEXT, AltInfo *altInfo, bool execute) {
if (altInfo->alt != NULL && altInfo->alt->checks != 0) {
- traceVerbCheck(altInfo, execute);
+ R0CALL2(traceVerbCheck, altInfo, execute)
+
// TODO Why does this not generate a regression error with !
// Need a new regression case?
- fail = FALSE;
- if (checksFailed(altInfo->alt->checks, execute)) return TRUE;
- if (fail) return TRUE;
+ R0FUNC2(checksFailed, fail, altInfo->alt->checks, execute)
+ return fail;
}
return FALSE;
}
/*----------------------------------------------------------------------*/
-static void traceVerbExecution(AltInfo *alt) {
+static void traceVerbExecution(CONTEXT, AltInfo *alt) {
if (traceSectionOption) {
printf("\n<VERB %d, ", current.verb);
- traceAltInfo(alt);
+ CALL1(traceAltInfo, alt)
printf(", DOES");
+
switch (alt->alt->qual) {
case Q_BEFORE:
printf(" (BEFORE)");
@@ -135,12 +136,12 @@ static void traceVerbExecution(AltInfo *alt) {
/*======================================================================*/
-bool executedOk(AltInfo *altInfo) {
+bool executedOk(CONTEXT, AltInfo *altInfo) {
fail = FALSE;
if (!altInfo->done && altInfo->alt->action != 0) {
- traceVerbExecution(altInfo);
+ R0CALL1(traceVerbExecution, altInfo)
current.instance = altInfo->instance;
- interpret(altInfo->alt->action);
+ R0CALL1(interpret, altInfo->alt->action)
}
altInfo->done = TRUE;
return !fail;
@@ -248,14 +249,16 @@ static void addAlternativesFromParameter(AltInfoArray altInfos, int verb, Parame
/*======================================================================*/
-bool anyCheckFailed(AltInfoArray altInfo, bool execute) {
+bool anyCheckFailed(CONTEXT, AltInfoArray altInfo, bool execute) {
int altIndex;
+ bool flag;
if (altInfo != NULL)
for (altIndex = 0; !altInfo[altIndex].end; altIndex++) {
current.instance = altInfo[altIndex].instance;
- if (checkFailed(&altInfo[altIndex], execute))
- return TRUE;
+
+ R0FUNC2(checkFailed, flag, &altInfo[altIndex], execute)
+ return flag;
}
return FALSE;
}
@@ -339,15 +342,17 @@ AltInfo *findAllAlternatives(int verb, Parameter parameters[]) {
/*----------------------------------------------------------------------*/
-static bool possibleWithFinder(int verb, Parameter parameters[], AltInfoFinder *finder) {
+static bool possibleWithFinder(CONTEXT, int verb, Parameter parameters[], AltInfoFinder *finder) {
bool anything;
AltInfo *allAlternatives;
+ bool flag;
allAlternatives = finder(verb, parameters);
// TODO Need to do this since anyCheckFailed() call execute() which assumes the global parameters
setGlobalParameters(parameters);
- if (anyCheckFailed(allAlternatives, DONT_EXECUTE_CHECK_BODY_ON_FAIL))
+ R0FUNC2(anyCheckFailed, flag, allAlternatives, DONT_EXECUTE_CHECK_BODY_ON_FAIL)
+ if (flag)
anything = FALSE;
else
anything = anythingToExecute(allAlternatives);
@@ -361,11 +366,11 @@ static bool possibleWithFinder(int verb, Parameter parameters[], AltInfoFinder *
/*======================================================================*/
-bool possible(int verb, Parameter inParameters[], ParameterPosition parameterPositions[]) {
+bool possible(CONTEXT, int verb, Parameter inParameters[], ParameterPosition parameterPositions[]) {
// This is a wrapper for possibleWithFinder() which is used in unit tests
// possible() should be used "for real".
- return possibleWithFinder(verb, inParameters, findAllAlternatives);
+ return possibleWithFinder(context, verb, inParameters, findAllAlternatives);
}
} // End of namespace Alan3
diff --git a/engines/glk/alan3/alt_info.h b/engines/glk/alan3/alt_info.h
index 2a7dd0c2f9..a46d16b933 100644
--- a/engines/glk/alan3/alt_info.h
+++ b/engines/glk/alan3/alt_info.h
@@ -27,6 +27,7 @@
#include "glk/alan3/types.h"
#include "glk/alan3/acode.h"
+#include "glk/alan3/jumps.h"
#include "glk/alan3/params.h"
#include "glk/alan3/parameter_position.h"
@@ -72,14 +73,14 @@ typedef AltInfo AltInfoArray[];
/* Functions */
extern void primeAltInfo(AltInfo *altInfo, int level, int parameter, int instance, int cls);
-extern bool executedOk(AltInfo *altInfo);
-extern bool checkFailed(AltInfo *altInfo, bool execute);
+extern bool executedOk(CONTEXT, AltInfo *altInfo);
+extern bool checkFailed(CONTEXT, AltInfo *altInfo, bool execute);
extern bool canBeExecuted(AltInfo *altInfo);
extern AltInfo *duplicateAltInfoArray(AltInfoArray altInfos);
extern int lastAltInfoIndex(AltInfoArray altInfos);
-extern bool anyCheckFailed(AltInfoArray altInfos, bool execute);
+extern bool anyCheckFailed(CONTEXT, AltInfoArray altInfos, bool execute);
extern bool anythingToExecute(AltInfoArray altInfos);
-extern bool possible(int verb, Parameter parameters[], ParameterPosition parameterPositions[]);
+extern bool possible(CONTEXT, int verb, Parameter parameters[], ParameterPosition parameterPositions[]);
extern AltInfo *findAllAlternatives(int verb, Parameter parameters[]);
} // End of namespace Alan3
diff --git a/engines/glk/alan3/checkentry.cpp b/engines/glk/alan3/checkentry.cpp
index 6a49128d71..3977d9e742 100644
--- a/engines/glk/alan3/checkentry.cpp
+++ b/engines/glk/alan3/checkentry.cpp
@@ -29,17 +29,20 @@ namespace Glk {
namespace Alan3 {
/*======================================================================*/
-bool checksFailed(Aaddr adr, bool execute) {
+bool checksFailed(CONTEXT, Aaddr adr, bool execute) {
CheckEntry *chk = (CheckEntry *) pointerTo(adr);
+ bool flag;
+
if (chk->exp == 0) {
if (execute == EXECUTE_CHECK_BODY_ON_FAIL)
- interpret(chk->stms);
+ R0CALL1(interpret, chk->stms)
return TRUE;
} else {
while (!isEndOfArray(chk)) {
- if (!evaluate(chk->exp)) {
+ R0FUNC1(evaluate, flag, chk->exp)
+ if (!flag) {
if (execute == EXECUTE_CHECK_BODY_ON_FAIL)
- interpret(chk->stms);
+ R0CALL1(interpret, chk->stms)
return TRUE;
}
chk++;
diff --git a/engines/glk/alan3/checkentry.h b/engines/glk/alan3/checkentry.h
index f5bcff197d..a0c3d25569 100644
--- a/engines/glk/alan3/checkentry.h
+++ b/engines/glk/alan3/checkentry.h
@@ -25,6 +25,7 @@
#include "glk/alan3/types.h"
#include "glk/alan3/acode.h"
+#include "glk/alan3/jumps.h"
namespace Glk {
namespace Alan3 {
@@ -48,7 +49,7 @@ typedef CheckEntry CheckEntryArray[];
/* FUNCTIONS */
-extern bool checksFailed(Aaddr adr, bool execute);
+extern bool checksFailed(CONTEXT, Aaddr adr, bool execute);
} // End of namespace Alan3
} // End of namespace Glk
diff --git a/engines/glk/alan3/container.cpp b/engines/glk/alan3/container.cpp
index 36469a336c..0ce44b06c2 100644
--- a/engines/glk/alan3/container.cpp
+++ b/engines/glk/alan3/container.cpp
@@ -79,14 +79,14 @@ static bool containerIsEmpty(int container) {
/*======================================================================*/
-void describeContainer(int container) {
+void describeContainer(CONTEXT, int container) {
if (!containerIsEmpty(container) && !isOpaque(container))
- list(container);
+ CALL1(list, container)
}
/*======================================================================*/
-bool passesContainerLimits(Aint theContainer, Aint theAddedInstance) {
+bool passesContainerLimits(CONTEXT, Aint theContainer, Aint theAddedInstance) {
LimitEntry *limit;
Aword props;
@@ -100,12 +100,12 @@ bool passesContainerLimits(Aint theContainer, Aint theAddedInstance) {
for (limit = (LimitEntry *) pointerTo(containers[props].limits); !isEndOfArray(limit); limit++)
if ((int)limit->atr == 1 - I_COUNT) { /* TODO This is actually some encoding of the attribute number, right? */
if (countInContainer(theContainer) >= (int)limit->val) {
- interpret(limit->stms);
+ R0CALL1(interpret, limit->stms)
return (FALSE);
}
} else {
if (sumAttributeInContainer(theContainer, limit->atr) + getInstanceAttribute(theAddedInstance, limit->atr) > limit->val) {
- interpret(limit->stms);
+ R0CALL1(interpret, limit->stms)
return (FALSE);
}
}
@@ -127,7 +127,7 @@ int containerSize(int container, ATrans trans) {
}
/*======================================================================*/
-void list(int container) {
+void list(CONTEXT, int container) {
uint i;
Aword props;
Aword foundInstance[2] = {0, 0};
@@ -145,9 +145,9 @@ void list(int container) {
/* We can only see objects and actors directly in this container... */
if (admin[i].location == container) { /* Yes, it's in this container */
if (found == 0) {
- if (containers[props].header != 0)
- interpret(containers[props].header);
- else {
+ if (containers[props].header != 0) {
+ CALL1(interpret, containers[props].header)
+ } else {
if (isAActor(containers[props].owner))
printMessageWithInstanceParameter(M_CARRIES, containers[props].owner);
else
@@ -169,9 +169,9 @@ void list(int container) {
printMessageWithInstanceParameter(M_CONTAINS_AND, foundInstance[1]);
printMessageWithInstanceParameter(M_CONTAINS_END, foundInstance[0]);
} else {
- if (containers[props].empty != 0)
- interpret(containers[props].empty);
- else {
+ if (containers[props].empty != 0) {
+ CALL1(interpret, containers[props].empty)
+ } else {
if (isAActor(containers[props].owner))
printMessageWithInstanceParameter(M_EMPTYHANDED, containers[props].owner);
else
diff --git a/engines/glk/alan3/container.h b/engines/glk/alan3/container.h
index 88aac47f6e..86d84c65e5 100644
--- a/engines/glk/alan3/container.h
+++ b/engines/glk/alan3/container.h
@@ -25,6 +25,7 @@
#include "glk/alan3/types.h"
#include "glk/alan3/acode.h"
+#include "glk/alan3/jumps.h"
namespace Glk {
namespace Alan3 {
@@ -35,9 +36,9 @@ extern ContainerEntry *containers; /* Container table pointer */
/* FUNCTIONS */
extern int containerSize(int container, ATrans trans);
-extern bool passesContainerLimits(Aint container, Aint addedInstance);
-extern void describeContainer(int container);
-extern void list(int cnt);
+extern bool passesContainerLimits(CONTEXT, Aint container, Aint addedInstance);
+extern void describeContainer(CONTEXT, int container);
+extern void list(CONTEXT, int cnt);
} // End of namespace Alan3
} // End of namespace Glk
diff --git a/engines/glk/alan3/debug.cpp b/engines/glk/alan3/debug.cpp
index d090021733..84f9e077a2 100644
--- a/engines/glk/alan3/debug.cpp
+++ b/engines/glk/alan3/debug.cpp
@@ -73,7 +73,7 @@ static void showAttributes(AttributeEntry *attrib) {
/*----------------------------------------------------------------------*/
-static void showContents(int cnt) {
+static void showContents(CONTEXT, int cnt) {
uint i;
char str[80];
Abool found = FALSE;
@@ -84,7 +84,7 @@ static void showContents(int cnt) {
if (!found)
found = TRUE;
output("$i$t");
- say(i);
+ say(context, i);
sprintf(str, "[%d] ", i);
output(str);
}
@@ -95,7 +95,7 @@ static void showContents(int cnt) {
/*----------------------------------------------------------------------*/
-static char *idOfInstance(int instance) {
+static char *idOfInstance(CONTEXT, int instance) {
int base = header->instanceTableAddress +
header->instanceMax * sizeof(InstanceEntry) / sizeof(Aword) + 1;
return (char *)&memory[memory[base + instance - 1]];
@@ -103,60 +103,61 @@ static char *idOfInstance(int instance) {
/*----------------------------------------------------------------------*/
-static void sayInstanceNumberAndName(int ins) {
+static void sayInstanceNumberAndName(CONTEXT, int ins) {
char buf[1000];
- sprintf(buf, "[%d] %s (\"$$", ins, idOfInstance(ins));
+ sprintf(buf, "[%d] %s (\"$$", ins, idOfInstance(context, ins));
output(buf);
- say(ins);
+ say(context, ins);
output("$$\")");
}
/*----------------------------------------------------------------------*/
-static void sayLocationOfInstance(int ins, const char *prefix) {
+static void sayLocationOfInstance(CONTEXT, int ins, const char *prefix) {
if (admin[ins].location == 0)
return;
else {
output(prefix);
if (isALocation(admin[ins].location)) {
output("at");
- sayInstanceNumberAndName(admin[ins].location);
- sayLocationOfInstance(admin[ins].location, prefix);
+ CALL1(sayInstanceNumberAndName, admin[ins].location)
+ CALL2(sayLocationOfInstance, admin[ins].location, prefix)
} else if (isAContainer(admin[ins].location)) {
if (isAObject(admin[ins].location))
output("in");
else if (isAActor(admin[ins].location))
output("carried by");
- sayInstanceNumberAndName(admin[ins].location);
- sayLocationOfInstance(admin[ins].location, prefix);
- } else
+ CALL1(sayInstanceNumberAndName, admin[ins].location)
+ CALL2(sayLocationOfInstance, admin[ins].location, prefix)
+ } else {
output("Illegal location!");
+ }
}
}
/*----------------------------------------------------------------------*/
-static void listInstance(int ins) {
+static void listInstance(CONTEXT, int ins) {
output("$i");
- sayInstanceNumberAndName(ins);
+ CALL1(sayInstanceNumberAndName, ins)
if (instances[ins].container)
output("(container)");
- sayLocationOfInstance(ins, ", ");
+ CALL2(sayLocationOfInstance, ins, ", ")
}
/*----------------------------------------------------------------------*/
-static void listInstances(char *pattern) {
+static void listInstances(CONTEXT, char *pattern) {
uint ins;
bool found = FALSE;
for (ins = 1; ins <= header->instanceMax; ins++) {
- if (pattern == NULL || (pattern != NULL && match(pattern, idOfInstance(ins)))) {
+ if (pattern == NULL || (pattern != NULL && match(pattern, idOfInstance(context, ins)))) {
if (!found) {
output("Instances:");
found = TRUE;
}
- listInstance(ins);
+ CALL1(listInstance, ins)
}
}
if (pattern != NULL && !found)
@@ -164,7 +165,7 @@ static void listInstances(char *pattern) {
}
/*----------------------------------------------------------------------*/
-static void showInstance(int ins) {
+static void showInstance(CONTEXT, int ins) {
char str[80];
if (ins > (int)header->instanceMax || ins < 1) {
@@ -174,7 +175,7 @@ static void showInstance(int ins) {
}
output("The");
- sayInstanceNumberAndName(ins);
+ CALL1(sayInstanceNumberAndName, ins)
if (instances[ins].parent) {
sprintf(str, "Isa %s[%d]", idOfClass(instances[ins].parent), instances[ins].parent);
output(str);
@@ -184,14 +185,14 @@ static void showInstance(int ins) {
sprintf(str, "$iLocation:");
output(str);
needSpace = TRUE;
- sayLocationOfInstance(ins, "");
+ CALL2(sayLocationOfInstance, ins, "")
}
output("$iAttributes:");
showAttributes(admin[ins].attributes);
if (instances[ins].container)
- showContents(ins);
+ CALL1(showContents, ins)
if (isA(ins, header->actorClassId)) {
if (admin[ins].script == 0)
@@ -205,18 +206,18 @@ static void showInstance(int ins) {
/*----------------------------------------------------------------------*/
-static void listObjects(void) {
+static void listObjects(CONTEXT) {
uint obj;
output("Objects:");
for (obj = 1; obj <= header->instanceMax; obj++)
if (isAObject(obj))
- listInstance(obj);
+ CALL1(listInstance, obj)
}
/*----------------------------------------------------------------------*/
-static void showObject(int obj) {
+static void showObject(CONTEXT, int obj) {
char str[80];
@@ -226,8 +227,7 @@ static void showObject(int obj) {
return;
}
- showInstance(obj);
-
+ CALL1(showInstance, obj)
}
/*----------------------------------------------------------------------*/
@@ -314,18 +314,18 @@ static void showClassHierarchy(int thisItem, int depth) {
/*----------------------------------------------------------------------*/
-static void listLocations(void) {
+static void listLocations(CONTEXT) {
uint loc;
output("Locations:");
for (loc = 1; loc <= header->instanceMax; loc++)
if (isALocation(loc))
- listInstance(loc);
+ listInstance(context, loc);
}
/*----------------------------------------------------------------------*/
-static void showLocation(int loc) {
+static void showLocation(CONTEXT, int loc) {
char str[80];
@@ -336,7 +336,7 @@ static void showLocation(int loc) {
}
output("The ");
- say(loc);
+ CALL1(say, loc)
sprintf(str, "(%d) Isa location :", loc);
output(str);
@@ -346,18 +346,18 @@ static void showLocation(int loc) {
/*----------------------------------------------------------------------*/
-static void listActors(void) {
+static void listActors(CONTEXT) {
uint act;
output("Actors:");
for (act = 1; act <= header->instanceMax; act++)
if (isAActor(act))
- listInstance(act);
+ CALL1(listInstance, act)
}
/*----------------------------------------------------------------------*/
-static void showActor(int act) {
+static void showActor(CONTEXT, int act) {
char str[80];
if (!isAActor(act)) {
@@ -366,12 +366,12 @@ static void showActor(int act) {
return;
}
- showInstance(act);
+ CALL1(showInstance, act)
}
/*----------------------------------------------------------------------*/
-static void showEvents(void) {
+static void showEvents(CONTEXT) {
uint event;
int i;
char str[80];
@@ -389,7 +389,7 @@ static void showEvents(void) {
if (scheduled) {
sprintf(str, "Scheduled for +%d, at ", eventQueue[i].after);
output(str);
- say(eventQueue[i].where);
+ CALL1(say, eventQueue[i].where)
} else
output("Not scheduled.");
}
@@ -734,15 +734,17 @@ static char parseDebugCommand(char *command) {
/*----------------------------------------------------------------------*/
-static void readCommand(char buf[]) {
+static void readCommand(CONTEXT, char buf[], size_t maxLen) {
char c;
+ bool flag;
capitalize = FALSE;
if (anyOutput) newline();
do {
output("adbg> ");
- if (!readline(buf)) {
+ FUNC2(readline, flag, buf, maxLen)
+ if (!flag) {
newline();
quitGame();
}
@@ -919,32 +921,32 @@ static void handleNextCommand(bool calledFromBreakpoint) {
/*----------------------------------------------------------------------*/
-static void handleLocationsCommand() {
+static void handleLocationsCommand(CONTEXT) {
char *parameter = strtok(NULL, "");
if (parameter == 0)
- listLocations();
+ listLocations(context);
else
- showLocation(atoi(parameter));
+ showLocation(context, atoi(parameter));
}
/*----------------------------------------------------------------------*/
-static void handleActorsCommand() {
+static void handleActorsCommand(CONTEXT) {
char *parameter = strtok(NULL, "");
if (parameter == NULL)
- listActors();
+ listActors(context);
else
- showActor(atoi(parameter));
+ showActor(context, atoi(parameter));
}
/*----------------------------------------------------------------------*/
-static void handleClassesCommand() {
+static void handleClassesCommand(CONTEXT) {
char *parameter = strtok(NULL, "");
if (parameter == NULL || strchr(parameter, '*') != 0) {
output("Classes:");
showClassHierarchy(1, 0);
- listInstances(parameter);
+ listInstances(context, parameter);
} else if (isdigit((int)parameter[0]))
showClass(atoi(parameter));
else {
@@ -954,28 +956,28 @@ static void handleClassesCommand() {
/*----------------------------------------------------------------------*/
-static void handleObjectsCommand() {
+static void handleObjectsCommand(CONTEXT) {
char *parameter = strtok(NULL, "");
if (parameter == NULL)
- listObjects();
+ listObjects(context);
else
- showObject(atoi(parameter));
+ showObject(context, atoi(parameter));
}
/*----------------------------------------------------------------------*/
-static void handleInstancesCommand() {
+static void handleInstancesCommand(CONTEXT) {
char *parameter = strtok(NULL, "");
uint i;
if (parameter == NULL || strchr(parameter, '*') != 0)
- listInstances(parameter);
+ listInstances(context, parameter);
else if (isdigit((int)parameter[0]))
- showInstance(atoi(parameter));
+ showInstance(context, atoi(parameter));
else {
for (i = 1; i < header->instanceMax; i++)
- if (strcmp(parameter, idOfInstance(i)) == 0) {
- showInstance(i);
+ if (strcmp(parameter, idOfInstance(context, i)) == 0) {
+ showInstance(context, i);
return;
}
printf("No instance named '%s'.", parameter);
@@ -992,7 +994,7 @@ static bool exactSameVersion() {
/*======================================================================*/
-void debug(bool calledFromBreakpoint, int line, int fileNumber) {
+void debug(CONTEXT, bool calledFromBreakpoint, int line, int fileNumber) {
static bool warned = FALSE;
saveInfo();
@@ -1011,9 +1013,9 @@ void debug(bool calledFromBreakpoint, int line, int fileNumber) {
}
while (TRUE) {
-
char commandLine[200];
- readCommand(commandLine);
+ CALL2(readCommand, commandLine, 200)
+
char *command = strtok(commandLine, " ");
char commandCode = parseDebugCommand(command);
@@ -1022,19 +1024,19 @@ void debug(bool calledFromBreakpoint, int line, int fileNumber) {
output("Ambiguous ADBG command abbreviation. ? for help.");
break;
case ACTORS_COMMAND:
- handleActorsCommand();
+ handleActorsCommand(context);
break;
case BREAK_COMMAND:
handleBreakCommand(fileNumber);
break;
case CLASSES_COMMAND:
- handleClassesCommand();
+ handleClassesCommand(context);
break;
case DELETE_COMMAND:
handleDeleteCommand(calledFromBreakpoint, line, fileNumber);
break;
case EVENTS_COMMAND:
- showEvents();
+ showEvents(context);
break;
case EXIT_COMMAND:
debugOption = FALSE;
@@ -1050,7 +1052,7 @@ void debug(bool calledFromBreakpoint, int line, int fileNumber) {
handleHelpCommand();
break;
case INSTANCES_COMMAND:
- handleInstancesCommand();
+ handleInstancesCommand(context);
break;
case TRACE_COMMAND:
handleTraceCommand();
@@ -1059,13 +1061,13 @@ void debug(bool calledFromBreakpoint, int line, int fileNumber) {
toggleInstructionTrace();
break;
case LOCATIONS_COMMAND:
- handleLocationsCommand();
+ handleLocationsCommand(context);
break;
case NEXT_COMMAND:
handleNextCommand(calledFromBreakpoint);
goto exit_debug;
case OBJECTS_COMMAND:
- handleObjectsCommand();
+ handleObjectsCommand(context);
break;
case QUIT_COMMAND:
terminate(0);
@@ -1085,7 +1087,7 @@ exit_debug:
/*======================================================================*/
-void traceSay(int item) {
+void traceSay(CONTEXT, int item) {
/*
Say something, but make sure we don't disturb anything and that it is
shown to the player. Needed for tracing. During debugging things are
@@ -1095,10 +1097,12 @@ void traceSay(int item) {
saveInfo();
needSpace = FALSE;
col = 1;
- if (item == 0)
+ if (item == 0) {
printf("$null$");
- else
- say(item);
+ } else {
+ CALL1(say, item)
+ }
+
needSpace = FALSE;
col = 1;
restoreInfo();
diff --git a/engines/glk/alan3/debug.h b/engines/glk/alan3/debug.h
index 3bfa32ee6c..1f5e2c1ebf 100644
--- a/engines/glk/alan3/debug.h
+++ b/engines/glk/alan3/debug.h
@@ -26,6 +26,7 @@
/* Header file for debug handler in Alan interpreter */
#include "glk/alan3/types.h"
+#include "glk/alan3/jumps.h"
namespace Glk {
namespace Alan3 {
@@ -49,8 +50,8 @@ extern int breakpointIndex(int file, int line);
extern char *sourceFileName(int file);
extern char *readSourceLine(int file, int line);
extern void showSourceLine(int fileNumber, int line);
-extern void debug(bool calledFromBreakpoint, int line, int fileNumber);
-extern void traceSay(int item);
+extern void debug(CONTEXT, bool calledFromBreakpoint, int line, int fileNumber);
+extern void traceSay(CONTEXT, int item);
} // End of namespace Alan3
} // End of namespace Glk
diff --git a/engines/glk/alan3/exe.cpp b/engines/glk/alan3/exe.cpp
index 5c6f09b2b7..39cec13c60 100644
--- a/engines/glk/alan3/exe.cpp
+++ b/engines/glk/alan3/exe.cpp
@@ -577,18 +577,18 @@ void playSound(int sound) {
/*======================================================================*/
-void empty(int cnt, int whr) {
+void empty(CONTEXT, int cnt, int whr) {
uint i;
for (i = 1; i <= header->instanceMax; i++)
if (isIn(i, cnt, DIRECT))
- locate(i, whr);
+ CALL2(locate, i, whr)
}
/*======================================================================*/
-void use(int actor, int script) {
+void use(CONTEXT, int actor, int script) {
char str[80];
StepEntry *step;
@@ -601,7 +601,7 @@ void use(int actor, int script) {
admin[actor].step = 0;
step = stepOf(actor);
if (step != NULL && step->after != 0) {
- admin[actor].waitCount = evaluate(step->after);
+ FUNC1(evaluate, admin[actor].waitCount, step->after)
}
gameStateChanged = TRUE;
diff --git a/engines/glk/alan3/exe.h b/engines/glk/alan3/exe.h
index 428f112609..a039d6f736 100644
--- a/engines/glk/alan3/exe.h
+++ b/engines/glk/alan3/exe.h
@@ -27,6 +27,7 @@
/* IMPORTS */
#include "glk/alan3/sysdep.h"
+#include "glk/alan3/jumps.h"
#include "glk/alan3/acode.h"
#include "glk/alan3/types.h"
#include "glk/alan3/set.h"
@@ -47,9 +48,7 @@ extern Common::SeekableReadStream *textFile; // The text and message file
extern bool printFlag;
/* Long jump buffer for restart, errors and undo */
-//extern jmp_buf restartLabel;
//extern jmp_buf returnLabel;
-//extern jmp_buf forfeitLabel;
/* FUNCTIONS */
@@ -69,10 +68,10 @@ extern void undo(void);
extern void quitGame(void);
extern void restartGame(void);
-extern void use(int act, int scr);
+extern void use(CONTEXT, int act, int scr);
extern void stop(int act);
-extern void empty(int cnt, int whr);
+extern void empty(CONTEXT, int cnt, int whr);
extern int getContainerMember(int container, int index, bool directly);
extern int randomInContainer(int cont);
diff --git a/engines/glk/alan3/instance.cpp b/engines/glk/alan3/instance.cpp
index 05ccd694bf..b5220577b3 100644
--- a/engines/glk/alan3/instance.cpp
+++ b/engines/glk/alan3/instance.cpp
@@ -425,29 +425,35 @@ int where(int instance, ATrans trans) {
/*----------------------------------------------------------------------*/
-static bool executeInheritedMentioned(int cls) {
+static bool executeInheritedMentioned(CONTEXT, int cls) {
if (cls == 0) return FALSE;
if (classes[cls].mentioned) {
- interpret(classes[cls].mentioned);
+ R0CALL1(interpret, classes[cls].mentioned)
return TRUE;
- } else
- return executeInheritedMentioned(classes[cls].parent);
+ } else {
+ bool flag;
+ R0FUNC1(executeInheritedMentioned, flag, classes[cls].parent)
+ return flag;
+ }
}
/*----------------------------------------------------------------------*/
-static bool mention(int instance) {
+static bool mention(CONTEXT, int instance) {
if (instances[instance].mentioned) {
- interpret(instances[instance].mentioned);
+ R0CALL1(interpret, instances[instance].mentioned)
return TRUE;
- } else
- return executeInheritedMentioned(instances[instance].parent);
+ } else {
+ bool flag;
+ R0FUNC1(executeInheritedMentioned, flag, instances[instance].parent)
+ return flag;
+ }
}
/*======================================================================*/
-void sayInstance(int instance) {
+void sayInstance(CONTEXT, int instance) {
#ifdef SAY_INSTANCE_WITH_PLAYER_WORDS_IF_PARAMETER
int p, i;
@@ -475,8 +481,11 @@ void sayInstance(int instance) {
return;
}
#endif
- if (!mention(instance))
- interpret(instances[instance].name);
+
+ bool flag;
+ FUNC1(mention, flag, instance)
+ if (!flag)
+ CALL1(interpret, instances[instance].name)
}
@@ -527,134 +536,157 @@ static char *wordWithCode(int classBit, int code) {
/*----------------------------------------------------------------------*/
-static bool sayInheritedDefiniteForm(int cls) {
+static bool sayInheritedDefiniteForm(CONTEXT, int cls) {
if (cls == 0) {
syserr("No default definite article");
return FALSE;
} else {
if (classes[cls].definite.address) {
- interpret(classes[cls].definite.address);
+ R0CALL1(interpret, classes[cls].definite.address)
return classes[cls].definite.isForm;
- } else
- return sayInheritedDefiniteForm(classes[cls].parent);
+ } else {
+ bool flag;
+ R0FUNC1(sayInheritedDefiniteForm, flag, classes[cls].parent)
+ return flag;
+ }
}
}
/*----------------------------------------------------------------------*/
-static void sayDefinite(int instance) {
+static void sayDefinite(CONTEXT, int instance) {
if (instances[instance].definite.address) {
- interpret(instances[instance].definite.address);
+ CALL1(interpret, instances[instance].definite.address)
+
if (!instances[instance].definite.isForm)
- sayInstance(instance);
- } else if (!sayInheritedDefiniteForm(instances[instance].parent))
- sayInstance(instance);
+ CALL1(sayInstance, instance)
+ } else {
+ bool flag;
+ FUNC1(sayInheritedDefiniteForm, flag, instances[instance].parent)
+ if (!flag)
+ CALL1(sayInstance, instance)
+ }
}
/*----------------------------------------------------------------------*/
-static bool sayInheritedIndefiniteForm(int cls) {
+static bool sayInheritedIndefiniteForm(CONTEXT, int cls) {
if (cls == 0) {
syserr("No default indefinite article");
return FALSE;
} else {
if (classes[cls].indefinite.address) {
- interpret(classes[cls].indefinite.address);
+ R0CALL1(interpret, classes[cls].indefinite.address)
return classes[cls].indefinite.isForm;
- } else
- return sayInheritedIndefiniteForm(classes[cls].parent);
+ } else {
+ bool flag;
+ R0FUNC1(sayInheritedIndefiniteForm, flag, classes[cls].parent)
+ return flag;
+ }
}
}
/*----------------------------------------------------------------------*/
-static void sayIndefinite(int instance) {
+static void sayIndefinite(CONTEXT, int instance) {
if (instances[instance].indefinite.address) {
- interpret(instances[instance].indefinite.address);
+ CALL1(interpret, instances[instance].indefinite.address)
+
if (!instances[instance].indefinite.isForm)
- sayInstance(instance);
- } else if (!sayInheritedIndefiniteForm(instances[instance].parent))
- sayInstance(instance);
+ CALL1(sayInstance, instance)
+ } else {
+ bool flag;
+ FUNC1(sayInheritedIndefiniteForm, flag, instances[instance].parent)
+ if (!flag)
+ CALL1(sayInstance, instance)
+ }
}
/*----------------------------------------------------------------------*/
-static bool sayInheritedNegativeForm(int cls) {
+static bool sayInheritedNegativeForm(CONTEXT, int cls) {
if (cls == 0) {
syserr("No default negative form");
return FALSE;
} else {
if (classes[cls].negative.address) {
- interpret(classes[cls].negative.address);
+ R0CALL1(interpret, classes[cls].negative.address)
return classes[cls].negative.isForm;
- } else
- return sayInheritedNegativeForm(classes[cls].parent);
+ } else {
+ bool flag;
+ R0FUNC1(sayInheritedNegativeForm, flag, classes[cls].parent)
+ return flag;
+ }
}
}
/*----------------------------------------------------------------------*/
-static void sayNegative(int instance) {
+static void sayNegative(CONTEXT, int instance) {
if (instances[instance].negative.address) {
- interpret(instances[instance].negative.address);
+ CALL1(interpret, instances[instance].negative.address)
if (!instances[instance].negative.isForm)
- sayInstance(instance);
- } else if (!sayInheritedNegativeForm(instances[instance].parent))
- sayInstance(instance);
+ CALL1(sayInstance, instance)
+ } else {
+ bool flag;
+ FUNC1(sayInheritedNegativeForm, flag, instances[instance].parent)
+ CALL1(sayInstance, instance)
+ }
}
/*----------------------------------------------------------------------*/
-static void sayInheritedPronoun(int instance) {
+static void sayInheritedPronoun(CONTEXT, int instance) {
if (instance == 0)
syserr("No default pronoun");
else {
if (classes[instance].pronoun != 0)
output(wordWithCode(PRONOUN_BIT, classes[instance].pronoun));
else
- sayInheritedPronoun(classes[instance].parent);
+ CALL1(sayInheritedPronoun, classes[instance].parent)
}
}
/*----------------------------------------------------------------------*/
-static void sayPronoun(int instance) {
+static void sayPronoun(CONTEXT, int instance) {
if (instances[instance].pronoun != 0)
output(wordWithCode(PRONOUN_BIT, instances[instance].pronoun));
else
- sayInheritedPronoun(instances[instance].parent);
+ CALL1(sayInheritedPronoun, instances[instance].parent)
}
/*----------------------------------------------------------------------*/
-static void sayArticleOrForm(int id, SayForm form) {
- if (!isLiteral(id))
+static void sayArticleOrForm(CONTEXT, int id, SayForm form) {
+ if (!isLiteral(id)) {
switch (form) {
case SAY_DEFINITE:
- sayDefinite(id);
+ CALL1(sayDefinite, id)
break;
case SAY_INDEFINITE:
- sayIndefinite(id);
+ CALL1(sayIndefinite, id)
break;
case SAY_NEGATIVE:
- sayNegative(id);
+ CALL1(sayNegative, id)
break;
case SAY_PRONOUN:
- sayPronoun(id);
+ CALL1(sayPronoun, id)
break;
case SAY_SIMPLE:
- say(id);
+ CALL1(say, id)
break;
default:
syserr("Unexpected form in 'sayArticleOrForm()'");
}
- else
- say(id);
+ } else {
+ CALL1(say, id)
+ }
}
/*======================================================================*/
-void say(int instance) {
+void say(CONTEXT, int instance) {
Aword previousInstance = current.instance;
current.instance = instance;
@@ -663,7 +695,7 @@ void say(int instance) {
sayLiteral(instance);
else {
verifyInstance(instance, "SAY");
- sayInstance(instance);
+ sayInstance(context, instance);
}
}
current.instance = previousInstance;
@@ -671,11 +703,11 @@ void say(int instance) {
/*======================================================================*/
-void sayForm(int instance, SayForm form) {
+void sayForm(CONTEXT, int instance, SayForm form) {
Aword previousInstance = current.instance;
current.instance = instance;
- sayArticleOrForm(instance, form);
+ sayArticleOrForm(context, instance, form);
current.instance = previousInstance;
}
@@ -710,66 +742,72 @@ bool hasDescription(int instance) {
/*----------------------------------------------------------------------*/
-static void describeClass(int instance) {
+static void describeClass(CONTEXT, int instance) {
if (classes[instance].description != 0) {
/* This class has a description, run it */
- interpret(classes[instance].description);
+ CALL1(interpret, classes[instance].description)
} else {
/* Search up the inheritance tree, if any, to find a description */
if (classes[instance].parent != 0)
- describeClass(classes[instance].parent);
+ CALL1(describeClass, classes[instance].parent)
}
}
/*======================================================================*/
-void describeAnything(int instance) {
+void describeAnything(CONTEXT, int instance) {
if (instances[instance].description != 0) {
/* This instance has its own description, run it */
- interpret(instances[instance].description);
+ CALL1(interpret, instances[instance].description)
} else {
/* Search up the inheritance tree to find a description */
if (instances[instance].parent != 0)
- describeClass(instances[instance].parent);
+ CALL1(describeClass, instances[instance].parent)
}
admin[instance].alreadyDescribed = TRUE;
}
/*----------------------------------------------------------------------*/
-static void describeObject(int object) {
- if (hasDescription(object))
- describeAnything(object);
- else {
+static void describeObject(CONTEXT, int object) {
+ if (hasDescription(object)) {
+ CALL1(describeAnything, object)
+ } else {
printMessageWithInstanceParameter(M_SEE_START, object);
printMessage(M_SEE_END);
if (instances[object].container != 0)
- describeContainer(object);
+ CALL1(describeContainer, object)
}
admin[object].alreadyDescribed = TRUE;
}
/*----------------------------------------------------------------------*/
-static bool inheritedDescriptionCheck(int cls) {
+static bool inheritedDescriptionCheck(CONTEXT, int cls) {
if (cls == 0) return TRUE;
- if (!inheritedDescriptionCheck(classes[cls].parent)) return FALSE;
+
+ bool flag;
+ R0FUNC1(inheritedDescriptionCheck, flag, classes[cls].parent)
+ if (!flag) return FALSE;
+
if (classes[cls].descriptionChecks == 0) return TRUE;
- return !checksFailed(classes[cls].descriptionChecks, TRUE);
+ R0FUNC2(checksFailed, flag, classes[cls].descriptionChecks, TRUE)
+ return !flag;
}
/*----------------------------------------------------------------------*/
-static bool descriptionCheck(int instance) {
+static bool descriptionCheck(CONTEXT, int instance) {
int previousInstance = current.instance;
bool r;
current.instance = instance;
- if (inheritedDescriptionCheck(instances[instance].parent)) {
+ if (inheritedDescriptionCheck(context, instances[instance].parent)) {
if (instances[instance].checks == 0)
r = TRUE;
else
- r = !checksFailed(instances[instance].checks, TRUE);
- } else
+ r = !checksFailed(context, instances[instance].checks, TRUE);
+ }
+ else
r = FALSE;
current.instance = previousInstance;
return r;
@@ -777,7 +815,7 @@ static bool descriptionCheck(int instance) {
/*======================================================================*/
-void describeInstances(void) {
+void describeInstances(CONTEXT) {
uint i;
int lastInstanceFound = 0;
int found = 0;
@@ -786,14 +824,14 @@ void describeInstances(void) {
for (i = 1; i <= header->instanceMax; i++)
if (admin[i].location == current.location && isAObject(i) &&
!admin[i].alreadyDescribed && hasDescription(i))
- describe(i);
+ CALL1(describe, i)
/* Then list all things without a description */
for (i = 1; i <= header->instanceMax; i++)
if (admin[i].location == current.location
&& !admin[i].alreadyDescribed
&& isAObject(i)
- && descriptionCheck(i)) {
+ && descriptionCheck(context, i)) {
if (found == 0)
printMessageWithInstanceParameter(M_SEE_START, i);
else if (found > 1)
@@ -805,7 +843,7 @@ void describeInstances(void) {
if (found > 0)
printMessageWithInstanceParameter(M_SEE_AND, i);
printMessage(M_SEE_END);
- describeContainer(i);
+ CALL1(describeContainer, i)
found = 0;
continue; /* Actually start another list. */
}
@@ -824,7 +862,7 @@ void describeInstances(void) {
for (i = 1; i <= header->instanceMax; i++)
if (admin[i].location == current.location && i != HERO && isAActor(i)
&& !admin[i].alreadyDescribed)
- describe(i);
+ CALL1(describe, i)
/* Clear the describe flag for all instances */
for (i = 1; i <= header->instanceMax; i++)
@@ -833,35 +871,37 @@ void describeInstances(void) {
/*======================================================================*/
-bool describe(int instance) {
+bool describe(CONTEXT, int instance) {
bool descriptionOk;
int previousInstance = current.instance;
current.instance = instance;
verifyInstance(instance, "DESCRIBE");
- if (descriptionCheck(instance)) {
+
+ if (descriptionCheck(context, instance)) {
descriptionOk = TRUE;
if (isAObject(instance)) {
- describeObject(instance);
+ describeObject(context, instance);
} else if (isAActor(instance)) {
- describeActor(instance);
+ describeActor(context, instance);
} else
- describeAnything(instance);
+ describeAnything(context, instance);
} else
descriptionOk = FALSE;
+
current.instance = previousInstance;
return descriptionOk;
}
/*----------------------------------------------------------------------*/
-static void locateIntoContainer(Aword theInstance, Aword theContainer) {
+static void locateIntoContainer(CONTEXT, Aword theInstance, Aword theContainer) {
if (!isA(theInstance, containers[instances[theContainer].container]._class))
printMessageUsing2InstanceParameters(M_CANNOTCONTAIN, theContainer, theInstance);
- else if (passesContainerLimits(theContainer, theInstance))
+ else if (passesContainerLimits(context, theContainer, theInstance))
admin[theInstance].location = theContainer;
else
- abortPlayerCommand();
+ abortPlayerCommand(context);
}
@@ -881,9 +921,9 @@ static void locateLocation(Aword loc, Aword whr) {
/*----------------------------------------------------------------------*/
-static void locateObject(Aword obj, Aword whr) {
+static void locateObject(CONTEXT, Aword obj, Aword whr) {
if (isAContainer(whr)) { /* Into a container */
- locateIntoContainer(obj, whr);
+ locateIntoContainer(context, obj, whr);
} else {
admin[obj].location = whr;
/* Make sure the location is described since it's changed */
@@ -901,36 +941,38 @@ static void traceEnteredClass(Aint theClass, bool empty) {
/*----------------------------------------------------------------------*/
-static void traceEnteredInstance(Aint instance, bool empty) {
+static void traceEnteredInstance(CONTEXT, Aint instance, bool empty) {
printf("\n<ENTERED in instance ");
- traceSay(instance);
+ traceSay(context, instance);
printf("[%d]%s>\n", instance, empty ? " is empty" : "");
}
/*----------------------------------------------------------------------*/
-static void executeInheritedEntered(Aint theClass) {
+static void executeInheritedEntered(CONTEXT, Aint theClass) {
if (theClass == 0) return;
- executeInheritedEntered(classes[theClass].parent);
+ CALL1(executeInheritedEntered, classes[theClass].parent)
+
if (traceSectionOption)
traceEnteredClass(theClass, classes[theClass].entered == 0);
if (classes[theClass].entered) {
- interpret(classes[theClass].entered);
+ CALL1(interpret, classes[theClass].entered)
}
}
/*----------------------------------------------------------------------*/
-static void executeEntered(Aint instance) {
+static void executeEntered(CONTEXT, Aint instance) {
int currentInstance = current.instance;
current.instance = instance;
if (admin[instance].location != 0)
- executeEntered(admin[instance].location);
- executeInheritedEntered(instances[instance].parent);
+ CALL1(executeEntered, admin[instance].location)
+ CALL1(executeInheritedEntered, instances[instance].parent)
+
if (traceSectionOption)
- traceEnteredInstance(instance, instances[instance].entered == 0);
+ CALL2(traceEnteredInstance, instance, instances[instance].entered == 0)
if (instances[instance].entered != 0) {
- interpret(instances[instance].entered);
+ CALL1(interpret, instances[instance].entered)
}
current.instance = currentInstance;
}
@@ -952,13 +994,13 @@ static void incrementVisits(int location) {
/*----------------------------------------------------------------------*/
-static void revisited(void) {
+static void revisited(CONTEXT) {
if (anyOutput)
para();
- say(where(HERO, DIRECT));
+ CALL1(say, where(HERO, DIRECT))
printMessage(M_AGAIN);
newline();
- describeInstances();
+ CALL0(describeInstances)
}
@@ -973,7 +1015,7 @@ static bool shouldBeDescribed(void) {
/*----------------------------------------------------------------------*/
-static void locateActor(Aint movingActor, Aint whr) {
+static void locateActor(CONTEXT, Aint movingActor, Aint whr) {
Aint previousCurrentLocation = current.location;
Aint previousActorLocation = admin[movingActor].location;
Aint previousActor = current.actor;
@@ -988,7 +1030,7 @@ static void locateActor(Aint movingActor, Aint whr) {
is now it allows the hero to be located into a container. And what
happens with current location if so... */
if (isAContainer(whr))
- locateIntoContainer(movingActor, whr);
+ CALL2(locateIntoContainer, movingActor, whr)
else {
current.location = whr;
admin[movingActor].location = whr;
@@ -1000,16 +1042,17 @@ static void locateActor(Aint movingActor, Aint whr) {
/* Execute possible entered */
current.actor = movingActor;
if (previousActorLocation != current.location) {
- executeEntered(current.location);
+ CALL1(executeEntered, current.location)
}
current.instance = previousInstance;
current.actor = previousActor;
if (movingActor == (int)HERO) {
- if (shouldBeDescribed())
- look();
- else
- revisited();
+ if (shouldBeDescribed()) {
+ CALL0(look)
+ } else {
+ CALL0(revisited)
+ }
admin[where(HERO, DIRECT)].visitsCount++;
} else
/* Ensure that the location will be described to the hero next time */
@@ -1023,17 +1066,17 @@ static void locateActor(Aint movingActor, Aint whr) {
/*----------------------------------------------------------------------*/
-static void traceExtract(int instance, int containerId, const char *what) {
+static void traceExtract(CONTEXT, int instance, int containerId, const char *what) {
if (traceSectionOption) {
printf("\n<EXTRACT from ");
- traceSay(instance);
+ traceSay(context, instance);
printf("[%d, container %d], %s:>\n", instance, containerId, what);
}
}
/*----------------------------------------------------------------------*/
-static void containmentLoopError(int instance, int whr) {
+static void containmentLoopError(CONTEXT, int instance, int whr) {
ParameterArray parameters = newParameterArray();
if (isPreBeta4(header->version))
output("That would be to put something inside itself.");
@@ -1046,28 +1089,28 @@ static void containmentLoopError(int instance, int whr) {
printMessageWithParameters(M_CONTAINMENT_LOOP2, parameters);
}
free(parameters);
- error(NO_MSG);
+ CALL1(error, NO_MSG)
}
/*----------------------------------------------------------------------*/
-static void runExtractStatements(int instance, int containerId) {
+static void runExtractStatements(CONTEXT, int instance, int containerId) {
ContainerEntry *theContainer = &containers[containerId];
if (theContainer->extractStatements != 0) {
- traceExtract(instance, containerId, "Executing");
- interpret(theContainer->extractStatements);
+ CALL3(traceExtract, instance, containerId, "Executing")
+ CALL1(interpret, theContainer->extractStatements)
}
}
/*----------------------------------------------------------------------*/
-static bool runExtractChecks(int instance, int containerId) {
+static bool runExtractChecks(CONTEXT, int instance, int containerId) {
ContainerEntry *theContainer = &containers[containerId];
if (theContainer->extractChecks != 0) {
- traceExtract(instance, containerId, "Checking");
- if (checksFailed(theContainer->extractChecks, EXECUTE_CHECK_BODY_ON_FAIL)) {
+ R0CALL3(traceExtract, instance, containerId, "Checking")
+ if (checksFailed(context, theContainer->extractChecks, EXECUTE_CHECK_BODY_ON_FAIL)) {
fail = TRUE;
return FALSE; /* Failed! */
}
@@ -1077,7 +1120,7 @@ static bool runExtractChecks(int instance, int containerId) {
/*======================================================================*/
-void locate(int instance, int whr) {
+void locate(CONTEXT, int instance, int whr) {
int containerId;
int previousInstance = current.instance;
@@ -1086,7 +1129,7 @@ void locate(int instance, int whr) {
/* Will this create a containment loop? */
if (whr == instance || (isAContainer(instance) && isIn(whr, instance, TRANSITIVE)))
- containmentLoopError(instance, whr);
+ CALL2(containmentLoopError, instance, whr)
/* First check if the instance is in a container, if so run extract checks */
if (isAContainer(admin[instance].location)) { /* In something? */
@@ -1097,23 +1140,23 @@ void locate(int instance, int whr) {
current.instance = loc;
containerId = instances[loc].container;
- if (!runExtractChecks(instance, containerId)) {
+ if (!runExtractChecks(context, instance, containerId)) {
current.instance = previousInstance;
return;
}
- runExtractStatements(instance, containerId);
+ runExtractStatements(context, instance, containerId);
loc = admin[loc].location;
}
current.instance = previousInstance;
}
- if (isAActor(instance))
- locateActor(instance, whr);
- else if (isALocation(instance))
+ if (isAActor(instance)) {
+ CALL2(locateActor, instance, whr)
+ } else if (isALocation(instance)) {
locateLocation(instance, whr);
- else
- locateObject(instance, whr);
-
+ } else {
+ CALL2(locateObject, instance, whr)
+ }
gameStateChanged = TRUE;
}
diff --git a/engines/glk/alan3/instance.h b/engines/glk/alan3/instance.h
index bd4319518d..7c2b9cf03e 100644
--- a/engines/glk/alan3/instance.h
+++ b/engines/glk/alan3/instance.h
@@ -25,6 +25,7 @@
#include "common/serializer.h"
#include "glk/alan3/acode.h"
+#include "glk/alan3/jumps.h"
#include "glk/alan3/types.h"
#include "glk/alan3/set.h"
@@ -73,15 +74,15 @@ extern void setInstanceAttribute(int instance, int atr, Aptr value);
extern void setInstanceStringAttribute(int instance, int attribute, char *string);
extern void setInstanceSetAttribute(int instance, int atr, Aptr set);
-extern void say(int instance);
-extern void sayForm(int instance, SayForm form);
-extern void sayInstance(int instance);
+extern void say(CONTEXT, int instance);
+extern void sayForm(CONTEXT, int instance, SayForm form);
+extern void sayInstance(CONTEXT, int instance);
extern bool hasDescription(int instance);
extern bool isDescribable(int instance);
-extern void describeAnything(int instance);
-extern void describeInstances(void);
-extern bool describe(int instance);
+extern void describeAnything(CONTEXT, int instance);
+extern void describeInstances(CONTEXT);
+extern bool describe(CONTEXT, int instance);
extern int where(int instance, ATrans trans);
extern int positionOf(int instance);
@@ -95,7 +96,7 @@ extern bool isNear(int instance, int other, ATrans trans);
extern bool isOpaque(int container);
-extern void locate(int instance, int whr);
+extern void locate(CONTEXT, int instance, int whr);
} // End of namespace Alan3
} // End of namespace Glk
diff --git a/engines/glk/alan3/inter.cpp b/engines/glk/alan3/inter.cpp
index 22198546f2..002a580e4c 100644
--- a/engines/glk/alan3/inter.cpp
+++ b/engines/glk/alan3/inter.cpp
@@ -346,10 +346,10 @@ static void tracePointerTopValue() {
}
/*----------------------------------------------------------------------*/
-static void traceInstanceTopValue() {
+static void traceInstanceTopValue(CONTEXT) {
if (traceInstructionOption) {
printf("\t=%ld ('", (long)top(stack));
- traceSay(top(stack));
+ CALL1(traceSay, top(stack))
printf("')");
if (traceStackOption)
printf("\n\t\t\t\t\t\t\t");
@@ -414,7 +414,7 @@ static bool stillOnSameLine(Aint line, Aint file) {
/*======================================================================*/
-void interpret(Aaddr adr) {
+void interpret(CONTEXT, Aaddr adr) {
Aaddr oldpc;
Aword i;
@@ -532,7 +532,7 @@ void interpret(Aaddr adr) {
current.sourceFile = file;
if (atNext || atBreakpoint) {
stopAtNextLine = FALSE;
- debug(TRUE, line, file);
+ CALL3(debug, TRUE, line, file)
}
}
break;
@@ -595,7 +595,7 @@ void interpret(Aaddr adr) {
case I_LOOK: {
if (traceInstructionOption)
printf("LOOK\t\t\t\t\t\t");
- look();
+ CALL0(look)
break;
}
case I_SAVE: {
@@ -636,7 +636,7 @@ void interpret(Aaddr adr) {
Aint cnt = pop(stack);
if (traceInstructionOption)
printf("LIST \t%7ld\t\t\t\t\t", (long)cnt);
- list(cnt);
+ CALL1(list, cnt)
break;
}
case I_EMPTY: {
@@ -644,7 +644,7 @@ void interpret(Aaddr adr) {
Aint whr = pop(stack);
if (traceInstructionOption)
printf("EMPTY \t%7ld, %7ld\t\t\t\t", (long)cnt, (long)whr);
- empty(cnt, whr);
+ CALL2(empty, cnt, whr)
break;
}
case I_SCHEDULE: {
@@ -844,7 +844,7 @@ void interpret(Aaddr adr) {
Aint whr = pop(stack);
if (traceInstructionOption)
printf("LOCATE \t%7ld, %7ld\t\t\t", (long)id, (long)whr);
- locate(id, whr);
+ CALL2(locate, id, whr)
break;
}
case I_WHERE: {
@@ -853,7 +853,7 @@ void interpret(Aaddr adr) {
if (traceInstructionOption)
printf("WHERE \t%7ld, %7s", (long)id, transitivityFlag((ATrans)transitivity));
push(stack, where(id, (ATrans)transitivity));
- traceInstanceTopValue();
+ CALL0(traceInstanceTopValue);
break;
}
case I_LOCATION: {
@@ -861,7 +861,7 @@ void interpret(Aaddr adr) {
if (traceInstructionOption)
printf("LOCATION \t%7ld\t\t", (long)id);
push(stack, locationOf(id));
- traceInstanceTopValue();
+ CALL0(traceInstanceTopValue)
break;
}
case I_HERE: {
@@ -927,7 +927,7 @@ void interpret(Aaddr adr) {
Aint scr = pop(stack);
if (traceInstructionOption)
printf("USE \t%7ld, %7ld\t\t\t\t", (long)act, (long)scr);
- use(act, scr);
+ CALL2(use, act, scr)
break;
}
case I_STOP: {
@@ -943,7 +943,7 @@ void interpret(Aaddr adr) {
printf("DESCRIBE \t%7ld\t\t\t", (long)id);
col = 41; /* To format it better! */
}
- describe(id);
+ CALL1(describe, id)
if (traceInstructionOption)
printf("\n\t\t\t\t\t\t");
break;
@@ -953,10 +953,12 @@ void interpret(Aaddr adr) {
Aid id = pop(stack);
if (traceInstructionOption)
printf("SAY\t%7s, %7ld\t\t\t", printForm((SayForm)form), (long)id);
- if (form == SAY_SIMPLE)
- say(id);
- else
- sayForm(id, (SayForm)form);
+ if (form == SAY_SIMPLE) {
+ CALL1(say, id)
+ } else {
+ CALL2(sayForm, id, (SayForm)form)
+ }
+
if (traceInstructionOption)
printf("\t\t\t\t\t\t\t");
break;
@@ -1400,8 +1402,8 @@ exitInterpreter:
}
/*======================================================================*/
-Aword evaluate(Aaddr adr) {
- interpret(adr);
+Aword evaluate(CONTEXT, Aaddr adr) {
+ R0CALL1(interpret, adr)
return pop(stack);
}
diff --git a/engines/glk/alan3/inter.h b/engines/glk/alan3/inter.h
index f451a06757..887a06a504 100644
--- a/engines/glk/alan3/inter.h
+++ b/engines/glk/alan3/inter.h
@@ -27,6 +27,7 @@
#include "glk/alan3/types.h"
#include "glk/alan3/stack.h"
+#include "glk/alan3/jumps.h"
namespace Glk {
namespace Alan3 {
@@ -45,8 +46,8 @@ extern bool fail;
extern void setInterpreterMock(void (*mock)(Aaddr adr));
extern void setInterpreterStack(Stack stack);
-extern void interpret(Aaddr adr);
-extern Aword evaluate(Aaddr adr);
+extern void interpret(CONTEXT, Aaddr adr);
+extern Aword evaluate(CONTEXT, Aaddr adr);
} // End of namespace Alan3
} // End of namespace Glk
diff --git a/engines/glk/alan3/location.cpp b/engines/glk/alan3/location.cpp
index 13076b4937..51c34f959d 100644
--- a/engines/glk/alan3/location.cpp
+++ b/engines/glk/alan3/location.cpp
@@ -39,51 +39,56 @@ namespace Glk {
namespace Alan3 {
/*----------------------------------------------------------------------*/
-static void traceExit(int location, int dir, const char *what) {
+static void traceExit(CONTEXT, int location, int dir, const char *what) {
printf("\n<EXIT %s[%d] from ",
(char *)pointerTo(dictionary[playerWords[currentWordIndex - 1].code].string), dir);
- traceSay(location);
+ CALL1(traceSay, location)
printf("[%d], %s:>\n", location, what);
}
/*======================================================================*/
-void go(int location, int dir) {
+void go(CONTEXT, int location, int dir) {
ExitEntry *theExit;
bool ok;
Aword oldloc;
theExit = (ExitEntry *) pointerTo(instances[location].exits);
- if (instances[location].exits != 0)
+ if (instances[location].exits != 0) {
while (!isEndOfArray(theExit)) {
if (theExit->code == (uint)dir) {
ok = TRUE;
if (theExit->checks != 0) {
if (traceSectionOption)
- traceExit(location, dir, "Checking");
- ok = !checksFailed(theExit->checks, EXECUTE_CHECK_BODY_ON_FAIL);
+ CALL3(traceExit, location, dir, "Checking")
+
+ FUNC2(checksFailed, ok, theExit->checks, EXECUTE_CHECK_BODY_ON_FAIL)
+ ok = !ok;
}
if (ok) {
oldloc = location;
if (theExit->action != 0) {
if (traceSectionOption)
- traceExit(location, dir, "Executing");
- interpret(theExit->action);
+ CALL3(traceExit, location, dir, "Executing")
+ CALL1(interpret, theExit->action)
}
/* Still at the same place? */
if (where(HERO, TRANSITIVE) == (int)oldloc) {
if (traceSectionOption)
- traceExit(location, dir, "Moving");
- locate(HERO, theExit->target);
+ CALL3(traceExit, location, dir, "Moving")
+ CALL2(locate, HERO, theExit->target)
}
return;
- } else
- error(NO_MSG);
+ } else {
+ CALL1(error, NO_MSG)
+ }
}
theExit++;
}
- error(M_NO_WAY);
+ }
+
+ CALL1(error, M_NO_WAY)
}
@@ -103,7 +108,7 @@ bool exitto(int to, int from) {
/*======================================================================*/
-void look(void) {
+void look(CONTEXT) {
uint i;
/* Set describe flag for all objects and actors */
@@ -114,13 +119,13 @@ void look(void) {
para();
setSubHeaderStyle();
- sayInstance(current.location);
+ CALL1(sayInstance, current.location)
setNormalStyle();
newline();
capitalize = TRUE;
- if (describe(current.location))
- describeInstances();
+ if (describe(context, current.location) && !context._break)
+ describeInstances(context);
}
} // End of namespace Alan3
diff --git a/engines/glk/alan3/location.h b/engines/glk/alan3/location.h
index 14cada9e4a..005f8bc0e8 100644
--- a/engines/glk/alan3/location.h
+++ b/engines/glk/alan3/location.h
@@ -24,13 +24,14 @@
#define GLK_ALAN3_LOCATION
#include "glk/alan3/types.h"
+#include "glk/alan3/jumps.h"
namespace Glk {
namespace Alan3 {
extern bool exitto(int to, int from);
-extern void go(int location, int dir);
-extern void look(void);
+extern void go(CONTEXT, int location, int dir);
+extern void look(CONTEXT);
} // End of namespace Alan3
} // End of namespace Glk
diff --git a/engines/glk/alan3/main.cpp b/engines/glk/alan3/main.cpp
index ad690c62f1..9abba883f6 100644
--- a/engines/glk/alan3/main.cpp
+++ b/engines/glk/alan3/main.cpp
@@ -79,7 +79,7 @@ static char *eventName(int event) {
/*----------------------------------------------------------------------*/
-static void runPendingEvents(void) {
+static void runPendingEvents(CONTEXT) {
int i;
resetRules();
@@ -92,11 +92,11 @@ static void runPendingEvents(void) {
if (traceSectionOption) {
printf("\n<EVENT %s[%d] (at ", eventName(eventQueue[eventQueueTop].event),
eventQueue[eventQueueTop].event);
- traceSay(current.location);
+ CALL1(traceSay, current.location)
printf(" [%d]):>\n", current.location);
}
- interpret(events[eventQueue[eventQueueTop].event].code);
- evaluateRules(rules);
+ CALL1(interpret, events[eventQueue[eventQueueTop].event].code)
+ CALL1(evaluateRules, rules)
}
for (i = 0; i < eventQueueTop; i++)
@@ -104,8 +104,6 @@ static void runPendingEvents(void) {
}
-
-
/*----------------------------------------------------------------------*\
Main program and initialisation
@@ -528,36 +526,38 @@ static void initDynamicData(void) {
/*----------------------------------------------------------------------*/
-static void runInheritedInitialize(Aint theClass) {
+static void runInheritedInitialize(CONTEXT, Aint theClass) {
if (theClass == 0) return;
- runInheritedInitialize(classes[theClass].parent);
+ CALL1(runInheritedInitialize, classes[theClass].parent)
+
if (classes[theClass].initialize)
- interpret(classes[theClass].initialize);
+ interpret(context, classes[theClass].initialize);
}
/*----------------------------------------------------------------------*/
-static void runInitialize(Aint theInstance) {
- runInheritedInitialize(instances[theInstance].parent);
+static void runInitialize(CONTEXT, Aint theInstance) {
+ CALL1(runInheritedInitialize, instances[theInstance].parent)
+
if (instances[theInstance].initialize != 0)
- interpret(instances[theInstance].initialize);
+ interpret(context, instances[theInstance].initialize);
}
/*----------------------------------------------------------------------*/
-static void initializeInstances() {
+static void initializeInstances(CONTEXT) {
uint instanceId;
/* Set initial locations */
for (instanceId = 1; instanceId <= header->instanceMax; instanceId++) {
current.instance = instanceId;
- runInitialize(instanceId);
+ CALL1(runInitialize, instanceId)
}
}
/*----------------------------------------------------------------------*/
-static void start(void) {
+static void start(CONTEXT) {
int startloc;
current.tick = 0;
@@ -565,19 +565,20 @@ static void start(void) {
current.actor = HERO;
current.score = 0;
- initializeInstances();
+ CALL0(initializeInstances)
if (traceSectionOption)
printf("\n<START:>\n");
- interpret(header->start);
+ CALL1(interpret, header->start)
para();
if (where(HERO, TRANSITIVE) == startloc) {
if (traceSectionOption)
printf("<CURRENT LOCATION:>");
- look();
+ CALL0(look)
}
- resetAndEvaluateRules(rules, header->version);
+
+ resetAndEvaluateRules(context, rules, header->version);
}
@@ -591,7 +592,7 @@ static void openFiles(void) {
/*----------------------------------------------------------------------*/
-static void init(void) {
+static void init(CONTEXT) {
int i;
/* Initialise some status */
@@ -611,25 +612,26 @@ static void init(void) {
}
/* Start the adventure */
- if (debugOption)
- debug(FALSE, 0, 0);
- else
+ if (debugOption) {
+ CALL3(debug, FALSE, 0, 0)
+ } else {
clear();
+ }
- start();
+ start(context);
}
/*----------------------------------------------------------------------*/
-static bool traceActor(int theActor) {
+static bool traceActor(CONTEXT, int theActor) {
if (traceSectionOption) {
printf("\n<ACTOR ");
- traceSay(theActor);
+ R0CALL1(traceSay, theActor)
printf("[%d]", theActor);
if (current.location != 0) {
printf(" (at ");
- traceSay(current.location);
+ R0CALL1(traceSay, current.location)
} else
printf(" (nowhere");
printf("[%d])", current.location);
@@ -655,6 +657,7 @@ static void moveActor(CONTEXT, int theActor) {
ScriptEntry *scr;
StepEntry *step;
Aint previousInstance = current.instance;
+ bool flag;
if (context._break) {
// forfeit setjmp replacement destination
@@ -682,34 +685,40 @@ static void moveActor(CONTEXT, int theActor) {
step = (StepEntry *) &step[admin[theActor].step];
/* Now execute it, maybe. First check wait count */
if (admin[theActor].waitCount > 0) { /* Wait some more ? */
- if (traceActor(theActor))
+ FUNC1(traceActor, flag, theActor)
+ if (flag)
printf(", SCRIPT %s[%ld], STEP %ld, Waiting another %ld turns>\n",
scriptName(theActor, admin[theActor].script),
(long)admin[theActor].script, (long)admin[theActor].step + 1,
(long)admin[theActor].waitCount);
+
admin[theActor].waitCount--;
break;
}
/* Then check possible expression to wait for */
if (step->exp != 0) {
- if (traceActor(theActor))
- printf(", SCRIPT %s[%ld], STEP %ld, Evaluating:>\n",
+ FUNC1(traceActor, flag, theActor)
+ if (flag)
+ printf(", SCRIPT %s[%ld], STEP %ld, Evaluating:>\n",
scriptName(theActor, admin[theActor].script),
(long)admin[theActor].script, (long)admin[theActor].step + 1);
- if (!evaluate(step->exp))
+ FUNC1(evaluate, flag, step->exp)
+ if (!flag)
break; /* Break loop, don't execute step*/
}
/* OK, so finally let him do his thing */
admin[theActor].step++; /* Increment step number before executing... */
if (!isEndOfArray(step + 1) && (step + 1)->after != 0) {
- admin[theActor].waitCount = evaluate((step + 1)->after);
+ FUNC1(evaluate, admin[theActor].waitCount, (step + 1)->after)
}
- if (traceActor(theActor))
+
+ FUNC1(traceActor, flag, theActor)
+ if (flag)
printf(", SCRIPT %s[%ld], STEP %ld, Executing:>\n",
scriptName(theActor, admin[theActor].script),
(long)admin[theActor].script,
(long)admin[theActor].step);
- interpret(step->stms);
+ CALL1(interpret, step->stms)
step++;
/* ... so that we can see if he failed or is USEing another script now */
if (fail || (admin[theActor].step != 0 && isEndOfArray(step)))
@@ -722,7 +731,8 @@ static void moveActor(CONTEXT, int theActor) {
if (isEndOfArray(scr))
syserr("Unknown actor script.");
} else {
- if (traceActor(theActor)) {
+ FUNC1(traceActor, flag, theActor)
+ if (flag) {
printf(", Idle>\n");
}
}
@@ -749,7 +759,7 @@ void run(void) {
initStateStack();
// Initialise and start the adventure
- init();
+ init(ctx);
while (!g_vm->shouldQuit()) {
if (!(ctx._break && ctx._label == "forfeit")) {
@@ -774,13 +784,15 @@ void run(void) {
ctx.clear();
} else {
if (debugOption)
- debug(FALSE, 0, 0);
+ debug(ctx, FALSE, 0, 0);
- if (stackDepth(theStack) != 0)
- syserr("Stack is not empty in main loop");
+ if (!ctx._break) {
+ if (stackDepth(theStack) != 0)
+ syserr("Stack is not empty in main loop");
- if (!current.meta)
- runPendingEvents();
+ if (!current.meta)
+ runPendingEvents(ctx);
+ }
}
recursionDepth = 0;
@@ -802,16 +814,20 @@ void run(void) {
current.tick++;
// Remove this call? Since Eval is done up there after each event...
- resetAndEvaluateRules(rules, header->version);
-
- /* Then all the other actors... */
- for (uint i = 1; i <= header->instanceMax; i++) {
- if (i != header->theHero && isAActor(i)) {
- moveActor(ctx, i);
- if (ctx._break)
- break;
-
- resetAndEvaluateRules(rules, header->version);
+ resetAndEvaluateRules(ctx, rules, header->version);
+
+ if (!ctx._break) {
+ // Then all the other actors...
+ for (uint i = 1; i <= header->instanceMax; i++) {
+ if (i != header->theHero && isAActor(i)) {
+ moveActor(ctx, i);
+ if (ctx._break)
+ break;
+
+ resetAndEvaluateRules(ctx, rules, header->version);
+ if (ctx._break)
+ break;
+ }
}
}
}
diff --git a/engines/glk/alan3/msg.cpp b/engines/glk/alan3/msg.cpp
index f748f26820..b26e78ac5e 100644
--- a/engines/glk/alan3/msg.cpp
+++ b/engines/glk/alan3/msg.cpp
@@ -34,7 +34,8 @@ MessageEntry *msgs; /* Message table pointer */
/*======================================================================*/
void printMessage(MsgKind msg) { /* IN - message number */
- interpret(msgs[msg].stms);
+ Context ctx;
+ interpret(ctx, msgs[msg].stms);
}
@@ -48,21 +49,21 @@ void setErrorHandler(void (*handler)(MsgKind msg)) { /* IN - The error message n
/*======================================================================*/
-void error(MsgKind msgno) { /* IN - The error message number */
+void error(CONTEXT, MsgKind msgno) { /* IN - The error message number */
if (errorHandler != NULL)
errorHandler(msgno);
else {
/* Print an error message and longjmp to main loop. */
if (msgno != NO_MSG)
printMessage(msgno);
- //longjmp(returnLabel, ERROR_RETURN);
+ LONG_JUMP_LABEL("return");
}
}
/*======================================================================*/
-void abortPlayerCommand(void) {
- error(NO_MSG);
+void abortPlayerCommand(CONTEXT) {
+ error(context, NO_MSG);
}
@@ -88,11 +89,12 @@ void printMessageUsing2InstanceParameters(MsgKind message, int instance1, int in
/*======================================================================*/
void printMessageWithParameters(MsgKind msg, Parameter *messageParameters) {
Parameter *savedParameters = newParameterArray();
+ Context ctx;
copyParameterArray(savedParameters, globalParameters);
copyParameterArray(globalParameters, messageParameters);
- interpret(msgs[msg].stms);
+ interpret(ctx, msgs[msg].stms);
copyParameterArray(globalParameters, savedParameters);
freeParameterArray(savedParameters);
diff --git a/engines/glk/alan3/msg.h b/engines/glk/alan3/msg.h
index 5b2f8d6912..6275c721a7 100644
--- a/engines/glk/alan3/msg.h
+++ b/engines/glk/alan3/msg.h
@@ -24,6 +24,7 @@
#define GLK_ALAN3_MSG
#include "glk/alan3/acode.h"
+#include "glk/alan3/jumps.h"
#include "glk/alan3/types.h"
#include "glk/alan3/params.h"
@@ -42,9 +43,9 @@ extern MessageEntry *msgs; /* Message table pointer */
/* FUNCTIONS */
extern void setErrorHandler(void (*handler)(MsgKind));
-extern void abortPlayerCommand(void);
-extern void error(MsgKind msg);
-extern bool confirm(MsgKind msgno);
+extern void abortPlayerCommand(CONTEXT);
+extern void error(CONTEXT, MsgKind msg);
+extern bool confirm(CONTEXT, MsgKind msgno);
extern void printMessage(MsgKind msg);
extern void printMessageWithParameters(MsgKind msg, Parameter *messageParameters);
extern void printMessageWithInstanceParameter(MsgKind message, int i);
diff --git a/engines/glk/alan3/output.cpp b/engines/glk/alan3/output.cpp
index 5f646923d4..aa699c960c 100644
--- a/engines/glk/alan3/output.cpp
+++ b/engines/glk/alan3/output.cpp
@@ -189,7 +189,7 @@ static void sayPlayerWordsForParameter(int p) {
/*----------------------------------------------------------------------*/
-static void sayParameter(int p, int form) {
+static void sayParameter(CONTEXT, int p, int form) {
int i;
for (i = 0; i <= p; i++)
@@ -201,13 +201,14 @@ static void sayParameter(int p, int form) {
/* Yes, so use them... */
sayPlayerWordsForParameter(p);
else
- sayForm(params[p].code, form);
+ CALL2(sayForm(params[p].code, form)
#else
if (globalParameters[p].useWords) {
/* Ambiguous instance referenced, so use the words he used */
sayPlayerWordsForParameter(p);
- } else
- sayForm(globalParameters[p].instance, (SayForm)form);
+ } else {
+ CALL2(sayForm, globalParameters[p].instance, (SayForm)form)
+ }
#endif
}
@@ -230,8 +231,10 @@ static void sayParameter(int p, int form) {
T = tabulation
$ = no space needed after this, and don't capitalize
_ = interpret this as a single dollar, if in doubt or conflict with other symbols
-*/
-static char *printSymbol(char str[]) { /* IN - The string starting with '$' */
+
+ str - The string starting with '$'
+ */
+static char *printSymbol(CONTEXT, char str[]) {
int advance = 2;
if (*str == '\0') printAndLog("$");
@@ -248,7 +251,7 @@ static char *printSymbol(char str[]) { /* IN - The string starting with '$' */
break;
case 'o':
space();
- sayParameter(0, 0);
+ R0CALL2(sayParameter, 0, 0)
needSpace = TRUE; /* We did print something non-white */
break;
case '+':
@@ -275,7 +278,7 @@ static char *printSymbol(char str[]) { /* IN - The string starting with '$' */
form = SAY_SIMPLE;
break;
}
- sayParameter(str[2] - '1', form);
+ R0CALL2(sayParameter, str[2] - '1', form)
needSpace = TRUE;
}
advance = 3;
@@ -290,17 +293,17 @@ static char *printSymbol(char str[]) { /* IN - The string starting with '$' */
case '8':
case '9':
space();
- sayParameter(str[1] - '1', SAY_SIMPLE);
+ R0CALL2(sayParameter, str[1] - '1', SAY_SIMPLE)
needSpace = TRUE; /* We did print something non-white */
break;
case 'l':
space();
- say(current.location);
+ R0CALL1(say, current.location)
needSpace = TRUE; /* We did print something non-white */
break;
case 'a':
space();
- say(current.actor);
+ R0CALL1(say, current.actor)
needSpace = TRUE; /* We did print something non-white */
break;
case 'v':
@@ -377,6 +380,7 @@ void output(const char *original) {
char ch;
char *str, *copy;
char *symptr;
+ Context ctx;
copy = strdup(original);
str = copy;
@@ -403,7 +407,7 @@ void output(const char *original) {
}
}
*symptr = ch; /* restore '$' */
- str = printSymbol(symptr); /* Print the symbolic reference and advance */
+ str = printSymbol(ctx, symptr); /* Print the symbolic reference and advance */
}
if (str[0] != 0) {
@@ -420,14 +424,16 @@ void output(const char *original) {
/*======================================================================*/
-bool confirm(MsgKind msgno) {
+bool confirm(CONTEXT, MsgKind msgno) {
char buf[80];
+ bool flag;
/* This is a bit of a hack since we really want to compare the input,
it could be affirmative, but for now any input is NOT! */
printMessage(msgno);
- if (!readline(buf))
+ R0FUNC2(readline, flag, buf, 80)
+ if (!flag)
return TRUE;
col = 1;
diff --git a/engines/glk/alan3/parse.cpp b/engines/glk/alan3/parse.cpp
index da9d7594f9..6618e9dde9 100644
--- a/engines/glk/alan3/parse.cpp
+++ b/engines/glk/alan3/parse.cpp
@@ -31,6 +31,7 @@
#include "glk/alan3/glkio.h"
#include "glk/alan3/instance.h"
#include "glk/alan3/inter.h"
+#include "glk/alan3/jumps.h"
#include "glk/alan3/lists.h"
#include "glk/alan3/literal.h"
#include "glk/alan3/location.h"
@@ -63,7 +64,7 @@ static void clearPronounList(Pronoun list[]) {
typedef Aint *(*ReferencesFinder)(int wordIndex);
-typedef void (*ParameterParser)(Parameter parameters[]);
+typedef void (*ParameterParser)(CONTEXT, Parameter parameters[]);
@@ -108,19 +109,21 @@ static bool endOfWords(int wordIndex) {
/*----------------------------------------------------------------------*/
-static void handleDirectionalCommand() {
+static void handleDirectionalCommand(CONTEXT) {
currentWordIndex++;
- if (!endOfWords(currentWordIndex) && !isConjunctionWord(currentWordIndex))
- error(M_WHAT);
- else
- go(current.location, dictionary[playerWords[currentWordIndex - 1].code].code);
+ if (!endOfWords(currentWordIndex) && !isConjunctionWord(currentWordIndex)) {
+ CALL1(error, M_WHAT)
+ } else {
+ CALL2(go, current.location, dictionary[playerWords[currentWordIndex - 1].code].code)
+ }
+
if (!endOfWords(currentWordIndex))
currentWordIndex++;
}
/*----------------------------------------------------------------------*/
-static void errorWhichOne(Parameter alternative[]) {
+static void errorWhichOne(CONTEXT, Parameter alternative[]) {
int p; /* Index into the list of alternatives */
ParameterArray parameters = newParameterArray();
@@ -136,11 +139,11 @@ static void errorWhichOne(Parameter alternative[]) {
addParameterToParameterArray(parameters, &alternative[p]);
printMessageWithParameters(M_WHICH_ONE_OR, parameters);
freeParameterArray(parameters);
- abortPlayerCommand(); /* Return with empty error message */
+ CALL0(abortPlayerCommand) /* Return with empty error message */
}
/*----------------------------------------------------------------------*/
-static void errorWhichPronoun(int pronounWordIndex, Parameter alternatives[]) {
+static void errorWhichPronoun(CONTEXT, int pronounWordIndex, Parameter alternatives[]) {
int p; /* Index into the list of alternatives */
Parameter *messageParameters = newParameterArray();
@@ -161,26 +164,26 @@ static void errorWhichPronoun(int pronounWordIndex, Parameter alternatives[]) {
addParameterToParameterArray(messageParameters, &alternatives[p]);
printMessageWithParameters(M_WHICH_ONE_OR, messageParameters);
freeParameterArray(messageParameters);
- abortPlayerCommand();
+ CALL0(abortPlayerCommand)
}
/*----------------------------------------------------------------------*/
-static void errorWhat(int playerWordIndex) {
+static void errorWhat(CONTEXT, int playerWordIndex) {
Parameter *messageParameters = newParameterArray();
addParameterForWord(messageParameters, playerWordIndex);
printMessageWithParameters(M_WHAT_WORD, messageParameters);
freeParameterArray(messageParameters);
- abortPlayerCommand();
+ CALL0(abortPlayerCommand)
}
/*----------------------------------------------------------------------*/
-static void errorAfterExcept(int butWordIndex) {
+static void errorAfterExcept(CONTEXT, int butWordIndex) {
Parameter *messageParameters = newParameterArray();
addParameterForWord(messageParameters, butWordIndex);
printMessageWithParameters(M_AFTER_BUT, messageParameters);
freeParameterArray(messageParameters);
- abortPlayerCommand();
+ CALL0(abortPlayerCommand)
}
/*----------------------------------------------------------------------*/
@@ -202,13 +205,13 @@ static int fakePlayerWordForAll() {
}
/*----------------------------------------------------------------------*/
-static void errorButAfterAll(int butWordIndex) {
+static void errorButAfterAll(CONTEXT, int butWordIndex) {
Parameter *messageParameters = newParameterArray();
addParameterForWord(messageParameters, butWordIndex);
addParameterForWord(messageParameters, fakePlayerWordForAll());
printMessageWithParameters(M_BUT_ALL, messageParameters);
freeParameterArray(messageParameters);
- abortPlayerCommand();
+ CALL0(abortPlayerCommand)
}
/*----------------------------------------------------------------------*/
@@ -220,7 +223,7 @@ static Aint findInstanceForNoun(int wordIndex) {
}
/*----------------------------------------------------------------------*/
-static void errorNoSuch(Parameter parameter) {
+static void errorNoSuch(CONTEXT, Parameter parameter) {
/* If there was no instance, assume the last word used is the noun,
* then find any instance with the noun he used */
@@ -232,11 +235,11 @@ static void errorNoSuch(Parameter parameter) {
clearParameterArray(globalParameters);
addParameterToParameterArray(globalParameters, &parameter);
- error(M_NO_SUCH);
+ CALL1(error, M_NO_SUCH)
}
/*----------------------------------------------------------------------*/
-static void buildAllHere(Parameter list[]) {
+static void buildAllHere(CONTEXT, Parameter list[]) {
uint instance;
bool found = FALSE;
int word = list[0].firstWord;
@@ -249,7 +252,7 @@ static void buildAllHere(Parameter list[]) {
found = TRUE;
}
if (!found)
- errorWhat(word);
+ errorWhat(context, word);
}
@@ -375,7 +378,8 @@ static void filterOutNonReachable(Parameter filteredCandidates[], bool (*reachab
*/
/*----------------------------------------------------------------------*/
-static void disambiguateCandidatesForPosition(ParameterPosition parameterPositions[], int position, Parameter candidates[]) {
+static void disambiguateCandidatesForPosition(CONTEXT, ParameterPosition parameterPositions[],
+ int position, Parameter candidates[]) {
int i;
Parameter *parameters = newParameterArray();
@@ -384,8 +388,15 @@ static void disambiguateCandidatesForPosition(ParameterPosition parameterPositio
if (candidates[i].instance != 0) { /* Already empty? */
copyParameter(&parameters[position], &candidates[i]);
// DISAMBIGUATION!!
- if (!reachable(candidates[i].instance) || !possible(current.verb, parameters, parameterPositions))
- candidates[i].instance = 0; /* Then remove this candidate from list */
+ if (!reachable(candidates[i].instance)) {
+ // Then remove this candidate from list
+ candidates[i].instance = 0;
+ } else {
+ bool flag;
+ FUNC3(possible, flag, current.verb, parameters, parameterPositions)
+ if (!flag)
+ candidates[i].instance = 0;
+ }
}
}
compressParameterArray(candidates);
@@ -409,7 +420,7 @@ static bool parseAnyAdjectives(Parameter parameters[]) {
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
/* Parse the input and note the word indices in the parameters,
matching will be done by the match* functions */
-static void parseAdjectivesAndNoun(Parameter parameters[]) {
+static void parseAdjectivesAndNoun(CONTEXT, Parameter parameters[]) {
int wordFirst, wordLast;
bool adjectiveOrNounFound = FALSE;
@@ -422,14 +433,14 @@ static void parseAdjectivesAndNoun(Parameter parameters[]) {
adjectiveOrNounFound = TRUE;
currentWordIndex++;
} else
- error(M_NOUN);
+ CALL1(error, M_NOUN)
} else if (adjectiveOrNounFound) {
/* Perhaps the last word could also be interpreted as a noun? */
if (isNounWord(currentWordIndex - 1)) {
// TODO When does this get executed? Maybe if conjunctions can be nouns? Or nouns be adjectives?
printf("DEBUG: When does this get executed? Found adjective or Noun and the previous word could also be a noun...\n");
} else
- error(M_NOUN);
+ CALL1(error, M_NOUN)
}
if (adjectiveOrNounFound) {
@@ -445,7 +456,7 @@ static void parseAdjectivesAndNoun(Parameter parameters[]) {
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
-static void parseReference(Parameter parameters[]) {
+static void parseReference(CONTEXT, Parameter parameters[]) {
clearParameterArray(parameters);
if (isLiteralWord(currentWordIndex)) {
@@ -453,7 +464,7 @@ static void parseReference(Parameter parameters[]) {
} else if (isPronounWord(currentWordIndex)) {
parsePronoun(parameters);
} else {
- parseAdjectivesAndNoun(parameters);
+ CALL1(parseAdjectivesAndNoun, parameters)
}
}
@@ -484,7 +495,7 @@ static void parseReferenceToPreviousMultipleParameters(Parameter parameters[]) {
/*----------------------------------------------------------------------*/
-static bool parseOneParameter(Parameter parameters[], int parameterIndex) {
+static bool parseOneParameter(CONTEXT, Parameter parameters[], int parameterIndex) {
Parameter *parameter = newParameterArray();
// TODO Maybe this should go in the complex()?
@@ -494,7 +505,7 @@ static bool parseOneParameter(Parameter parameters[], int parameterIndex) {
// are previous multiple parameters we give precedence to those
parseReferenceToPreviousMultipleParameters(parameter);
} else {
- parseReference(parameter);
+ R0CALL1(parseReference, parameter)
if (lengthOfParameterArray(parameter) == 0) { /* Failed to find any exceptions! */
freeParameterArray(parameter);
return FALSE;
@@ -528,13 +539,14 @@ static bool parseOneParameter(Parameter parameters[], int parameterIndex) {
*/
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
-static void simpleParameterParser(Parameter parameters[]) {
+static void simpleParameterParser(CONTEXT, Parameter parameters[]) {
+ bool flag;
/* This will loop until all references are collected (typically "a and b and c") */
int parameterIndex;
for (parameterIndex = 0;; parameterIndex++) {
-
- if (!parseOneParameter(parameters, parameterIndex))
+ FUNC2(parseOneParameter, flag, parameters, parameterIndex)
+ if (!flag)
return;
if (!endOfWords(currentWordIndex)
@@ -551,13 +563,14 @@ static void simpleParameterParser(Parameter parameters[]) {
/*----------------------------------------------------------------------*/
-static void parseExceptions(ParameterPosition *parameterPosition, ParameterParser simpleParameterParser) {
+static void parseExceptions(CONTEXT, ParameterPosition *parameterPosition, ParameterParser simpleParameterParser) {
int exceptWordIndex = currentWordIndex;
currentWordIndex++;
parameterPosition->exceptions = ensureParameterArrayAllocated(parameterPosition->exceptions);
- simpleParameterParser(parameterPosition->exceptions);
+ CALL1(simpleParameterParser, parameterPosition->exceptions)
+
if (lengthOfParameterArray(parameterPosition->exceptions) == 0)
- errorAfterExcept(exceptWordIndex);
+ errorAfterExcept(context, exceptWordIndex);
}
@@ -572,7 +585,8 @@ static void parseExceptions(ParameterPosition *parameterPosition, ParameterParse
*/
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
-static void complexParameterParserDelegate(ParameterPosition *parameterPosition, ParameterParser simpleParameterParser) {
+static void complexParameterParserDelegate(CONTEXT, ParameterPosition *parameterPosition,
+ ParameterParser simpleParameterParser) {
parameterPosition->parameters = ensureParameterArrayAllocated(parameterPosition->parameters);
parameterPosition->all = FALSE;
@@ -588,9 +602,9 @@ static void complexParameterParserDelegate(ParameterPosition *parameterPosition,
parameterPosition->parameters[0].instance = 0;
setEndOfArray(&parameterPosition->parameters[1]);
if (!endOfWords(currentWordIndex) && isExceptWord(currentWordIndex))
- parseExceptions(parameterPosition, simpleParameterParser);
+ CALL2(parseExceptions, parameterPosition, simpleParameterParser)
} else {
- simpleParameterParser(parameterPosition->parameters);
+ CALL1(simpleParameterParser, parameterPosition->parameters)
if (lengthOfParameterArray(parameterPosition->parameters) > 1)
parameterPosition->explicitMultiple = TRUE;
}
@@ -598,8 +612,8 @@ static void complexParameterParserDelegate(ParameterPosition *parameterPosition,
}
/*----------------------------------------------------------------------*/
-static void complexReferencesParser(ParameterPosition *parameterPosition) {
- complexParameterParserDelegate(parameterPosition, simpleParameterParser);
+static void complexReferencesParser(CONTEXT, ParameterPosition *parameterPosition) {
+ complexParameterParserDelegate(context, parameterPosition, simpleParameterParser);
}
@@ -653,12 +667,13 @@ static bool restrictionCheck(RestrictionEntry *restriction, int instance) {
/*----------------------------------------------------------------------*/
-static void runRestriction(RestrictionEntry *restriction, Parameter parameters[]) {
+static void runRestriction(CONTEXT, RestrictionEntry *restriction, Parameter parameters[]) {
if (restriction->stms) {
setGlobalParameters(parameters);
- interpret(restriction->stms);
- } else
- error(M_CANT0);
+ interpret(context, restriction->stms);
+ } else {
+ error(context, M_CANT0);
+ }
}
@@ -722,15 +737,16 @@ static bool multipleAllowed(Aword flags) {
*/
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
-static void parseParameterPosition(ParameterPosition *parameterPosition, Aword flags, void (*complexReferencesParser)(ParameterPosition *parameterPosition)) {
+static void parseParameterPosition(CONTEXT, ParameterPosition *parameterPosition,
+ Aword flags, void (*complexReferencesParser)(CONTEXT, ParameterPosition *parameterPosition)) {
parameterPosition->parameters = ensureParameterArrayAllocated(parameterPosition->parameters);
- complexReferencesParser(parameterPosition);
+ CALL1(complexReferencesParser, parameterPosition)
if (lengthOfParameterArray(parameterPosition->parameters) == 0) /* No object!? */
- error(M_WHAT);
+ CALL1(error, M_WHAT)
if (parameterPosition->explicitMultiple && !multipleAllowed(flags))
- error(M_MULTIPLE);
+ CALL1(error, M_MULTIPLE)
}
/*----------------------------------------------------------------------*/
@@ -776,7 +792,7 @@ static bool endOfPlayerCommand(int wordIndex) {
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
-static ElementEntry *parseInputAccordingToSyntax(SyntaxEntry *syntax, ParameterPosition parameterPositions[]) {
+static ElementEntry *parseInputAccordingToSyntax(CONTEXT, SyntaxEntry *syntax, ParameterPosition parameterPositions[]) {
ElementEntry *currentElement = elementTreeOf(syntax);
ElementEntry *nextElement = currentElement;
@@ -798,7 +814,8 @@ static ElementEntry *parseInputAccordingToSyntax(SyntaxEntry *syntax, ParameterP
// Create parameter structure for the parameter position based on player words
// but without resolving them
ParameterPosition *parameterPosition = &parameterPositions[parameterCount];
- parseParameterPosition(parameterPosition, nextElement->flags, complexReferencesParser);
+ R0CALL3(parseParameterPosition, parameterPosition, nextElement->flags, complexReferencesParser)
+
parameterPosition->flags = nextElement->flags;
parameterPosition->endOfList = FALSE;
@@ -821,7 +838,7 @@ static ElementEntry *parseInputAccordingToSyntax(SyntaxEntry *syntax, ParameterP
/* Anything else is an error, but we'll handle 'but' specially here */
if (isExceptWord(currentWordIndex))
- errorButAfterAll(currentWordIndex);
+ R0CALL1(errorButAfterAll, currentWordIndex)
/* If we get here we couldn't match anything... */
nextElement = NULL;
@@ -853,7 +870,7 @@ static bool anyAll(ParameterPosition parameterPositions[]) {
/*----------------------------------------------------------------------*/
-static void checkRestrictedParameters(ParameterPosition parameterPositions[], ElementEntry elms[]) {
+static void checkRestrictedParameters(CONTEXT, ParameterPosition parameterPositions[], ElementEntry elms[]) {
RestrictionEntry *restriction;
static Parameter *localParameters = NULL;
int i;
@@ -880,7 +897,7 @@ static void checkRestrictedParameters(ParameterPosition parameterPositions[], El
sprintf(marker, "($%ld)", (unsigned long) restriction->parameterNumber);
setGlobalParameters(localParameters);
output(marker);
- runRestriction(restriction, localParameters);
+ CALL2(runRestriction, restriction, localParameters)
para();
}
parameterPosition->parameters[i].instance = 0; /* In any case remove it from the list */
@@ -888,8 +905,8 @@ static void checkRestrictedParameters(ParameterPosition parameterPositions[], El
}
} else {
if (!restrictionCheck(restriction, parameterPosition->parameters[0].instance)) {
- runRestriction(restriction, localParameters);
- abortPlayerCommand();
+ CALL2(runRestriction, restriction, localParameters)
+ CALL0(abortPlayerCommand)
}
}
parameterPositions[restriction->parameterNumber - 1].checked = TRUE;
@@ -900,19 +917,19 @@ static void checkRestrictedParameters(ParameterPosition parameterPositions[], El
/*----------------------------------------------------------------------*/
-static void impossibleWith(ParameterPosition parameterPositions[], int positionIndex) {
+static void impossibleWith(CONTEXT, ParameterPosition parameterPositions[], int positionIndex) {
if (isPreBeta2(header->version)) {
- error(M_CANT0);
+ error(context, M_CANT0);
} else {
printMessageWithInstanceParameter(M_IMPOSSIBLE_WITH, parameterPositions[positionIndex].parameters[0].instance);
- error(NO_MSG);
+ error(context, NO_MSG);
}
}
/*----------------------------------------------------------------------*/
-static void checkNonRestrictedParameters(ParameterPosition parameterPositions[]) {
+static void checkNonRestrictedParameters(CONTEXT, ParameterPosition parameterPositions[]) {
int positionIndex;
for (positionIndex = 0; !parameterPositions[positionIndex].endOfList; positionIndex++)
if (!parameterPositions[positionIndex].checked) {
@@ -924,16 +941,17 @@ static void checkNonRestrictedParameters(ParameterPosition parameterPositions[])
if (!isAObject(parameterPositions[positionIndex].parameters[i].instance))
parameterPositions[positionIndex].parameters[i].instance = 0;
} else if (!isAObject(parameterPositions[positionIndex].parameters[0].instance))
- impossibleWith(parameterPositions, positionIndex);
+ impossibleWith(context, parameterPositions, positionIndex);
}
}
/*----------------------------------------------------------------------*/
-static void restrictParametersAccordingToSyntax(ParameterPosition parameterPositions[], ElementEntry *elms) {
+static void restrictParametersAccordingToSyntax(CONTEXT, ParameterPosition parameterPositions[], ElementEntry *elms) {
uncheckAllParameterPositions(parameterPositions);
- checkRestrictedParameters(parameterPositions, elms);
- checkNonRestrictedParameters(parameterPositions);
+ CALL2(checkRestrictedParameters, parameterPositions, elms)
+ CALL1(checkNonRestrictedParameters, parameterPositions)
+
int positionIndex;
for (positionIndex = 0; !parameterPositions[positionIndex].endOfList; positionIndex++)
compressParameterArray(parameterPositions[positionIndex].parameters);
@@ -941,16 +959,16 @@ static void restrictParametersAccordingToSyntax(ParameterPosition parameterPosit
/*----------------------------------------------------------------------*/
-static void matchPronoun(Parameter *parameter) {
+static void matchPronoun(CONTEXT, Parameter *parameter) {
static Parameter *pronounInstances = NULL;
pronounInstances = ensureParameterArrayAllocated(pronounInstances);
int pronounCandidateCount = getPronounInstances(playerWords[parameter->firstWord].code, pronounInstances);
- if (pronounCandidateCount == 0)
- errorWhat(parameter->firstWord);
- else if (pronounCandidateCount > 1)
- errorWhichPronoun(parameter->firstWord, pronounInstances);
- else {
+ if (pronounCandidateCount == 0) {
+ CALL1(errorWhat, parameter->firstWord)
+ } else if (pronounCandidateCount > 1) {
+ CALL2(errorWhichPronoun, parameter->firstWord, pronounInstances)
+ } else {
parameter->candidates[0] = pronounInstances[0];
setEndOfArray(&parameter->candidates[1]);
}
@@ -968,7 +986,7 @@ static void matchNounPhrase(Parameter *parameter, ReferencesFinder adjectiveRefe
/*----------------------------------------------------------------------*/
-static void instanceMatcher(Parameter *parameter) {
+static void instanceMatcher(CONTEXT, Parameter *parameter) {
Parameter *candidates = parameter->candidates;
int i;
@@ -976,7 +994,7 @@ static void instanceMatcher(Parameter *parameter) {
candidates[0].instance = instanceFromLiteral(playerWords[parameter->firstWord].code - dictionarySize);
setEndOfArray(&candidates[1]);
} else if (parameter->isPronoun) {
- matchPronoun(parameter);
+ CALL1(matchPronoun, parameter)
} else
matchNounPhrase(parameter, adjectiveReferencesForWord, nounReferencesForWord);
@@ -991,24 +1009,25 @@ static void instanceMatcher(Parameter *parameter) {
/*----------------------------------------------------------------------*/
-static void findCandidates(Parameter parameters[], void (*instanceMatcher)(Parameter *parameter)) {
+static void findCandidates(CONTEXT, Parameter parameters[], void (*instanceMatcher)(CONTEXT, Parameter *parameter)) {
int i;
for (i = 0; i < lengthOfParameterArray(parameters); i++) {
parameters[i].candidates = ensureParameterArrayAllocated(parameters[i].candidates);
- instanceMatcher(&parameters[i]);
+ CALL1(instanceMatcher, &parameters[i])
+
parameters[i].candidates[0].isPronoun = parameters[i].isPronoun;
}
}
/*----------------------------------------------------------------------*/
-static void handleFailedParse(ElementEntry *elms) {
+static void handleFailedParse(CONTEXT, ElementEntry *elms) {
if (elms == NULL)
- error(M_WHAT);
- if (elms->next == 0) { /* No verb code, verb not declared! */
+ error(context, M_WHAT);
+ else if (elms->next == 0) { /* No verb code, verb not declared! */
/* TODO Does this ever happen? */
- error(M_CANT0);
+ error(context, M_CANT0);
}
}
@@ -1025,13 +1044,14 @@ static void convertMultipleCandidatesToMultipleParameters(ParameterPosition para
/*----------------------------------------------------------------------*/
-static ElementEntry *parseInput(ParameterPosition *parameterPositions) {
+static ElementEntry *parseInput(CONTEXT, ParameterPosition *parameterPositions) {
ElementEntry *element;
SyntaxEntry *stx;
- stx = findSyntaxTreeForVerb(verbWordCode);
- element = parseInputAccordingToSyntax(stx, parameterPositions);
- handleFailedParse(element);
+ R0FUNC1(findSyntaxTreeForVerb, stx, verbWordCode)
+ R0FUNC2(parseInputAccordingToSyntax, element, stx, parameterPositions)
+ R0CALL1(handleFailedParse, element)
+
current.syntax = element->flags;
current.verb = remapParameterOrder(current.syntax, parameterPositions);
return element;
@@ -1039,7 +1059,7 @@ static ElementEntry *parseInput(ParameterPosition *parameterPositions) {
/*----------------------------------------------------------------------*/
-static void findCandidatesForPlayerWords(ParameterPosition *parameterPosition) {
+static void findCandidatesForPlayerWords(CONTEXT, ParameterPosition *parameterPosition) {
ParameterArray parameters = parameterPosition->parameters;
if (!parameterArrayIsEmpty(parameters)) {
@@ -1047,36 +1067,39 @@ static void findCandidatesForPlayerWords(ParameterPosition *parameterPosition) {
parameterPosition->them = TRUE;
getPreviousMultipleParameters(parameters);
if (lengthOfParameterArray(parameters) == 0)
- errorWhat(parameters[0].firstWord);
+ CALL1(errorWhat, parameters[0].firstWord)
if (lengthOfParameterArray(parameters) > 1)
parameterPosition->explicitMultiple = TRUE;
} else if (parameterPosition->all) {
- buildAllHere(parameters);
+ CALL1(buildAllHere, parameters)
if (!parameterArrayIsEmpty(parameterPosition->exceptions))
- findCandidates(parameterPosition->exceptions, instanceMatcher);
+ CALL2(findCandidates, parameterPosition->exceptions, instanceMatcher)
} else
- findCandidates(parameters, instanceMatcher);
+ CALL2(findCandidates, parameters, instanceMatcher)
}
}
/*----------------------------------------------------------------------*/
-static void handleMultiplePosition(ParameterPosition parameterPositions[]) {
+static void handleMultiplePosition(CONTEXT, ParameterPosition parameterPositions[]) {
int multiplePosition = findMultipleParameterPosition(parameterPositions);
if (anyAll(parameterPositions)) {
/* If the player used ALL, try to find out what was applicable */
- disambiguateCandidatesForPosition(parameterPositions, multiplePosition, parameterPositions[multiplePosition].parameters);
+ CALL3(disambiguateCandidatesForPosition, parameterPositions, multiplePosition,
+ parameterPositions[multiplePosition].parameters)
+
if (lengthOfParameterArray(parameterPositions[multiplePosition].parameters) == 0)
- errorWhat(parameterPositions[multiplePosition].parameters[0].firstWord);
+ CALL1(errorWhat, parameterPositions[multiplePosition].parameters[0].firstWord)
+
subtractParameterArrays(parameterPositions[multiplePosition].parameters, parameterPositions[multiplePosition].exceptions);
if (lengthOfParameterArray(parameterPositions[multiplePosition].parameters) == 0)
- error(M_NOT_MUCH);
+ CALL1(error, M_NOT_MUCH)
} else if (anyExplicitMultiple(parameterPositions)) {
compressParameterArray(parameterPositions[multiplePosition].parameters);
if (lengthOfParameterArray(parameterPositions[multiplePosition].parameters) == 0) {
/* If there where multiple parameters but non left, exit without a */
/* word, assuming we have already said enough */
- abortPlayerCommand();
+ CALL0(abortPlayerCommand)
}
}
}
@@ -1115,81 +1138,89 @@ static void handleMultiplePosition(ParameterPosition parameterPositions[]) {
*/
-typedef Parameter *DisambiguationHandler(Parameter allCandidates[], Parameter presentCandidates[]);
+typedef Parameter *DisambiguationHandler(CONTEXT, Parameter allCandidates[], Parameter presentCandidates[]);
typedef DisambiguationHandler *DisambiguationHandlerTable[3][3][2];
-static Parameter *disambiguate00N(Parameter allCandidates[], Parameter presentCandidates[]) {
+static Parameter *disambiguate00N(CONTEXT, Parameter allCandidates[], Parameter presentCandidates[]) {
if (allCandidates[0].isPronoun)
- errorWhat(allCandidates[0].firstWord);
+ R0CALL1(errorWhat, allCandidates[0].firstWord)
else
- errorNoSuch(allCandidates[0]);
+ R0CALL1(errorNoSuch, allCandidates[0]);
return NULL;
}
-static Parameter *disambiguate01N(Parameter allCandidates[], Parameter presentCandidates[]) {
+
+static Parameter *disambiguate01N(CONTEXT, Parameter allCandidates[], Parameter presentCandidates[]) {
if (allCandidates[0].isPronoun)
- errorWhat(allCandidates[0].firstWord);
+ R0CALL1(errorWhat, allCandidates[0].firstWord)
else
- errorNoSuch(allCandidates[0]);
+ R0CALL1(errorNoSuch, allCandidates[0])
return NULL;
}
-static Parameter *disambiguate0MN(Parameter allCandidates[], Parameter presentCandidates[]) {
+
+static Parameter *disambiguate0MN(CONTEXT, Parameter allCandidates[], Parameter presentCandidates[]) {
if (allCandidates[0].isPronoun)
- errorWhat(allCandidates[0].firstWord);
+ R0CALL1(errorWhat, allCandidates[0].firstWord)
else
- errorNoSuch(allCandidates[0]);
+ R0CALL1(errorNoSuch, allCandidates[0])
return NULL;
}
-static Parameter *disambiguate10N(Parameter allCandidates[], Parameter presentCandidates[]) {
+
+static Parameter *disambiguate10N(CONTEXT, Parameter allCandidates[], Parameter presentCandidates[]) {
return presentCandidates;
}
-static Parameter *disambiguate11N(Parameter allCandidates[], Parameter presentCandidates[]) {
+
+static Parameter *disambiguate11N(CONTEXT, Parameter allCandidates[], Parameter presentCandidates[]) {
return presentCandidates;
}
-static Parameter *disambiguate1MN(Parameter allCandidates[], Parameter presentCandidates[]) {
+
+static Parameter *disambiguate1MN(CONTEXT, Parameter allCandidates[], Parameter presentCandidates[]) {
return presentCandidates;
}
-static Parameter *disambiguateM0N(Parameter allCandidates[], Parameter presentCandidates[]) {
- errorWhichOne(presentCandidates);
+static Parameter *disambiguateM0N(CONTEXT, Parameter allCandidates[], Parameter presentCandidates[]) {
+ R0CALL1(errorWhichOne, presentCandidates)
return NULL;
}
-static Parameter *disambiguateM1N(Parameter allCandidates[], Parameter presentCandidates[]) {
- errorWhichOne(presentCandidates);
+
+static Parameter *disambiguateM1N(CONTEXT, Parameter allCandidates[], Parameter presentCandidates[]) {
+ R0CALL1(errorWhichOne, presentCandidates)
return NULL;
}
-static Parameter *disambiguateMMN(Parameter allCandidates[], Parameter presentCandidates[]) {
- errorWhichOne(presentCandidates);
+
+static Parameter *disambiguateMMN(CONTEXT, Parameter allCandidates[], Parameter presentCandidates[]) {
+ R0CALL1(errorWhichOne, presentCandidates)
return NULL;
}
-static Parameter *disambiguate00Y(Parameter allCandidates[], Parameter presentCandidates[]) {
- errorNoSuch(allCandidates[0]);
+
+static Parameter *disambiguate00Y(CONTEXT, Parameter allCandidates[], Parameter presentCandidates[]) {
+ errorNoSuch(context, allCandidates[0]);
return NULL;
}
-static Parameter *disambiguate01Y(Parameter allCandidates[], Parameter presentCandidates[]) {
+static Parameter *disambiguate01Y(CONTEXT, Parameter allCandidates[], Parameter presentCandidates[]) {
return allCandidates;
}
-static Parameter *disambiguate0MY(Parameter allCandidates[], Parameter presentCandidates[]) {
- errorWhichOne(allCandidates);
+static Parameter *disambiguate0MY(CONTEXT, Parameter allCandidates[], Parameter presentCandidates[]) {
+ R0CALL1(errorWhichOne, allCandidates)
return NULL;
}
-static Parameter *disambiguate10Y(Parameter allCandidates[], Parameter presentCandidates[]) {
+static Parameter *disambiguate10Y(CONTEXT, Parameter allCandidates[], Parameter presentCandidates[]) {
return presentCandidates;
}
-static Parameter *disambiguate11Y(Parameter allCandidates[], Parameter presentCandidates[]) {
+static Parameter *disambiguate11Y(CONTEXT, Parameter allCandidates[], Parameter presentCandidates[]) {
return presentCandidates;
}
-static Parameter *disambiguate1MY(Parameter allCandidates[], Parameter presentCandidates[]) {
+static Parameter *disambiguate1MY(CONTEXT, Parameter allCandidates[], Parameter presentCandidates[]) {
return presentCandidates;
}
-static Parameter *disambiguateM0Y(Parameter allCandidates[], Parameter presentCandidates[]) {
- errorWhichOne(presentCandidates);
+static Parameter *disambiguateM0Y(CONTEXT, Parameter allCandidates[], Parameter presentCandidates[]) {
+ R0CALL1(errorWhichOne, presentCandidates)
return NULL;
}
-static Parameter *disambiguateM1Y(Parameter allCandidates[], Parameter presentCandidates[]) {
- errorWhichOne(presentCandidates);
+static Parameter *disambiguateM1Y(CONTEXT, Parameter allCandidates[], Parameter presentCandidates[]) {
+ R0CALL1(errorWhichOne, presentCandidates)
return NULL;
}
-static Parameter *disambiguateMMY(Parameter allCandidates[], Parameter presentCandidates[]) {
- errorWhichOne(presentCandidates);
+static Parameter *disambiguateMMY(CONTEXT, Parameter allCandidates[], Parameter presentCandidates[]) {
+ R0CALL1(errorWhichOne, presentCandidates)
return NULL;
}
@@ -1242,7 +1273,7 @@ static DisambiguationHandlerTable disambiguationHandlerTable = {
};
/*----------------------------------------------------------------------*/
-static void disambiguateCandidates(Parameter *allCandidates, bool omnipotent, bool (*reachable)(int), DisambiguationHandlerTable handler) {
+static void disambiguateCandidates(CONTEXT, Parameter *allCandidates, bool omnipotent, bool (*reachable)(int), DisambiguationHandlerTable handler) {
static Parameter *presentCandidates = NULL;
int present;
int distant;
@@ -1259,7 +1290,7 @@ static void disambiguateCandidates(Parameter *allCandidates, bool omnipotent, bo
distant = lengthOfParameterArray(allCandidates) - present;
if (distant > 1) distant = 2; /* 2 = M */
- result = handler[present][distant][omnipotent](allCandidates, presentCandidates);
+ FUNC2(handler[present][distant][omnipotent], result, allCandidates, presentCandidates)
// If we returned then it's ok, use the single candidate found
allCandidates[0] = result[0];
@@ -1268,13 +1299,13 @@ static void disambiguateCandidates(Parameter *allCandidates, bool omnipotent, bo
/*----------------------------------------------------------------------*/
-static void disambiguate(ParameterPosition parameterPositions[], ElementEntry *element) {
+static void disambiguate(CONTEXT, ParameterPosition parameterPositions[], ElementEntry *element) {
/* The New Strategy! Parsing has only collected word indications,
not built anything, so we need to match parameters to instances here */
int position;
for (position = 0; !parameterPositions[position].endOfList; position++) {
- findCandidatesForPlayerWords(&parameterPositions[position]);
+ CALL1(findCandidatesForPlayerWords, &parameterPositions[position])
}
/* Now we have candidates for everything the player said, except
@@ -1291,7 +1322,8 @@ static void disambiguate(ParameterPosition parameterPositions[], ElementEntry *e
for (p = 0; p < lengthOfParameterArray(parameters); p++) {
Parameter *parameter = &parameters[p];
Parameter *candidates = parameter->candidates;
- disambiguateCandidates(candidates, omni, reachable, disambiguationHandlerTable);
+ CALL4(disambiguateCandidates, candidates, omni, reachable, disambiguationHandlerTable)
+
parameter->instance = candidates[0].instance;
}
}
@@ -1301,21 +1333,22 @@ static void disambiguate(ParameterPosition parameterPositions[], ElementEntry *e
for (p = 0; p < lengthOfParameterArray(exceptions); p++) {
Parameter *parameter = &exceptions[p];
Parameter *candidates = parameter->candidates;
- disambiguateCandidates(candidates, omni, reachable, disambiguationHandlerTable);
+ CALL4(disambiguateCandidates, candidates, omni, reachable, disambiguationHandlerTable)
+
parameter->instance = candidates[0].instance;
}
}
}
- handleMultiplePosition(parameterPositions);
+ CALL1(handleMultiplePosition, parameterPositions)
/* Now perform restriction checks */
- restrictParametersAccordingToSyntax(parameterPositions, element);
+ CALL2(restrictParametersAccordingToSyntax, parameterPositions, element)
}
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
-static void tryParam(Parameter parameters[], Parameter multipleParameters[]) {
+static void tryParam(CONTEXT, Parameter parameters[], Parameter multipleParameters[]) {
ElementEntry *element; /* Pointer to element list */
static ParameterPosition *parameterPositions = NULL;
if (parameterPositions != NULL)
@@ -1325,9 +1358,8 @@ static void tryParam(Parameter parameters[], Parameter multipleParameters[]) {
parameterPositions = (ParameterPosition *)allocate(sizeof(ParameterPosition) * (MAXPARAMS + 1));
parameterPositions[0].endOfList = TRUE;
- element = parseInput(parameterPositions);
-
- disambiguate(parameterPositions, element);
+ FUNC1(parseInput, element, parameterPositions)
+ CALL2(disambiguate, parameterPositions, element)
// TODO: Now we need to convert back to legacy parameter and multipleParameter format
convertPositionsToParameters(parameterPositions, parameters);
@@ -1340,15 +1372,16 @@ static void tryParam(Parameter parameters[], Parameter multipleParameters[]) {
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
-static void parseOneCommand(Parameter parameters[], Parameter multipleParameters[]) {
- tryParam(parameters, multipleParameters); /* ... to understand what he said */
+static void parseOneCommand(CONTEXT, Parameter parameters[], Parameter multipleParameters[]) {
+ // ... to understand what he said
+ CALL2(tryParam, parameters, multipleParameters)
/* More on this line? */
if (!endOfWords(currentWordIndex)) {
if (isConjunctionWord(currentWordIndex))
currentWordIndex++; /* If so skip the conjunction */
else
- error(M_WHAT);
+ error(context, M_WHAT);
}
}
@@ -1410,27 +1443,27 @@ static void notePronounsForParameters(Parameter parameters[]) {
/*----------------------------------------------------------------------*/
-static void parseVerbCommand(Parameter parameters[], Parameter multipleParameters[]) {
+static void parseVerbCommand(CONTEXT, Parameter parameters[], Parameter multipleParameters[]) {
verbWord = playerWords[currentWordIndex].code;
verbWordCode = dictionary[verbWord].code;
if (isPreBeta2(header->version))
/* Pre-beta2 didn't generate syntax elements for verb words,
need to skip first word which should be the verb */
currentWordIndex++;
- parseOneCommand(parameters, multipleParameters);
+ CALL2(parseOneCommand, parameters, multipleParameters)
notePronounsForParameters(parameters);
fail = FALSE;
}
/*----------------------------------------------------------------------*/
-static void parseInstanceCommand(Parameter parameters[], Parameter multipleParameters[]) {
+static void parseInstanceCommand(CONTEXT, Parameter parameters[], Parameter multipleParameters[]) {
/* Pick up the parse tree for the syntaxes that start with an
instance reference and parse according to that. The
verbWord code is set to 0 to indicate that it is not a verb
but an instance that starts the command. */
verbWordCode = 0;
- parseOneCommand(parameters, multipleParameters);
+ CALL2(parseOneCommand, parameters, multipleParameters)
notePronounsForParameters(parameters);
fail = FALSE;
}
@@ -1455,19 +1488,20 @@ void parse(CONTEXT) {
firstWord = currentWordIndex;
if (isVerbWord(currentWordIndex)) {
- parseVerbCommand(parameters, multipleParameters);
- action(current.verb, parameters, multipleParameters);
+ CALL2(parseVerbCommand, parameters, multipleParameters);
+ CALL3(action, current.verb, parameters, multipleParameters)
} else if (isDirectionWord(currentWordIndex)) {
clearParameterArray(previousMultipleParameters);
clearPronounList(pronouns);
- handleDirectionalCommand();
+ CALL0(handleDirectionalCommand)
} else if (isInstanceReferenceWord(currentWordIndex)) {
- parseInstanceCommand(parameters, multipleParameters);
- action(current.verb, parameters, multipleParameters);
+ CALL2(parseInstanceCommand, parameters, multipleParameters)
+ CALL3(action, current.verb, parameters, multipleParameters)
} else
- error(M_WHAT);
+ CALL1(error, M_WHAT)
- if (fail) error(NO_MSG);
+ if (fail)
+ CALL1(error, NO_MSG)
lastWord = currentWordIndex - 1;
if (isConjunctionWord(lastWord))
diff --git a/engines/glk/alan3/readline.cpp b/engines/glk/alan3/readline.cpp
index 34e9e645c6..832f00d87e 100644
--- a/engines/glk/alan3/readline.cpp
+++ b/engines/glk/alan3/readline.cpp
@@ -48,14 +48,14 @@ namespace Alan3 {
*/
/* TODO - length of user buffer should be used */
-bool readline(char buffer[]) {
+bool readline(CONTEXT, char *buffer, size_t maxLen) {
event_t event;
static bool readingCommands = FALSE;
static frefid_t commandFileRef;
static strid_t commandFile;
if (readingCommands) {
- if (g_vm->glk_get_line_stream(commandFile, buffer, 255) == 0) {
+ if (g_vm->glk_get_line_stream(commandFile, buffer, maxLen) == 0) {
g_vm->glk_stream_close(commandFile, NULL);
readingCommands = FALSE;
} else {
@@ -64,18 +64,16 @@ bool readline(char buffer[]) {
g_vm->glk_set_style(style_Normal);
}
} else {
- g_vm->glk_request_line_event(glkMainWin, buffer, 255, 0);
- /* FIXME: buffer size should be infallible: all existing calls use 256 or
- 80 character buffers, except parse which uses LISTLEN (currently 100)
- */
+ g_vm->glk_request_line_event(glkMainWin, buffer, maxLen, 0);
+
do {
g_vm->glk_select(&event);
if (g_vm->shouldQuit())
- return FALSE;
+ LONG_JUMP0
switch (event.type) {
case evtype_Arrange:
- statusline();
+ R0CALL0(statusline)
break;
default:
@@ -87,7 +85,7 @@ bool readline(char buffer[]) {
commandFileRef = g_vm->glk_fileref_create_by_name(fileusage_InputRecord + fileusage_TextMode, &buffer[1], 0);
commandFile = g_vm->glk_stream_open_file(commandFileRef, filemode_Read, 0);
if (commandFile != NULL)
- if (g_vm->glk_get_line_stream(commandFile, buffer, 255) != 0) {
+ if (g_vm->glk_get_line_stream(commandFile, buffer, maxLen) != 0) {
readingCommands = TRUE;
g_vm->glk_set_style(style_Input);
printf(buffer);
diff --git a/engines/glk/alan3/readline.h b/engines/glk/alan3/readline.h
index 3ab217c057..624bf4a69d 100644
--- a/engines/glk/alan3/readline.h
+++ b/engines/glk/alan3/readline.h
@@ -26,13 +26,14 @@
/* Header file for user input, history and editing support */
#include "glk/alan3/types.h"
+#include "glk/alan3/jumps.h"
namespace Glk {
namespace Alan3 {
#define HISTORYLENGTH 20
-extern bool readline(char usrbuf[]);
+extern bool readline(CONTEXT, char *usrBuf, size_t maxLen);
} // End of namespace Alan3
} // End of namespace Glk
diff --git a/engines/glk/alan3/rules.cpp b/engines/glk/alan3/rules.cpp
index b589168fa9..2adc819400 100644
--- a/engines/glk/alan3/rules.cpp
+++ b/engines/glk/alan3/rules.cpp
@@ -87,11 +87,11 @@ void initRules(Aaddr ruleTableAddress) {
/*----------------------------------------------------------------------*/
-static void traceRuleStart(int rule, const char *what) {
+static void traceRuleStart(CONTEXT, int rule, const char *what) {
printf("\n<RULE %d", rule);
if (current.location != 0) {
printf(" (at ");
- traceSay(current.location);
+ CALL1(traceSay, current.location)
} else
printf(" (nowhere");
printf("[%d]), %s", current.location, what);
@@ -103,14 +103,14 @@ static bool detailedTraceOn() {
/*----------------------------------------------------------------------*/
-static void traceRuleEvaluation(int rule) {
+static void traceRuleEvaluation(CONTEXT, int rule) {
if (traceSectionOption) {
if (detailedTraceOn()) {
- traceRuleStart(rule, "Evaluating:>");
+ CALL2(traceRuleStart, rule, "Evaluating:>")
if (!traceInstructionOption)
printf("\n");
} else {
- traceRuleStart(rule, "Evaluating to ");
+ CALL2(traceRuleStart, rule, "Evaluating to ")
}
}
}
@@ -126,12 +126,12 @@ static void traceRuleResult(int rule, bool result) {
}
/*----------------------------------------------------------------------*/
-static void traceRuleExecution(int rule) {
+static void traceRuleExecution(CONTEXT, int rule) {
if (traceSectionOption) {
if (!traceInstructionOption && !traceSourceOption)
printf(", Executing:>\n");
else {
- traceRuleStart(rule, "Executing:>");
+ CALL2(traceRuleStart, rule, "Executing:>")
if (!traceInstructionOption)
printf("\n");
}
@@ -141,8 +141,9 @@ static void traceRuleExecution(int rule) {
/*----------------------------------------------------------------------*/
-static void evaluateRulesPreBeta2(void) {
+static void evaluateRulesPreBeta2(CONTEXT) {
bool change = TRUE;
+ bool flag;
int i;
for (i = 1; !isEndOfArray(&rules[i - 1]); i++)
@@ -152,12 +153,13 @@ static void evaluateRulesPreBeta2(void) {
change = FALSE;
for (i = 1; !isEndOfArray(&rules[i - 1]); i++)
if (!rules[i - 1].alreadyRun) {
- traceRuleEvaluation(i);
- if (evaluate(rules[i - 1].exp)) {
+ CALL1(traceRuleEvaluation, i)
+ FUNC1(evaluate, flag, rules[i - 1].exp)
+ if (flag) {
change = TRUE;
rules[i - 1].alreadyRun = TRUE;
- traceRuleExecution(i);
- interpret(rules[i - 1].stms);
+ CALL1(traceRuleExecution, i)
+ CALL1(interpret, rules[i - 1].stms)
} else if (traceSectionOption && !traceInstructionOption)
printf(":>\n");
}
@@ -168,8 +170,9 @@ static void evaluateRulesPreBeta2(void) {
/*----------------------------------------------------------------------*/
/* This is how beta2 thought rules should be evaluated:
*/
-static void evaluateRulesBeta2(void) {
+static void evaluateRulesBeta2(CONTEXT) {
bool change = TRUE;
+ bool triggered;
int i;
for (i = 1; !isEndOfArray(&rules[i - 1]); i++)
@@ -182,14 +185,15 @@ static void evaluateRulesBeta2(void) {
change = FALSE;
for (i = 1; !isEndOfArray(&rules[i - 1]); i++)
if (!rules[i - 1].alreadyRun) {
- traceRuleEvaluation(i);
- bool triggered = evaluate(rules[i - 1].exp);
+ CALL1(traceRuleEvaluation, i)
+ FUNC1(evaluate, triggered, rules[i - 1].exp)
+
if (triggered) {
if (rulesAdmin[i - 1].lastEval == false) {
change = TRUE;
rules[i - 1].alreadyRun = TRUE;
- traceRuleExecution(i);
- interpret(rules[i - 1].stms);
+ CALL1(traceRuleExecution, i)
+ CALL1(interpret, rules[i - 1].stms)
}
rulesAdmin[i - 1].lastEval = triggered;
} else {
@@ -212,8 +216,9 @@ void resetRules() {
/*======================================================================*/
-void evaluateRules(RuleEntry ruleList[]) {
+void evaluateRules(CONTEXT, RuleEntry ruleList[]) {
bool change = TRUE;
+ bool evaluated_value;
int rule;
current.location = NOWHERE;
@@ -222,14 +227,15 @@ void evaluateRules(RuleEntry ruleList[]) {
while (change) {
change = FALSE;
for (rule = 1; !isEndOfArray(&ruleList[rule - 1]); rule++) {
- traceRuleEvaluation(rule);
- bool evaluated_value = evaluate(ruleList[rule - 1].exp);
+ CALL1(traceRuleEvaluation, rule)
+ FUNC1(evaluate, evaluated_value, ruleList[rule - 1].exp)
traceRuleResult(rule, evaluated_value);
+
if (evaluated_value == true && rulesAdmin[rule - 1].lastEval == false
&& !rulesAdmin[rule - 1].alreadyRun) {
change = TRUE;
- traceRuleExecution(rule);
- interpret(ruleList[rule - 1].stms);
+ CALL1(traceRuleExecution, rule)
+ CALL1(interpret, ruleList[rule - 1].stms)
rulesAdmin[rule - 1].alreadyRun = TRUE;
anyRuleRun = TRUE;
} else {
@@ -243,14 +249,14 @@ void evaluateRules(RuleEntry ruleList[]) {
/*=======================================================================*/
-void resetAndEvaluateRules(RuleEntry ruleList[], const byte *version) {
+void resetAndEvaluateRules(CONTEXT, RuleEntry ruleList[], const byte *version) {
if (isPreBeta2(version))
- evaluateRulesPreBeta2();
+ evaluateRulesPreBeta2(context);
else if (isPreBeta3(version))
- evaluateRulesBeta2();
+ evaluateRulesBeta2(context);
else {
resetRules();
- evaluateRules(ruleList);
+ evaluateRules(context, ruleList);
}
}
diff --git a/engines/glk/alan3/rules.h b/engines/glk/alan3/rules.h
index 65291a0a70..abb5a2b065 100644
--- a/engines/glk/alan3/rules.h
+++ b/engines/glk/alan3/rules.h
@@ -25,6 +25,7 @@
/* Header file for rules handler in Alan interpreter */
+#include "glk/alan3/jumps.h"
#include "glk/alan3/acode.h"
namespace Glk {
@@ -36,9 +37,9 @@ extern bool anyRuleRun; /* Did any rule run? */
/* FUNCTIONS */
extern void initRules(Aaddr rulesTableAddress);
-extern void resetAndEvaluateRules(RuleEntry rules[], const byte *version);
+extern void resetAndEvaluateRules(CONTEXT, RuleEntry rules[], const byte *version);
extern void resetRules(void);
-extern void evaluateRules(RuleEntry rules[]);
+extern void evaluateRules(CONTEXT, RuleEntry rules[]);
} // End of namespace Alan3
} // End of namespace Glk
diff --git a/engines/glk/alan3/save.cpp b/engines/glk/alan3/save.cpp
index 0d33ea6959..935d08f7bd 100644
--- a/engines/glk/alan3/save.cpp
+++ b/engines/glk/alan3/save.cpp
@@ -214,57 +214,62 @@ static void restoreCurrentValues(Common::SeekableReadStream *saveFile) {
/*----------------------------------------------------------------------*/
-static void verifyGameId(Common::SeekableReadStream *saveFile) {
+static void verifyGameId(CONTEXT, Common::SeekableReadStream *saveFile) {
Aword savedUid = saveFile->readUint32LE();
if (!ignoreErrorOption && savedUid != header->uid)
- error(M_SAVEVERS);
+ error(context, M_SAVEVERS);
}
/*----------------------------------------------------------------------*/
-static void verifyGameName(Common::SeekableReadStream *saveFile) {
+static void verifyGameName(CONTEXT, Common::SeekableReadStream *saveFile) {
char savedName[256];
int i = 0;
while ((savedName[i++] = saveFile->readByte()) != '\0');
if (strcmp(savedName, adventureName) != 0)
- error(M_SAVENAME);
+ error(context, M_SAVENAME);
}
/*----------------------------------------------------------------------*/
-static void verifyCompilerVersion(Common::SeekableReadStream *saveFile) {
+static void verifyCompilerVersion(CONTEXT, Common::SeekableReadStream *saveFile) {
char savedVersion[4];
saveFile->read(&savedVersion, 4);
if (!ignoreErrorOption && memcmp(savedVersion, header->version, 4))
- error(M_SAVEVERS);
+ error(context, M_SAVEVERS);
}
/*----------------------------------------------------------------------*/
-static void verifySaveFile(Common::SeekableReadStream *saveFile) {
+static void verifySaveFile(CONTEXT, Common::SeekableReadStream *saveFile) {
char string[5];
saveFile->read(string, 4);
string[4] = '\0';
if (strcmp(string, "ASAV") != 0)
- error(M_NOTASAVEFILE);
+ error(context, M_NOTASAVEFILE);
}
/*----------------------------------------------------------------------*/
-void restoreGame(Common::SeekableReadStream *saveFile) {
- verifySaveFile(saveFile);
+bool restoreGame(Common::SeekableReadStream *saveFile) {
+ Context ctx;
+ verifySaveFile(ctx, saveFile);
+ if (ctx._break) return false;
- /* Verify version of compiler/interpreter of saved game with us */
- verifyCompilerVersion(saveFile);
+ // Verify version of compiler/interpreter of saved game with us
+ verifyCompilerVersion(ctx, saveFile);
+ if (ctx._break) return false;
- /* Verify name of game */
- verifyGameName(saveFile);
+ // Verify name of game
+ verifyGameName(ctx, saveFile);
+ if (ctx._break) return false;
- /* Verify unique id of game */
- verifyGameId(saveFile);
+ // Verify unique id of game
+ verifyGameId(ctx, saveFile);
+ if (ctx._break) return false;
restoreCurrentValues(saveFile);
restoreAttributeArea(saveFile);
@@ -273,6 +278,8 @@ void restoreGame(Common::SeekableReadStream *saveFile) {
restoreScores(saveFile);
restoreStrings(saveFile);
restoreSets(saveFile);
+
+ return true;
}
} // End of namespace Alan3
diff --git a/engines/glk/alan3/save.h b/engines/glk/alan3/save.h
index e4b00f6746..dbcf2908e2 100644
--- a/engines/glk/alan3/save.h
+++ b/engines/glk/alan3/save.h
@@ -29,7 +29,7 @@ namespace Glk {
namespace Alan3 {
extern void saveGame(Common::WriteStream *saveFile);
-extern void restoreGame(Common::SeekableReadStream *saveFile);
+extern bool restoreGame(Common::SeekableReadStream *saveFile);
} // End of namespace Alan3
} // End of namespace Glk
diff --git a/engines/glk/alan3/scan.cpp b/engines/glk/alan3/scan.cpp
index 6785b2a11b..6d1e7d408d 100644
--- a/engines/glk/alan3/scan.cpp
+++ b/engines/glk/alan3/scan.cpp
@@ -59,7 +59,7 @@ void forceNewPlayerInput() {
/*----------------------------------------------------------------------*/
-static void unknown(char tok[]) {
+static void unknown(CONTEXT, char tok[]) {
char *str = strdup(tok);
Parameter *messageParameters = newParameterArray();
@@ -67,7 +67,7 @@ static void unknown(char tok[]) {
printMessageWithParameters(M_UNKNOWN_WORD, messageParameters);
deallocate(messageParameters);
free(str);
- abortPlayerCommand();
+ CALL0(abortPlayerCommand)
}
@@ -81,7 +81,7 @@ static int number(char tok[]) {
/*----------------------------------------------------------------------*/
-static int lookup(char wrd[]) {
+static int lookup(CONTEXT, char wrd[]) {
int i;
for (i = 0; !isEndOfArray(&dictionary[i]); i++) {
@@ -89,7 +89,7 @@ static int lookup(char wrd[]) {
return (i);
}
}
- unknown(wrd);
+ R0CALL1(unknown, wrd)
return (int)EOD;
}
@@ -137,22 +137,21 @@ static char *gettoken(char *txtBuf) {
static void getLine(CONTEXT) {
para();
do {
- statusline();
+ CALL0(statusline)
+
if (header->prompt) {
anyOutput = FALSE;
- interpret(header->prompt);
+ CALL1(interpret, header->prompt)
+
if (anyOutput)
printAndLog(" ");
needSpace = FALSE;
} else
printAndLog("> ");
- if (!readline(buf)) {
- if (g_vm->shouldQuit()) {
- context._break = true;
- return;
- }
-
+ bool flag;
+ FUNC2(readline, flag, buf, 255);
+ if (!flag) {
newline();
quitGame();
}
@@ -175,12 +174,13 @@ static void getLine(CONTEXT) {
if (token != NULL) {
if (strcmp("debug", token) == 0 && header->debug) {
debugOption = TRUE;
- debug(FALSE, 0, 0);
+ CALL3(debug, FALSE, 0, 0)
+
token = NULL;
} else if (strcmp("undo", token) == 0) {
token = gettoken(NULL);
if (token != NULL) /* More tokens? */
- error(M_WHAT);
+ CALL1(error, M_WHAT)
undo();
}
}
@@ -215,7 +215,7 @@ void scan(CONTEXT) {
playerWords[i].start = token;
playerWords[i].end = strchr(token, '\0');
if (isISOLetter(token[0])) {
- w = lookup(token);
+ FUNC1(lookup, w, token);
if (!isNoise(w))
playerWords[i++].code = w;
} else if (isdigit((int)token[0]) || token[0] == '\"') {
@@ -236,7 +236,7 @@ void scan(CONTEXT) {
eol = TRUE;
break;
} else
- unknown(token);
+ CALL1(unknown, token)
setEndOfArray(&playerWords[i]);
eol = (token = gettoken(NULL)) == NULL;
} while (!eol);
diff --git a/engines/glk/alan3/syntax.cpp b/engines/glk/alan3/syntax.cpp
index 940c1ffe6e..a3c44c6bb0 100644
--- a/engines/glk/alan3/syntax.cpp
+++ b/engines/glk/alan3/syntax.cpp
@@ -69,7 +69,7 @@ static SyntaxEntry *findSyntaxEntry(int verbCode) {
/*======================================================================*/
-SyntaxEntry *findSyntaxTreeForVerb(int verbCode) {
+SyntaxEntry *findSyntaxTreeForVerb(CONTEXT, int verbCode) {
SyntaxEntry *foundStx = NULL;
if (isPreBeta2(header->version)) {
foundStx = findSyntaxEntryForPreBeta2(verbCode, foundStx);
@@ -77,8 +77,8 @@ SyntaxEntry *findSyntaxTreeForVerb(int verbCode) {
foundStx = findSyntaxEntry(verbCode);
}
if (foundStx == NULL)
- /* No matching syntax */
- error(M_WHAT);
+ // No matching syntax
+ R0CALL1(error, M_WHAT)
return foundStx;
}
diff --git a/engines/glk/alan3/syntax.h b/engines/glk/alan3/syntax.h
index de7e48423b..8aebc23e80 100644
--- a/engines/glk/alan3/syntax.h
+++ b/engines/glk/alan3/syntax.h
@@ -24,6 +24,7 @@
#define GLK_ALAN3_SYNTAX
#include "glk/alan3/types.h"
+#include "glk/alan3/jumps.h"
#include "glk/alan3/memory.h"
namespace Glk {
@@ -36,7 +37,7 @@ extern SyntaxEntry *stxs; /* Syntax table pointer */
/* FUNCTIONS */
extern ElementEntry *elementTreeOf(SyntaxEntry *stx);
extern char *parameterNameInSyntax(int syntaxNumber, int parameterNumber);
-extern SyntaxEntry *findSyntaxTreeForVerb(int verbCode);
+extern SyntaxEntry *findSyntaxTreeForVerb(CONTEXT, int verbCode);
} // End of namespace Alan3
} // End of namespace Glk
diff --git a/engines/glk/alan3/term.cpp b/engines/glk/alan3/term.cpp
index 86c6036cf6..37f709e377 100644
--- a/engines/glk/alan3/term.cpp
+++ b/engines/glk/alan3/term.cpp
@@ -48,7 +48,7 @@ void getPageSize(void) {
}
/*======================================================================*/
-void statusline(void) {
+void statusline(CONTEXT) {
uint32 glkWidth;
char line[100];
int pcol = col;
@@ -64,7 +64,7 @@ void statusline(void) {
onStatusLine = TRUE;
col = 1;
g_vm->glk_window_move_cursor(glkStatusWin, 1, 0);
- sayInstance(where(HERO, /*TRUE*/ TRANSITIVE));
+ CALL1(sayInstance, where(HERO, /*TRUE*/ TRANSITIVE))
// TODO Add status message1 & 2 as author customizable messages
if (header->maximumScore > 0)
diff --git a/engines/glk/alan3/term.h b/engines/glk/alan3/term.h
index df19a63610..1f6dadc6b6 100644
--- a/engines/glk/alan3/term.h
+++ b/engines/glk/alan3/term.h
@@ -25,6 +25,8 @@
/* Header file for terminal functions in ARUN, the Alan interpreter */
+#include "glk/alan3/jumps.h"
+
namespace Glk {
namespace Alan3 {
@@ -33,7 +35,7 @@ extern bool onStatusLine;
/* FUNCTIONS */
extern void getPageSize();
-extern void statusline();
+extern void statusline(CONTEXT);
} // End of namespace Alan3
} // End of namespace Glk