calls within parameter lists

This commit is contained in:
2022-08-26 13:03:18 +01:00
parent 7bd67765aa
commit 151f681954
2 changed files with 19 additions and 0 deletions

View File

@@ -405,6 +405,12 @@ static void writeCompilerWithJumps(Compiler* compiler, Node* node, void* breakAd
//NOTE: assume the function definition/name is above us //NOTE: assume the function definition/name is above us
for (int i = 0; i < node->fnCall.arguments->fnCollection.count; i++) { //reverse order, to count from the beginning in the interpreter for (int i = 0; i < node->fnCall.arguments->fnCollection.count; i++) { //reverse order, to count from the beginning in the interpreter
//sub-calls
if (node->fnCall.arguments->fnCollection.nodes[i].type != NODE_LITERAL) {
writeCompilerWithJumps(compiler, &node->fnCall.arguments->fnCollection.nodes[i], breakAddressesPtr, continueAddressesPtr);
continue;
}
//write each argument to the bytecode //write each argument to the bytecode
int argumentsIndex = findLiteralIndex(&compiler->literalCache, node->fnCall.arguments->fnCollection.nodes[i].atomic.literal); int argumentsIndex = findLiteralIndex(&compiler->literalCache, node->fnCall.arguments->fnCollection.nodes[i].atomic.literal);
if (argumentsIndex < 0) { if (argumentsIndex < 0) {

View File

@@ -29,4 +29,17 @@ var tally = make();
assert tally() == 1 && tally() == 2, "Closures failed"; assert tally() == 1 && tally() == 2, "Closures failed";
//expressions as arguments
fn argFn() {
return 42;
}
fn outerFn(val) {
assert val == 42, "expression as argument failed";
}
outerFn(argFn());
print "All good"; print "All good";