mirror of
https://github.com/krgamestudios/Toy.git
synced 2026-04-15 23:04:08 +10:00
Functions take a set number of arguments
This commit is contained in:
@@ -750,8 +750,10 @@ static bool execFnCall(Interpreter* interpreter) {
|
||||
LiteralArray arguments;
|
||||
initLiteralArray(&arguments);
|
||||
|
||||
//unpack the arguments
|
||||
while (interpreter->stack.count > 1) {
|
||||
Literal stackSize = popLiteralArray(&interpreter->stack);
|
||||
|
||||
//unpack the stack of arguments
|
||||
for (int i = 0; i < AS_INTEGER(stackSize); i++) {
|
||||
pushLiteralArray(&arguments, popLiteralArray(&interpreter->stack)); //NOTE: also reverses the order
|
||||
}
|
||||
|
||||
@@ -780,6 +782,19 @@ static bool execFnCall(Interpreter* interpreter) {
|
||||
LiteralArray* paramArray = AS_ARRAY(inner.literalCache.literals[ readShort(inner.bytecode, &inner.count) ]);
|
||||
LiteralArray* returnArray = AS_ARRAY(inner.literalCache.literals[ readShort(inner.bytecode, &inner.count) ]);
|
||||
|
||||
//check the param total is correct
|
||||
if (paramArray->count != arguments.count * 2) {
|
||||
printf(ERROR "ERROR: Incorrect number of arguments passed to function \"\n");
|
||||
printLiteral(identifier);
|
||||
printf("\"\n" RESET);
|
||||
|
||||
//free, and skip out
|
||||
freeLiteralArray(&arguments);
|
||||
freeInterpreter(&inner);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int i = 0; i < paramArray->count; i += 2) { //contents is the indexes of identifier & type
|
||||
//declare and define each entry in the scope
|
||||
if (!declareScopeVariable(inner.scope, paramArray->literals[i], paramArray->literals[i + 1])) {
|
||||
|
||||
Reference in New Issue
Block a user