Compare commits

...

3 Commits

Author SHA1 Message Date
Luna 34481c8ea8 main: call gcc to make out executable 2019-09-29 13:16:49 -03:00
Luna 88e505b524 parser: rename main function to __rayoko_main 2019-09-29 12:46:31 -03:00
Luna f00741deca add main() to example 2019-09-29 12:03:17 -03:00
6 changed files with 21 additions and 6 deletions

1
.gitignore vendored
View File

@ -2,3 +2,4 @@ zig-cache/
*.bc
*.ll
*.o
*.out

View File

@ -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;
}

BIN
hello

Binary file not shown.

3
src/entry.c Normal file
View File

@ -0,0 +1,3 @@
int main(void) {
__rayoko_main();
}

View File

@ -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;
}

View File

@ -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);