~ntgg/PGLang

22f028b6b30afb166b0d5b258c8e1d0abc86652d — Noah Graff 7 months ago 5b56eb7
Do some more parse-time checking

This results in ~1 second of speedup for mandelbrot.bf on my laptop
2 files changed, 7 insertions(+), 1 deletions(-)

M src/main.zig
M src/parse.zig
M src/main.zig => src/main.zig +2 -1
@@ 71,7 71,8 @@ pub const VM = struct {
                cell.* = try vm.stdin.readByte();
            },
            .LoopStart => |end| if (cell.* == 0) {
                vm.current_instr = end orelse return error.MismatchedLoop;
                // parse returns only vaild code, so .? is safe
                vm.current_instr = end.?;
            },
            .LoopEnd => |start| if (cell.* != 0) {
                vm.current_instr = start;

M src/parse.zig => src/parse.zig +5 -0
@@ 147,6 147,11 @@ pub fn parse(allocator: *Allocator, source: []const u8) !std.ArrayList(Instructi
        }
    }

    for (instructions.toSliceConst()) |instr| switch (instr) {
        .LoopStart => |maybe| if (maybe == null) return error.MismatchedLoop,
        else => {},
    };

    return instructions;
}