scritcher/src/main.zig

43 lines
1.1 KiB
Zig
Raw Normal View History

2019-07-05 19:59:45 +00:00
const std = @import("std");
2019-07-08 02:03:55 +00:00
const langs = @import("lang.zig");
2019-07-08 15:38:16 +00:00
const runners = @import("runner.zig");
2019-07-05 19:59:45 +00:00
2019-08-08 00:04:51 +00:00
test "scritcher" {
_ = @import("lang.zig");
}
2019-07-07 05:26:05 +00:00
pub fn main() !void {
var arena = std.heap.ArenaAllocator.init(std.heap.c_allocator);
2019-07-08 16:13:03 +00:00
defer arena.deinit();
2019-07-08 02:03:55 +00:00
const allocator = &arena.allocator;
var lang = langs.Lang.init(allocator);
2019-08-08 00:04:51 +00:00
defer lang.deinit();
2019-07-08 02:03:55 +00:00
2019-07-08 16:13:03 +00:00
var runner = runners.Runner.init(allocator);
defer runner.deinit();
2019-07-08 16:13:03 +00:00
2019-07-08 02:03:55 +00:00
var args_it = std.process.args();
const exe_name = try (args_it.next(allocator) orelse @panic("expected exe name"));
// args[1] is the path to scri file
const scri_path = try (args_it.next(allocator) orelse @panic("expected scri path"));
var file = try std.fs.File.openRead(scri_path);
defer file.close();
// sadly, we read it all into memory. such is life
const total_bytes = try file.getEndPos();
2019-07-08 02:03:55 +00:00
var data = try allocator.alloc(u8, total_bytes);
defer allocator.free(data);
2019-07-08 02:03:55 +00:00
_ = try file.read(data);
2019-07-08 03:09:34 +00:00
var cmds = try lang.parse(data);
defer cmds.deinit();
2019-07-08 16:13:03 +00:00
try runner.runCommands(cmds, true);
2019-07-08 02:03:55 +00:00
}