aboutsummaryrefslogtreecommitdiff
path: root/src/main.zig
diff options
context:
space:
mode:
authorMathias Magnusson <mathias@magnusson.space>2025-06-03 00:34:15 +0200
committerMathias Magnusson <mathias@magnusson.space>2025-06-03 00:34:15 +0200
commit5a421bb91780e74404d83df2e99d7469b3cb8b90 (patch)
treee0b4fdf996701d7f143a59201f227c7013313e75 /src/main.zig
parente2e77b4b06e51c7f7d3ea187defaf1ad08e513c1 (diff)
downloadhuginn-5a421bb91780e74404d83df2e99d7469b3cb8b90.tar.gz
add { blocks } with scoped local variables
Diffstat (limited to 'src/main.zig')
-rw-r--r--src/main.zig21
1 files changed, 12 insertions, 9 deletions
diff --git a/src/main.zig b/src/main.zig
index a9c77ac..9678d0b 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -37,9 +37,15 @@ pub fn main() !void {
// }
const source =
- \\let x = read_int(0);
- \\print(18446744073709551615);
- \\print(x + x);
+ \\{
+ \\ let x = 69;
+ \\ {
+ \\ let x = read_int(0);
+ \\ print(18446744073709551615);
+ \\ print(x + x);
+ \\ }
+ \\ print(x);
+ \\}
;
var lexer: Lexer = .{ .source = source };
std.debug.print("Tokens:\n", .{});
@@ -49,15 +55,12 @@ pub fn main() !void {
if (token.type == .eof) break;
}
lexer = .{ .source = source };
- const stmts = try parse.statements(allocator, &lexer);
- std.debug.print("Statements:\n", .{});
- for (stmts) |stmt| {
- std.debug.print(" {}\n", .{stmt.fmt(source)});
- }
+ const ast = try parse.block(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()});
}
- const block = try compile.compile(allocator, source, stmts);
+ const block = try compile.compile(allocator, source, ast);
std.debug.print("Bytecode instructions:\n", .{});
for (block.instrs) |instr| {
std.debug.print(" {}\n", .{instr});