Compare commits
2 Commits
9937365433
...
73c5214146
Author | SHA1 | Date |
---|---|---|
Luna | 73c5214146 | |
Luna | 32b01976d8 |
50
src/main.zig
50
src/main.zig
|
@ -230,6 +230,13 @@ pub fn doRepl(allocator: *std.mem.Allocator, args_it: anytype) !void {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn doHelp() void {
|
||||||
|
std.debug.warn("scritcher!\n", .{});
|
||||||
|
std.debug.warn("usage: scritcher [run|help|repl]\n", .{});
|
||||||
|
std.debug.warn("\tscritcher run path_to_script.scri path_to_input_file.bmp\n", .{});
|
||||||
|
std.debug.warn("\tscritcher repl path_to_script.scri path_to_input_file.bmp\n", .{});
|
||||||
|
}
|
||||||
|
|
||||||
pub fn main() !void {
|
pub fn main() !void {
|
||||||
// const allocator = std.heap.page_allocator;
|
// const allocator = std.heap.page_allocator;
|
||||||
var allocator_instance = std.heap.GeneralPurposeAllocator(.{}){};
|
var allocator_instance = std.heap.GeneralPurposeAllocator(.{}){};
|
||||||
|
@ -248,25 +255,38 @@ pub fn main() !void {
|
||||||
|
|
||||||
// TODO print help
|
// TODO print help
|
||||||
_ = args_it.skip();
|
_ = args_it.skip();
|
||||||
const scri_path = try (args_it.next(allocator) orelse @panic("expected scri path or 'repl'"));
|
const cli_command_opt = args_it.next(allocator);
|
||||||
defer allocator.free(scri_path);
|
if (cli_command_opt == null) {
|
||||||
|
return doHelp();
|
||||||
if (std.mem.eql(u8, scri_path, "repl")) {
|
|
||||||
return try doRepl(allocator, &args_it);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var file = try std.fs.cwd().openFile(scri_path, .{});
|
const cli_command = try cli_command_opt.?;
|
||||||
defer file.close();
|
defer allocator.free(cli_command);
|
||||||
|
|
||||||
// sadly, we read it all into memory. such is life
|
if (std.mem.eql(u8, cli_command, "help")) {
|
||||||
const total_bytes = try file.getEndPos();
|
return doHelp();
|
||||||
|
} else if (std.mem.eql(u8, cli_command, "repl")) {
|
||||||
|
return try doRepl(allocator, &args_it);
|
||||||
|
} else if (std.mem.eql(u8, cli_command, "run")) {
|
||||||
|
const scri_path = try (args_it.next(allocator) orelse @panic("run: expected scri path"));
|
||||||
|
defer allocator.free(scri_path);
|
||||||
|
|
||||||
var data = try allocator.alloc(u8, total_bytes);
|
var file = try std.fs.cwd().openFile(scri_path, .{});
|
||||||
defer allocator.free(data);
|
defer file.close();
|
||||||
_ = try file.read(data);
|
|
||||||
|
|
||||||
var cmds = try lang.parse(data);
|
// sadly, we read it all into memory. such is life
|
||||||
defer cmds.deinit();
|
const total_bytes = try file.getEndPos();
|
||||||
|
|
||||||
try runner.runCommands(cmds, true);
|
var data = try allocator.alloc(u8, total_bytes);
|
||||||
|
defer allocator.free(data);
|
||||||
|
_ = try file.read(data);
|
||||||
|
|
||||||
|
var cmds = try lang.parse(data);
|
||||||
|
defer cmds.deinit();
|
||||||
|
|
||||||
|
try runner.runCommands(cmds, true);
|
||||||
|
} else {
|
||||||
|
std.debug.warn("unknown command: '{s}'\n", .{cli_command});
|
||||||
|
return error.UnknownCommand;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,7 +65,7 @@ pub const Runner = struct {
|
||||||
// 'scritcher repl ./script ./image'
|
// 'scritcher repl ./script ./image'
|
||||||
|
|
||||||
// ':0' should ALWAYS point to the image.
|
// ':0' should ALWAYS point to the image.
|
||||||
if (self.repl) index += 3 else index += 2;
|
if (self.repl) index += 4 else index += 3;
|
||||||
|
|
||||||
for (self.args) |arg, idx| {
|
for (self.args) |arg, idx| {
|
||||||
std.debug.warn("arg{d} = {s}\n", .{ idx, arg });
|
std.debug.warn("arg{d} = {s}\n", .{ idx, arg });
|
||||||
|
|
Loading…
Reference in New Issue