| ... | @@ -1297,10 +1297,28 @@ fn astGenExpr(self: *Module, scope: *Scope, ast_node: *ast.Node) InnerError!*zir | ... | @@ -1297,10 +1297,28 @@ fn astGenExpr(self: *Module, scope: *Scope, ast_node: *ast.Node) InnerError!*zir |
| 1297 | .Unreachable => return self.astGenUnreachable(scope, @fieldParentPtr(ast.Node.Unreachable, "base", ast_node)), | 1297 | .Unreachable => return self.astGenUnreachable(scope, @fieldParentPtr(ast.Node.Unreachable, "base", ast_node)), |
| 1298 | .ControlFlowExpression => return self.astGenControlFlowExpression(scope, @fieldParentPtr(ast.Node.ControlFlowExpression, "base", ast_node)), | 1298 | .ControlFlowExpression => return self.astGenControlFlowExpression(scope, @fieldParentPtr(ast.Node.ControlFlowExpression, "base", ast_node)), |
| 1299 | .If => return self.astGenIf(scope, @fieldParentPtr(ast.Node.If, "base", ast_node)), | 1299 | .If => return self.astGenIf(scope, @fieldParentPtr(ast.Node.If, "base", ast_node)), |
| | 1300 | .InfixOp => return self.astGenInfixOp(scope, @fieldParentPtr(ast.Node.InfixOp, "base", ast_node)), |
| 1300 | else => return self.failNode(scope, ast_node, "TODO implement astGenExpr for {}", .{@tagName(ast_node.id)}), | 1301 | else => return self.failNode(scope, ast_node, "TODO implement astGenExpr for {}", .{@tagName(ast_node.id)}), |
| 1301 | } | 1302 | } |
| 1302 | } | 1303 | } |
| 1303 | | 1304 | |
| | 1305 | fn astGenInfixOp(self: *Module, scope: *Scope, infix_node: *ast.Node.InfixOp) InnerError!*zir.Inst { |
| | 1306 | switch (infix_node.op) { |
| | 1307 | .Add => { |
| | 1308 | const lhs = try self.astGenExpr(scope, infix_node.lhs); |
| | 1309 | const rhs = try self.astGenExpr(scope, infix_node.rhs); |
| | 1310 | |
| | 1311 | const tree = scope.tree(); |
| | 1312 | const src = tree.token_locs[infix_node.op_token].start; |
| | 1313 | |
| | 1314 | return self.addZIRInst(scope, src, zir.Inst.Add, .{ .lhs = lhs, .rhs = rhs }, .{}); |
| | 1315 | }, |
| | 1316 | else => |op| { |
| | 1317 | return self.failNode(scope, &infix_node.base, "TODO implement infix operator {}", .{op}); |
| | 1318 | }, |
| | 1319 | } |
| | 1320 | } |
| | 1321 | |
| 1304 | fn astGenIf(self: *Module, scope: *Scope, if_node: *ast.Node.If) InnerError!*zir.Inst { | 1322 | fn astGenIf(self: *Module, scope: *Scope, if_node: *ast.Node.If) InnerError!*zir.Inst { |
| 1305 | if (if_node.payload) |payload| { | 1323 | if (if_node.payload) |payload| { |
| 1306 | return self.failNode(scope, payload, "TODO implement astGenIf for optionals", .{}); | 1324 | return self.failNode(scope, payload, "TODO implement astGenIf for optionals", .{}); |
| ... | @@ -1496,7 +1514,12 @@ fn astGenBuiltinCall(self: *Module, scope: *Scope, call: *ast.Node.BuiltinCall) | ... | @@ -1496,7 +1514,12 @@ fn astGenBuiltinCall(self: *Module, scope: *Scope, call: *ast.Node.BuiltinCall) |
| 1496 | const arg_count: ?usize = if (positionals.fields[0].field_type == []*zir.Inst) null else positionals.fields.len; | 1514 | const arg_count: ?usize = if (positionals.fields[0].field_type == []*zir.Inst) null else positionals.fields.len; |
| 1497 | if (arg_count) |some| { | 1515 | if (arg_count) |some| { |
| 1498 | if (call.params_len != some) { | 1516 | if (call.params_len != some) { |
| 1499 | return self.failTok(scope, call.builtin_token, "expected {} parameter, found {}", .{ some, call.params_len }); | 1517 | return self.failTok( |
| | 1518 | scope, |
| | 1519 | call.builtin_token, |
| | 1520 | "expected {} parameter{}, found {}", |
| | 1521 | .{ some, if (some == 1) "" else "s", call.params_len }, |
| | 1522 | ); |
| 1500 | } | 1523 | } |
| 1501 | const params = call.params(); | 1524 | const params = call.params(); |
| 1502 | inline for (positionals.fields) |p, i| { | 1525 | inline for (positionals.fields) |p, i| { |
| ... | @@ -2902,7 +2925,9 @@ fn analyzeInstAdd(self: *Module, scope: *Scope, inst: *zir.Inst.Add) InnerError! | ... | @@ -2902,7 +2925,9 @@ fn analyzeInstAdd(self: *Module, scope: *Scope, inst: *zir.Inst.Add) InnerError! |
| 2902 | const lhs = try self.resolveInst(scope, inst.positionals.lhs); | 2925 | const lhs = try self.resolveInst(scope, inst.positionals.lhs); |
| 2903 | const rhs = try self.resolveInst(scope, inst.positionals.rhs); | 2926 | const rhs = try self.resolveInst(scope, inst.positionals.rhs); |
| 2904 | | 2927 | |
| 2905 | if (lhs.ty.zigTypeTag() == .Int and rhs.ty.zigTypeTag() == .Int) { | 2928 | if ((lhs.ty.zigTypeTag() == .Int or lhs.ty.zigTypeTag() == .ComptimeInt) and |
| | 2929 | (rhs.ty.zigTypeTag() == .Int or rhs.ty.zigTypeTag() == .ComptimeInt)) |
| | 2930 | { |
| 2906 | if (!lhs.ty.eql(rhs.ty)) { | 2931 | if (!lhs.ty.eql(rhs.ty)) { |
| 2907 | return self.fail(scope, inst.base.src, "TODO implement peer type resolution", .{}); | 2932 | return self.fail(scope, inst.base.src, "TODO implement peer type resolution", .{}); |
| 2908 | } | 2933 | } |
| ... | @@ -2946,8 +2971,7 @@ fn analyzeInstAdd(self: *Module, scope: *Scope, inst: *zir.Inst.Add) InnerError! | ... | @@ -2946,8 +2971,7 @@ fn analyzeInstAdd(self: *Module, scope: *Scope, inst: *zir.Inst.Add) InnerError! |
| 2946 | .rhs = rhs, | 2971 | .rhs = rhs, |
| 2947 | }); | 2972 | }); |
| 2948 | } | 2973 | } |
| 2949 | | 2974 | return self.fail(scope, inst.base.src, "TODO analyze add for {} + {}", .{ lhs.ty.zigTypeTag(), rhs.ty.zigTypeTag() }); |
| 2950 | return self.fail(scope, inst.base.src, "TODO implement more analyze add", .{}); | | |
| 2951 | } | 2975 | } |
| 2952 | | 2976 | |
| 2953 | fn analyzeInstDeref(self: *Module, scope: *Scope, deref: *zir.Inst.Deref) InnerError!*Inst { | 2977 | fn analyzeInstDeref(self: *Module, scope: *Scope, deref: *zir.Inst.Deref) InnerError!*Inst { |