|
@@ -198,11 +198,12 @@ static void cCallFunction(const char* literal) {
|
|
|
cAddInt(0);
|
|
|
int arguments = cCallFunctionArguments();
|
|
|
int address = fmSearchAddress(&functions, literal, arguments);
|
|
|
+ cAddOperation(OP_GOSUB);
|
|
|
if(address == -1) {
|
|
|
- cError("unknown function on line %d", line);
|
|
|
+ fmEnqueue(&functions, literal, arguments, line, cReserveInt());
|
|
|
+ } else {
|
|
|
+ cAddInt(address);
|
|
|
}
|
|
|
- cAddOperation(OP_GOSUB);
|
|
|
- cAddInt(address);
|
|
|
cAddInt(arguments);
|
|
|
cConsumeToken(T_SEMICOLON);
|
|
|
}
|
|
@@ -314,6 +315,16 @@ static void cForEachLine() {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+static void cLinkQueuedFunctions() {
|
|
|
+ for(int i = 0; i < functions.queueEntries; i++) {
|
|
|
+ int address = fmSearchAddress(&functions, functions.queue[i].name, functions.queue[i].arguments);
|
|
|
+ if(address == -1) {
|
|
|
+ cError("unknown function on line %d", functions.queue[i].line);
|
|
|
+ }
|
|
|
+ cSetInt(functions.queue[i].reserved, address);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
static void cAllocAndCompile() {
|
|
|
varIndex = 0;
|
|
|
returnIndex = 0;
|
|
@@ -324,6 +335,7 @@ static void cAllocAndCompile() {
|
|
|
int p = cAddPush(0);
|
|
|
cForEachLine();
|
|
|
cAddPop(p, vars[varIndex].entries);
|
|
|
+ cLinkQueuedFunctions();
|
|
|
}
|
|
|
fmDelete(&functions);
|
|
|
simDelete(vars + 1);
|