Re-implemented allocation calculations
This commit is contained in:
parent
6d426753c8
commit
d18f1c6956
@ -771,7 +771,30 @@ def _generate_struct_constructor(wgn: WasmGenerator, inp: ourlang.StructConstruc
|
|||||||
wgn.local.get(tmp_var)
|
wgn.local.get(tmp_var)
|
||||||
|
|
||||||
def _calculate_alloc_size(typ: Union[type3types.StructType3, type3types.Type3]) -> int:
|
def _calculate_alloc_size(typ: Union[type3types.StructType3, type3types.Type3]) -> int:
|
||||||
return 0 # FIXME: Stub
|
if typ is type3types.u8:
|
||||||
|
return 1
|
||||||
|
|
||||||
|
if typ is type3types.u32 or typ is type3types.i32 or typ is type3types.f32:
|
||||||
|
return 4
|
||||||
|
|
||||||
|
if typ is type3types.u64 or typ is type3types.i64 or typ is type3types.f64:
|
||||||
|
return 8
|
||||||
|
|
||||||
|
if isinstance(typ, type3types.StructType3):
|
||||||
|
return sum(
|
||||||
|
_calculate_alloc_size(x)
|
||||||
|
for x in typ.members.values()
|
||||||
|
)
|
||||||
|
|
||||||
|
raise NotImplementedError(_calculate_alloc_size, typ)
|
||||||
|
|
||||||
def _calculate_member_offset(struct_type3: type3types.StructType3, member: str) -> int:
|
def _calculate_member_offset(struct_type3: type3types.StructType3, member: str) -> int:
|
||||||
return 0 # FIXME: Stub
|
result = 0
|
||||||
|
|
||||||
|
for mem, memtyp in struct_type3.members.items():
|
||||||
|
if member == mem:
|
||||||
|
return result
|
||||||
|
|
||||||
|
result += _calculate_alloc_size(memtyp)
|
||||||
|
|
||||||
|
raise Exception(f'{member} not in {struct_type3}')
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user