diff --git a/scripts/small.toy b/scripts/small.toy index f80b992..e69de29 100644 --- a/scripts/small.toy +++ b/scripts/small.toy @@ -1,56 +0,0 @@ - - -fn _b(self) { - print "running _b"; - print self; - return self; -} - -fn _c(self) { - print "running _c"; - print self; - return self; -} - -fn _d(self) { - print "running _d"; - print self; - return self; -} - -fn _e(self) { - print "running _e"; - print self; - return self; -} - -fn _f(self) { - print "running _f"; - print self; - return self; -} - - -fn b() { - print "running b"; -} - -fn c() { - print "running c"; -} - -fn d() { - print "running d"; -} - -fn e() { - print "running e"; -} - -fn f() { - print "running f"; -} - -var a = 42; - -print a.b().c().d().e().f(); \ No newline at end of file diff --git a/scripts/test/dottify-bugfix.toy b/scripts/test/dottify-bugfix.toy new file mode 100644 index 0000000..94b0b81 --- /dev/null +++ b/scripts/test/dottify-bugfix.toy @@ -0,0 +1,9 @@ + +fn _add(self, inc) { + return self + inc; +} + +assert 1.add(2).add(3).add(4) == 10, "dottify bugfix failed"; + + +print "All good"; diff --git a/source/parser.c b/source/parser.c index ad98533..fd47d3c 100644 --- a/source/parser.c +++ b/source/parser.c @@ -798,12 +798,6 @@ static Opcode dot(Parser* parser, ASTNode** nodeHandle) { return OP_EOF; } - //hijack the function call, and hack in an extra parameter - 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 } @@ -1090,6 +1084,7 @@ static void dottify(Parser* parser, ASTNode** nodeHandle) { if ((*nodeHandle)->type == AST_NODEBINARY) { if ((*nodeHandle)->binary.opcode == OP_FN_CALL) { (*nodeHandle)->binary.opcode = OP_DOT; + (*nodeHandle)->binary.right->fnCall.argumentCount++; } dottify(parser, &(*nodeHandle)->binary.left); dottify(parser, &(*nodeHandle)->binary.right); diff --git a/test/test_interpreter.c b/test/test_interpreter.c index 9d2f613..e482599 100644 --- a/test/test_interpreter.c +++ b/test/test_interpreter.c @@ -184,6 +184,7 @@ int main() { "dot-and-matrix.toy", "dot-assignments-bugfix.toy", "dot-chaining.toy", + "dottify-bugfix.toy", "functions.toy", "imports-and-exports.toy", "index-arrays.toy",