authorgravatar for pfg@pfg.pwpfg <pfg@pfg.pw> 2020-07-04 01:58:35-07:00
committergravatar for pfg@pfg.pwpfg <pfg@pfg.pw> 2020-07-04 15:16:46-07:00
log1d52438bd54adcb5cf5dfb7b664a5d4c3bcaee03
tree924973c279a23b16a1d75666f73d62d9a8cd3d62
parent0ae1157e4553d6f54e0d489daebb006c402e0f63

stage2: InfixOp add


1 files changed, 22 insertions(+), 3 deletions(-)

src-self-hosted/Module.zig+22-3
......@@ -1317,10 +1317,28 @@ fn astGenExpr(self: *Module, scope: *Scope, ast_node: *ast.Node) InnerError!*zir
13171317 .Unreachable => return self.astGenUnreachable(scope, @fieldParentPtr(ast.Node.Unreachable, "base", ast_node)),
13181318 .ControlFlowExpression => return self.astGenControlFlowExpression(scope, @fieldParentPtr(ast.Node.ControlFlowExpression, "base", ast_node)),
13191319 .If => return self.astGenIf(scope, @fieldParentPtr(ast.Node.If, "base", ast_node)),
1320 .InfixOp => return self.astGenInfixOp(scope, @fieldParentPtr(ast.Node.InfixOp, "base", ast_node)),
13201321 else => return self.failNode(scope, ast_node, "TODO implement astGenExpr for {}", .{@tagName(ast_node.id)}),
13211322 }
13221323}
13231324
1325fn astGenInfixOp(self: *Module, scope: *Scope, infix_node: *ast.Node.InfixOp) InnerError!*zir.Inst {
1326 switch (infix_node.op) {
1327 .Add => {
1328 const lhs = try self.astGenExpr(scope, infix_node.lhs);
1329 const rhs = try self.astGenExpr(scope, infix_node.rhs);
1330
1331 const tree = scope.tree();
1332 const src = tree.token_locs[infix_node.op_token].start;
1333
1334 return self.addZIRInst(scope, src, zir.Inst.Add, .{ .lhs = lhs, .rhs = rhs }, .{});
1335 },
1336 else => |op| {
1337 return self.failNode(scope, &infix_node.base, "TODO implement infix operator {}", .{op});
1338 },
1339 }
1340}
1341
13241342fn astGenIf(self: *Module, scope: *Scope, if_node: *ast.Node.If) InnerError!*zir.Inst {
13251343 if (if_node.payload) |payload| {
13261344 return self.failNode(scope, payload, "TODO implement astGenIf for optionals", .{});
......@@ -2933,7 +2951,9 @@ fn analyzeInstAdd(self: *Module, scope: *Scope, inst: *zir.Inst.Add) InnerError!
29332951 const lhs = try self.resolveInst(scope, inst.positionals.lhs);
29342952 const rhs = try self.resolveInst(scope, inst.positionals.rhs);
29352953
2936 if (lhs.ty.zigTypeTag() == .Int and rhs.ty.zigTypeTag() == .Int) {
2954 if ((lhs.ty.zigTypeTag() == .Int or lhs.ty.zigTypeTag() == .ComptimeInt) and
2955 (rhs.ty.zigTypeTag() == .Int or rhs.ty.zigTypeTag() == .ComptimeInt))
2956 {
29372957 if (!lhs.ty.eql(rhs.ty)) {
29382958 return self.fail(scope, inst.base.src, "TODO implement peer type resolution", .{});
29392959 }
......@@ -2977,8 +2997,7 @@ fn analyzeInstAdd(self: *Module, scope: *Scope, inst: *zir.Inst.Add) InnerError!
29772997 .rhs = rhs,
29782998 });
29792999 }
2980
2981 return self.fail(scope, inst.base.src, "TODO implement more analyze add", .{});
3000 return self.fail(scope, inst.base.src, "TODO analyze add for {} + {}", .{ lhs.ty.zigTypeTag(), rhs.ty.zigTypeTag() });
29823001}
29833002
29843003fn analyzeInstDeref(self: *Module, scope: *Scope, deref: *zir.Inst.Deref) InnerError!*Inst {