implement wasm traits for roc_std::RocBox

This commit is contained in:
Folkert 2023-02-08 15:04:28 +01:00
parent b022175489
commit 625b9c161a
No known key found for this signature in database
GPG key ID: 1F17F6FFD112B97C
4 changed files with 27 additions and 4 deletions

View file

@ -8,7 +8,7 @@ use bumpalo::{collections::Vec, Bump};
use roc_builtins::bitcode::{FloatWidth, IntWidth};
use roc_mono::layout::{Builtin, InLayout, Layout, LayoutInterner, UnionLayout};
use roc_std::{RocDec, RocList, RocOrder, RocResult, RocStr, I128, U128};
use roc_std::{RocBox, RocDec, RocList, RocOrder, RocResult, RocStr, I128, U128};
use roc_wasm_module::{
linking::SymInfo, linking::WasmObjectSymbol, Align, Export, ExportType, LocalId, Signature,
ValueType, WasmModule,
@ -203,6 +203,13 @@ impl<T: Wasm32Result> Wasm32Result for RocList<T> {
}
}
impl<T: Wasm32Result> Wasm32Result for RocBox<T> {
fn build_wrapper_body(code_builder: &mut CodeBuilder, main_function_index: u32) {
// treat box as if it's just a isize value
<i32 as Wasm32Result>::build_wrapper_body(code_builder, main_function_index)
}
}
impl<T: Wasm32Sized, E: Wasm32Sized> Wasm32Result for RocResult<T, E> {
fn build_wrapper_body(code_builder: &mut CodeBuilder, main_function_index: u32) {
build_wrapper_body_stack_memory(

View file

@ -1,4 +1,4 @@
use roc_std::{RocDec, RocList, RocOrder, RocResult, RocStr, I128, U128};
use roc_std::{RocBox, RocDec, RocList, RocOrder, RocResult, RocStr, I128, U128};
pub trait Wasm32Sized: Sized {
const SIZE_OF_WASM: usize;
@ -45,6 +45,11 @@ impl<T: Wasm32Sized> Wasm32Sized for RocList<T> {
const ALIGN_OF_WASM: usize = 4;
}
impl<T: Wasm32Sized> Wasm32Sized for RocBox<T> {
const SIZE_OF_WASM: usize = 4;
const ALIGN_OF_WASM: usize = 4;
}
impl<T: Wasm32Sized, E: Wasm32Sized> Wasm32Sized for RocResult<T, E> {
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;