1#![no_std]
9
10#[cfg(feature = "alloc")]
11extern crate alloc;
12
13pub const PAGE_SIZE: usize = 65536;
15
16mod memory;
17pub use memory::IsolatedMemory;
18
19mod table;
20pub use table::{FuncRef, Table};
21
22mod module;
23pub use module::{LibraryModule, Module};
24
25mod ops;
26pub use ops::{
27 i32_div_s, i32_div_u, i32_rem_s, i32_rem_u, i32_trunc_f32_s, i32_trunc_f32_u, i32_trunc_f64_s,
28 i32_trunc_f64_u, i64_div_s, i64_div_u, i64_rem_s, i64_rem_u, i64_trunc_f32_s, i64_trunc_f32_u,
29 i64_trunc_f64_s, i64_trunc_f64_u,
30};
31
32#[derive(Debug, Clone, Copy, PartialEq, Eq)]
34pub enum WasmTrap {
35 OutOfBounds,
37 DivisionByZero,
39 IntegerOverflow,
41 Unreachable,
43 IndirectCallTypeMismatch,
45 TableOutOfBounds,
47 UndefinedElement,
49}
50
51pub type WasmResult<T> = Result<T, WasmTrap>;
53
54#[derive(Clone, Copy)]
59pub struct NoHost;
60
61#[derive(Debug, Clone, Copy, PartialEq, Eq)]
65pub enum ConstructionError {
66 MemoryInitialPagesExceedsMax { initial: usize, max: usize },
68 TableInitialSizeExceedsMax { initial: usize, max: usize },
70}
71
72impl From<ConstructionError> for WasmTrap {
73 fn from(_: ConstructionError) -> Self {
74 WasmTrap::OutOfBounds
77 }
78}
79
80#[cfg(test)]
81mod tests {
82 use super::*;
83
84 #[test]
85 fn wasm_trap_is_copy() {
86 let trap = WasmTrap::OutOfBounds;
87 let trap2 = trap; assert_eq!(trap, trap2);
89 }
90
91 #[test]
92 fn wasm_result_ok() {
93 let result: WasmResult<i32> = Ok(42);
94 assert!(result.is_ok());
95 assert_eq!(result, Ok(42));
96 }
97
98 #[test]
99 fn wasm_result_err() {
100 let result: WasmResult<i32> = Err(WasmTrap::DivisionByZero);
101 assert!(result.is_err());
102 assert_eq!(result, Err(WasmTrap::DivisionByZero));
103 }
104}