From 735c7cb636edfd4704460c94a9c7d65e5bf4df48 Mon Sep 17 00:00:00 2001 From: Henry Gressmann Date: Sat, 9 Mar 2024 13:51:32 +0100 Subject: chore: improve documentation, tests Closes #6 Signed-off-by: Henry Gressmann --- crates/types/src/lib.rs | 48 ++++++++++++++++++++++++++++------------------- crates/types/src/value.rs | 2 +- 2 files changed, 30 insertions(+), 20 deletions(-) (limited to 'crates/types') diff --git a/crates/types/src/lib.rs b/crates/types/src/lib.rs index d2da7d7..679f3bf 100644 --- a/crates/types/src/lib.rs +++ b/crates/types/src/lib.rs @@ -41,37 +41,54 @@ pub mod archive; #[derive(Debug, Clone, Default, PartialEq)] #[cfg_attr(feature = "archive", derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize), archive(check_bytes))] pub struct TinyWasmModule { - /// The version of the WebAssembly module. - pub version: Option, - - /// The start function of the WebAssembly module. + /// Optional address of the start function + /// + /// Corresponds to the `start` section of the original WebAssembly module. pub start_func: Option, - /// The functions of the WebAssembly module. - pub funcs: Box<[TypedWasmFunction]>, + /// Optimized and validated WebAssembly functions + /// + /// Contains data from to the `code`, `func`, and `type` sections of the original WebAssembly module. + pub funcs: Box<[WasmFunction]>, - /// The types of the WebAssembly module. + /// A vector of type definitions, indexed by `TypeAddr` + /// + /// Corresponds to the `type` section of the original WebAssembly module. pub func_types: Box<[FuncType]>, - /// The exports of the WebAssembly module. + /// Exported items of the WebAssembly module. + /// + /// Corresponds to the `export` section of the original WebAssembly module. pub exports: Box<[Export]>, - /// The tables of the WebAssembly module. + /// Global components of the WebAssembly module. + /// + /// Corresponds to the `global` section of the original WebAssembly module. pub globals: Box<[Global]>, - /// The tables of the WebAssembly module. + /// Table components of the WebAssembly module used to initialize tables. + /// + /// Corresponds to the `table` section of the original WebAssembly module. pub table_types: Box<[TableType]>, - /// The memories of the WebAssembly module. + /// Memory components of the WebAssembly module used to initialize memories. + /// + /// Corresponds to the `memory` section of the original WebAssembly module. pub memory_types: Box<[MemoryType]>, - /// The imports of the WebAssembly module. + /// Imports of the WebAssembly module. + /// + /// Corresponds to the `import` section of the original WebAssembly module. pub imports: Box<[Import]>, /// Data segments of the WebAssembly module. + /// + /// Corresponds to the `data` section of the original WebAssembly module. pub data: Box<[Data]>, /// Element segments of the WebAssembly module. + /// + /// Corresponds to the `elem` section of the original WebAssembly module. pub elements: Box<[Element]>, } @@ -164,13 +181,6 @@ pub struct WasmFunction { pub ty: FuncType, } -#[derive(Debug, Clone, PartialEq)] -#[cfg_attr(feature = "archive", derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize), archive(check_bytes))] -pub struct TypedWasmFunction { - pub type_addr: u32, - pub wasm_function: WasmFunction, -} - /// A WebAssembly Module Export #[derive(Debug, Clone, PartialEq)] #[cfg_attr(feature = "archive", derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize), archive(check_bytes))] diff --git a/crates/types/src/value.rs b/crates/types/src/value.rs index bcd43e5..28ca6e2 100644 --- a/crates/types/src/value.rs +++ b/crates/types/src/value.rs @@ -5,7 +5,7 @@ use crate::{ConstInstruction, ExternAddr, FuncAddr}; /// A WebAssembly value. /// /// See -#[derive(Clone, Copy)] +#[derive(Clone, Copy, PartialEq)] pub enum WasmValue { // Num types /// A 32-bit integer. -- cgit v1.3.1