mirror of
https://github.com/krgamestudios/Toy.git
synced 2026-04-15 23:04:08 +10:00
Fixed chained functions, resolved #52
This commit is contained in:
@@ -1229,12 +1229,8 @@ static bool execFnCall(Toy_Interpreter* interpreter, bool looseFirstArgument) {
|
|||||||
|
|
||||||
//get the function literal
|
//get the function literal
|
||||||
Toy_Literal func = identifier;
|
Toy_Literal func = identifier;
|
||||||
|
if (!TOY_IS_FUNCTION(func) && Toy_parseIdentifierToValue(interpreter, &func)) {
|
||||||
if (!Toy_parseIdentifierToValue(interpreter, &func)) {
|
|
||||||
Toy_freeLiteralArray(&arguments);
|
|
||||||
Toy_freeLiteral(stackSize);
|
|
||||||
Toy_freeLiteral(identifier);
|
Toy_freeLiteral(identifier);
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!TOY_IS_FUNCTION(func) && !TOY_IS_FUNCTION_NATIVE(func)) {
|
if (!TOY_IS_FUNCTION(func) && !TOY_IS_FUNCTION_NATIVE(func)) {
|
||||||
@@ -1271,7 +1267,6 @@ static bool execFnCall(Toy_Interpreter* interpreter, bool looseFirstArgument) {
|
|||||||
Toy_freeLiteralArray(&arguments);
|
Toy_freeLiteralArray(&arguments);
|
||||||
Toy_freeLiteral(func);
|
Toy_freeLiteral(func);
|
||||||
Toy_freeLiteral(stackSize);
|
Toy_freeLiteral(stackSize);
|
||||||
Toy_freeLiteral(identifier);
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|||||||
30
test/scripts/function-within-function-bugfix.toy
Normal file
30
test/scripts/function-within-function-bugfix.toy
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
{
|
||||||
|
fn a() {
|
||||||
|
fn b() {
|
||||||
|
return 42;
|
||||||
|
}
|
||||||
|
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
|
||||||
|
assert a()() == 42, "function within function failed";
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
fn a() {
|
||||||
|
fn b() {
|
||||||
|
fn c() {
|
||||||
|
return 42;
|
||||||
|
}
|
||||||
|
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
|
||||||
|
assert a()()() == 42, "function within function within function failed";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
print "All good";
|
||||||
@@ -117,6 +117,7 @@ int main() {
|
|||||||
"dot-chaining.toy",
|
"dot-chaining.toy",
|
||||||
"dot-modulo-bugfix.toy",
|
"dot-modulo-bugfix.toy",
|
||||||
"dottify-bugfix.toy",
|
"dottify-bugfix.toy",
|
||||||
|
"function-within-function-bugfix.toy",
|
||||||
"functions.toy",
|
"functions.toy",
|
||||||
"index-arrays.toy",
|
"index-arrays.toy",
|
||||||
"index-assignment-both-bugfix.toy",
|
"index-assignment-both-bugfix.toy",
|
||||||
|
|||||||
Reference in New Issue
Block a user