1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
use std::cell::Cell;
use thiserror::Error as ThisError;
pub const DEFAULT_MEMORY_INDEX: usize = 0;
pub type MemSlice<'m> = &'m [Cell<u8>];
pub trait Allocatable {
fn allocate(&self, size: u32, type_tag: u32) -> Result<usize, AllocatableError>;
fn memory_slice(&self, memory_index: usize) -> Result<MemSlice<'_>, AllocatableError>;
}
#[derive(Debug, ThisError)]
pub enum AllocatableError {
#[error("memory `{memory_index}` does not exist")]
MemoryIsMissing {
memory_index: usize,
},
#[error("the allocate function with index `{function_index}` doesn't exist in Wasm module")]
AllocateFuncIsMissing {
function_index: u32,
},
#[error("call to allocated was failed")]
AllocateCallFailed,
#[error(
"allocate func doesn't receive two i32 values,\
probably a Wasm module's built with unsupported sdk version"
)]
AllocateFuncIncompatibleSignature,
#[error(
"allocate func doesn't return a one value of I32 type,\
probably a Wasm module's built with unsupported sdk version"
)]
AllocateFuncIncompatibleOutput,
#[error("{0}")]
UserDefinedError(String),
}