From 9cb82e3180b2325ab95170f81e60c415f41fee36 Mon Sep 17 00:00:00 2001 From: Luna Date: Mon, 1 Jun 2020 22:34:48 -0300 Subject: [PATCH 1/5] remove unecessary code --- src/runner.zig | 23 +++++------------------ 1 file changed, 5 insertions(+), 18 deletions(-) diff --git a/src/runner.zig b/src/runner.zig index 445c391..036975d 100644 --- a/src/runner.zig +++ b/src/runner.zig @@ -239,19 +239,11 @@ pub const Runner = struct { ) !void { comptime const typ = lang.Command.tagToType(tag); const command = cmd.cast(typ).?; - inline for (@typeInfo(typ).Struct.decls) |decl| { - comptime { - if (!std.mem.eql(u8, decl.name, "command_type")) { - continue; - } - } - - const ctype = typ.command_type; - switch (ctype) { - .lv2_command => try self.executeLV2Command(command.*), - .custom_command => try self.executeCustomCommand(command.*), - else => @panic("TODO support command type"), - } + const ctype = typ.command_type; + switch (ctype) { + .lv2_command => try self.executeLV2Command(command.*), + .custom_command => try self.executeCustomCommand(command.*), + else => @panic("TODO support command type"), } } @@ -297,11 +289,6 @@ pub const Runner = struct { .wildnoise => try self.runSingleCommand(cmd, .wildnoise), .write => try self.runSingleCommand(cmd, .write), .embed => try self.runSingleCommand(cmd, .embed), - - else => { - std.debug.warn("TODO support {}\n", .{@tagName(cmd.tag)}); - @panic("TODO support tag"); - }, } } /// Run a list of commands. From e71eba583e2a92928d72821e2444c35ced987979 Mon Sep 17 00:00:00 2001 From: Luna Date: Mon, 1 Jun 2020 22:34:56 -0300 Subject: [PATCH 2/5] make load command own its path memory --- src/lang.zig | 3 ++- src/main.zig | 15 +++++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/lang.zig b/src/lang.zig index b8f5a85..305eb4a 100644 --- a/src/lang.zig +++ b/src/lang.zig @@ -159,7 +159,7 @@ pub const Command = struct { pub const Load = struct { pub const base_tag = Tag.load; base: Command, - path: []const u8, + path: []u8, }; pub const Quicksave = struct { @@ -566,6 +566,7 @@ pub const Lang = struct { usize => try std.fmt.parseInt(usize, arg, 10), i32 => try std.fmt.parseInt(i32, arg, 10), f32 => try std.fmt.parseFloat(f32, arg), + []u8 => try self.allocator.dupe(u8, arg), []const u8 => try self.allocator.dupe(u8, arg), else => @compileError("Invalid parameter type (" ++ @typeName(cmd_field.field_type) ++ ") left on command struct " ++ @typeName(command_struct) ++ "."), }; diff --git a/src/main.zig b/src/main.zig index 9971f24..1553aff 100644 --- a/src/main.zig +++ b/src/main.zig @@ -57,13 +57,16 @@ pub fn doRepl(allocator: *std.mem.Allocator, args_it: var) !void { } else { // if there isn't any commands on the file, we load our default // 'load :0' command - var loadargs = langs.ArgList.init(allocator); - try loadargs.append(":0"); - try cmds.append(langs.Command{ - .command = .Load, - .args = loadargs, - }); + // TODO: deliberate memleak here. we only allocate this + // command once, for the start of the file, so. + var load_cmd = try allocator.create(langs.Command.Load); + std.mem.copy(u8, load_cmd.path, ":0"); + load_cmd.base.tag = langs.Command.Tag.load; + + // taking address is fine, because load_cmd lives in the lifetime + // of the allocator. + try cmds.append(&load_cmd.base); } if (file_read_opt) |file_read| { From 128f58c5022104937c7d08cbefd1ffb83acfe737 Mon Sep 17 00:00:00 2001 From: Luna Date: Mon, 1 Jun 2020 22:35:07 -0300 Subject: [PATCH 3/5] re-enable repl --- src/main.zig | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main.zig b/src/main.zig index 1553aff..541ba53 100644 --- a/src/main.zig +++ b/src/main.zig @@ -188,8 +188,7 @@ pub fn main() !void { const scri_path = try (args_it.next(allocator) orelse @panic("expected scri path or 'repl'")); if (std.mem.eql(u8, scri_path, "repl")) { - @panic("TODO bring repl back"); - // return try doRepl(allocator, &args_it); + return try doRepl(allocator, &args_it); } var file = try std.fs.cwd().openFile(scri_path, .{}); From f973d6807daa3d34cb1d14c47b3010419962d61b Mon Sep 17 00:00:00 2001 From: Luna Date: Mon, 1 Jun 2020 22:35:16 -0300 Subject: [PATCH 4/5] add basics of printing under new command structure --- src/printer.zig | 66 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 64 insertions(+), 2 deletions(-) diff --git a/src/printer.zig b/src/printer.zig index b7592db..73a0e8a 100644 --- a/src/printer.zig +++ b/src/printer.zig @@ -1,12 +1,74 @@ const langs = @import("lang.zig"); +pub fn printCommand(cmd: langs.Command, comptime tag: langs.Command.Tag) !void { + const CommandStruct = langs.Command.tagToType(tag); + const casted = cmd.cast(CommandStruct).?; + + // TODO move this to Tag method? + const is_typed = switch (tag) { + .noop, .load, .quicksave, .runqs, .rotate => false, + else => true, + }; + + const ctype = typ.command_type; + switch (ctype) { + .lv2_command => try printLV2Command(casted), + .custom_command => try printCustomCommand(casted), + else => @panic("TODO support command type"), + } +} + pub fn printList(list: langs.CommandList, stream: var) !void { for (list.items) |cmd| { const command = @tagName(cmd.tag); try stream.print("{}", .{command}); - for (cmd.args.items) |arg| { - try stream.print(" {}", .{arg}); + switch (cmd.tag) { + .load => { + const load = command.cast(langs.Command.Load).?; + try stream.print("{}", .{load.path}); + }, + .quicksave => {}, + .rotate => { + const rotate = command.cast(langs.Command.Rotate).?; + try stream.print("{} {}", .{ rotate.deg, rotate.bgfill }); + }, + + .amp => try printCommand(cmd, .amp), + .rflanger => try printCommand(cmd, .rflanger), + .eq => try printCommand(cmd, .eq), + .phaser => try printCommand(cmd, .phaser), + .mbeq => try printCommand(cmd, .mbeq), + .chorus => try printCommand(cmd, .chorus), + .pitchscaler => try printCommand(cmd, .pitchscaler), + .reverb => try printCommand(cmd, .reverb), + .highpass => try printCommand(cmd, .highpass), + .delay => try printCommand(cmd, .delay), + .vinyl => try printCommand(cmd, .vinyl), + .revdelay => try printCommand(cmd, .revdelay), + .gate => try printCommand(cmd, .gate), + .detune => try printCommand(cmd, .detune), + .overdrive => try printCommand(cmd, .overdrive), + .degrade => try printCommand(cmd, .degrade), + .repsycho => try printCommand(cmd, .repsycho), + .talkbox => try printCommand(cmd, .talkbox), + .dyncomp => try printCommand(cmd, .dyncomp), + .thruzero => try printCommand(cmd, .thruzero), + .foverdrive => try printCommand(cmd, .foverdrive), + .gverb => try printCommand(cmd, .gverb), + .invert => try printCommand(cmd, .invert), + .tapedelay => try printCommand(cmd, .tapedelay), + .moddelay => try printCommand(cmd, .moddelay), + .multichorus => try printCommand(cmd, .multichorus), + .saturator => try printCommand(cmd, .saturator), + .vintagedelay => try printCommand(cmd, .vintagedelay), + + .noise => try printCommand(cmd, .noise), + .wildnoise => try printCommand(cmd, .wildnoise), + .write => try printCommand(cmd, .write), + .embed => try printCommand(cmd, .embed), + + else => @compileError("unhandled command"), } _ = try stream.write(";\n"); From b06bab9ec56bc10f5eddcd89398b5dbee311c944 Mon Sep 17 00:00:00 2001 From: Luna Date: Mon, 1 Jun 2020 22:35:29 -0300 Subject: [PATCH 5/5] remove unecessary compileError call --- src/printer.zig | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/printer.zig b/src/printer.zig index 73a0e8a..3efdde7 100644 --- a/src/printer.zig +++ b/src/printer.zig @@ -67,8 +67,6 @@ pub fn printList(list: langs.CommandList, stream: var) !void { .wildnoise => try printCommand(cmd, .wildnoise), .write => try printCommand(cmd, .write), .embed => try printCommand(cmd, .embed), - - else => @compileError("unhandled command"), } _ = try stream.write(";\n");