diff --git a/source/compiler.c b/source/compiler.c index dd5bbb7..ac0fd9f 100644 --- a/source/compiler.c +++ b/source/compiler.c @@ -405,6 +405,12 @@ static void writeCompilerWithJumps(Compiler* compiler, Node* node, void* breakAd //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 + //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 int argumentsIndex = findLiteralIndex(&compiler->literalCache, node->fnCall.arguments->fnCollection.nodes[i].atomic.literal); if (argumentsIndex < 0) { diff --git a/test/functions.toy b/test/functions.toy index 24be460..8a1ee05 100644 --- a/test/functions.toy +++ b/test/functions.toy @@ -29,4 +29,17 @@ var tally = make(); 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"; \ No newline at end of file