diff --git a/src/Ast.zig b/src/Ast.zig index 948a9d4d..a09eb7fe 100644 --- a/src/Ast.zig +++ b/src/Ast.zig @@ -1002,10 +1002,14 @@ fn binaryValue(self: Self, node: Node.Index, gc: *GarbageCollector) !?Value { }, )).toValue(); } else { - var new_map = try left_map.?.map.clone(); + var new_map = try left_map.?.map.clone(gc.allocator); var it = right_map.?.map.iterator(); while (it.next()) |entry| { - try new_map.put(entry.key_ptr.*, entry.value_ptr.*); + try new_map.put( + gc.allocator, + entry.key_ptr.*, + entry.value_ptr.*, + ); } return (try gc.allocateObject( @@ -1161,6 +1165,7 @@ pub fn toValue(self: Self, node: Node.Index, gc: *GarbageCollector) Error!Value for (components.entries) |entry| { try map.map.put( + gc.allocator, try self.toValue(entry.key, gc), try self.toValue(entry.value, gc), ); diff --git a/src/builtin/map.zig b/src/builtin/map.zig index 6056bed5..5479f675 100644 --- a/src/builtin/map.zig +++ b/src/builtin/map.zig @@ -28,8 +28,8 @@ pub fn clone(ctx: *NativeCtx) c_int { ctx.vm.panic("Out of memory"); unreachable; }; - new_map.map.deinit(); - new_map.map = self.map.clone() catch { + new_map.map.deinit(ctx.vm.gc.allocator); + new_map.map = self.map.clone(ctx.vm.gc.allocator) catch { ctx.vm.panic("Out of memory"); unreachable; }; @@ -131,7 +131,9 @@ pub fn map(ctx: *NativeCtx) c_int { const self = ObjMap.cast(ctx.vm.peek(1).obj()).?; const closure = ObjClosure.cast(ctx.vm.peek(0).obj()).?; - const mapped_type = closure.function.type_def.resolved_type.?.Function.return_type.resolved_type.?.ObjectInstance.resolved_type.?.Object; + const mapped_type = closure.function.type_def.resolved_type.?.Function + .return_type.resolved_type.?.ObjectInstance + .resolved_type.?.Object; var new_map: *ObjMap = ctx.vm.gc.allocateObject( ObjMap, diff --git a/src/buzz_api.zig b/src/buzz_api.zig index 59187a15..f741117b 100644 --- a/src/buzz_api.zig +++ b/src/buzz_api.zig @@ -596,10 +596,14 @@ export fn bz_mapConcat(vm: *VM, map: Value, other_map: Value) Value { const left: *ObjMap = ObjMap.cast(map.obj()).?; const right: *ObjMap = ObjMap.cast(other_map.obj()).?; - var new_map = left.map.clone() catch @panic("Could not concatenate maps"); + var new_map = left.map.clone(vm.gc.allocator) catch @panic("Could not concatenate maps"); var it = right.map.iterator(); while (it.next()) |entry| { - new_map.put(entry.key_ptr.*, entry.value_ptr.*) catch @panic("Could not concatenate maps"); + new_map.put( + vm.gc.allocator, + entry.key_ptr.*, + entry.value_ptr.*, + ) catch @panic("Could not concatenate maps"); } return (vm.gc.allocateObject(ObjMap, ObjMap{ diff --git a/src/obj.zig b/src/obj.zig index 0f053626..f4ce1965 100644 --- a/src/obj.zig +++ b/src/obj.zig @@ -153,11 +153,13 @@ pub const Obj = struct { ) catch return error.OutOfMemory; serialized_range.map.put( + vm.gc.allocator, (vm.gc.copyString("low") catch return error.OutOfMemory).toValue(), Value.fromInteger(range.low), ) catch return error.OutOfMemory; serialized_range.map.put( + vm.gc.allocator, (vm.gc.copyString("high") catch return error.OutOfMemory).toValue(), Value.fromInteger(range.high), ) catch return error.OutOfMemory; @@ -2910,14 +2912,14 @@ pub const ObjMap = struct { type_def: *ObjTypeDef, // We need an ArrayHashMap for `next` - map: std.AutoArrayHashMap(Value, Value), + map: std.AutoArrayHashMapUnmanaged(Value, Value), methods: []?*ObjNative, pub fn init(allocator: Allocator, type_def: *ObjTypeDef) !Self { const self = Self{ .type_def = type_def, - .map = std.AutoArrayHashMap(Value, Value).init(allocator), + .map = std.AutoArrayHashMapUnmanaged(Value, Value){}, .methods = try allocator.alloc( ?*ObjNative, Self.members.len, @@ -2932,7 +2934,11 @@ pub const ObjMap = struct { } pub fn set(self: *Self, gc: *GarbageCollector, key: Value, value: Value) !void { - try self.map.put(key, value); + try self.map.put( + gc.allocator, + key, + value, + ); try gc.markObjDirty(&self.obj); } @@ -3022,7 +3028,7 @@ pub const ObjMap = struct { } pub fn deinit(self: *Self, allocator: Allocator) void { - self.map.deinit(); + self.map.deinit(allocator); allocator.free(self.methods); } @@ -4947,7 +4953,7 @@ pub fn cloneObject(obj: *Obj, vm: *VM) !Value { ObjMap, .{ .type_def = map.type_def, - .map = try map.map.clone(), + .map = try map.map.clone(vm.gc.allocator), .methods = map.methods, }, )).toValue(); diff --git a/src/vm.zig b/src/vm.zig index 9a5d2223..ab38c511 100644 --- a/src/vm.zig +++ b/src/vm.zig @@ -3559,13 +3559,17 @@ pub const VM = struct { const right: *ObjMap = self.pop().obj().access(ObjMap, .Map, self.gc).?; const left: *ObjMap = self.pop().obj().access(ObjMap, .Map, self.gc).?; - var new_map = left.map.clone() catch { + var new_map = left.map.clone(self.gc.allocator) catch { self.panic("Out of memory"); unreachable; }; var it = right.map.iterator(); while (it.next()) |entry| { - new_map.put(entry.key_ptr.*, entry.value_ptr.*) catch { + new_map.put( + self.gc.allocator, + entry.key_ptr.*, + entry.value_ptr.*, + ) catch { self.panic("Out of memory"); unreachable; };