BREAKING CHANGE: changed method parsing to allow for a->b()->c()...
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Sat, 3 Sep 2022 04:39:28 +0000 (23:39 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Sat, 3 Sep 2022 04:39:28 +0000 (23:39 -0500)
core/net/tcp.onyx
src/checker.c
src/parser.c
src/symres.c
tests/aoc-2021/day15.onyx

index f57da68daf9a3958190c351eec912ec1f538a804..ced09615bd763c22d2b5106077fafa4bb394bede 100644 (file)
@@ -183,7 +183,7 @@ tcp_server_make :: (max_clients := 32, allocator := context.allocator) -> ^TCP_S
 tcp_server_listen :: (use server: ^TCP_Server, port: u16) -> bool {
     sa: Socket_Address;
     make_ipv4_address(^sa, 0x00000000, port);
-    if !socket->bind(^sa) do return false;
+    if !(socket->bind(^sa)) do return false;
 
     socket->listen();
     thread.spawn(^listener_thread, server, tcp_server_listener);
index fb54439901fa9a77c222077f50826010b9a9d401..333e331cf30c910becd47b4e802b7cb395d34211 100644 (file)
@@ -1726,6 +1726,7 @@ CheckStatus check_method_call(AstBinaryOp** pmcall) {
     CHECK(expression, &mcall->left);
     if (mcall->left->type == NULL) YIELD(mcall->token->pos, "Trying to resolve type of left hand side.");
 
+    mcall->type = mcall->left->type;
     AstTyped* implicit_argument = mcall->left;
 
     // Symbol resolution should have ensured that this is call node.
index 7050bf65f1f65fbc941a1a24f0c533c4a3ec4f5f..1ccf7521e24bf6b6bb1de40693c62b32763e8bd5 100644 (file)
@@ -825,25 +825,6 @@ static AstTyped* parse_factor(OnyxParser* parser) {
                 break;
             }
 
-            case Token_Type_Right_Arrow: {
-                AstBinaryOp* method_call = make_node(AstBinaryOp, Ast_Kind_Method_Call);
-                method_call->token = expect_token(parser, Token_Type_Right_Arrow);
-                method_call->left = retval;
-                method_call->right = parse_factor(parser);
-
-                if (method_call->right && method_call->right->kind == Ast_Kind_Method_Call) {
-                    AstBinaryOp *inner_method_call = (AstBinaryOp *) method_call->right;
-                    method_call->right = inner_method_call->left;
-                    inner_method_call->left = (AstTyped *) method_call;
-
-                    retval = (AstTyped *) inner_method_call;
-
-                } else {
-                    retval = (AstTyped *) method_call;
-                }
-                break;
-            }
-
             case Token_Type_Keyword_If: {
                 AstIfExpression* if_expression = make_node(AstIfExpression, Ast_Kind_If_Expression);
                 if_expression->token = expect_token(parser, Token_Type_Keyword_If);
@@ -909,6 +890,8 @@ static inline i32 get_precedence(BinaryOp kind) {
         case Binary_Op_Divide:          return 8;
 
         case Binary_Op_Modulus:         return 9;
+        
+        case Binary_Op_Method_Call:     return 10;
 
         default:                        return -1;
     }
@@ -955,6 +938,7 @@ static BinaryOp binary_op_from_token_type(TokenType t) {
         case Token_Type_Pipe:              return Binary_Op_Pipe;
         case Token_Type_Dot_Dot:           return Binary_Op_Range;
         case '[':                          return Binary_Op_Subscript;
+        case Token_Type_Right_Arrow:       return Binary_Op_Method_Call;
         default: return Binary_Op_Count;
     }
 }
@@ -1023,9 +1007,10 @@ static AstTyped* parse_expression(OnyxParser* parser, b32 assignment_allowed) {
         consume_token(parser);
 
         AstBinaryOp* bin_op;
-        if      (bin_op_kind == Binary_Op_Pipe)  bin_op = make_node(AstBinaryOp, Ast_Kind_Pipe);
-        else if (bin_op_kind == Binary_Op_Range) bin_op = (AstBinaryOp *) make_node(AstRangeLiteral, Ast_Kind_Range_Literal);
-        else                                     bin_op = make_node(AstBinaryOp, Ast_Kind_Binary_Op);
+        if      (bin_op_kind == Binary_Op_Pipe)        bin_op = make_node(AstBinaryOp, Ast_Kind_Pipe);
+        else if (bin_op_kind == Binary_Op_Method_Call) bin_op = make_node(AstBinaryOp, Ast_Kind_Method_Call);
+        else if (bin_op_kind == Binary_Op_Range)       bin_op = (AstBinaryOp *) make_node(AstRangeLiteral, Ast_Kind_Range_Literal);
+        else                                           bin_op = make_node(AstBinaryOp, Ast_Kind_Binary_Op);
 
         bin_op->token = bin_op_tok;
         bin_op->operation = bin_op_kind;
index ea2c400b79898beffd4b88ec853b6f06e6483865..4410bb6264e3d0e4a7746b82765c50211ea69303 100644 (file)
@@ -430,11 +430,6 @@ static SymresStatus symres_method_call(AstBinaryOp** mcall) {
             return Symres_Error;
         }
 
-        // AstAlias *left_alias = onyx_ast_node_new(context.ast_alloc, sizeof(AstAlias), Ast_Kind_Alias);
-        // left_alias->token = (*mcall)->left->token;
-        // left_alias->alias = (*mcall)->left;
-        // (*mcall)->left = (AstTyped *) left_alias;
-
         AstFieldAccess* implicit_field_access = make_field_access(context.ast_alloc, (*mcall)->left, NULL);
         implicit_field_access->token = ((AstCall *) (*mcall)->right)->callee->token;
         ((AstCall *) (*mcall)->right)->callee = (AstTyped *) implicit_field_access;
index 4fc704ab9ee345c19264a62ce1cc83f9958c2cf5..8686600297b9842f9576ed6e9b016e97e6d04809 100644 (file)
@@ -46,7 +46,7 @@ main :: (args) => {
 
             attempt_add :: macro (cond: Code, dx, dy: i32) {
                 if #unquote cond {
-                    if !tried->has(.{try.x + dx, try.y + dy}) {
+                    if !(tried->has(.{try.x + dx, try.y + dy})) {
                         if found := array.find_ptr(to_try.data, .{try.x + dx, try.y + dy, 0}); found != null {
                             found.cost = math.min(cell_value, found.cost);
                         } else {