mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-27 05:49:08 +00:00
test_gen: support RocResult for Wasm tests
This commit is contained in:
parent
617e18af98
commit
a9aee13086
4 changed files with 49 additions and 6 deletions
|
@ -1,5 +1,5 @@
|
|||
use roc_gen_wasm::wasm32_sized::Wasm32Sized;
|
||||
use roc_std::{RocDec, RocList, RocOrder, RocStr};
|
||||
use roc_std::{RocDec, RocList, RocOrder, RocResult, RocStr};
|
||||
use std::convert::TryInto;
|
||||
|
||||
pub trait FromWasmerMemory: Wasm32Sized {
|
||||
|
@ -95,6 +95,26 @@ impl<T: FromWasmerMemory + Clone> FromWasmerMemory for RocList<T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<T: FromWasmerMemory + Wasm32Sized, E: FromWasmerMemory + Wasm32Sized> FromWasmerMemory
|
||||
for RocResult<T, E>
|
||||
{
|
||||
fn decode(memory: &wasmer::Memory, offset: u32) -> Self {
|
||||
let tag_offset = if T::ACTUAL_WIDTH > E::ACTUAL_WIDTH {
|
||||
T::ACTUAL_WIDTH
|
||||
} else {
|
||||
E::ACTUAL_WIDTH
|
||||
};
|
||||
let tag = <u8 as FromWasmerMemory>::decode(memory, offset + tag_offset as u32);
|
||||
if tag == 1 {
|
||||
let value = <T as FromWasmerMemory>::decode(memory, offset);
|
||||
RocResult::ok(value)
|
||||
} else {
|
||||
let payload = <E as FromWasmerMemory>::decode(memory, offset);
|
||||
RocResult::err(payload)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: FromWasmerMemory> FromWasmerMemory for &'_ T {
|
||||
fn decode(memory: &wasmer::Memory, offset: u32) -> Self {
|
||||
let elements = <u32 as FromWasmerMemory>::decode(memory, offset);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue