aboutsummaryrefslogtreecommitdiff
path: root/src/value.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/value.zig')
-rw-r--r--src/value.zig18
1 files changed, 17 insertions, 1 deletions
diff --git a/src/value.zig b/src/value.zig
index 84167e394f..a3569be29a 100644
--- a/src/value.zig
+++ b/src/value.zig
@@ -1090,7 +1090,12 @@ pub const Value = extern union {
}
}
- pub fn readFromMemory(ty: Type, target: Target, buffer: []const u8, arena: Allocator) !Value {
+ pub fn readFromMemory(
+ ty: Type,
+ target: Target,
+ buffer: []const u8,
+ arena: Allocator,
+ ) Allocator.Error!Value {
switch (ty.zigTypeTag()) {
.Int => {
const int_info = ty.intInfo(target);
@@ -1111,6 +1116,17 @@ pub const Value = extern union {
128 => return Value.Tag.float_128.create(arena, floatReadFromMemory(f128, target, buffer)),
else => unreachable,
},
+ .Array => {
+ const elem_ty = ty.childType();
+ const elem_size = elem_ty.abiSize(target);
+ const elems = try arena.alloc(Value, @intCast(usize, ty.arrayLen()));
+ var offset: usize = 0;
+ for (elems) |*elem| {
+ elem.* = try readFromMemory(elem_ty, target, buffer[offset..], arena);
+ offset += elem_size;
+ }
+ return Tag.array.create(arena, elems);
+ },
else => @panic("TODO implement readFromMemory for more types"),
}
}