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...@@ -1317,10 +1317,28 @@ fn astGenExpr(self: *Module, scope: *Scope, ast_node: *ast.Node) InnerError!*zir
1317 .Unreachable => return self.astGenUnreachable(scope, @fieldParentPtr(ast.Node.Unreachable, "base", ast_node)),1317 .Unreachable => return self.astGenUnreachable(scope, @fieldParentPtr(ast.Node.Unreachable, "base", ast_node)),
1318 .ControlFlowExpression => return self.astGenControlFlowExpression(scope, @fieldParentPtr(ast.Node.ControlFlowExpression, "base", ast_node)),1318 .ControlFlowExpression => return self.astGenControlFlowExpression(scope, @fieldParentPtr(ast.Node.ControlFlowExpression, "base", ast_node)),
1319 .If => return self.astGenIf(scope, @fieldParentPtr(ast.Node.If, "base", ast_node)),1319 .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)),
1320 else => return self.failNode(scope, ast_node, "TODO implement astGenExpr for {}", .{@tagName(ast_node.id)}),1321 else => return self.failNode(scope, ast_node, "TODO implement astGenExpr for {}", .{@tagName(ast_node.id)}),
1321 }1322 }
1322}1323}
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
1324fn astGenIf(self: *Module, scope: *Scope, if_node: *ast.Node.If) InnerError!*zir.Inst {1342fn astGenIf(self: *Module, scope: *Scope, if_node: *ast.Node.If) InnerError!*zir.Inst {
1325 if (if_node.payload) |payload| {1343 if (if_node.payload) |payload| {
1326 return self.failNode(scope, payload, "TODO implement astGenIf for optionals", .{});1344 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!...@@ -2933,7 +2951,9 @@ fn analyzeInstAdd(self: *Module, scope: *Scope, inst: *zir.Inst.Add) InnerError!
2933 const lhs = try self.resolveInst(scope, inst.positionals.lhs);2951 const lhs = try self.resolveInst(scope, inst.positionals.lhs);
2934 const rhs = try self.resolveInst(scope, inst.positionals.rhs);2952 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 {
2937 if (!lhs.ty.eql(rhs.ty)) {2957 if (!lhs.ty.eql(rhs.ty)) {
2938 return self.fail(scope, inst.base.src, "TODO implement peer type resolution", .{});2958 return self.fail(scope, inst.base.src, "TODO implement peer type resolution", .{});
2939 }2959 }
...@@ -2977,8 +2997,7 @@ fn analyzeInstAdd(self: *Module, scope: *Scope, inst: *zir.Inst.Add) InnerError!...@@ -2977,8 +2997,7 @@ fn analyzeInstAdd(self: *Module, scope: *Scope, inst: *zir.Inst.Add) InnerError!
2977 .rhs = rhs,2997 .rhs = rhs,
2978 });2998 });
2979 }2999 }
29803000 return self.fail(scope, inst.base.src, "TODO analyze add for {} + {}", .{ lhs.ty.zigTypeTag(), rhs.ty.zigTypeTag() });
2981 return self.fail(scope, inst.base.src, "TODO implement more analyze add", .{});
2982}3001}
29833002
2984fn analyzeInstDeref(self: *Module, scope: *Scope, deref: *zir.Inst.Deref) InnerError!*Inst {3003fn analyzeInstDeref(self: *Module, scope: *Scope, deref: *zir.Inst.Deref) InnerError!*Inst {