summaryrefslogtreecommitdiff
path: root/crates/parser
diff options
context:
space:
mode:
authorHenry <mail@henrygressmann.de>2026-08-09 16:11:57 +0200
committerHenry <mail@henrygressmann.de>2026-08-09 16:11:57 +0200
commit9893a51d2712f82a2ee57316a66bc26500eb3fdd (patch)
tree55578e887155323c57f05ac1905c552af82f5767 /crates/parser
parent8ca9c3580990bc973218d944f2262a7d98a8380e (diff)
feat: add reusable host imports and simplify function calls
- make host definitions reusable across stores with gc-aware import linking - reorganize function calls, resumable execution, and typed value handling - expand typed tuples to arity 20 and update parser and store APIs Signed-off-by: Henry <mail@henrygressmann.de>
Diffstat (limited to 'crates/parser')
-rw-r--r--crates/parser/README.md6
-rw-r--r--crates/parser/src/lib.rs20
2 files changed, 13 insertions, 13 deletions
diff --git a/crates/parser/README.md b/crates/parser/README.md
index 05c2af2..cf1a6c4 100644
--- a/crates/parser/README.md
+++ b/crates/parser/README.md
@@ -16,10 +16,10 @@ use tinywasm_parser::{Parser, ParserOptions};
let bytes = include_bytes!("./file.wasm");
-let parser = Parser::new();
+let parser = Parser::default();
let module = parser.parse_module_bytes(bytes)?;
-let parser = Parser::with_options(ParserOptions::default().with_rewrite_optimization(false));
+let parser = Parser::new(ParserOptions::default().with_rewrite_optimization(false));
let module = parser.parse_module_bytes(bytes)?;
let module = parser.parse_module_file("path/to/file.wasm")?;
@@ -27,4 +27,4 @@ let mut stream = std::fs::File::open("path/to/file.wasm")?;
let module = parser.parse_module_stream(&mut stream)?;
```
-If you just want the default configuration, the top-level `parse_bytes`, `parse_file`, and `parse_stream` helpers are thin wrappers around `Parser::new()`.
+If you just want the default configuration, the top-level `parse_bytes`, `parse_file`, and `parse_stream` helpers are thin wrappers around `Parser::default()`.
diff --git a/crates/parser/src/lib.rs b/crates/parser/src/lib.rs
index 5439558..fe968d8 100644
--- a/crates/parser/src/lib.rs
+++ b/crates/parser/src/lib.rs
@@ -90,6 +90,11 @@ impl Default for ParserOptions {
}
impl ParserOptions {
+ /// Create parser options with default settings.
+ pub fn new() -> Self {
+ Self::default()
+ }
+
/// Enable or disable WebAssembly validation.
///
/// Requires the `validate` feature to have any effect.
@@ -152,13 +157,8 @@ pub struct Parser {
}
impl Parser {
- /// Create a new parser instance
- pub fn new() -> Self {
- Self::default()
- }
-
- /// Create a new parser with explicit options.
- pub fn with_options(options: ParserOptions) -> Self {
+ /// Create a parser with the given options.
+ pub const fn new(options: ParserOptions) -> Self {
Self { options }
}
@@ -352,17 +352,17 @@ impl TryFrom<ModuleReader<'_>> for Module {
/// Parse a module from bytes
pub fn parse_bytes(wasm: &[u8]) -> Result<Module> {
- Parser::new().parse_module_bytes(wasm)
+ Parser::default().parse_module_bytes(wasm)
}
#[cfg(feature = "std")]
/// Parse a module from a file. Requires the `std` feature.
pub fn parse_file(path: impl AsRef<crate::std::path::Path> + Clone) -> Result<Module> {
- Parser::new().parse_module_file(path)
+ Parser::default().parse_module_file(path)
}
#[cfg(feature = "std")]
/// Parse a module from a stream. Requires the `std` feature.
pub fn parse_stream(stream: impl crate::std::io::Read) -> Result<Module> {
- Parser::new().parse_module_stream(stream)
+ Parser::default().parse_module_stream(stream)
}