aboutsummaryrefslogtreecommitdiff
path: root/src/main.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.zig')
-rw-r--r--src/main.zig32
1 files changed, 13 insertions, 19 deletions
diff --git a/src/main.zig b/src/main.zig
index 3c21f19..87dc493 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -1,10 +1,7 @@
const std = @import("std");
const parse = @import("./parse.zig");
-const peek = @import("./peek.zig");
const codegen = @import("./codegen.zig");
-pub const peekable = peek.peekable;
-pub const Peekable = peek.Peekable;
pub const Expr = parse.Expr;
pub const Lexer = @import("./Lexer.zig");
pub const compile = @import("./compile.zig");
@@ -34,22 +31,23 @@ pub fn main() !void {
// const source = "17216961135462248174 + 4095 - 4294967295 + 2147483647";
const source = "print 18446744073709551615";
- // var lexer = Lexer{ .source = source };
- // while (true) {
- // const token = lexer.next().?;
- // std.debug.print("{}\n", .{token});
- // if (token.type == .Eof) break;
- // }
- // std.debug.print("\n", .{});
- var lexer = peekable(Lexer{ .source = source });
+ var lexer: Lexer = .{ .source = source };
+ std.debug.print("Tokens:\n", .{});
+ while (true) {
+ const token = lexer.next();
+ std.debug.print(" {}\n", .{token});
+ if (token.type == .eof) break;
+ }
+ lexer = .{ .source = source };
const expr = try parse.expression(allocator, &lexer);
std.debug.print("{}\n", .{expr});
- if (lexer.next()) |token| if (token.type != .eof) {
- std.debug.print("Unexpected token {}, expected end of file\n", .{token});
- };
const block = try compile.compile(allocator, source, expr);
+ if (lexer.peek().type != .eof) {
+ std.debug.print("Unexpected token {}, expected end of file\n", .{lexer.next()});
+ }
+ std.debug.print("Bytecode instructions:\n", .{});
for (block.instrs) |instr| {
- std.debug.print("{}\n", .{instr});
+ std.debug.print(" {}\n", .{instr});
}
const elf = try codegen.create_elf(allocator, block);
try output.writeAll(elf);
@@ -81,7 +79,3 @@ fn HashMapFormatter(HashMap: type) type {
pub fn fmtHashMap(hash_map: anytype) HashMapFormatter(@TypeOf(hash_map)) {
return .{ .data = hash_map };
}
-
-test {
- _ = peek;
-}