mirror of
https://github.com/krgamestudios/Toy.git
synced 2026-04-15 14:54:07 +10:00
Fixed indexing in argument lists, resolved #102
This commit is contained in:
@@ -1,13 +1,12 @@
|
|||||||
fn doA() {
|
import standard;
|
||||||
print "doA()";
|
var array = [42];
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
fn doB() {
|
var result = null;
|
||||||
print "doB()";
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (doA() || doB()) {
|
//problematic line
|
||||||
print "success";
|
result = max(0, array[0]);
|
||||||
}
|
|
||||||
|
assert result == 42, "Indexing in argument list failed";
|
||||||
|
|
||||||
|
|
||||||
|
print "All good";
|
||||||
|
|||||||
@@ -649,7 +649,7 @@ static Toy_Opcode Toy_writeCompilerWithJumps(Toy_Compiler* compiler, Toy_ASTNode
|
|||||||
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
|
//sub-calls
|
||||||
if (node->fnCall.arguments->fnCollection.nodes[i].type != TOY_AST_NODE_LITERAL) {
|
if (node->fnCall.arguments->fnCollection.nodes[i].type != TOY_AST_NODE_LITERAL) {
|
||||||
Toy_Opcode override = Toy_writeCompilerWithJumps(compiler, &node->fnCall.arguments->fnCollection.nodes[i], breakAddressesPtr, continueAddressesPtr, jumpOffsets, rootNode);
|
Toy_Opcode override = Toy_writeCompilerWithJumps(compiler, &node->fnCall.arguments->fnCollection.nodes[i], breakAddressesPtr, continueAddressesPtr, jumpOffsets, node); //BUGFIX: use node as rootNode, to allow indexing within argument lists
|
||||||
if (override != TOY_OP_EOF) {//compensate for indexing & dot notation being screwy
|
if (override != TOY_OP_EOF) {//compensate for indexing & dot notation being screwy
|
||||||
compiler->bytecode[compiler->count++] = (unsigned char)override; //1 byte
|
compiler->bytecode[compiler->count++] = (unsigned char)override; //1 byte
|
||||||
}
|
}
|
||||||
|
|||||||
20
test/scripts/indexing-in-argument-list-bugfix.toy
Normal file
20
test/scripts/indexing-in-argument-list-bugfix.toy
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
fn max(lhs, rhs) {
|
||||||
|
if (lhs > rhs) {
|
||||||
|
return lhs;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return rhs;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var array = [42];
|
||||||
|
|
||||||
|
var result = null;
|
||||||
|
|
||||||
|
//problematic line
|
||||||
|
result = max(0, array[0]);
|
||||||
|
|
||||||
|
assert result == 42, "Indexing in argument list failed";
|
||||||
|
|
||||||
|
|
||||||
|
print "All good";
|
||||||
@@ -129,6 +129,7 @@ int main() {
|
|||||||
"index-assignment-left-bugfix.toy",
|
"index-assignment-left-bugfix.toy",
|
||||||
"index-dictionaries.toy",
|
"index-dictionaries.toy",
|
||||||
"index-strings.toy",
|
"index-strings.toy",
|
||||||
|
"indexing-in-argument-list-bugfix.toy",
|
||||||
"jumps.toy",
|
"jumps.toy",
|
||||||
"jumps-in-functions.toy",
|
"jumps-in-functions.toy",
|
||||||
"logicals.toy",
|
"logicals.toy",
|
||||||
|
|||||||
Reference in New Issue
Block a user