| ... | @@ -275,6 +275,7 @@ pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: *ast.Node) InnerEr | ... | @@ -275,6 +275,7 @@ pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: *ast.Node) InnerEr |
| 275 | .ErrorType => return rlWrap(mod, scope, rl, try errorType(mod, scope, node.castTag(.ErrorType).?)), | 275 | .ErrorType => return rlWrap(mod, scope, rl, try errorType(mod, scope, node.castTag(.ErrorType).?)), |
| 276 | .For => return forExpr(mod, scope, rl, node.castTag(.For).?), | 276 | .For => return forExpr(mod, scope, rl, node.castTag(.For).?), |
| 277 | .ArrayAccess => return arrayAccess(mod, scope, rl, node.castTag(.ArrayAccess).?), | 277 | .ArrayAccess => return arrayAccess(mod, scope, rl, node.castTag(.ArrayAccess).?), |
| | 278 | .Slice => return rlWrap(mod, scope, rl, try sliceExpr(mod, scope, node.castTag(.Slice).?)), |
| 278 | .Catch => return catchExpr(mod, scope, rl, node.castTag(.Catch).?), | 279 | .Catch => return catchExpr(mod, scope, rl, node.castTag(.Catch).?), |
| 279 | .Comptime => return comptimeKeyword(mod, scope, rl, node.castTag(.Comptime).?), | 280 | .Comptime => return comptimeKeyword(mod, scope, rl, node.castTag(.Comptime).?), |
| 280 | .OrElse => return orelseExpr(mod, scope, rl, node.castTag(.OrElse).?), | 281 | .OrElse => return orelseExpr(mod, scope, rl, node.castTag(.OrElse).?), |
| ... | @@ -284,7 +285,6 @@ pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: *ast.Node) InnerEr | ... | @@ -284,7 +285,6 @@ pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: *ast.Node) InnerEr |
| 284 | .Await => return mod.failNode(scope, node, "TODO implement astgen.expr for .Await", .{}), | 285 | .Await => return mod.failNode(scope, node, "TODO implement astgen.expr for .Await", .{}), |
| 285 | .Resume => return mod.failNode(scope, node, "TODO implement astgen.expr for .Resume", .{}), | 286 | .Resume => return mod.failNode(scope, node, "TODO implement astgen.expr for .Resume", .{}), |
| 286 | .Try => return mod.failNode(scope, node, "TODO implement astgen.expr for .Try", .{}), | 287 | .Try => return mod.failNode(scope, node, "TODO implement astgen.expr for .Try", .{}), |
| 287 | .Slice => return mod.failNode(scope, node, "TODO implement astgen.expr for .Slice", .{}), | | |
| 288 | .ArrayInitializer => return mod.failNode(scope, node, "TODO implement astgen.expr for .ArrayInitializer", .{}), | 288 | .ArrayInitializer => return mod.failNode(scope, node, "TODO implement astgen.expr for .ArrayInitializer", .{}), |
| 289 | .ArrayInitializerDot => return mod.failNode(scope, node, "TODO implement astgen.expr for .ArrayInitializerDot", .{}), | 289 | .ArrayInitializerDot => return mod.failNode(scope, node, "TODO implement astgen.expr for .ArrayInitializerDot", .{}), |
| 290 | .StructInitializer => return mod.failNode(scope, node, "TODO implement astgen.expr for .StructInitializer", .{}), | 290 | .StructInitializer => return mod.failNode(scope, node, "TODO implement astgen.expr for .StructInitializer", .{}), |
| ... | @@ -951,6 +951,36 @@ fn arrayAccess(mod: *Module, scope: *Scope, rl: ResultLoc, node: *ast.Node.Array | ... | @@ -951,6 +951,36 @@ fn arrayAccess(mod: *Module, scope: *Scope, rl: ResultLoc, node: *ast.Node.Array |
| 951 | return rlWrapPtr(mod, scope, rl, try addZIRInst(mod, scope, src, zir.Inst.ElemPtr, .{ .array_ptr = array_ptr, .index = index }, .{})); | 951 | return rlWrapPtr(mod, scope, rl, try addZIRInst(mod, scope, src, zir.Inst.ElemPtr, .{ .array_ptr = array_ptr, .index = index }, .{})); |
| 952 | } | 952 | } |
| 953 | | 953 | |
| | 954 | fn sliceExpr(mod: *Module, scope: *Scope, node: *ast.Node.Slice) InnerError!*zir.Inst { |
| | 955 | const tree = scope.tree(); |
| | 956 | const src = tree.token_locs[node.rtoken].start; |
| | 957 | |
| | 958 | const usize_type = try addZIRInstConst(mod, scope, src, .{ |
| | 959 | .ty = Type.initTag(.type), |
| | 960 | .val = Value.initTag(.usize_type), |
| | 961 | }); |
| | 962 | |
| | 963 | const array_ptr = try expr(mod, scope, .ref, node.lhs); |
| | 964 | const start = try expr(mod, scope, .{ .ty = usize_type }, node.start); |
| | 965 | |
| | 966 | if (node.end == null and node.sentinel == null) { |
| | 967 | return try addZIRBinOp(mod, scope, src, .slice_start, array_ptr, start); |
| | 968 | } |
| | 969 | |
| | 970 | const end = if (node.end) |end| try expr(mod, scope, .{ .ty = usize_type }, end) else null; |
| | 971 | // we could get the child type here, but it is easier to just do it in semantic analysis. |
| | 972 | const sentinel = if (node.sentinel) |sentinel| try expr(mod, scope, .none, sentinel) else null; |
| | 973 | |
| | 974 | return try addZIRInst( |
| | 975 | mod, |
| | 976 | scope, |
| | 977 | src, |
| | 978 | zir.Inst.Slice, |
| | 979 | .{ .array_ptr = array_ptr, .start = start }, |
| | 980 | .{ .end = end, .sentinel = sentinel }, |
| | 981 | ); |
| | 982 | } |
| | 983 | |
| 954 | fn deref(mod: *Module, scope: *Scope, node: *ast.Node.SimpleSuffixOp) InnerError!*zir.Inst { | 984 | fn deref(mod: *Module, scope: *Scope, node: *ast.Node.SimpleSuffixOp) InnerError!*zir.Inst { |
| 955 | const tree = scope.tree(); | 985 | const tree = scope.tree(); |
| 956 | const src = tree.token_locs[node.rtoken].start; | 986 | const src = tree.token_locs[node.rtoken].start; |