| ... | @@ -175,7 +175,12 @@ pub const Tree = struct { | ... | @@ -175,7 +175,12 @@ pub const Tree = struct { |
| 175 | } | 175 | } |
| 176 | } | 176 | } |
| 177 | | 177 | |
| 178 | fn writeInstToStream(self: Tree, stream: var, decl: *Inst, inst_table: *const InstPtrTable) !void { | 178 | fn writeInstToStream( |
| | 179 | self: Tree, |
| | 180 | stream: var, |
| | 181 | decl: *Inst, |
| | 182 | inst_table: *const InstPtrTable, |
| | 183 | ) @TypeOf(stream).Error!void { |
| 179 | // TODO I tried implementing this with an inline for loop and hit a compiler bug | 184 | // TODO I tried implementing this with an inline for loop and hit a compiler bug |
| 180 | switch (decl.tag) { | 185 | switch (decl.tag) { |
| 181 | .constant => return self.writeInstToStreamGeneric(stream, .constant, decl, inst_table), | 186 | .constant => return self.writeInstToStreamGeneric(stream, .constant, decl, inst_table), |
| ... | @@ -201,14 +206,16 @@ pub const Tree = struct { | ... | @@ -201,14 +206,16 @@ pub const Tree = struct { |
| 201 | if (@hasField(SpecificInst, "ty")) { | 206 | if (@hasField(SpecificInst, "ty")) { |
| 202 | try stream.print(": {} ", .{inst.ty}); | 207 | try stream.print(": {} ", .{inst.ty}); |
| 203 | } | 208 | } |
| 204 | if (inst_tag == .constant) switch (inst.positionals.value.tag()) { | 209 | if (inst_tag == .constant) { |
| 205 | .bytes => { | 210 | if (inst.positionals.value.cast(Value.Payload.Bytes)) |bytes_value| { |
| 206 | try stream.writeAll("= "); | 211 | try stream.writeAll("= "); |
| 207 | const bytes_value = inst.positionals.value.cast(Value.Payload.Bytes).?; | | |
| 208 | return std.zig.renderStringLiteral(bytes_value.data, stream); | 212 | return std.zig.renderStringLiteral(bytes_value.data, stream); |
| 209 | }, | 213 | } else if (inst.positionals.value.cast(Value.Payload.Int_u64)) |v| { |
| 210 | else => {}, | 214 | return stream.print("= {}", .{v.int}); |
| 211 | }; | 215 | } else if (inst.positionals.value.cast(Value.Payload.Int_i64)) |v| { |
| | 216 | return stream.print("= {}", .{v.int}); |
| | 217 | } |
| | 218 | } |
| 212 | const Positionals = @TypeOf(inst.positionals); | 219 | const Positionals = @TypeOf(inst.positionals); |
| 213 | try stream.writeAll("= " ++ @tagName(inst_tag) ++ "("); | 220 | try stream.writeAll("= " ++ @tagName(inst_tag) ++ "("); |
| 214 | inline for (@typeInfo(Positionals).Struct.fields) |arg_field, i| { | 221 | inline for (@typeInfo(Positionals).Struct.fields) |arg_field, i| { |
| ... | @@ -231,7 +238,13 @@ pub const Tree = struct { | ... | @@ -231,7 +238,13 @@ pub const Tree = struct { |
| 231 | try stream.print("{}{}", .{ prefix, info.index }); | 238 | try stream.print("{}{}", .{ prefix, info.index }); |
| 232 | }, | 239 | }, |
| 233 | Inst.Fn.Body => { | 240 | Inst.Fn.Body => { |
| 234 | try stream.print("(fn body)", .{}); | 241 | try stream.writeAll("{\n"); |
| | 242 | for (param.instructions) |inst, i| { |
| | 243 | try stream.print(" %{} ", .{i}); |
| | 244 | try self.writeInstToStream(stream, inst, inst_table); |
| | 245 | try stream.writeByte('\n'); |
| | 246 | } |
| | 247 | try stream.writeByte('}'); |
| 235 | }, | 248 | }, |
| 236 | else => |T| @compileError("unimplemented: rendering parameter of type " ++ @typeName(T)), | 249 | else => |T| @compileError("unimplemented: rendering parameter of type " ++ @typeName(T)), |
| 237 | } | 250 | } |