add doRepl func

This commit is contained in:
Luna 2019-09-08 17:06:19 -03:00
parent 7e8023a383
commit fc8dcf4583

View file

@ -7,6 +7,29 @@ test "scritcher" {
_ = @import("runner.zig");
}
pub fn doRepl(allocator: *std.mem.Allocator, args_it: var) !void {
const scri_path = try (args_it.next(allocator) orelse @panic("expected scri path"));
// the thing here is that 'load :0' would load the scri_path, since we
// now have a 'repl' argument right before it. to counteract that, the
// initial repl buffer contains 'load :1' instead.
var buf = langs.CommandList.init(allocator);
defer buf.deinit();
var loadargs = langs.ArgList.init(allocator);
defer loadargs.deinit();
try loadargs.append(":1");
try buf.append(langs.Command{
.command = .Load,
.args = loadargs,
});
// TODO the rest
}
pub fn main() !void {
const allocator = std.heap.direct_allocator;
@ -18,9 +41,15 @@ pub fn main() !void {
var args_it = std.process.args();
// TODO print help
_ = try (args_it.next(allocator) orelse @panic("expected exe name"));
const scri_path = try (args_it.next(allocator) orelse @panic("expected scri path"));
if (std.mem.eql(u8, scri_path, "repl")) {
return try doRepl(allocator, &args_it);
}
var file = try std.fs.File.openRead(scri_path);
defer file.close();