| ... | ... | @@ -397,9 +397,11 @@ const usage_build_generic = |
| 397 | 397 | |
| 398 | 398 | const repl_help = |
| 399 | 399 | \\Commands: |
| 400 | | \\ update Detect changes to source files and update output files. |
| 401 | | \\ help Print this text |
| 402 | | \\ exit Quit this repl |
| 400 | \\ update Detect changes to source files and update output files. |
| 401 | \\ run Execute the output file, if it is an executable or test. |
| 402 | \\ update-and-run Perform an `update` followed by `run`. |
| 403 | \\ help Print this text |
| 404 | \\ exit Quit this repl |
| 403 | 405 | \\ |
| 404 | 406 | ; |
| 405 | 407 | |
| ... | ... | @@ -1990,6 +1992,15 @@ fn buildOutputType( |
| 1990 | 1992 | const stderr = std.io.getStdErr().writer(); |
| 1991 | 1993 | var repl_buf: [1024]u8 = undefined; |
| 1992 | 1994 | |
| 1995 | const ReplCmd = enum { |
| 1996 | update, |
| 1997 | help, |
| 1998 | run, |
| 1999 | update_and_run, |
| 2000 | }; |
| 2001 | |
| 2002 | var last_cmd: ReplCmd = .help; |
| 2003 | |
| 1993 | 2004 | while (watch) { |
| 1994 | 2005 | try stderr.print("(zig) ", .{}); |
| 1995 | 2006 | try comp.makeBinFileExecutable(); |
| ... | ... | @@ -1998,36 +2009,78 @@ fn buildOutputType( |
| 1998 | 2009 | continue; |
| 1999 | 2010 | }) |line| { |
| 2000 | 2011 | const actual_line = mem.trimRight(u8, line, "\r\n "); |
| 2001 | | |
| 2002 | | if (mem.eql(u8, actual_line, "update")) { |
| 2003 | | if (output_mode == .Exe) { |
| 2004 | | try comp.makeBinFileWritable(); |
| 2012 | const cmd: ReplCmd = blk: { |
| 2013 | if (mem.eql(u8, actual_line, "update")) { |
| 2014 | break :blk .update; |
| 2015 | } else if (mem.eql(u8, actual_line, "exit")) { |
| 2016 | break; |
| 2017 | } else if (mem.eql(u8, actual_line, "help")) { |
| 2018 | break :blk .help; |
| 2019 | } else if (mem.eql(u8, actual_line, "run")) { |
| 2020 | break :blk .run; |
| 2021 | } else if (mem.eql(u8, actual_line, "update-and-run")) { |
| 2022 | break :blk .update_and_run; |
| 2023 | } else if (actual_line.len == 0) { |
| 2024 | break :blk last_cmd; |
| 2025 | } else { |
| 2026 | try stderr.print("unknown command: {s}\n", .{actual_line}); |
| 2027 | continue; |
| 2005 | 2028 | } |
| 2006 | | updateModule(gpa, comp, hook) catch |err| switch (err) { |
| 2007 | | error.SemanticAnalyzeFail => continue, |
| 2008 | | else => |e| return e, |
| 2009 | | }; |
| 2010 | | } else if (mem.eql(u8, actual_line, "exit")) { |
| 2011 | | break; |
| 2012 | | } else if (mem.eql(u8, actual_line, "help")) { |
| 2013 | | try stderr.writeAll(repl_help); |
| 2014 | | } else if (mem.eql(u8, actual_line, "run")) { |
| 2015 | | try runOrTest( |
| 2016 | | comp, |
| 2017 | | gpa, |
| 2018 | | arena, |
| 2019 | | emit_bin_loc, |
| 2020 | | test_exec_args.items, |
| 2021 | | self_exe_path, |
| 2022 | | arg_mode, |
| 2023 | | target_info.target, |
| 2024 | | watch, |
| 2025 | | &comp_destroyed, |
| 2026 | | all_args, |
| 2027 | | runtime_args_start, |
| 2028 | | ); |
| 2029 | | } else { |
| 2030 | | try stderr.print("unknown command: {s}\n", .{actual_line}); |
| 2029 | }; |
| 2030 | last_cmd = cmd; |
| 2031 | switch (cmd) { |
| 2032 | .update => { |
| 2033 | if (output_mode == .Exe) { |
| 2034 | try comp.makeBinFileWritable(); |
| 2035 | } |
| 2036 | updateModule(gpa, comp, hook) catch |err| switch (err) { |
| 2037 | error.SemanticAnalyzeFail => continue, |
| 2038 | else => |e| return e, |
| 2039 | }; |
| 2040 | }, |
| 2041 | .help => { |
| 2042 | try stderr.writeAll(repl_help); |
| 2043 | }, |
| 2044 | .run => { |
| 2045 | try runOrTest( |
| 2046 | comp, |
| 2047 | gpa, |
| 2048 | arena, |
| 2049 | emit_bin_loc, |
| 2050 | test_exec_args.items, |
| 2051 | self_exe_path, |
| 2052 | arg_mode, |
| 2053 | target_info.target, |
| 2054 | watch, |
| 2055 | &comp_destroyed, |
| 2056 | all_args, |
| 2057 | runtime_args_start, |
| 2058 | ); |
| 2059 | }, |
| 2060 | .update_and_run => { |
| 2061 | if (output_mode == .Exe) { |
| 2062 | try comp.makeBinFileWritable(); |
| 2063 | } |
| 2064 | updateModule(gpa, comp, hook) catch |err| switch (err) { |
| 2065 | error.SemanticAnalyzeFail => continue, |
| 2066 | else => |e| return e, |
| 2067 | }; |
| 2068 | try comp.makeBinFileExecutable(); |
| 2069 | try runOrTest( |
| 2070 | comp, |
| 2071 | gpa, |
| 2072 | arena, |
| 2073 | emit_bin_loc, |
| 2074 | test_exec_args.items, |
| 2075 | self_exe_path, |
| 2076 | arg_mode, |
| 2077 | target_info.target, |
| 2078 | watch, |
| 2079 | &comp_destroyed, |
| 2080 | all_args, |
| 2081 | runtime_args_start, |
| 2082 | ); |
| 2083 | }, |
| 2031 | 2084 | } |
| 2032 | 2085 | } else { |
| 2033 | 2086 | break; |