mirror of
https://github.com/krgamestudios/Toy.git
synced 2026-04-15 23:04:08 +10:00
Added dot chaining for functions
Well, it should work without issues...
This commit is contained in:
@@ -799,8 +799,10 @@ static Opcode dot(Parser* parser, ASTNode** nodeHandle) {
|
||||
}
|
||||
|
||||
//hijack the function call, and hack in an extra parameter
|
||||
node->binary.right->fnCall.argumentCount++;
|
||||
node->binary.opcode = OP_DOT;
|
||||
if (node->binary.opcode == OP_FN_CALL) {
|
||||
node->binary.right->fnCall.argumentCount++;
|
||||
node->binary.opcode = OP_DOT;
|
||||
}
|
||||
|
||||
(*nodeHandle) = node;
|
||||
return OP_DOT; //signal that the function name and arguments are in the wrong order
|
||||
@@ -1083,6 +1085,17 @@ static bool calcStaticBinaryArithmetic(Parser* parser, ASTNode** nodeHandle) {
|
||||
return true;
|
||||
}
|
||||
|
||||
static void dottify(Parser* parser, ASTNode** nodeHandle) {
|
||||
//only if this is chained from a higher binary "fn_call"
|
||||
if ((*nodeHandle)->type == AST_NODEBINARY) {
|
||||
if ((*nodeHandle)->binary.opcode == OP_FN_CALL) {
|
||||
(*nodeHandle)->binary.opcode = OP_DOT;
|
||||
}
|
||||
dottify(parser, &(*nodeHandle)->binary.left);
|
||||
dottify(parser, &(*nodeHandle)->binary.right);
|
||||
}
|
||||
}
|
||||
|
||||
static void parsePrecedence(Parser* parser, ASTNode** nodeHandle, PrecedenceRule rule) {
|
||||
//every valid expression has a prefix rule
|
||||
advance(parser);
|
||||
@@ -1116,6 +1129,11 @@ static void parsePrecedence(Parser* parser, ASTNode** nodeHandle, PrecedenceRule
|
||||
return; //we're done here
|
||||
}
|
||||
|
||||
//BUGFIX: dot-chaining
|
||||
if (opcode == OP_DOT) {
|
||||
dottify(parser, &rhsNode);
|
||||
}
|
||||
|
||||
emitASTNodeBinary(nodeHandle, rhsNode, opcode);
|
||||
|
||||
if (!calcStaticBinaryArithmetic(parser, nodeHandle)) {
|
||||
|
||||
Reference in New Issue
Block a user