Compare commits

..

No commits in common. "6b2ce7e4250719ac4b15158ec289bd3fcf645fb5" and "1987c4d497d479fe81367fa7bef9c7768518a40d" have entirely different histories.

4 changed files with 19 additions and 18 deletions

1
.gitignore vendored
View file

@ -1,5 +1,4 @@
zig-cache/ zig-cache/
zig-out/
*.mp3 *.mp3
*.wav *.wav
build_runner.zig build_runner.zig

View file

@ -161,7 +161,7 @@ pub const Image = struct {
var in_fmt = mkSfInfo(); var in_fmt = mkSfInfo();
// clone sndfile // clone sndfile
var sndfile = try sopen(self.allocator, self.curpath, c.SFM_READ, &in_fmt); var sndfile = try sopen(self.allocator, self.curpath, c.SFM_READ, &in_fmt);
std.debug.assert(self.frames == @intCast(usize, in_fmt.frames)); std.testing.expectEqual(self.frames, @intCast(usize, in_fmt.frames));
var image = try self.allocator.create(Image); var image = try self.allocator.create(Image);

View file

@ -479,24 +479,25 @@ pub const CommandList = struct {
pub fn deinit(self: *Self) void { pub fn deinit(self: *Self) void {
for (self.list.items) |cmd_ptr| { for (self.list.items) |cmd_ptr| {
//self.list.allocator.destroy(cmd_ptr);
inline for (@typeInfo(Command.Tag).Enum.fields) |field| { inline for (@typeInfo(Command.Tag).Enum.fields) |field| {
if (cmd_ptr.tag == @field(Command.Tag, field.name)) { if (cmd_ptr.tag == @field(Command.Tag, field.name)) {
const actual_tag = const actual_tag =
@field(Command.Tag, field.name); @field(Command.Tag, field.name);
// if we find a match on the tag, we can get the type // if we find a match on the tag, we can get the type
const typ = Command.tagToType(actual_tag); const typ = Command.tagToType(actual_tag);
_ = typ;
const inner_command = cmd_ptr.cast(typ).?; // TODO fix
inline for (@typeInfo(typ).Struct.fields) |cmd_field| {
switch (cmd_field.field_type) { //inline for (@typeInfo(typ).Struct.fields) |cmd_field| {
[]u8, []const u8 => self.list.allocator.free(@field(inner_command, cmd_field.name)), // switch (cmd_field.field_type) {
else => {}, // []u8, []const u8 => self.list.allocator.destroy(@field(typ, cmd_field.name)),
} // else => {},
} // }
//}
} }
} }
self.list.allocator.destroy(cmd_ptr);
} }
self.list.deinit(); self.list.deinit();
} }

View file

@ -41,7 +41,7 @@ fn copyCommandToHeap(allocator: std.mem.Allocator, command: langs.Command, compt
pub fn doRepl(allocator: std.mem.Allocator, args_it: anytype) !void { pub fn doRepl(allocator: std.mem.Allocator, args_it: anytype) !void {
var stdout_file = std.io.getStdOut(); var stdout_file = std.io.getStdOut();
const stdout = &stdout_file.writer(); const stdout = &stdout_file.writer();
const scri_path = (args_it.next() orelse @panic("expected scri path")); const scri_path = try (args_it.next(allocator) orelse @panic("expected scri path"));
errdefer allocator.free(scri_path); errdefer allocator.free(scri_path);
defer allocator.free(scri_path); defer allocator.free(scri_path);
@ -246,7 +246,8 @@ fn doRun(allocator: std.mem.Allocator, args_it: anytype) !void {
var runner = runners.Runner.init(allocator, false); var runner = runners.Runner.init(allocator, false);
defer runner.deinit(); defer runner.deinit();
const scri_path = (args_it.next() orelse @panic("run: expected scri path")); const scri_path = try (args_it.next(allocator) orelse @panic("run: expected scri path"));
defer allocator.free(scri_path);
var file = try std.fs.cwd().openFile(scri_path, .{}); var file = try std.fs.cwd().openFile(scri_path, .{});
defer file.close(); defer file.close();
@ -269,18 +270,18 @@ pub fn main() !void {
defer { defer {
_ = allocator_instance.deinit(); _ = allocator_instance.deinit();
} }
const allocator = allocator_instance.allocator(); const allocator = &allocator_instance.allocator;
var args_it = try std.process.argsWithAllocator(allocator); var args_it = std.process.args();
defer args_it.deinit();
_ = args_it.skip(); _ = args_it.skip();
const cli_command_opt = args_it.next(); const cli_command_opt = args_it.next(allocator);
if (cli_command_opt == null) { if (cli_command_opt == null) {
return doHelp(); return doHelp();
} }
const cli_command = cli_command_opt.?; const cli_command = try cli_command_opt.?;
defer allocator.free(cli_command);
if (std.mem.eql(u8, cli_command, "help")) { if (std.mem.eql(u8, cli_command, "help")) {
return doHelp(); return doHelp();