From cc8768d33a6ff6cc64306d01679a10c3a1847736 Mon Sep 17 00:00:00 2001 From: hachem Date: Sat, 10 Oct 2026 10:31:01 +0200 Subject: chore: small refactor --- bridge/bridge.zig | 28 ++++++++++++++-------------- bridge/hosts.zig | 16 ++++++++-------- bridge/serial.zig | 8 ++++---- 3 files changed, 26 insertions(+), 26 deletions(-) (limited to 'bridge') 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, "