aboutsummaryrefslogtreecommitdiff
path: root/src/main.zig
blob: ff4f09b88f26587772f8f301993ad96b97d246c6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
const std = @import("std");
const interpreter = @import("interpreter.zig");
const io = @import("io.zig");

pub fn main() anyerror!void {
    var gpa = std.heap.GeneralPurposeAllocator(.{}){};
    defer std.debug.assert(!gpa.deinit());
    var args = try std.process.argsAlloc(gpa.allocator());
    defer std.process.argsFree(gpa.allocator(), args);
    if (args.len < 2) {
        std.debug.print("Usage: {s} <b98_file_to_run>\n", .{args[0]});
        std.os.exit(1);
    }

    var file = try std.fs.cwd().openFile("mycology/sanity.bf", .{});
    defer file.close();

    var i = try interpreter.Interpreter.init(gpa.allocator(), file.reader(), io.defaultFunctions, args);
    defer i.deinit();

    std.os.exit(@intCast(u8, try i.run()));
}

test "all" {
    std.testing.refAllDecls(@This());
}
test "sanity" {
    var file = try std.fs.cwd().openFile("mycology/sanity.bf", .{});
    defer file.close();
    const args = [_][]const u8{"sanity"};
    var i = try interpreter.Interpreter.init(std.testing.allocator, file.reader(), io.defaultFunctions, args[0..]);
    defer i.deinit();
    try std.testing.expectEqual(try i.run(), 0);
}