Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
32 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -95,7 +95,24 @@ pub const Value = union(Type) { | |
.str = str[iter.index - cp_len .. iter.index], | ||
}; | ||
}, | ||
.map => {}, | ||
.map => |*map| { | ||
if (iter.index == map.entries.items.len) { | ||
res.* = &Value.None; | ||
return; | ||
} | ||
|
||
if (res.* == null) | ||
res.* = try vm.gc.alloc(); | ||
if (iter.index == 0) { | ||
res.*.?.* = .{ .tuple = try vm.gc.gpa.alloc(*Value, 2) }; | ||
} | ||
const e = &map.entries.items[iter.index]; | ||
const t = res.*.?.tuple; | ||
// removing `const` on `Map` causes dependency loop?? | ||
t[0] = @intToPtr(*Value, @ptrToInt(e.key)); | ||
t[1] = e.value; | ||
iter.index += 1; | ||
}, | ||
.range => @panic("TODO: range iterator"), | ||
else => unreachable, | ||
} | ||
|
@@ -123,7 +140,7 @@ pub const Value = union(Type) { | |
switch (value.*) { | ||
.int, .num, .none, .bool, .native, .tagged, .err, .range, .iterator => {}, | ||
.tuple => |t| allocator.free(t), | ||
// I really, really hate `deinit` taking a mutable pointer. | ||
// I really, really hate `deinit` taking a mutable pointer. | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
Vexu
Author
Owner
|
||
.map => |*m| m.deinit(allocator), | ||
.list => |*l| l.deinit(allocator), | ||
.str => { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
you could do this pattern:
But here's an argument for deinit taking a mutable pointer:
init()
takes a mutable pointer toundefined
memory and initializes statedeinit()
takes a mutable pointer to initialized state and makes itundefined
memory againOn the other hand, a lot of people agree with you and it's probably worth making a proposal