From 151f6819543e8f149ffa996293bf235ea90e4afd Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Fri, 26 Aug 2022 13:03:18 +0100 Subject: [PATCH] calls within parameter lists --- source/compiler.c | 6 ++++++ test/functions.toy | 13 +++++++++++++ 2 files changed, 19 insertions(+) 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