Generate hello world Zig code

This commit is contained in:
2025-05-24 16:38:46 -05:00
parent d002309e93
commit 44f3cfca5c
3 changed files with 129 additions and 35 deletions

View File

@@ -19,21 +19,49 @@ func Expect[T cmp.Ordered](expected, actual T) error {
func TestHelloWorld(t *testing.T) {
expected := `//! Hello, world!
const std = @import("std");
fn main() void {
return;
std.debug.print("Hello, world!\n", .{});
}
`
root := &zig.Root{
ContainerDocComment: "Hello, world!",
ContainerMembers: []*zig.ContainerMember{
{
Decl: &zig.GlobalVarDecl{
Const: true,
Name: "std",
Value: &zig.CallExpr{
Fun: &zig.Identifier{Name: "@import"},
Args: []zig.Expr{
&zig.Literal{Kind: "string", Value: "std"},
},
},
},
},
{
Decl: &zig.FnDecl{
Name: "main",
ReturnType: &zig.Identifier{Name: "void"},
Body: &zig.Block{
Stmts: []zig.Stmt{
&zig.ReturnStmt{},
&zig.ExprStmt{
Expr: &zig.CallExpr{
Fun: &zig.FieldAccessExpr{
Receiver: &zig.FieldAccessExpr{
Receiver: &zig.Identifier{Name: "std"},
Field: "debug",
},
Field: "print",
},
Args: []zig.Expr{
&zig.Literal{Kind: "string", Value: "Hello, world!\n"},
&zig.InitListExpr{Empty: true},
},
},
},
},
},
},