fix formatting

This commit is contained in:
Jeeves 2025-03-04 22:38:24 -07:00
parent 164b947ce7
commit 5d3c733921

View file

@ -24,7 +24,7 @@ const Memory = struct {
return switch (T) { return switch (T) {
u8 => self.m[idx], u8 => self.m[idx],
u16 => @as(u16, @intCast(self.m[idx])) << 8 | self.m[idx +% 1], u16 => @as(u16, @intCast(self.m[idx])) << 8 | self.m[idx +% 1],
else => unreachable, else => @compileError("expected u8 or u16, got " + @typeName(T)),
}; };
} }
@ -35,7 +35,7 @@ const Memory = struct {
self.m[idx] = @truncate(val >> 8); self.m[idx] = @truncate(val >> 8);
self.m[idx +% 1] = @truncate(val & 0xFF); self.m[idx +% 1] = @truncate(val & 0xFF);
}, },
else => unreachable, else => @compileError("expected u8 or u16, got " + @typeName(T)),
} }
} }
}; };
@ -48,7 +48,7 @@ const Stack = struct {
return switch (T) { return switch (T) {
u8 => self.s[self.sp], u8 => self.s[self.sp],
u16 => @as(u16, @intCast(self.s[self.sp])) << 8 | self.s[self.sp +% 1], u16 => @as(u16, @intCast(self.s[self.sp])) << 8 | self.s[self.sp +% 1],
else => unreachable, else => @compileError("expected u8 or u16, got " + @typeName(T)),
}; };
} }
@ -59,7 +59,7 @@ const Stack = struct {
self.s[self.sp] = @truncate(v >> 8); self.s[self.sp] = @truncate(v >> 8);
self.s[self.sp +% 1] = @truncate(v & 0xFF); self.s[self.sp +% 1] = @truncate(v & 0xFF);
}, },
else => unreachable, else => @compileError("expected u8 or u16, got " + @typeName(T)),
} }
} }
@ -220,6 +220,7 @@ pub fn eval(self: *Uxn) bool {
0x80 => { 0x80 => {
self.ws.push(u8, self.mem.m[self.pc +% 1]); self.ws.push(u8, self.mem.m[self.pc +% 1]);
std.debug.print("LIT: {d}\n", .{self.ws.peek(u8)});
self.pc +%= 1; self.pc +%= 1;
}, // LIT }, // LIT
0x81 => inc(&self.ws, u8, true), // INCk 0x81 => inc(&self.ws, u8, true), // INCk
@ -256,6 +257,7 @@ pub fn eval(self: *Uxn) bool {
0xA0 => { 0xA0 => {
self.ws.push(u16, self.mem.m[self.pc +% 1]); self.ws.push(u16, self.mem.m[self.pc +% 1]);
std.debug.print("LIT2: {d}\n", .{self.ws.peek(u16)});
self.pc +%= 2; self.pc +%= 2;
}, // LIT2 }, // LIT2
0xA1 => inc(&self.ws, u16, true), // INC2k 0xA1 => inc(&self.ws, u16, true), // INC2k
@ -292,6 +294,7 @@ pub fn eval(self: *Uxn) bool {
0xC0 => { 0xC0 => {
self.rs.push(u8, self.mem.m[self.pc +% 1]); self.rs.push(u8, self.mem.m[self.pc +% 1]);
std.debug.print("LITr: {d}\n", .{self.rs.peek(u8)});
self.pc +%= 1; self.pc +%= 1;
}, // LITr }, // LITr
0xC1 => inc(&self.rs, u8, true), // INCkr 0xC1 => inc(&self.rs, u8, true), // INCkr
@ -328,6 +331,7 @@ pub fn eval(self: *Uxn) bool {
0xE0 => { 0xE0 => {
self.rs.push(u16, self.mem.m[self.pc +% 1]); self.rs.push(u16, self.mem.m[self.pc +% 1]);
std.debug.print("LIT2r: {d}\n", .{self.rs.peek(u16)});
self.pc +%= 2; self.pc +%= 2;
}, // LIT2r }, // LIT2r
0xE1 => inc(&self.rs, u16, true), // INC2kr 0xE1 => inc(&self.rs, u16, true), // INC2kr
@ -646,12 +650,15 @@ pub fn formatInstruction(
_ = options; _ = options;
std.debug.assert(bytes.len == 1); std.debug.assert(bytes.len == 1);
switch (bytes[0] & 0x1F) { switch (bytes[0] & 0x1F) {
0x00 => switch (bytes[0]) { 0x00 => return switch (bytes[0]) {
0x00 => try writer.writeAll("BRK"), 0x00 => try writer.writeAll("BRK"),
0x20 => try writer.writeAll("JCI"), 0x20 => try writer.writeAll("JCI"),
0x40 => try writer.writeAll("JMI"), 0x40 => try writer.writeAll("JMI"),
0x60 => try writer.writeAll("JSI"), 0x60 => try writer.writeAll("JSI"),
0x80, 0xA0, 0xC0, 0xE0 => try writer.writeAll("LIT"), 0x80 => try writer.writeAll("LIT"),
0xA0 => try writer.writeAll("LIT2"),
0xC0 => try writer.writeAll("LITr"),
0xE0 => try writer.writeAll("LIT2r"),
else => unreachable, else => unreachable,
}, },
0x01 => try writer.writeAll("INC"), 0x01 => try writer.writeAll("INC"),