Browse Source

Fix deprecations

master
Cassidy Dingenskirchen 7 months ago
parent
commit
bbcbada927
Signed by: StDingenskirchen GPG Key ID: 14FE9712CC42FE8B
3 changed files with 8 additions and 9 deletions
  1. +6
    -7
      src/main.zig
  2. +1
    -1
      src/oidavm.zig
  3. +1
    -1
      src/parser.zig

+ 6
- 7
src/main.zig View File

@@ -34,8 +34,7 @@ pub fn main() !void {
defer file.close();
const file_content = try file.inStream().readAllAlloc(alloc, try file.getEndPos());

var timestamp = std.time.timestamp();

var timestamp = std.time.timestamp(); // `var` to avoid comptime initialization of RNG
var vm: OidaVm = .{
.memory = try parser.assemble(file_content),
.rng = std.rand.DefaultPrng.init(timestamp).random,
@@ -124,7 +123,7 @@ pub fn main() !void {
// Add breakpoint
const address_token = tokens.next() orelse continue;
const address = std.fmt.parseInt(u12, address_token, 16) catch continue;
for (breakpoints.toSlice()) |bp| {
for (breakpoints.items) |bp| {
if (bp == address) {
std.debug.warn("Breakpoint already present at 0x{X:0^3}", .{address});
continue :repl;
@@ -135,14 +134,14 @@ pub fn main() !void {
},
'l' => {
// List breakpoints
const num_breakpoints = breakpoints.toSlice().len;
const num_breakpoints = breakpoints.items.len;
const fmt_pluralize = if (num_breakpoints == 0) "s" else if (num_breakpoints == 1) ":" else "s:";

std.debug.warn("{} Breakpoint{} ", .{
num_breakpoints,
fmt_pluralize,
});
for (breakpoints.toSlice()) |bp, i| {
for (breakpoints.items) |bp, i| {
const fmt_cond_comma = if (i == num_breakpoints - 1) "" else ", ";
std.debug.warn("0x{X:0^3}{}", .{
bp,
@@ -154,7 +153,7 @@ pub fn main() !void {
// Remove breakpoint
const address_token = tokens.next() orelse continue;
const address = std.fmt.parseInt(u12, address_token, 16) catch continue;
for (breakpoints.toSlice()) |bp, i| {
for (breakpoints.items) |bp, i| {
if (bp == address) {
_ = breakpoints.orderedRemove(i);
std.debug.warn("Removed breakpoint at 0x{X:0^3}", .{address});
@@ -171,7 +170,7 @@ pub fn main() !void {
std.debug.warn("Reached cease instruction", .{});
continue :repl;
}
for (breakpoints.toSlice()) |bp| {
for (breakpoints.items) |bp| {
if (vm.instruction_ptr == bp and !(pointer_at_start == bp)) continue :repl;
}
vm.step();


+ 1
- 1
src/oidavm.zig View File

@@ -151,7 +151,7 @@ pub const OidaVm = struct {
this.accumulator = while (true) : (std.debug.warn("Please use hex format: 0000-ffff\n", .{})) {
std.debug.warn("Instruction at 0x{X:0^3} requests one word input: ", .{this.instruction_ptr});
std.io.getStdIn().inStream().readUntilDelimiterArrayList(&in_buffer, '\n', 1024) catch this.vm_panic("Failed to read from stdin", .{});
break std.fmt.parseInt(u16, in_buffer.toSlice(), 16) catch continue;
break std.fmt.parseInt(u16, in_buffer.items, 16) catch continue;
} else unreachable;
},
.Randomize => {


+ 1
- 1
src/parser.zig View File

@@ -175,7 +175,7 @@ pub fn assemble(code: []const u8) ![4096]u16 {
// Commit blocks into memory
var block_iter = blocks.iterator();
while (block_iter.next()) |block| {
for (block.value.instructions.toSlice()) |instruction, index| {
for (block.value.instructions.items) |instruction, index| {
const opcode = parse_instruction(instruction.opcode) catch {
warn("Encountered invalid opcode {}\n", .{instruction});
had_errors = true;


Loading…
Cancel
Save