diff options
| author | hachem <im@hachem.wtf> | 2026-10-10 10:31:01 +0200 |
|---|---|---|
| committer | hachem <im@hachem.wtf> | 2026-10-10 10:31:01 +0200 |
| commit | cc8768d33a6ff6cc64306d01679a10c3a1847736 (patch) | |
| tree | 144b2f68c6e6ed482b99e45e981854bfd5db59e6 /bridge | |
| parent | 89abe49aad1ac7416844f3c5e95655ad2614392b (diff) | |
chore: small refactor
Diffstat (limited to 'bridge')
| -rw-r--r-- | bridge/bridge.zig | 28 | ||||
| -rw-r--r-- | bridge/hosts.zig | 16 | ||||
| -rw-r--r-- | bridge/serial.zig | 8 |
3 files changed, 26 insertions, 26 deletions
diff --git a/bridge/bridge.zig b/bridge/bridge.zig index 4570e3d..0b56525 100644 --- a/bridge/bridge.zig +++ b/bridge/bridge.zig @@ -27,7 +27,7 @@ const init_program = blk: { // gils shit const gils_embedded = .{ "gils", "ed" }; - for (gils_embedded) |g| s = s ++ @embedFile("k_gils_" ++ g) ++ "\n"; + for (gils_embedded) |name| s = s ++ @embedFile("k_gils_" ++ name) ++ "\n"; s = s ++ @embedFile("k_proc") ++ "\n" ++ @embedFile("k_ttf") ++ "\n" ++ @@ -114,9 +114,9 @@ pub fn onKey(scancode: u8) void { if (cb.asFunction() == null) return; g_vm_running = true; defer g_vm_running = false; - _ = vm.callFunctionParts(cb, null, &[_]revo.Value{revo.Value.new.num(scancode)}, null) catch |e| { + _ = vm.callFunctionParts(cb, null, &[_]revo.Value{revo.Value.new.num(scancode)}, null) catch |err| { serial.emit("bridge: on_key threw: "); - serial.emit(@errorName(e)); + serial.emit(@errorName(err)); serial.emit("\r\n"); }; flushConsole(vm); @@ -148,8 +148,8 @@ pub fn fsSize(name: []const u8) i64 { const name_val = vm.ownValueString(name) catch return -1; g_vm_running = true; defer g_vm_running = false; - const r = vm.callFunctionParts(func, null, &[_]revo.Value{name_val}, null) catch return -1; - return @intFromFloat(r.asNumOpt() orelse return -1); + const result = vm.callFunctionParts(func, null, &[_]revo.Value{name_val}, null) catch return -1; + return @intFromFloat(result.asNumOpt() orelse return -1); } pub fn fsReadInto(name: []const u8, offset: u64, dst: []u8) usize { @@ -158,16 +158,16 @@ pub fn fsReadInto(name: []const u8, offset: u64, dst: []u8) usize { const name_val = vm.ownValueString(name) catch return 0; g_vm_running = true; defer g_vm_running = false; - const r = vm.callFunctionParts(func, null, &[_]revo.Value{ + const result = vm.callFunctionParts(func, null, &[_]revo.Value{ name_val, revo.Value.new.num(offset), revo.Value.new.num(dst.len), }, null) catch return 0; - const sid = r.asString() orelse return 0; + const sid = result.asString() orelse return 0; const bytes = vm.stringValue(sid); - const n = @min(bytes.len, dst.len); - @memcpy(dst[0..n], bytes[0..n]); - return n; + const count = @min(bytes.len, dst.len); + @memcpy(dst[0..count], bytes[0..count]); + return count; } pub fn fsStore(name: []const u8, data: []const u8) bool { @@ -177,8 +177,8 @@ pub fn fsStore(name: []const u8, data: []const u8) bool { const data_val = vm.ownValueString(data) catch return false; g_vm_running = true; defer g_vm_running = false; - const r = vm.callFunctionParts(func, null, &[_]revo.Value{ name_val, data_val }, null) catch return false; - return (r.asNumOpt() orelse 0) == 1; + const result = vm.callFunctionParts(func, null, &[_]revo.Value{ name_val, data_val }, null) catch return false; + return (result.asNumOpt() orelse 0) == 1; } pub fn fsWriteAt(name: []const u8, offset: u64, data: []const u8) bool { @@ -188,6 +188,6 @@ pub fn fsWriteAt(name: []const u8, offset: u64, data: []const u8) bool { const data_val = vm.ownValueString(data) catch return false; g_vm_running = true; defer g_vm_running = false; - const r = vm.callFunctionParts(func, null, &[_]revo.Value{ name_val, revo.Value.new.num(@as(f64, @floatFromInt(offset))), data_val }, null) catch return false; - return (r.asNumOpt() orelse 0) == 1; + const result = vm.callFunctionParts(func, null, &[_]revo.Value{ name_val, revo.Value.new.num(@as(f64, @floatFromInt(offset))), data_val }, null) catch return false; + return (result.asNumOpt() orelse 0) == 1; } diff --git a/bridge/hosts.zig b/bridge/hosts.zig index 5f401aa..7ce5650 100644 --- a/bridge/hosts.zig +++ b/bridge/hosts.zig @@ -128,13 +128,13 @@ fn hostFillRect(args: []const revo.Value, _: *revo.VM) anyerror!HostResult { const fb = g_fb orelse return HostResult.data(Data.new.nil()); // no screen, no op const x = argInt(usize, args, 0) orelse return HostResult.other("fill_rect: bad x"); const y = argInt(usize, args, 1) orelse return HostResult.other("fill_rect: bad y"); - const w = argInt(usize, args, 2) orelse return HostResult.other("fill_rect: bad w"); - const h = argInt(usize, args, 3) orelse return HostResult.other("fill_rect: bad h"); + const width = argInt(usize, args, 2) orelse return HostResult.other("fill_rect: bad width"); + const height = argInt(usize, args, 3) orelse return HostResult.other("fill_rect: bad height"); const color = argInt(u32, args, 4) orelse return HostResult.other("fill_rect: bad color"); var yy = y; - const y_end = @min(y + h, fb.height); - const x_end = @min(x + w, fb.width); + const y_end = @min(y + height, fb.height); + const x_end = @min(x + width, fb.width); while (yy < y_end) : (yy += 1) { const row = fb.ptr + yy * fb.pitch; var xx = x; @@ -383,8 +383,8 @@ fn hostDiskWrite(args: []const revo.Value, _: *revo.VM) anyerror!HostResult { // pass shit to revo fn hostAllocContig(args: []const revo.Value, _: *revo.VM) anyerror!HostResult { - const n = argInt(u64, args, 0) orelse return HostResult.other("alloc_contig: bad count"); - return HostResult.data(Data.new.num(kops().alloc_contig(n))); + const count = argInt(u64, args, 0) orelse return HostResult.other("alloc_contig: bad count"); + return HostResult.data(Data.new.num(kops().alloc_contig(count))); } // pass shit to revo @@ -428,8 +428,8 @@ fn hostScriptSrc(args: []const revo.Value, vm: *revo.VM) anyerror!HostResult { fn hostEvalScript(args: []const revo.Value, vm: *revo.VM) anyerror!HostResult { const sid = args[0].asString() orelse return HostResult.other("eval_script: not a string"); const src = vm.stringValue(sid); - const res = revo.run.runModule(vm, "<script>", src, false) catch |e| { - return HostResult.data(try vm.ownValueString(@errorName(e))); + const res = revo.run.runModule(vm, "<script>", src, false) catch |err| { + return HostResult.data(try vm.ownValueString(@errorName(err))); }; return switch (res) { .ok => HostResult.data(Data.new.nil()), diff --git a/bridge/serial.zig b/bridge/serial.zig index f765efe..a9c3827 100644 --- a/bridge/serial.zig +++ b/bridge/serial.zig @@ -4,8 +4,8 @@ pub const Sink = *const fn ([]const u8) void; fn noopSink(_: []const u8) void {} var sink: Sink = noopSink; -pub fn setSink(s: Sink) void { - sink = s; +pub fn setSink(new_sink: Sink) void { + sink = new_sink; } // mirror everything to serial @@ -125,8 +125,8 @@ pub const SinkWriter = struct { return .{ .interface = .{ .buffer = &.{}, .vtable = &.{ .drain = drain, .flush = flush }, .end = 0 } }; } - fn drain(w: *std.Io.Writer, data: []const []const u8, splat: usize) std.Io.Writer.Error!usize { - _ = w; + fn drain(writer: *std.Io.Writer, data: []const []const u8, splat: usize) std.Io.Writer.Error!usize { + _ = writer; var total: usize = 0; for (data[0..data.len -| 1]) |slice| { if (slice.len > 0) emit(slice); |
