| ... | ... | @@ -169,8 +169,9 @@ pub const Tree = struct { |
| 169 | 169 | } |
| 170 | 170 | |
| 171 | 171 | for (self.decls) |decl, i| { |
| 172 | | try stream.print("@{} = ", .{i}); |
| 172 | try stream.print("@{} ", .{i}); |
| 173 | 173 | try self.writeInstToStream(stream, decl, &inst_table); |
| 174 | try stream.writeByte('\n'); |
| 174 | 175 | } |
| 175 | 176 | } |
| 176 | 177 | |
| ... | ... | @@ -197,15 +198,26 @@ pub const Tree = struct { |
| 197 | 198 | ) !void { |
| 198 | 199 | const SpecificInst = Inst.TagToType(inst_tag); |
| 199 | 200 | const inst = @fieldParentPtr(SpecificInst, "base", base); |
| 201 | if (@hasField(SpecificInst, "ty")) { |
| 202 | try stream.print(": {} ", .{inst.ty}); |
| 203 | } |
| 204 | if (inst_tag == .constant) switch (inst.positionals.value.tag()) { |
| 205 | .bytes => { |
| 206 | try stream.writeAll("= "); |
| 207 | const bytes_value = inst.positionals.value.cast(Value.Payload.Bytes).?; |
| 208 | return std.zig.renderStringLiteral(bytes_value.data, stream); |
| 209 | }, |
| 210 | else => {}, |
| 211 | }; |
| 200 | 212 | const Positionals = @TypeOf(inst.positionals); |
| 201 | | try stream.writeAll(@tagName(inst_tag) ++ "("); |
| 213 | try stream.writeAll("= " ++ @tagName(inst_tag) ++ "("); |
| 202 | 214 | inline for (@typeInfo(Positionals).Struct.fields) |arg_field, i| { |
| 203 | 215 | if (i != 0) { |
| 204 | 216 | try stream.writeAll(", "); |
| 205 | 217 | } |
| 206 | 218 | try self.writeParamToStream(stream, @field(inst.positionals, arg_field.name), inst_table); |
| 207 | 219 | } |
| 208 | | try stream.writeAll(")\n"); |
| 220 | try stream.writeByte(')'); |
| 209 | 221 | } |
| 210 | 222 | |
| 211 | 223 | pub fn writeParamToStream(self: Tree, stream: var, param: var, inst_table: *const InstPtrTable) !void { |
| ... | ... | @@ -576,8 +588,14 @@ fn parseStringLiteralConst(ctx: *ParseContext, opt_type: ?Type) !*Inst { |
| 576 | 588 | bytes_payload.* = .{ .data = parsed }; |
| 577 | 589 | |
| 578 | 590 | const ty = opt_type orelse blk: { |
| 579 | | const ty_payload = try ctx.allocator.create(Type.Payload.Array_u8_Sentinel0); |
| 580 | | ty_payload.* = .{ .len = parsed.len }; |
| 591 | const array_payload = try ctx.allocator.create(Type.Payload.Array_u8_Sentinel0); |
| 592 | errdefer ctx.allocator.destroy(array_payload); |
| 593 | array_payload.* = .{ .len = parsed.len }; |
| 594 | |
| 595 | const ty_payload = try ctx.allocator.create(Type.Payload.SingleConstPointer); |
| 596 | errdefer ctx.allocator.destroy(ty_payload); |
| 597 | ty_payload.* = .{ .pointee_type = Type.initPayload(&array_payload.base) }; |
| 598 | |
| 581 | 599 | break :blk Type.initPayload(&ty_payload.base); |
| 582 | 600 | }; |
| 583 | 601 | |