From fc8dcf4583a42716e904f5c89e083b6ffceac78e Mon Sep 17 00:00:00 2001 From: Luna Date: Sun, 8 Sep 2019 17:06:19 -0300 Subject: [PATCH] add doRepl func --- src/main.zig | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/main.zig b/src/main.zig index 156855e..4211446 100644 --- a/src/main.zig +++ b/src/main.zig @@ -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();