| ... | @@ -131,6 +131,8 @@ pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: *ast.Node) InnerEr | ... | @@ -131,6 +131,8 @@ pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: *ast.Node) InnerEr |
| 131 | .ArrayType => return rlWrap(mod, scope, rl, try arrayType(mod, scope, node.castTag(.ArrayType).?)), | 131 | .ArrayType => return rlWrap(mod, scope, rl, try arrayType(mod, scope, node.castTag(.ArrayType).?)), |
| 132 | .ArrayTypeSentinel => return rlWrap(mod, scope, rl, try arrayTypeSentinel(mod, scope, node.castTag(.ArrayTypeSentinel).?)), | 132 | .ArrayTypeSentinel => return rlWrap(mod, scope, rl, try arrayTypeSentinel(mod, scope, node.castTag(.ArrayTypeSentinel).?)), |
| 133 | .EnumLiteral => return rlWrap(mod, scope, rl, try enumLiteral(mod, scope, node.castTag(.EnumLiteral).?)), | 133 | .EnumLiteral => return rlWrap(mod, scope, rl, try enumLiteral(mod, scope, node.castTag(.EnumLiteral).?)), |
| | 134 | .MultilineStringLiteral => return rlWrap(mod, scope, rl, try multilineStrLiteral(mod, scope, node.castTag(.MultilineStringLiteral).?)), |
| | 135 | .CharLiteral => return rlWrap(mod, scope, rl, try charLiteral(mod, scope, node.castTag(.CharLiteral).?)), |
| 134 | | 136 | |
| 135 | .Defer => return mod.failNode(scope, node, "TODO implement astgen.expr for .Defer", .{}), | 137 | .Defer => return mod.failNode(scope, node, "TODO implement astgen.expr for .Defer", .{}), |
| 136 | .Catch => return mod.failNode(scope, node, "TODO implement astgen.expr for .Catch", .{}), | 138 | .Catch => return mod.failNode(scope, node, "TODO implement astgen.expr for .Catch", .{}), |
| ... | @@ -159,8 +161,6 @@ pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: *ast.Node) InnerEr | ... | @@ -159,8 +161,6 @@ pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: *ast.Node) InnerEr |
| 159 | .ErrorType => return mod.failNode(scope, node, "TODO implement astgen.expr for .ErrorType", .{}), | 161 | .ErrorType => return mod.failNode(scope, node, "TODO implement astgen.expr for .ErrorType", .{}), |
| 160 | .FnProto => return mod.failNode(scope, node, "TODO implement astgen.expr for .FnProto", .{}), | 162 | .FnProto => return mod.failNode(scope, node, "TODO implement astgen.expr for .FnProto", .{}), |
| 161 | .AnyFrameType => return mod.failNode(scope, node, "TODO implement astgen.expr for .AnyFrameType", .{}), | 163 | .AnyFrameType => return mod.failNode(scope, node, "TODO implement astgen.expr for .AnyFrameType", .{}), |
| 162 | .MultilineStringLiteral => return mod.failNode(scope, node, "TODO implement astgen.expr for .MultilineStringLiteral", .{}), | | |
| 163 | .CharLiteral => return mod.failNode(scope, node, "TODO implement astgen.expr for .CharLiteral", .{}), | | |
| 164 | .ErrorSetDecl => return mod.failNode(scope, node, "TODO implement astgen.expr for .ErrorSetDecl", .{}), | 164 | .ErrorSetDecl => return mod.failNode(scope, node, "TODO implement astgen.expr for .ErrorSetDecl", .{}), |
| 165 | .ContainerDecl => return mod.failNode(scope, node, "TODO implement astgen.expr for .ContainerDecl", .{}), | 165 | .ContainerDecl => return mod.failNode(scope, node, "TODO implement astgen.expr for .ContainerDecl", .{}), |
| 166 | .Comptime => return mod.failNode(scope, node, "TODO implement astgen.expr for .Comptime", .{}), | 166 | .Comptime => return mod.failNode(scope, node, "TODO implement astgen.expr for .Comptime", .{}), |
| ... | @@ -497,6 +497,7 @@ fn arrayType(mod: *Module, scope: *Scope, node: *ast.Node.ArrayType) !*zir.Inst | ... | @@ -497,6 +497,7 @@ fn arrayType(mod: *Module, scope: *Scope, node: *ast.Node.ArrayType) !*zir.Inst |
| 497 | .val = Value.initTag(.usize_type), | 497 | .val = Value.initTag(.usize_type), |
| 498 | }); | 498 | }); |
| 499 | | 499 | |
| | 500 | // TODO check for [_]T |
| 500 | const len = try expr(mod, scope, .{ .ty = usize_type }, node.len_expr); | 501 | const len = try expr(mod, scope, .{ .ty = usize_type }, node.len_expr); |
| 501 | const child_type = try expr(mod, scope, .{ .ty = meta_type }, node.rhs); | 502 | const child_type = try expr(mod, scope, .{ .ty = meta_type }, node.rhs); |
| 502 | | 503 | |
| ... | @@ -515,6 +516,7 @@ fn arrayTypeSentinel(mod: *Module, scope: *Scope, node: *ast.Node.ArrayTypeSenti | ... | @@ -515,6 +516,7 @@ fn arrayTypeSentinel(mod: *Module, scope: *Scope, node: *ast.Node.ArrayTypeSenti |
| 515 | .val = Value.initTag(.usize_type), | 516 | .val = Value.initTag(.usize_type), |
| 516 | }); | 517 | }); |
| 517 | | 518 | |
| | 519 | // TODO check for [_]T |
| 518 | const len = try expr(mod, scope, .{ .ty = usize_type }, node.len_expr); | 520 | const len = try expr(mod, scope, .{ .ty = usize_type }, node.len_expr); |
| 519 | const sentinel_uncasted = try expr(mod, scope, .none, node.sentinel); | 521 | const sentinel_uncasted = try expr(mod, scope, .none, node.sentinel); |
| 520 | const elem_type = try expr(mod, scope, .{ .ty = meta_type }, node.rhs); | 522 | const elem_type = try expr(mod, scope, .{ .ty = meta_type }, node.rhs); |
| ... | @@ -1120,6 +1122,53 @@ fn stringLiteral(mod: *Module, scope: *Scope, str_lit: *ast.Node.OneToken) Inner | ... | @@ -1120,6 +1122,53 @@ fn stringLiteral(mod: *Module, scope: *Scope, str_lit: *ast.Node.OneToken) Inner |
| 1120 | return addZIRInst(mod, scope, src, zir.Inst.Str, .{ .bytes = bytes }, .{}); | 1122 | return addZIRInst(mod, scope, src, zir.Inst.Str, .{ .bytes = bytes }, .{}); |
| 1121 | } | 1123 | } |
| 1122 | | 1124 | |
| | 1125 | fn multilineStrLiteral(mod: *Module, scope: *Scope, node: *ast.Node.MultilineStringLiteral) !*zir.Inst { |
| | 1126 | const tree = scope.tree(); |
| | 1127 | const lines = node.linesConst(); |
| | 1128 | const src = tree.token_locs[lines[0]].start; |
| | 1129 | |
| | 1130 | // line lengths and new lines |
| | 1131 | var len = lines.len - 1; |
| | 1132 | for (lines) |line| { |
| | 1133 | len += tree.tokenSlice(line).len - 2; |
| | 1134 | } |
| | 1135 | |
| | 1136 | const bytes = try scope.arena().alloc(u8, len); |
| | 1137 | var i: usize = 0; |
| | 1138 | for (lines) |line, line_i| { |
| | 1139 | if (line_i != 0) { |
| | 1140 | bytes[i] = '\n'; |
| | 1141 | i += 1; |
| | 1142 | } |
| | 1143 | const slice = tree.tokenSlice(line)[2..]; |
| | 1144 | mem.copy(u8, bytes[i..], slice); |
| | 1145 | i += slice.len; |
| | 1146 | } |
| | 1147 | |
| | 1148 | return addZIRInst(mod, scope, src, zir.Inst.Str, .{ .bytes = bytes }, .{}); |
| | 1149 | } |
| | 1150 | |
| | 1151 | fn charLiteral(mod: *Module, scope: *Scope, node: *ast.Node.OneToken) !*zir.Inst { |
| | 1152 | const tree = scope.tree(); |
| | 1153 | const src = tree.token_locs[node.token].start; |
| | 1154 | const slice = tree.tokenSlice(node.token); |
| | 1155 | |
| | 1156 | var bad_index: usize = undefined; |
| | 1157 | const value = std.zig.parseCharLiteral(slice, &bad_index) catch |err| switch (err) { |
| | 1158 | error.InvalidCharacter => { |
| | 1159 | const bad_byte = slice[bad_index]; |
| | 1160 | return mod.fail(scope, src + bad_index, "invalid character: '{c}'\n", .{bad_byte}); |
| | 1161 | }, |
| | 1162 | }; |
| | 1163 | |
| | 1164 | const int_payload = try scope.arena().create(Value.Payload.Int_u64); |
| | 1165 | int_payload.* = .{ .int = value }; |
| | 1166 | return addZIRInstConst(mod, scope, src, .{ |
| | 1167 | .ty = Type.initTag(.comptime_int), |
| | 1168 | .val = Value.initPayload(&int_payload.base), |
| | 1169 | }); |
| | 1170 | } |
| | 1171 | |
| 1123 | fn integerLiteral(mod: *Module, scope: *Scope, int_lit: *ast.Node.OneToken) InnerError!*zir.Inst { | 1172 | fn integerLiteral(mod: *Module, scope: *Scope, int_lit: *ast.Node.OneToken) InnerError!*zir.Inst { |
| 1124 | const arena = scope.arena(); | 1173 | const arena = scope.arena(); |
| 1125 | const tree = scope.tree(); | 1174 | const tree = scope.tree(); |