also looking at this
fix(compat): stop describing ArrayList's layout, and read it instead
#876
5 files
+88
-42
| @@ -214,22 +214,30 @@ const OperandStack = struct { | ||
| 214 | 214 | self.items[self.items.len - 1] = item; |
| 215 | 215 | } |
| 216 | 216 | |
| 217 | /// The stack as the `ArrayListUnmanaged` it is a view of, so the list can | |
| 218 | /// grow and free the buffer on the stack's behalf. | |
| 219 | /// | |
| 220 | /// Built with `initBuffer` rather than a struct literal. A literal names | |
| 221 | /// every field, and Zig 0.17.0-dev.1963 added `pointer_stability` to the | |
| 222 | /// list — so a literal that was complete on 1818 is a compile error on | |
| 223 | /// 1963. `initBuffer` fills whatever fields the current std has, and | |
| 224 | /// `items.len` is the only thing this type adds on top. | |
| 225 | fn asList(self: *const OperandStack) std.ArrayListUnmanaged(Value) { | |
| 226 | var list: std.ArrayListUnmanaged(Value) = .initBuffer(self.items.ptr[0..self.capacity]); | |
| 227 | list.items.len = self.items.len; | |
| 228 | return list; | |
| 229 | } | |
| 230 | ||
| 217 | 231 | pub fn ensureTotalCapacity(self: *OperandStack, allocator: std.mem.Allocator, new_capacity: usize) std.mem.Allocator.Error!void { |
| 218 | 232 | if (new_capacity <= self.capacity) return; |
| 219 | var list: std.ArrayListUnmanaged(Value) = .{ | |
| 220 | .items = self.items, | |
| 221 | .capacity = self.capacity, | |
| 222 | }; | |
| 233 | var list = self.asList(); | |
| 223 | 234 | try list.ensureTotalCapacity(allocator, new_capacity); |
| 224 | 235 | self.items = list.items; |
| 225 | 236 | self.capacity = list.capacity; |
| 226 | 237 | } |
| 227 | 238 | |
| 228 | 239 | noinline fn grow(self: *OperandStack, allocator: std.mem.Allocator) std.mem.Allocator.Error!void { |
| 229 | var list: std.ArrayListUnmanaged(Value) = .{ | |
| 230 | .items = self.items, | |
| 231 | .capacity = self.capacity, | |
| 232 | }; | |
| 240 | var list = self.asList(); | |
| 233 | 241 | try list.ensureTotalCapacity(allocator, self.items.len + 1); |
| 234 | 242 | self.items = list.items; |
| 235 | 243 | self.capacity = list.capacity; |
| @@ -252,10 +260,7 @@ const OperandStack = struct { | ||
| 252 | 260 | } |
| 253 | 261 | |
| 254 | 262 | pub fn deinit(self: *OperandStack, allocator: std.mem.Allocator) void { |
| 255 | var list: std.ArrayListUnmanaged(Value) = .{ | |
| 256 | .items = self.items, | |
| 257 | .capacity = self.capacity, | |
| 258 | }; | |
| 263 | var list = self.asList(); | |
| 259 | 264 | list.deinit(allocator); |
| 260 | 265 | self.* = .empty; |
| 261 | 266 | } |
| @@ -10044,7 +10049,7 @@ fn runChunk( | ||
| 10044 | 10049 | try vm.notifyDebuggerException(false); |
| 10045 | 10050 | return error.Throw; |
| 10046 | 10051 | }, |
| 10047 | .throw_not_a_reference => return vm.throwNotAReference(@enumFromInt(inst.a)), | |
| 10052 | .throw_not_a_reference => return vm.throwNotAReference(@fromBackingInt(@intCast(inst.a))), | |
| 10048 | 10053 | .push_handler, .push_handler_catch, .push_handler_outer => { |
| 10049 | 10054 | const outer = inst.op == .push_handler_outer; |
| 10050 | 10055 | if (outer and (exec.environment_depth == 0 or vm.env.parent == null)) return error.OutOfMemory; |