mirror of
https://github.com/ziglang/zig.git
synced 2025-12-30 01:53:16 +00:00
Sema: implement readFromMemory for arrays
This commit is contained in:
parent
bfff8544e1
commit
01638c250f
@ -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"),
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user