diff --git a/source/coral/slab.zig b/source/coral/slab.zig index 6d1957e..4dd6d30 100644 --- a/source/coral/slab.zig +++ b/source/coral/slab.zig @@ -52,17 +52,6 @@ pub fn Map(comptime index_int: std.builtin.Type.Int, comptime Value: type) type entry.value = value; } - /// - /// Fetches the value referenced by `index` in `self`, returning it. - /// - pub fn fetch(self: *Self, index: Index) Value { - const entry = &self.table[index]; - - debug.assert(entry.* == .value); - - return entry.value; - } - /// /// Deinitializes `self` and sets it to an invalid state, freeing all memory allocated by `allocator`. /// @@ -81,6 +70,17 @@ pub fn Map(comptime index_int: std.builtin.Type.Int, comptime Value: type) type self.free_index = 0; } + /// + /// Fetches the value referenced by `index` in `self`, returning it. + /// + pub fn fetch(self: *Self, index: Index) Value { + const entry = &self.table[index]; + + debug.assert(entry.* == .value); + + return entry.value; + } + /// /// Attempts to grow the internal buffer of `self` by `growth_amount` using `allocator`. /// @@ -147,12 +147,20 @@ pub fn Map(comptime index_int: std.builtin.Type.Int, comptime Value: type) type debug.assert(entry.* == .free_index); + self.count += 1; self.free_index = entry.free_index; entry.* = .{.value = value}; return entry_index; } + /// + /// Returns `true` if `self` contains no values, otherwise `false`. + /// + pub fn is_empty(self: Self) bool { + return self.count == 0; + } + /// /// Removes the value referenced by `index` from `self`. /// @@ -161,6 +169,7 @@ pub fn Map(comptime index_int: std.builtin.Type.Int, comptime Value: type) type debug.assert(entry.* == .value); + self.count -= 1; entry.* = .{.free_index = self.free_index}; self.free_index = index; } diff --git a/source/ona/kym/Environment.zig b/source/ona/kym/Environment.zig index 4969f3b..b23c243 100644 --- a/source/ona/kym/Environment.zig +++ b/source/ona/kym/Environment.zig @@ -183,6 +183,7 @@ pub fn deinit(self: *Self) void { self.interned.deinit(self.allocator); self.values.deinit(self.allocator); self.calls.deinit(self.allocator); + coral.debug.assert(self.heap.is_empty()); self.heap.deinit(self.allocator); }