mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-04 04:08:19 +00:00
implement wasm memory traits for 4-tuples
This commit is contained in:
parent
7e0e635f60
commit
3ca24a6476
3 changed files with 87 additions and 13 deletions
|
@ -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,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue