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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
//! A small and portable WebAssembly interpreter.
//!
//! `tinywasm` passes the full WebAssembly 3.0 core testsuite and supports the
//! [Lime1](https://github.com/WebAssembly/tool-conventions/blob/main/Lime.md#lime1)
//! interoperability target. It is designed for embedding in applications, tools,
//! and `no_std + alloc` environments.
//!
//! ## Getting started
//!
//! Use [`parse_bytes`] to parse and validate a WebAssembly module, then instantiate it
//! in a [`Store`]. A module can be reused, while each store owns its runtime state.
//!
//! ```rust
//! # #[cfg(feature = "parser")]
//! # fn main() -> tinywasm::Result<()> {
//! use tinywasm::{ModuleInstance, Store};
//!
//! let wasm = include_bytes!("../../../examples/wasm/add.wasm");
//! let module = tinywasm::parse_bytes(wasm)?;
//!
//! let mut store = Store::default();
//! let instance = ModuleInstance::instantiate(&mut store, &module, None)?;
//!
//! let add = instance.func::<(i32, i32), i32>(&store, "add")?;
//! let result = add.call(&mut store, (1, 2))?;
//!
//! assert_eq!(result, 3);
//! # Ok(())
//! # }
//! # #[cfg(not(feature = "parser"))]
//! # fn main() {}
//! ```
//!
//! Typed functions convert Rust values directly. Use [`ModuleInstance::func_untyped`]
//! and [`WasmValue`] when types are selected at runtime. References such as [`StructRef`]
//! and [`ExternRef`] are owned handles tied to their store. Cloning a managed reference
//! keeps its referent live.
//!
//! Construct a store with a custom [`Engine`] and [`engine::Config`] to configure
//! stack limits, fuel, and GC collection. A [`ResourceLimiter`] can bound guest memory,
//! table, and GC heap growth.
//!
//! ## References and GC
//!
//! Runtime references belong to a [`Store`]. Passing a reference to another store
//! returns [`Trap::InvalidStore`]. Managed references are cloneable owned handles, and
//! their referents become collectible after the last handle is dropped. Nullable typed
//! parameters and results use `Option<T>`. Use [`RefValue`] for dynamic reference values
//! and [`Store::gc`] to request collection explicitly.
//!
//! For more examples, see the [`examples`](https://github.com/explodingcamera/tinywasm/tree/next/examples) directory.
//!
//! ## Cargo features
//!
//! - **`full`:** Enables `archive`, `debug`, `parallel-parser`, `parser`, `state`, and `validate`. Enabled by default.
//! - **`std`:** Enables `std` and parsing from files and streams. Enabled by default.
//! - **`parser`:** Enables `tinywasm-parser` and top-level parse helpers. Enabled by default.
//! - **`validate`:** Enables WebAssembly validation while parsing. Enabled by default and configurable through `ParserOptions`.
//! - **`parallel-parser`:** Parallelizes function parsing when `std` is enabled. Enabled by default.
//! - **`archive`:** Enables serialization and deserialization of the internal `twasm` format. Enabled by default.
//! - **`log`:** Enables integration with the `log` crate.
//! - **`send`:** Makes stores and store-local handles movable across threads.
//! - **`state`:** Adds store-owned host state for access from host callbacks. Enabled by default.
//! - **`portable-atomic`:** Supports targets without native atomic compare-and-swap.
//! - **`canonicalize-nans`:** Uses a [canonical NaN](https://en.wikipedia.org/wiki/NaN#Canonical_NaN) for normalized NaN results.
//! - **`debug`:** Derives `Debug` for runtime types. Enabled by default.
//! - **`guest-debug`:** Exposes module-internal by-index inspection APIs (`*_by_index`).
//! - **`nightly-tail-calls`:** Uses Rust's unstable explicit tail calls for interpreter dispatch. Requires nightly Rust (recommended for maximum performance).
//! - **`simd-x86`:** Enables x86-specific SIMD intrinsics and uses `unsafe` internally.
//!
//! With default features disabled, `tinywasm` depends only on `core`, `alloc`, and `libm`,
//! making it usable in `no_std + alloc` environments with a custom allocator.
//!
//! ## Imports
//!
//! To provide imports to a module, you can use the [`Imports`] struct.
//! This struct allows you to register custom functions, globals, memories, tables,
//! tags, and other modules to be linked into the module when it is instantiated.
//!
//! See the [`Imports`] documentation for more information.
extern crate alloc;
compile_error!;
// log for logging (optional).
use log;
// noop fallback if logging is disabled.
pub
pub use *;
pub use ;
pub use *;
pub use ;
pub use *;
pub use *;
use InterpreterRuntime;
/// Global configuration for the WebAssembly interpreter
pub use ;
/// Re-export of [`tinywasm_parser`]. Requires `parser` feature.
pub use parse_bytes;
pub use ;
/// Re-export of [`tinywasm_types`].
pub use Module;