Compare commits

..

No commits in common. "cdca993048aea437b31d98f82a2d2c221cc659ef" and "c05be26dbdbb4e887a5f65cec5e35e6f4e6b843a" have entirely different histories.

View file

@ -27,11 +27,8 @@ pub fn doRepl(allocator: *std.mem.Allocator, args_it: var) !void {
const stdout = &stdout_file.outStream().stream; const stdout = &stdout_file.outStream().stream;
const scri_path = try (args_it.next(allocator) orelse @panic("expected scri path")); const scri_path = try (args_it.next(allocator) orelse @panic("expected scri path"));
var file_read_opt: ?std.fs.File = std.fs.File.openRead(scri_path) catch |err| blk: { var file_read = try std.fs.File.openRead(scri_path);
if (err == error.FileNotFound) break :blk null; const total_bytes = try file_read.getEndPos();
return err;
};
const total_bytes = if (file_read_opt) |file_read| try file_read.getEndPos() else 0;
var cmds = langs.CommandList.init(allocator); var cmds = langs.CommandList.init(allocator);
defer cmds.deinit(); defer cmds.deinit();
@ -44,7 +41,7 @@ pub fn doRepl(allocator: *std.mem.Allocator, args_it: var) !void {
// existing_cmds, and then passed along to cmds), // existing_cmds, and then passed along to cmds),
// we can't defer them here // we can't defer them here
var scri_existing = try allocator.alloc(u8, total_bytes); var scri_existing = try allocator.alloc(u8, total_bytes);
_ = try file_read_opt.?.read(scri_existing); _ = try file_read.read(scri_existing);
// we can defer this because we copy the Command structs back to cmds // we can defer this because we copy the Command structs back to cmds
var existing_cmds = try lang.parse(scri_existing); var existing_cmds = try lang.parse(scri_existing);
@ -67,9 +64,7 @@ pub fn doRepl(allocator: *std.mem.Allocator, args_it: var) !void {
}); });
} }
if (file_read_opt) |file_read| { file_read.close();
file_read.close();
}
var file = try std.fs.File.openWrite(scri_path); var file = try std.fs.File.openWrite(scri_path);
defer file.close(); defer file.close();
@ -111,7 +106,7 @@ pub fn doRepl(allocator: *std.mem.Allocator, args_it: var) !void {
var rd_line = readline.readline(c"> "); var rd_line = readline.readline(c"> ");
if (rd_line == null) break; if (rd_line == null) break;
readline.add_history(rd_line); readline.add_history(rd_line);
//defer std.heap.c_allocator.destroy(rd_line); defer std.heap.c_allocator.destroy(rd_line);
var line = rd_line[0..std.mem.len(u8, rd_line)]; var line = rd_line[0..std.mem.len(u8, rd_line)];