From 61f87806e4e0beade8597a5f7a8fdf7769a7f081 Mon Sep 17 00:00:00 2001 From: Taylan Kammer Date: Wed, 24 Jun 2026 00:25:22 +0200 Subject: Minor cleanup. --- src/zisp/io/Parser.zig | 10 +++++----- src/zisp/value.zig | 10 +++++----- src/zisp/value/fixnum.zig | 14 +++++++------- src/zisp/value/rune.zig | 2 +- src/zisp/value/sstr.zig | 2 +- 5 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/zisp/io/Parser.zig b/src/zisp/io/Parser.zig index cddd397..29b8590 100644 --- a/src/zisp/io/Parser.zig +++ b/src/zisp/io/Parser.zig @@ -84,14 +84,14 @@ pub const Error = enum { pub const Context = struct { /// What to do next. - next: ?Fn = undefined, + next: ?Fn = null, /// For storing a context value, like datum to join in join syntax. - val: Value = undefined, + val: Value = value.none, /// For storing a context char, like list opening bracket. - char: u8 = undefined, + char: u8 = 0, /// Start index of list elements on current parse level, within the global /// list element accumulation array. - list_start: usize = undefined, + list_start: usize = 0, /// Are we in a comment? comment: bool = false, }; @@ -178,7 +178,7 @@ fn readNoEof(p: *Parser, comptime emsg: []const u8) !u8 { // Fake optional, for use in: while (readNoEofOpt()) |c| { } fn readNoEofOpt(p: *Parser, comptime emsg: []const u8) !?u8 { - return try p.read() orelse p.err(.UnexpectedEof, emsg); + return try p.readNoEof(emsg); } fn unread(p: *Parser, c: u8) void { diff --git a/src/zisp/value.zig b/src/zisp/value.zig index fc815bd..c16b937 100644 --- a/src/zisp/value.zig +++ b/src/zisp/value.zig @@ -27,8 +27,8 @@ const endian = builtin.target.cpu.arch.endian(); const max = std.math.maxInt; /// Used to find the length of a rune or short string. -pub fn sstrLen(x: u64) u8 { - const bytes: @Vector(8, u8) = @bitCast(x); +pub fn sstrLen(v: *const Value) u8 { + const bytes: @Vector(8, u8) = @bitCast(v.bits); const nulls: @Vector(8, u8) = @splat(0); const comps: u8 = @bitCast(bytes == nulls); // Two bits will always be 0, since the actual short string starts at the @@ -64,16 +64,16 @@ pub const Zptr = *align(16) anyopaque; /// Values for the lowest 4 bits of a heap pointer, indicating the heap type. pub const HeapType = enum(u4) { /// Unused so the 48-bit payload of a NaN-packed pointer is never zero and - /// cannot be confused for an actual NaN even in case of a null-index. + /// cannot be confused for an actual NaN even in case of a null index. _unused = 0, - /// Array of various types (see `Array` type for details) + /// Array of various types: see `ArrayPtr`. array, pub fn PtrType(self: HeapType) type { return switch (self) { .array => array.ArrayPtr, - else => @panic("not implemented"), + else => @panic("Invalid HeapType."), }; } }; diff --git a/src/zisp/value/fixnum.zig b/src/zisp/value/fixnum.zig index 0a6dd46..1929ba2 100644 --- a/src/zisp/value/fixnum.zig +++ b/src/zisp/value/fixnum.zig @@ -23,14 +23,14 @@ pub fn assert(v: Value) void { pub const min = std.math.minInt(i52) + 1; pub const max = std.math.maxInt(i52) - 1; +fn checkValidRange(int: i64) bool { + return min < int and int < max; +} + fn assertValidRange(int: i64) void { - if (int < min) { - std.debug.print("int too small for fixnum: {}\n", .{int}); - @panic("int too small for fixnum"); - } - if (int > max) { - std.debug.print("int too large for fixnum: {}\n", .{int}); - @panic("int too large for fixnum"); + if (!checkValidRange(int)) { + std.debug.print("Fixnum out of range: {}\n", .{int}); + @panic("Fixnum out of range."); } } diff --git a/src/zisp/value/rune.zig b/src/zisp/value/rune.zig index 89f6467..67124ea 100644 --- a/src/zisp/value/rune.zig +++ b/src/zisp/value/rune.zig @@ -50,7 +50,7 @@ pub fn packForced(s: []const u8) Value { pub fn unpack(v: *const Value) []const u8 { assert(v.*); - const len = value.sstrLen(v.bits); + const len = value.sstrLen(v); return v.bufRO()[ofs .. ofs + len]; } diff --git a/src/zisp/value/sstr.zig b/src/zisp/value/sstr.zig index 59995f3..78a84e9 100644 --- a/src/zisp/value/sstr.zig +++ b/src/zisp/value/sstr.zig @@ -46,7 +46,7 @@ pub fn pack(s: []const u8) Value { pub fn unpack(v: *const Value) []const u8 { assert(v.*); - const len = value.sstrLen(v.bits); + const len = value.sstrLen(v); return v.bufRO()[ofs .. ofs + len]; } -- cgit v1.2.3