DzLox

:)
git clone https://git.sr.ht/~ashymad/DzLox
Log | Files | Refs | Submodules | LICENSE

commit 351564613a2016715a2a5cf8e4f4642ca043f90b
parent ec78fb1986020c2c2b9d2b11fcad0fb6b49f17d1
Author: Szymon Mikulicz <szymon.mikulicz@posteo.net>
Date:   Fri, 21 Aug 2026 19:44:26 +0200

Small cleanup

Diffstat:
Mzlox/src/lib::list.zig | 6+-----
Mzlox/src/lib::utils.zig | 4++++
Mzlox/src/obj.zig | 20++++++++++----------
3 files changed, 15 insertions(+), 15 deletions(-)

diff --git a/zlox/src/lib::list.zig b/zlox/src/lib::list.zig @@ -2,10 +2,6 @@ const std = @import("std"); const utils = @import("lib::utils.zig"); -fn sign(v: anytype) @TypeOf(v) { - return if (v >= 0) 1 else -1; -} - pub fn List(T: type) type { return struct { const Self = @This(); @@ -152,7 +148,7 @@ pub fn List(T: type) type { fn _at(self: *Self, idx: isize) Error!*Element { if (self.tip) |tip| { - const haf: isize = sign(idx) * @divTrunc(self._len, 2); + const haf: isize = utils.sign(idx) * @divTrunc(self._len, 2); return tip.jmp(@rem(idx + haf, self._len) - haf); } else { return Error.Empty; diff --git a/zlox/src/lib::utils.zig b/zlox/src/lib::utils.zig @@ -1,5 +1,9 @@ const std = @import("std"); +pub fn sign(v: anytype) @TypeOf(v) { + return if (v >= 0) 1 else -1; +} + pub fn with_size(T: type, comptime size: std.lang.Type.Pointer.Size) type { return mod_ptr_t(T, "size", size); } diff --git a/zlox/src/obj.zig b/zlox/src/obj.zig @@ -2,15 +2,6 @@ const std = @import("std"); const utils = @import("lib::utils.zig"); -fn nameOf(fqn: []const u8) []const u8 { - var lastDot = 0; - for (fqn, 0..) |c, i| { - if (c == '.') lastDot = i + 1; - if (c == '(') return fqn[lastDot..i]; - } - return fqn; -} - pub fn Obj(fields: anytype) type { return packed struct { const Self = @This(); @@ -42,6 +33,15 @@ pub fn Obj(fields: anytype) type { } }; + fn child_name(fqn: []const u8) []const u8 { + var lastDot = 0; + for (fqn, 0..) |c, i| { + if (c == '.') lastDot = i + 1; + if (c == '(') return fqn[lastDot..i]; + } + return fqn; + } + pub fn is_child(T: type) bool { inline for (std.meta.tags(Type)) |tag| { if (*tag.get() == T) return true; @@ -51,7 +51,7 @@ pub fn Obj(fields: anytype) type { pub fn make(child: type) Self { return Self{ - .type = @field(Type, nameOf(@typeName(child))), + .type = @field(Type, child_name(@typeName(child))), }; }