aboutsummaryrefslogtreecommitdiff
path: root/src/main.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.zig')
-rw-r--r--src/main.zig47
1 files changed, 14 insertions, 33 deletions
diff --git a/src/main.zig b/src/main.zig
index 367edf8..5873c66 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -14,45 +14,26 @@ pub fn main() !void {
var args = std.process.args();
_ = args.next();
+ const in_path = args.next();
+ const in_file = if (in_path) |path|
+ try std.fs.cwd().openFile(path, .{})
+ else
+ std.io.getStdIn();
+
const out_path = args.next();
const out_file = if (out_path) |path|
try std.fs.cwd().createFile(path, .{ .mode = 0o777 })
else
std.io.getStdOut();
+
const run = if (args.next()) |arg| std.mem.eql(u8, arg, "run") else false;
- // var br = std.io.bufferedReader(std.io.getStdIn().reader());
- // const stdin = br.reader();
- //
- // var line: std.ArrayList(u8) = .init(alloc);
- // defer line.deinit();
- // while (true) {
- // try stdin.streamUntilDelimiter(line.writer(), '\n', null);
- //
- // const lexer = Lexer{.source = line};
- //
- // try stdout.print("{s}\n", .{line.items});
- // }
+ const source = try in_file.readToEndAlloc(
+ allocator,
+ 640 * 1024, // ought to be enough for anyone
+ );
+ defer allocator.free(source);
- const source =
- \\{
- \\ let x = 10
- \\ let y = 0
- \\ print(x > y)
- \\ while y < 3 {
- \\ x = x + x
- \\ y = y + 1
- \\ }
- \\ if x {
- \\ # let x = read_int(0)
- \\ # print(18446744073709551615)
- \\ x = x + x
- \\ } else {
- \\ x = 69
- \\ }
- \\ print(x)
- \\}
- ;
var lexer: Lexer = .{ .source = source };
std.debug.print("Tokens:\n", .{});
while (true) {
@@ -61,7 +42,7 @@ pub fn main() !void {
if (token.type == .eof) break;
}
lexer = .{ .source = source };
- const ast = try parse.block(allocator, &lexer);
+ const ast = try parse.file(allocator, &lexer);
std.debug.print("Parse tree:\n{}\n", .{parse.fmt(ast, source, 0)});
if (lexer.peek().type != .eof) {
std.debug.print("Unexpected token {}, expected end of file\n", .{lexer.next()});
@@ -81,7 +62,7 @@ pub fn main() !void {
else
&.{ "qemu-riscv64", out_path.? },
);
- std.debug.print("{}\n{any}\n", .{err, @errorReturnTrace()});
+ std.debug.print("{}\n{any}\n", .{ err, @errorReturnTrace() });
}
}