| ... | ... | @@ -232,6 +232,11 @@ pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: *ast.Node) InnerEr |
| 232 | 232 | .BoolAnd => return boolBinOp(mod, scope, rl, node.castTag(.BoolAnd).?), |
| 233 | 233 | .BoolOr => return boolBinOp(mod, scope, rl, node.castTag(.BoolOr).?), |
| 234 | 234 | |
| 235 | .BoolNot => return rlWrap(mod, scope, rl, try boolNot(mod, scope, node.castTag(.BoolNot).?)), |
| 236 | .BitNot => return rlWrap(mod, scope, rl, try bitNot(mod, scope, node.castTag(.BitNot).?)), |
| 237 | .Negation => return rlWrap(mod, scope, rl, try negation(mod, scope, node.castTag(.Negation).?, .sub)), |
| 238 | .NegationWrap => return rlWrap(mod, scope, rl, try negation(mod, scope, node.castTag(.NegationWrap).?, .subwrap)), |
| 239 | |
| 235 | 240 | .Identifier => return try identifier(mod, scope, rl, node.castTag(.Identifier).?), |
| 236 | 241 | .Asm => return rlWrap(mod, scope, rl, try assembly(mod, scope, node.castTag(.Asm).?)), |
| 237 | 242 | .StringLiteral => return rlWrap(mod, scope, rl, try stringLiteral(mod, scope, node.castTag(.StringLiteral).?)), |
| ... | ... | @@ -244,7 +249,6 @@ pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: *ast.Node) InnerEr |
| 244 | 249 | .While => return whileExpr(mod, scope, rl, node.castTag(.While).?), |
| 245 | 250 | .Period => return rlWrap(mod, scope, rl, try field(mod, scope, node.castTag(.Period).?)), |
| 246 | 251 | .Deref => return rlWrap(mod, scope, rl, try deref(mod, scope, node.castTag(.Deref).?)), |
| 247 | | .BoolNot => return rlWrap(mod, scope, rl, try boolNot(mod, scope, node.castTag(.BoolNot).?)), |
| 248 | 252 | .AddressOf => return rlWrap(mod, scope, rl, try addressOf(mod, scope, node.castTag(.AddressOf).?)), |
| 249 | 253 | .FloatLiteral => return rlWrap(mod, scope, rl, try floatLiteral(mod, scope, node.castTag(.FloatLiteral).?)), |
| 250 | 254 | .UndefinedLiteral => return rlWrap(mod, scope, rl, try undefLiteral(mod, scope, node.castTag(.UndefinedLiteral).?)), |
| ... | ... | @@ -271,9 +275,6 @@ pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: *ast.Node) InnerEr |
| 271 | 275 | .Range => return mod.failNode(scope, node, "TODO implement astgen.expr for .Range", .{}), |
| 272 | 276 | .OrElse => return mod.failNode(scope, node, "TODO implement astgen.expr for .OrElse", .{}), |
| 273 | 277 | .Await => return mod.failNode(scope, node, "TODO implement astgen.expr for .Await", .{}), |
| 274 | | .BitNot => return mod.failNode(scope, node, "TODO implement astgen.expr for .BitNot", .{}), |
| 275 | | .Negation => return mod.failNode(scope, node, "TODO implement astgen.expr for .Negation", .{}), |
| 276 | | .NegationWrap => return mod.failNode(scope, node, "TODO implement astgen.expr for .NegationWrap", .{}), |
| 277 | 278 | .Resume => return mod.failNode(scope, node, "TODO implement astgen.expr for .Resume", .{}), |
| 278 | 279 | .Try => return mod.failNode(scope, node, "TODO implement astgen.expr for .Try", .{}), |
| 279 | 280 | .Slice => return mod.failNode(scope, node, "TODO implement astgen.expr for .Slice", .{}), |
| ... | ... | @@ -554,6 +555,27 @@ fn boolNot(mod: *Module, scope: *Scope, node: *ast.Node.SimplePrefixOp) InnerErr |
| 554 | 555 | return addZIRUnOp(mod, scope, src, .boolnot, operand); |
| 555 | 556 | } |
| 556 | 557 | |
| 558 | fn bitNot(mod: *Module, scope: *Scope, node: *ast.Node.SimplePrefixOp) InnerError!*zir.Inst { |
| 559 | const tree = scope.tree(); |
| 560 | const src = tree.token_locs[node.op_token].start; |
| 561 | const operand = try expr(mod, scope, .none, node.rhs); |
| 562 | return addZIRUnOp(mod, scope, src, .bitnot, operand); |
| 563 | } |
| 564 | |
| 565 | fn negation(mod: *Module, scope: *Scope, node: *ast.Node.SimplePrefixOp, op_inst_tag: zir.Inst.Tag) InnerError!*zir.Inst { |
| 566 | const tree = scope.tree(); |
| 567 | const src = tree.token_locs[node.op_token].start; |
| 568 | |
| 569 | const lhs = addZIRInstConst(mod, scope, src, .{ |
| 570 | .ty = Type.initTag(.comptime_int), |
| 571 | .val = Value.initTag(.zero), |
| 572 | }); |
| 573 | const rhs = try expr(mod, scope, .none, node.rhs); |
| 574 | |
| 575 | const result = try addZIRBinOp(mod, scope, src, op_inst_tag, lhs, rhs); |
| 576 | return rlWrap(mod, scope, rl, result); |
| 577 | } |
| 578 | |
| 557 | 579 | fn addressOf(mod: *Module, scope: *Scope, node: *ast.Node.SimplePrefixOp) InnerError!*zir.Inst { |
| 558 | 580 | return expr(mod, scope, .ref, node.rhs); |
| 559 | 581 | } |