implement wasm memory traits for 4-tuples

This commit is contained in:
Folkert 2022-07-16 12:12:28 +02:00
parent 7e0e635f60
commit 3ca24a6476
No known key found for this signature in database
GPG key ID: 1F17F6FFD112B97C
3 changed files with 87 additions and 13 deletions

View file

@ -260,3 +260,19 @@ where
)
}
}
impl<T, U, V, W> Wasm32Result for (T, U, V, W)
where
T: Wasm32Result + Wasm32Sized,
U: Wasm32Result + Wasm32Sized,
V: Wasm32Result + Wasm32Sized,
W: Wasm32Result + Wasm32Sized,
{
fn build_wrapper_body(code_builder: &mut CodeBuilder, main_function_index: u32) {
build_wrapper_body_stack_memory(
code_builder,
main_function_index,
T::ACTUAL_WIDTH + U::ACTUAL_WIDTH + V::ACTUAL_WIDTH + W::ACTUAL_WIDTH,
)
}
}

View file

@ -47,8 +47,8 @@ impl<T: Wasm32Sized> Wasm32Sized for RocList<T> {
}
impl<T: Wasm32Sized, E: Wasm32Sized> Wasm32Sized for RocResult<T, E> {
const ALIGN_OF_WASM: usize = max2(T::ALIGN_OF_WASM, E::ALIGN_OF_WASM);
const SIZE_OF_WASM: usize = max2(T::ACTUAL_WIDTH, E::ACTUAL_WIDTH) + 1;
const ALIGN_OF_WASM: usize = max(&[T::ALIGN_OF_WASM, E::ALIGN_OF_WASM]);
const SIZE_OF_WASM: usize = max(&[T::ACTUAL_WIDTH, E::ACTUAL_WIDTH]) + 1;
}
impl<T: Wasm32Sized> Wasm32Sized for &'_ T {
@ -68,22 +68,34 @@ impl Wasm32Sized for usize {
impl<T: Wasm32Sized, U: Wasm32Sized> Wasm32Sized for (T, U) {
const SIZE_OF_WASM: usize = T::SIZE_OF_WASM + U::SIZE_OF_WASM;
const ALIGN_OF_WASM: usize = max2(T::SIZE_OF_WASM, U::SIZE_OF_WASM);
const ALIGN_OF_WASM: usize = max(&[T::SIZE_OF_WASM, U::SIZE_OF_WASM]);
}
impl<T: Wasm32Sized, U: Wasm32Sized, V: Wasm32Sized> Wasm32Sized for (T, U, V) {
const SIZE_OF_WASM: usize = T::SIZE_OF_WASM + U::SIZE_OF_WASM + V::SIZE_OF_WASM;
const ALIGN_OF_WASM: usize = max3(T::SIZE_OF_WASM, U::SIZE_OF_WASM, V::SIZE_OF_WASM);
const ALIGN_OF_WASM: usize = max(&[T::SIZE_OF_WASM, U::SIZE_OF_WASM, V::SIZE_OF_WASM]);
}
const fn max2(a: usize, b: usize) -> usize {
if a > b {
a
} else {
b
impl<T: Wasm32Sized, U: Wasm32Sized, V: Wasm32Sized, W: Wasm32Sized> Wasm32Sized for (T, U, V, W) {
const SIZE_OF_WASM: usize =
T::SIZE_OF_WASM + U::SIZE_OF_WASM + V::SIZE_OF_WASM + W::SIZE_OF_WASM;
const ALIGN_OF_WASM: usize = max(&[T::SIZE_OF_WASM, U::SIZE_OF_WASM, V::SIZE_OF_WASM]);
}
const fn max(alignments: &[usize]) -> usize {
assert!(!alignments.is_empty());
let mut largest = 0;
let mut i = 0;
while i < alignments.len() {
largest = if largest > alignments[i] {
largest
} else {
alignments[i]
};
i += 1;
}
}
const fn max3(a: usize, b: usize, c: usize) -> usize {
max2(max2(a, b), c)
largest
}