|
|
|
@ -13,15 +13,15 @@ fn printIdent(ident: usize) void {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn print(ident: usize, comptime fmt: []const u8, args: var) void {
|
|
|
|
|
fn print(ident: usize, comptime fmt: []const u8, args: anytype) void {
|
|
|
|
|
printIdent(ident);
|
|
|
|
|
std.debug.warn(fmt, args);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn printBlock(ident: usize, block: var, endNewline: bool) void {
|
|
|
|
|
fn printBlock(ident: usize, block: anytype, endNewline: bool) void {
|
|
|
|
|
std.debug.warn("(\n", .{});
|
|
|
|
|
|
|
|
|
|
for (block.toSlice()) |stmt| {
|
|
|
|
|
for (block.items) |stmt| {
|
|
|
|
|
printIdent(ident);
|
|
|
|
|
printStmt(ident, stmt);
|
|
|
|
|
std.debug.warn("\n", .{});
|
|
|
|
@ -56,7 +56,7 @@ pub fn printNode(node: *Node, ident: usize) void {
|
|
|
|
|
warn("(fn {} {} (", .{ name, ret_type });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (decl.params.toSlice()) |param| {
|
|
|
|
|
for (decl.params.items) |param| {
|
|
|
|
|
warn("({} {}) ", .{ param.name.lexeme, param.typ.lexeme });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -67,7 +67,7 @@ pub fn printNode(node: *Node, ident: usize) void {
|
|
|
|
|
.ConstDecl => |consts| {
|
|
|
|
|
print(ident, "(const (\n", .{});
|
|
|
|
|
|
|
|
|
|
for (consts.toSlice()) |const_decl| {
|
|
|
|
|
for (consts.items) |const_decl| {
|
|
|
|
|
print(ident + 1, "({} ", .{
|
|
|
|
|
const_decl.name.lexeme,
|
|
|
|
|
});
|
|
|
|
@ -82,7 +82,7 @@ pub fn printNode(node: *Node, ident: usize) void {
|
|
|
|
|
.Enum => |decl| {
|
|
|
|
|
print(ident, "(enum {} (\n", .{decl.name.lexeme});
|
|
|
|
|
|
|
|
|
|
for (decl.fields.toSlice()) |field| {
|
|
|
|
|
for (decl.fields.items) |field| {
|
|
|
|
|
print(ident + 1, "{}\n", .{
|
|
|
|
|
field.lexeme,
|
|
|
|
|
});
|
|
|
|
@ -92,7 +92,7 @@ pub fn printNode(node: *Node, ident: usize) void {
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
.Root => {
|
|
|
|
|
for (node.Root.toSlice()) |child| {
|
|
|
|
|
for (node.Root.items) |child| {
|
|
|
|
|
printNode(child, ident + 1);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
@ -105,7 +105,7 @@ pub fn printNode(node: *Node, ident: usize) void {
|
|
|
|
|
|
|
|
|
|
.Struct => |struc| {
|
|
|
|
|
print(ident, "(struct {} (\n", .{struc.name.lexeme});
|
|
|
|
|
for (struc.fields.toSlice()) |field| {
|
|
|
|
|
for (struc.fields.items) |field| {
|
|
|
|
|
printIdent(ident + 1);
|
|
|
|
|
if (field.mutable) {
|
|
|
|
|
std.debug.warn("(mut ", .{});
|
|
|
|
@ -157,7 +157,7 @@ pub fn printExpr(expr: *const Expr) void {
|
|
|
|
|
.Float => |val| std.debug.warn("{}", .{val}),
|
|
|
|
|
.String => |val| std.debug.warn("'{}'", .{val}),
|
|
|
|
|
.Array => |exprs| {
|
|
|
|
|
parenthetize("array", exprs.toSlice());
|
|
|
|
|
parenthetize("array", exprs.items);
|
|
|
|
|
},
|
|
|
|
|
else => |typ| std.debug.warn("UnknownLiteral-{}", .{typ}),
|
|
|
|
|
}
|
|
|
|
@ -188,7 +188,7 @@ pub fn printExpr(expr: *const Expr) void {
|
|
|
|
|
std.debug.warn("(", .{});
|
|
|
|
|
printExpr(call.callee);
|
|
|
|
|
|
|
|
|
|
for (call.arguments.toSlice()) |arg| {
|
|
|
|
|
for (call.arguments.items) |arg| {
|
|
|
|
|
std.debug.warn(" ", .{});
|
|
|
|
|
printExpr(arg);
|
|
|
|
|
}
|
|
|
|
@ -199,7 +199,7 @@ pub fn printExpr(expr: *const Expr) void {
|
|
|
|
|
.Struct => |val| {
|
|
|
|
|
std.debug.warn("({} (", .{val.name.lexeme});
|
|
|
|
|
|
|
|
|
|
for (val.inits.toSlice()) |init| {
|
|
|
|
|
for (val.inits.items) |init| {
|
|
|
|
|
std.debug.warn(" ({} ", .{init.field.lexeme});
|
|
|
|
|
printExpr(init.expr);
|
|
|
|
|
std.debug.warn(")", .{});
|
|
|
|
|