| ... | ... | @@ -58,8 +58,7 @@ pub fn main() !void { |
| 58 | 58 | stderr = &stderr_file.outStream().stream; |
| 59 | 59 | |
| 60 | 60 | const args = try process.argsAlloc(allocator); |
| 61 | | // TODO I'm getting unreachable code here, which shouldn't happen |
| 62 | | //defer process.argsFree(allocator, args); |
| 61 | defer process.argsFree(allocator, args); |
| 63 | 62 | |
| 64 | 63 | if (args.len <= 1) { |
| 65 | 64 | try stderr.write("expected command argument\n\n"); |
| ... | ... | @@ -67,64 +66,33 @@ pub fn main() !void { |
| 67 | 66 | process.exit(1); |
| 68 | 67 | } |
| 69 | 68 | |
| 70 | | const commands = [_]Command{ |
| 71 | | Command{ |
| 72 | | .name = "build-exe", |
| 73 | | .exec = cmdBuildExe, |
| 74 | | }, |
| 75 | | Command{ |
| 76 | | .name = "build-lib", |
| 77 | | .exec = cmdBuildLib, |
| 78 | | }, |
| 79 | | Command{ |
| 80 | | .name = "build-obj", |
| 81 | | .exec = cmdBuildObj, |
| 82 | | }, |
| 83 | | Command{ |
| 84 | | .name = "fmt", |
| 85 | | .exec = cmdFmt, |
| 86 | | }, |
| 87 | | Command{ |
| 88 | | .name = "libc", |
| 89 | | .exec = cmdLibC, |
| 90 | | }, |
| 91 | | Command{ |
| 92 | | .name = "targets", |
| 93 | | .exec = cmdTargets, |
| 94 | | }, |
| 95 | | Command{ |
| 96 | | .name = "version", |
| 97 | | .exec = cmdVersion, |
| 98 | | }, |
| 99 | | Command{ |
| 100 | | .name = "zen", |
| 101 | | .exec = cmdZen, |
| 102 | | }, |
| 103 | | |
| 104 | | // undocumented commands |
| 105 | | Command{ |
| 106 | | .name = "help", |
| 107 | | .exec = cmdHelp, |
| 108 | | }, |
| 109 | | Command{ |
| 110 | | .name = "internal", |
| 111 | | .exec = cmdInternal, |
| 112 | | }, |
| 113 | | }; |
| 114 | | |
| 115 | | inline for (commands) |command| { |
| 116 | | if (mem.eql(u8, command.name, args[1])) { |
| 117 | | var frame = try allocator.create(@Frame(command.exec)); |
| 118 | | defer allocator.destroy(frame); |
| 119 | | frame.* = async command.exec(allocator, args[2..]); |
| 120 | | return await frame; |
| 121 | | } |
| 69 | const cmd = args[1]; |
| 70 | const cmd_args = args[2..]; |
| 71 | if (mem.eql(u8, cmd, "build-exe")) { |
| 72 | return buildOutputType(allocator, cmd_args, .Exe); |
| 73 | } else if (mem.eql(u8, cmd, "build-lib")) { |
| 74 | return buildOutputType(allocator, cmd_args, .Lib); |
| 75 | } else if (mem.eql(u8, cmd, "build-obj")) { |
| 76 | return buildOutputType(allocator, cmd_args, .Obj); |
| 77 | } else if (mem.eql(u8, cmd, "fmt")) { |
| 78 | return cmdFmt(allocator, cmd_args); |
| 79 | } else if (mem.eql(u8, cmd, "libc")) { |
| 80 | return cmdLibC(allocator, cmd_args); |
| 81 | } else if (mem.eql(u8, cmd, "targets")) { |
| 82 | return cmdTargets(allocator, cmd_args); |
| 83 | } else if (mem.eql(u8, cmd, "version")) { |
| 84 | return cmdVersion(allocator, cmd_args); |
| 85 | } else if (mem.eql(u8, cmd, "zen")) { |
| 86 | return cmdZen(allocator, cmd_args); |
| 87 | } else if (mem.eql(u8, cmd, "help")) { |
| 88 | return cmdHelp(allocator, cmd_args); |
| 89 | } else if (mem.eql(u8, cmd, "internal")) { |
| 90 | return cmdInternal(allocator, cmd_args); |
| 91 | } else { |
| 92 | try stderr.print("unknown command: {}\n\n", .{args[1]}); |
| 93 | try stderr.write(usage); |
| 94 | process.exit(1); |
| 122 | 95 | } |
| 123 | | |
| 124 | | try stderr.print("unknown command: {}\n\n", .{args[1]}); |
| 125 | | try stderr.write(usage); |
| 126 | | process.argsFree(allocator, args); |
| 127 | | process.exit(1); |
| 128 | 96 | } |
| 129 | 97 | |
| 130 | 98 | const usage_build_generic = |
| ... | ... | @@ -555,18 +523,6 @@ fn processBuildEvents(comp: *Compilation, color: errmsg.Color) void { |
| 555 | 523 | } |
| 556 | 524 | } |
| 557 | 525 | |
| 558 | | fn cmdBuildExe(allocator: *Allocator, args: []const []const u8) !void { |
| 559 | | return buildOutputType(allocator, args, Compilation.Kind.Exe); |
| 560 | | } |
| 561 | | |
| 562 | | fn cmdBuildLib(allocator: *Allocator, args: []const []const u8) !void { |
| 563 | | return buildOutputType(allocator, args, Compilation.Kind.Lib); |
| 564 | | } |
| 565 | | |
| 566 | | fn cmdBuildObj(allocator: *Allocator, args: []const []const u8) !void { |
| 567 | | return buildOutputType(allocator, args, Compilation.Kind.Obj); |
| 568 | | } |
| 569 | | |
| 570 | 526 | pub const usage_fmt = |
| 571 | 527 | \\usage: zig fmt [file]... |
| 572 | 528 | \\ |