feat: basic code generation
This commit is contained in:
parent
3ab279de0f
commit
55346fcd85
4 changed files with 579 additions and 16 deletions
|
|
@ -16,7 +16,7 @@ fn dumpByteInst(d: Dumper, context: *const Object.ContentPath, offset: usize, op
|
|||
const arg = context.bytes[offset + 1];
|
||||
if (op == .load_const) {
|
||||
try d.writer.print("{s} {d} (", .{ @tagName(op), arg });
|
||||
try printObject(d.writer, context.const_pool[arg]);
|
||||
try d.dumpObject(context.const_pool[arg]);
|
||||
try d.writer.print(")\n", .{});
|
||||
} else {
|
||||
try d.writer.print("{s} {x}\n", .{ @tagName(op), arg });
|
||||
|
|
@ -141,28 +141,28 @@ fn getObjectType(object: *const Object) []const u8 {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn printObject(writer: *std.Io.Writer, object: *const Object) !void {
|
||||
pub fn dumpObject(d: Dumper, object: *const Object) !void {
|
||||
const type_string = getObjectType(object);
|
||||
switch (object.tag) {
|
||||
.number => {
|
||||
const typed_object: *const Object.Number = @ptrCast(object);
|
||||
switch (typed_object.data) {
|
||||
.boolean => |value| {
|
||||
try writer.print("<type={s} value={s}, address={*}>", .{
|
||||
try d.writer.print("<type={s} value={s}, address={*}>", .{
|
||||
type_string,
|
||||
if (value) "true" else "false",
|
||||
object,
|
||||
});
|
||||
},
|
||||
.floating => |value| {
|
||||
try writer.print("<type={s} value={d}, address={*}>", .{
|
||||
try d.writer.print("<type={s} value={d}, address={*}>", .{
|
||||
type_string,
|
||||
value,
|
||||
object,
|
||||
});
|
||||
},
|
||||
.integer => |value| {
|
||||
try writer.print("<type={s} value={d}, address={*}>", .{
|
||||
try d.writer.print("<type={s} value={d}, address={*}>", .{
|
||||
type_string,
|
||||
value,
|
||||
object,
|
||||
|
|
@ -173,14 +173,14 @@ pub fn printObject(writer: *std.Io.Writer, object: *const Object) !void {
|
|||
.string => {
|
||||
const typed_object: *const Object.String = @ptrCast(object);
|
||||
const string_bytes = typed_object.bytes[0..typed_object.length];
|
||||
try writer.print("<type={s} value=\"{s}\", address={*}>", .{
|
||||
try d.writer.print("<type={s} value=\"{s}\", address={*}>", .{
|
||||
type_string,
|
||||
string_bytes,
|
||||
object,
|
||||
});
|
||||
},
|
||||
.content_path => {
|
||||
try writer.print("<type={s} address={*}>", .{ type_string, object });
|
||||
try d.writer.print("<type={s} address={*}>", .{ type_string, object });
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue