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
//! `tinywasm` provides a small, portable WebAssembly interpreter with support for
//! the WebAssembly MVP, WebAssembly 2.0, and a growing set of newer proposals.
//! It is designed to stay lightweight while still being practical to embed in
//! applications, tools, and `no_std + alloc` environments.
//!
//! ## Features
//! - **`std`**\
//! Enables parsing from files and streams. Enabled by default.
//! - **`log`**\
//! Enables integration with the `log` crate. Enabled by default.
//! - **`parser`**\
//! Enables the bundled `tinywasm-parser` crate and top-level parse helpers. Enabled by default.
//! - **`archive`**\
//! Enables serialization and deserialization of compiled modules in the internal `twasm` format. Enabled by default.
//! - **`canonicalize-nans`**\
//! Canonicalizes NaN values to a single representation. Enabled by default.
//! - **`debug`**\
//! Derives `Debug` for runtime types. Enabled by default.
//! - **`parallel-parser`**\
//! Parallelizes function parsing and validation across threads when `std` is enabled. Enabled by default.
//! - **`guest-debug`**\
//! Exposes module-internal by-index inspection APIs (`*_by_index`).
//! - **`simd-x86`**\
//! Enables x86-specific SIMD intrinsics for selected operations and uses `unsafe` internally.
//!
//! With default features disabled, `tinywasm` only depends on `core`, `alloc`, and `libm`.
//! By disabling `std`, you can use `tinywasm` in `no_std` environments. This requires
//! a custom allocator and removes support for parsing from files and streams, but otherwise the API is the same.
//!
//! ## Getting Started
//! The easiest way to get started is to use the [`crate::parse_bytes`] function to load a
//! WebAssembly module from bytes. This will parse the module and validate it, returning
//! a [`Module`] that can be used to instantiate the module.
//!
//!
//! ```rust
//! use tinywasm::{ModuleInstance, Store};
//!
//! // Load a module from bytes
//! let wasm = include_bytes!("../../../examples/wasm/add.wasm");
//! let module = tinywasm::parse_bytes(wasm)?;
//!
//! // Create a new store
//! // Stores are used to allocate objects like functions and globals
//! let mut store = Store::default();
//!
//! // Instantiate the module
//! // This will allocate the module and its globals into the store
//! // and execute the module's start function.
//! // Every ModuleInstance has its own ID space for functions, globals, etc.
//! let instance = ModuleInstance::instantiate(&mut store, &module, None)?;
//!
//! // Get a typed handle to the exported "add" function
//! // Alternatively, you can use `instance.func` to get an untyped handle
//! // that takes and returns [`WasmValue`]s
//! let func = instance.func::<(i32, i32), i32>(&mut store, "add")?;
//! let res = func.call(&mut store, (1, 2))?;
//!
//! assert_eq!(res, 3);
//! # Ok::<(), tinywasm::Error>(())
//! ```
//!
//! For non-default runtime behavior, construct a [`Store`] with a custom [`Engine`]
//! and [`engine::Config`] to control stack sizing, fuel accounting, memory backends,
//! and trap-on-OOM behavior.
//!
//! For more examples, see the [`examples`](https://github.com/explodingcamera/tinywasm/tree/main/examples) directory.
//!
//! ## Imports
//!
//! To provide imports to a module, you can use the [`Imports`] struct.
//! This struct allows you to register custom functions, globals, memories, tables,
//! and other modules to be linked into the module when it is instantiated.
//!
//! See the [`Imports`] documentation for more information.
extern crate alloc;
// 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;
pub