diff --git a/src/lang.zig b/src/lang.zig index 305eb4a..b8f5a85 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: []u8, + path: []const u8, }; pub const Quicksave = struct { @@ -566,7 +566,6 @@ 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 541ba53..9971f24 100644 --- a/src/main.zig +++ b/src/main.zig @@ -57,16 +57,13 @@ 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"); - // 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); + try cmds.append(langs.Command{ + .command = .Load, + .args = loadargs, + }); } if (file_read_opt) |file_read| { @@ -188,7 +185,8 @@ 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")) { - return try doRepl(allocator, &args_it); + @panic("TODO bring repl back"); + // return try doRepl(allocator, &args_it); } var file = try std.fs.cwd().openFile(scri_path, .{}); diff --git a/src/printer.zig b/src/printer.zig index 3efdde7..b7592db 100644 --- a/src/printer.zig +++ b/src/printer.zig @@ -1,72 +1,12 @@ 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}); - 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), + for (cmd.args.items) |arg| { + try stream.print(" {}", .{arg}); } _ = try stream.write(";\n"); diff --git a/src/runner.zig b/src/runner.zig index 036975d..445c391 100644 --- a/src/runner.zig +++ b/src/runner.zig @@ -239,11 +239,19 @@ pub const Runner = struct { ) !void { comptime const typ = lang.Command.tagToType(tag); const command = cmd.cast(typ).?; - 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"), + 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"), + } } } @@ -289,6 +297,11 @@ 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.