| ... | ... | @@ -1090,7 +1090,12 @@ pub const Value = extern union { |
| 1090 | 1090 | } |
| 1091 | 1091 | } |
| 1092 | 1092 | |
| 1093 | | pub fn readFromMemory(ty: Type, target: Target, buffer: []const u8, arena: Allocator) !Value { |
| 1093 | pub fn readFromMemory( |
| 1094 | ty: Type, |
| 1095 | target: Target, |
| 1096 | buffer: []const u8, |
| 1097 | arena: Allocator, |
| 1098 | ) Allocator.Error!Value { |
| 1094 | 1099 | switch (ty.zigTypeTag()) { |
| 1095 | 1100 | .Int => { |
| 1096 | 1101 | const int_info = ty.intInfo(target); |
| ... | ... | @@ -1111,6 +1116,17 @@ pub const Value = extern union { |
| 1111 | 1116 | 128 => return Value.Tag.float_128.create(arena, floatReadFromMemory(f128, target, buffer)), |
| 1112 | 1117 | else => unreachable, |
| 1113 | 1118 | }, |
| 1119 | .Array => { |
| 1120 | const elem_ty = ty.childType(); |
| 1121 | const elem_size = elem_ty.abiSize(target); |
| 1122 | const elems = try arena.alloc(Value, @intCast(usize, ty.arrayLen())); |
| 1123 | var offset: usize = 0; |
| 1124 | for (elems) |*elem| { |
| 1125 | elem.* = try readFromMemory(elem_ty, target, buffer[offset..], arena); |
| 1126 | offset += elem_size; |
| 1127 | } |
| 1128 | return Tag.array.create(arena, elems); |
| 1129 | }, |
| 1114 | 1130 | else => @panic("TODO implement readFromMemory for more types"), |
| 1115 | 1131 | } |
| 1116 | 1132 | } |