diff --git a/.gitignore b/.gitignore index 7f3834b..86de850 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ zig-cache/ *.bc *.ll *.o +*.out diff --git a/examples/hello.ry b/examples/hello.ry index 3b05145..961e4aa 100644 --- a/examples/hello.ry +++ b/examples/hello.ry @@ -29,8 +29,6 @@ fn add(a: i32, b: i32) i32 { return a + b; } -// type is void by default -//fn main() { -// print("piss\n"); -// // print("2 + 2 = %d\n", add(1, 2)); -//} +fn main() i32 { + return 1; +} diff --git a/hello b/hello deleted file mode 100755 index a4b5094..0000000 Binary files a/hello and /dev/null differ diff --git a/src/entry.c b/src/entry.c new file mode 100644 index 0000000..b2119d0 --- /dev/null +++ b/src/entry.c @@ -0,0 +1,3 @@ +int main(void) { + __rayoko_main(); +} diff --git a/src/main.zig b/src/main.zig index 2becea9..a249060 100644 --- a/src/main.zig +++ b/src/main.zig @@ -59,6 +59,13 @@ pub fn run(allocator: *std.mem.Allocator, slice: []const u8) !Result { var cgen = codegen.Codegen.init(allocator, &ctx); try cgen.gen(root); + var child = try std.ChildProcess.init( + [_][]const u8{ "gcc", "src/entry.c", "outpath.o", "-o", "a.out" }, + allocator, + ); + try child.spawn(); + _ = try child.wait(); + return Result.Ok; } diff --git a/src/parsers.zig b/src/parsers.zig index 81c83cb..7fa359b 100644 --- a/src/parsers.zig +++ b/src/parsers.zig @@ -464,7 +464,13 @@ pub const Parser = struct { method = try self.parsePreMethod(); } - const name = try self.consumeSingle(.Identifier); + const orig_name = try self.consumeSingle(.Identifier); + + const name = if (std.mem.eql(u8, orig_name.lexeme, "main")) blk: { + break :blk try self.mkToken(.Identifier, "__rayoko_main", orig_name.line); + } else blk: { + break :blk orig_name; + }; self.setErrContext("function {}", name.lexeme);