mirror of
https://github.com/krgamestudios/Toy.git
synced 2026-04-15 23:04:08 +10:00
calls within parameter lists
This commit is contained in:
@@ -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) {
|
||||||
|
|||||||
@@ -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";
|
||||||
Reference in New Issue
Block a user