diff --git a/.cargo/config.toml b/.cargo/config.toml index bfe56dd..df52e1c 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -5,5 +5,5 @@ test-mvp="test --package tinywasm --test test-mvp --release -- --enable " test-2="test --package tinywasm --test test-two --release -- --enable " test-wast="test --package tinywasm --test test-wast -- --enable " test-wast-release="test --package tinywasm --test test-wast --release -- --enable " -generate-charts="test --package tinywasm --test generate-charts -- --enable " +generate-charts="run --package scripts --bin generate-charts --release" benchmark="bench -p benchmarks --bench" diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 9061eb8..6f2da8d 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -7,7 +7,25 @@ on: branches: [main] jobs: + build-wasm: + name: Build wasm + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + submodules: true + - name: Install Rust toolchain & Binaryen + run: rustup update && rustup target add wasm32-unknown-unknown && sudo apt-get install -y binaryen wabt + - name: Build wasm + run: ./examples/rust/build.sh + - name: Save artifacts + uses: actions/upload-artifact@v4 + with: + name: wasm + path: examples/rust/out + test-std: + needs: build-wasm name: Test with default features on stable Rust runs-on: ubuntu-latest @@ -16,26 +34,26 @@ jobs: with: submodules: true - - name: Install stable Rust toolchain & Binaryen - run: | - rustup update stable - rustup update nightly - rustup target add wasm32-unknown-unknown - sudo apt-get install -y binaryen wabt + - name: Install latest stable Rust toolchain + run: rustup update stable - - name: Build wasm - run: ./examples/rust/build.sh + - name: Load wasm + uses: actions/download-artifact@v4 + with: + name: wasm + path: examples/rust/out - name: Build (stable) run: cargo +stable build --workspace - name: Run tests (stable) - run: cargo +stable test --workspace + run: cargo +stable test --workspace && cargo +stable run --example wasm-rust all - name: Run MVP testsuite run: cargo +stable test-mvp test-no-std: + needs: build-wasm name: Test without default features on nightly Rust runs-on: ubuntu-latest @@ -44,20 +62,75 @@ jobs: with: submodules: true - - name: Install nightly Rust toolchain & Binaryen - run: | - rustup update nightly - rustup target add wasm32-unknown-unknown - sudo apt-get install -y binaryen wabt + - name: Install latest nightly Rust toolchain + run: rustup update nightly - - name: Build wasm - run: ./examples/rust/build.sh + - name: Load wasm + uses: actions/download-artifact@v4 + with: + name: wasm + path: examples/rust/out - name: Build (nightly, no default features) run: cargo +nightly build --workspace --no-default-features - name: Run tests (nightly, no default features) - run: cargo +nightly test --workspace --no-default-features + run: cargo +nightly test --workspace --no-default-features && cargo +nightly run --example wasm-rust all - name: Run MVP testsuite (nightly) run: cargo +nightly test-mvp + + test-m1: + needs: build-wasm + name: Test on arm64 (Apple M1) + runs-on: macos-14 + steps: + - uses: actions/checkout@v4 + with: + submodules: true + - name: Install stable Rust toolchain + run: rustup update stable + + - name: Load wasm + uses: actions/download-artifact@v4 + with: + name: wasm + path: examples/rust/out + + - name: Build (stable) + run: cargo +stable build + - name: Run tests (stable) + run: cargo +stable test + - name: Run MVP testsuite + run: cargo +stable test-mvp + + test-armv7: + needs: build-wasm + name: Test on armv7 (32-Bit Raspberry Pi) + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + with: + submodules: true + + - name: Load wasm + uses: actions/download-artifact@v4 + with: + name: wasm + path: examples/rust/out + + - name: Run all tests (for the default workspace members) + uses: houseabsolute/actions-rust-cross@v0.0.12 + with: + command: test + target: armv7-unknown-linux-gnueabihf + toolchain: nightly + + - name: Run MVP testsuite + uses: houseabsolute/actions-rust-cross@v0.0.12 + with: + command: test + args: "-p tinywasm --test test-mvp --release -- --enable" + target: armv7-unknown-linux-gnueabihf + toolchain: nightly diff --git a/.gitignore b/.gitignore index d2fbb51..1ae1f15 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,5 @@ examples/rust/Cargo.lock examples/wast/* perf.* flamegraph.svg +/.idea +/*.iml diff --git a/ARCHITECTURE.md b/ARCHITECTURE.md index d3816d0..7aaa99c 100644 --- a/ARCHITECTURE.md +++ b/ARCHITECTURE.md @@ -3,26 +3,24 @@ TinyWasm follows the general Runtime Structure described in the [WebAssembly Specification](https://webassembly.github.io/spec/core/exec/runtime.html). Some key differences are: -- Values are stored without their type, (as `u64`), and the type is inferred from the instruction that uses them. This is possible because the instructions are validated before execution and the type of each value can be inferred from the instruction. -- TinyWasm has a explicit stack for values, labels and frames. This is mostly for simplicity in the implementation, but also allows for some optimizations. -- Floats always use a canonical NaN representation, the spec allows for multiple NaN representations. -- TinyWasm uses a custom bytecode format (see [Bytecode Format](#bytecode-format) for more details) -- Global state in the `Store` can be addressed from module instances other than the owning module. This is to allow more efficient access to imports and exports. Ownership is still enforced implicitly by requiring a reference to the instance to access it which can not be changed using the WebAssembly instructions. -- The `Store` is not thread-safe. This is to allow for more efficient access to the `Store` and its contents. When later adding support for threads, a `Mutex` can be used to make it thread-safe but the overhead of requiring a lock for every access is not necessary for single-threaded applications. -- TinyWasm is architectured to allow for a JIT compiler to be added later. Functions are stored as FunctionInstances which can contain either a `WasmFunction` or a `HostFunction`. A third variant `JitFunction` could be added later to store a pointer to the compiled function. This would allow for the JIT to be used transparently without changing the rest of the runtime. -- TinyWasm is designed to be used in `no_std` environments. The `std` feature is enabled by default, but can be disabled to remove the dependency on `std` and `std::io`. This is done by disabling the `std` and `parser` features. The `logging` feature can also be disabled to remove the dependency on `log`. This is not recommended, since `libm` is not as performant as the compiler's math intrinsics, especially on wasm32 targets, but can be useful for resource-constrained devices or other environments where `std` is not available such as OS kernels. -- Call Frames are executed in a loop instead of recursively. This allows the use of a single stack for all frames and makes it easier to pause execution and resume it later, or to step through the code one instruction at a time. -- While other interpreters convert `locals` to be register-based when parsing the function body, TinyWasm keeps them in a stack. This is mostly for simplicity in the implementation, but performance is still comparable or better than other interpreters. +- **Type Storage**: Types are inferred from usage context rather than stored explicitly, with all values held as `u64`. +- **Stack Design**: Implements a specific stack for values, labels, and frames to simplify the implementation and enable optimizations. +- **Bytecode Format**: Adopts a custom bytecode format to reduce memory usage and improve performance by allowing direct execution without the need for decoding. +- **Global State Access**: Allows cross-module access to the `Store`'s global state, optimizing imports and exports access. Access requires a module instance reference, maintaining implicit ownership through a reference count. +- **Non-thread-safe Store**: Designed for efficiency in single-threaded applications. +- **JIT Compilation Support**: Prepares for JIT compiler integration with function instances designed to accommodate `WasmFunction`, `HostFunction`, or future `JitFunction`. +- **`no_std` Environment Support**: Offers compatibility with `no_std` environments by allowing disabling of `std` feature +- **Call Frame Execution**: Executes call frames in a single loop rather than recursively, using a single stack for all frames, facilitating easier pause, resume, and step-through. ## Bytecode Format To improve performance and reduce code size, instructions are encoded as enum variants instead of opcodes. -This allows preprocessing the bytecode into a more compact format, which can be loaded directly into memory and executed without decoding later. This can skip the decoding step entirely on resource-constrained devices where memory is limited. See this [blog post](https://wasmer.io/posts/improving-with-zero-copy-deserialization) by Wasmer +This allows preprocessing the bytecode into a more memory aligned format, which can be loaded directly into memory and executed without decoding later. This can skip the decoding step entirely on resource-constrained devices where memory is limited. See this [blog post](https://wasmer.io/posts/improving-with-zero-copy-deserialization) by Wasmer for more details which inspired this design. Some instructions are split into multiple variants to reduce the size of the enum (e.g. `br_table` and `br_label`). Additionally, label instructions contain offsets relative to the current instruction to make branching faster and easier to implement. -Also, `End` instructions are split into `End` and `EndBlock`. +Also, `End` instructions are split into `End` and `EndBlock`. Others are also combined, especially in cases where the stack can be skipped. See [instructions.rs](./crates/types/src/instructions.rs) for the full list of instructions. diff --git a/BENCHMARKS.md b/BENCHMARKS.md index 2cded9d..3a85e19 100644 --- a/BENCHMARKS.md +++ b/BENCHMARKS.md @@ -1,10 +1,13 @@ # Benchmark results -All benchmarks are run on a Ryzen 7 5800X with 32GB of RAM, running Linux 6.6. +All benchmarks are run on a Ryzen 7 5800X with 32GB of RAM on Linux 6.6. WebAssembly files are optimized using [wasm-opt](https://github.com/WebAssembly/binaryen), and the benchmark code is available in the `crates/benchmarks` folder. -These are mainly preliminary benchmarks, and I will be adding more in the future that are also looking into memory usage and other metrics. +These are mainly preliminary benchmarks, and I will be rewriting the benchmarks to be more accurate and to test more features in the future. +In particular, I want to test and improve memory usage, as well as the performance of the parser. + +Take these results with a grain of salt, as they are not very accurate and are likely to change in the future. ## WebAssembly Settings @@ -35,24 +38,25 @@ All runtimes are compiled with the following settings: | `argon2id` | `0.53ms` | ` 99.16ms` | `45.00ms` | ` 4.59ms` | | `selfhosted` | `0.05ms` | ` 1.84ms` | ` 6.51ms` | `446.48ms` | -_\* converting WASM to TinyWasm bytecode is not included. I takes ~5.7ms to convert `tinywasm.wasm` to TinyWasm bytecode._ +_\* Uses tinywasm's internal module format instead of `wasm`. It takes ~5.7ms to parse and validate `tinywasm.wasm`._ + _\*\* essentially instant as it gets computed at compile time._ ### Fib -The first benchmark is a simple optimized Fibonacci function, which is a good way to show the overhead of calling functions and parsing the bytecode. +The first benchmark is a simple optimized Fibonacci function, a good way to show the overhead of calling functions and parsing the bytecode. TinyWasm is slightly faster than Wasmi here, but that's probably because of the overhead of parsing the bytecode, as TinyWasm uses a custom bytecode to pre-process the WebAssembly bytecode. ### Fib-Rec -This benchmark is a recursive Fibonacci function, which highlights some of the issues with the current implementation of TinyWasm's Call Stack. -TinyWasm is a lot slower here, but that's because there's currently no way to reuse the same Call Frame for recursive calls, so a new Call Frame is allocated for every call. This is not a problem for most programs, and the upcoming `tail-call` proposal will make this a lot easier to implement. +This benchmark is a recursive Fibonacci function, highlighting some issues with the current implementation of TinyWasm's Call Stack. +TinyWasm is a lot slower here, but that's because there's currently no way to reuse the same Call Frame for recursive calls, so a new Call Frame is allocated for every call. This is not a problem for most programs; the upcoming `tail-call` proposal will make this much easier to implement. ### Argon2id -This benchmark runs the Argon2id hashing algorithm, with 2 iterations, 1KB of memory, and 1 parallel lane. -I had to decrease the memory usage from the default to 1KB, because especially the interpreters were struggling to finish in a reasonable amount of time. -This is where `simd` instructions would be really useful, and it also highlights some of the issues with the current implementation of TinyWasm's Value Stack and Memory Instances. These spend a lot of time on `Vec` operations, so they might be a good place to start experimenting with Arena Allocation. +This benchmark runs the Argon2id hashing algorithm with 2 iterations, 1KB of memory, and 1 parallel lane. +I had to decrease the memory usage from the default to 1KB because the interpreters were struggling to finish in a reasonable amount of time. +This is where `simd` instructions would be really useful, and it also highlights some of the issues with the current implementation of TinyWasm's Value Stack and Memory Instances. These spend much time on stack operations, so they might be a good place to experiment with Arena Allocation. ### Selfhosted @@ -63,9 +67,9 @@ Wasmer also offers a pre-parsed module format, so keep in mind that this number ### Conclusion -After profiling and fixing some low-hanging fruits, I found the biggest bottleneck to be Vector operations, especially for the Value Stack, and having shared access to Memory Instances using RefCell. These are the two areas I will be focusing on improving in the future, trying out Arena Allocation and other data structures to improve performance. Additionally, typed FuncHandles have a significant overhead over the untyped ones, so I will be looking into improving that as well. Still, I'm quite happy with the results, especially considering the use of standard Rust data structures. +After profiling and fixing some low-hanging fruits, I found the biggest bottleneck to be Vector operations, especially for the Value Stack, and having shared access to Memory Instances using RefCell. These are the two areas I will focus on improving in the future, trying out Arena Allocation and other data structures to improve performance. Additionally, typed FuncHandles have a significant overhead over the untyped ones, so I will also look into improving that. Still, I'm pretty happy with the results, especially considering the focus on simplicity and portability over performance. -Something that made a much bigger difference than I expected was to give compiler hints about cold paths, and to force inlining of some functions. This made the benchmarks 30%+ faster in some cases. A lot of places in the codebase have comments about what optimizations have been done. +Something that made a much more significant difference than I expected was to give compiler hints about cold paths and to force the inlining of some functions. This made the benchmarks 30%+ faster in some cases. Many places in the codebase have comments about what optimizations have been done. # Running benchmarks diff --git a/CHANGELOG.md b/CHANGELOG.md index f33ee83..1c51b74 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,27 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## [Unreleased] +## [0.6.0] - 2024-03-27 + +**All Commits**: https://github.com/explodingcamera/tinywasm/compare/v0.5.0...v0.6.0 + +### Added + +- `Imports` and `Module` are now cloneable (#9) + +### Changed + +- Improved documentation and added more tests +- Tests can now be run on more targets (#11) +- Nightly version has been updated to fix broken builds in some cases (#12) +- Add `aarch64-apple-darwin` and `armv7-unknown-linux-gnueabihf` targets to CI (#12) + +### Removed + +- Removed the `EndFunc` instruction, as it was already covered by the `Return` instruction\ + This also fixes a weird bug that only occurred on certain nightly versions of Rust + +## [0.5.0] - 2024-03-01 **All Commits**: https://github.com/explodingcamera/tinywasm/compare/v0.4.0...v0.5.0 @@ -21,13 +41,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Reduced the overhead of control flow instructions - Reduced the size of bytecode instructions - Fixed issues on the latest nightly Rust compiler -- Simpliefied a lot of the internal macros +- Simplified a lot of the internal macros ### Removed - Removed duplicate internal code -## [0.4.0] - 2024-02-04 [(commits)](https://github.com/explodingcamera/tinywasm/compare/v0.3.0...v0.4.0) +## [0.4.0] - 2024-02-04 **All Commits**: https://github.com/explodingcamera/tinywasm/compare/v0.3.0...v0.4.0 @@ -64,9 +84,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 **All Commits**: https://github.com/explodingcamera/tinywasm/compare/v0.1.0...v0.2.0 -- Support for br_table -- Memory trapping improvments -- Implicit function lable scopes +- Support for `br_table` +- Memory trapping improvements +- Implicit function label scopes - else Instructions - All Memory instructions - Imports diff --git a/Cargo.lock b/Cargo.lock index 902dd10..27fa197 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -30,9 +30,9 @@ dependencies = [ [[package]] name = "ahash" -version = "0.8.9" +version = "0.8.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d713b3834d76b85304d4d525563c1276e2e30dc97cc67bfb4585a4a29fc2c89f" +checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" dependencies = [ "cfg-if", "const-random", @@ -43,9 +43,9 @@ dependencies = [ [[package]] name = "aho-corasick" -version = "1.1.2" +version = "1.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2969dcb958b36655471fc61f7e416fa76033bdd4bfed0678d8fee1e2d07a1f0" +checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" dependencies = [ "memchr", ] @@ -96,7 +96,7 @@ dependencies = [ "argh_shared", "proc-macro2", "quote", - "syn 2.0.51", + "syn 2.0.55", ] [[package]] @@ -128,15 +128,15 @@ checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" [[package]] name = "autocfg" -version = "1.1.0" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +checksum = "f1fdabc7756949593fe60f30ec81974b613357de856987752631dea1e3394c80" [[package]] name = "backtrace" -version = "0.3.69" +version = "0.3.71" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2089b7e3f35b9dd2d0ed921ead4f6d318c27680d4a5bd167b3ee120edb105837" +checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d" dependencies = [ "addr2line", "cc", @@ -173,9 +173,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bitflags" -version = "2.4.2" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed570934406eb16438a4e976b1b4500774099c13b8cb96eec99f620f05090ddf" +checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" [[package]] name = "bitvec" @@ -219,9 +219,9 @@ dependencies = [ [[package]] name = "bumpalo" -version = "3.15.3" +version = "3.15.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ea184aa71bb362a1157c896979544cc23974e08fd265f29ea96b59f0b4a555b" +checksum = "7ff69b9dd49fd426c69a0db9fc04dd934cdb6645ff000864d98f7e2af8830eaa" [[package]] name = "bytecheck" @@ -269,9 +269,9 @@ dependencies = [ [[package]] name = "bytemuck" -version = "1.14.3" +version = "1.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2ef034f05691a48569bd920a96c81b9d91bbad1ab5ac7c4616c1f6ef36cb79f" +checksum = "5d6d68c57235a3a081186990eca2867354726650f42f7516ca50c28d6281fd15" [[package]] name = "byteorder" @@ -281,9 +281,9 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "bytes" -version = "1.5.0" +version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223" +checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" [[package]] name = "cast" @@ -293,9 +293,9 @@ checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5" [[package]] name = "cc" -version = "1.0.88" +version = "1.0.90" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02f341c093d19155a6e41631ce5971aac4e9a868262212153124c15fa22d1cdc" +checksum = "8cd6604a82acf3039f1144f54b8eb34e91ffba622051189e71b781822d5ee1f5" [[package]] name = "cfg-if" @@ -305,16 +305,16 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "chrono" -version = "0.4.34" +version = "0.4.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5bc015644b92d5890fab7489e49d21f879d5c990186827d42ec511919404f38b" +checksum = "8eaf5903dcbc0a39312feb77df2ff4c76387d591b9fc7b04a238dcf8bb62639a" dependencies = [ "android-tzdata", "iana-time-zone", "js-sys", "num-traits", "wasm-bindgen", - "windows-targets 0.52.3", + "windows-targets 0.52.4", ] [[package]] @@ -346,18 +346,18 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.1" +version = "4.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c918d541ef2913577a0f9566e9ce27cb35b6df072075769e0b26cb5a554520da" +checksum = "90bc066a67923782aa8515dbaea16946c5bcc5addbd668bb80af688e53e548a0" dependencies = [ "clap_builder", ] [[package]] name = "clap_builder" -version = "4.5.1" +version = "4.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f3e7391dad68afb0c2ede1bf619f579a3dc9c2ec67f089baa397123a2f3d1eb" +checksum = "ae129e2e766ae0ec03484e609954119f123cc1fe650337e155d03b022f24f7b4" dependencies = [ "anstyle", "clap_lex", @@ -371,9 +371,9 @@ checksum = "98cc8fbded0c607b7ba9dd60cd98df59af97e84d24e49c8557331cfc26d301ce" [[package]] name = "color-eyre" -version = "0.6.2" +version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a667583cca8c4f8436db8de46ea8233c42a7d9ae424a82d338f2e4675229204" +checksum = "55146f5e46f237f7423d74111267d4597b59b0dad0ffaf7303bce9945d843ad5" dependencies = [ "backtrace", "color-spantrace", @@ -410,9 +410,9 @@ checksum = "ed3d0b5ff30645a68f35ece8cea4556ca14ef8a1651455f789a099a0513532a6" [[package]] name = "const-random" -version = "0.1.17" +version = "0.1.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5aaf16c9c2c612020bcfd042e170f6e32de9b9d75adb5277cdbbd2e2c8c8299a" +checksum = "87e00182fe74b066627d63b85fd550ac2998d4b0bd86bfed477a0ae4c7c71359" dependencies = [ "const-random-macro", ] @@ -700,7 +700,7 @@ dependencies = [ "ident_case", "proc-macro2", "quote", - "syn 2.0.51", + "syn 2.0.55", ] [[package]] @@ -711,7 +711,7 @@ checksum = "a668eda54683121533a393014d8692171709ff57a7d61f187b6e782719f8933f" dependencies = [ "darling_core", "quote", - "syn 2.0.51", + "syn 2.0.55", ] [[package]] @@ -867,7 +867,7 @@ dependencies = [ "darling", "proc-macro2", "quote", - "syn 2.0.51", + "syn 2.0.55", ] [[package]] @@ -976,15 +976,6 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" -[[package]] -name = "form_urlencoded" -version = "1.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" -dependencies = [ - "percent-encoding", -] - [[package]] name = "freetype" version = "0.7.1" @@ -1107,14 +1098,14 @@ version = "0.14.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" dependencies = [ - "ahash 0.8.9", + "ahash 0.8.11", ] [[package]] name = "hermit-abi" -version = "0.3.8" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "379dada1584ad501b383485dd706b8afb7a70fcbc7f4da7d780638a5a6124a60" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" [[package]] name = "humantime" @@ -1151,16 +1142,6 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" -[[package]] -name = "idna" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" -dependencies = [ - "unicode-bidi", - "unicode-normalization", -] - [[package]] name = "image" version = "0.24.9" @@ -1193,9 +1174,9 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.2.3" +version = "2.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "233cf39063f058ea2caae4091bf4a3ef70a653afbc026f5c4a4135d114e3c177" +checksum = "168fb715dda47215e360912c096649d23d58bf392ac62f73919e831745e40f26" dependencies = [ "equivalent", "hashbrown 0.14.3", @@ -1229,9 +1210,9 @@ dependencies = [ [[package]] name = "itoa" -version = "1.0.10" +version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" [[package]] name = "jpeg-decoder" @@ -1241,9 +1222,9 @@ checksum = "f5d4a7da358eff58addd2877a45865158f0d78c911d43a5784ceb7bbf52833b0" [[package]] name = "js-sys" -version = "0.3.68" +version = "0.3.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "406cda4b368d531c842222cf9d2600a9a4acce8d29423695379c6868a143a9ee" +checksum = "29c15563dc2726973df627357ce0c9ddddbea194836909d655df6a75d2cf296d" dependencies = [ "wasm-bindgen", ] @@ -1268,12 +1249,12 @@ checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" [[package]] name = "libloading" -version = "0.8.1" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c571b676ddfc9a8c12f1f3d3085a7b163966a8fd8098a90640953ce5f6170161" +checksum = "0c2a198fb6b0eada2a8df47933734e6d35d350665a33a3593d7164fa52c75c19" dependencies = [ "cfg-if", - "windows-sys 0.48.0", + "windows-targets 0.52.4", ] [[package]] @@ -1288,7 +1269,7 @@ version = "0.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "85c833ca1e66078851dba29046874e38f08b2c883700aa29a03ddd3b23814ee8" dependencies = [ - "bitflags 2.4.2", + "bitflags 2.5.0", "libc", "redox_syscall", ] @@ -1305,9 +1286,9 @@ dependencies = [ [[package]] name = "log" -version = "0.4.20" +version = "0.4.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" +checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" [[package]] name = "mach" @@ -1318,6 +1299,15 @@ dependencies = [ "libc", ] +[[package]] +name = "mach2" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19b955cdeb2a02b9117f121ce63aa52d08ade45de53e48fe6a38b39c10f6f709" +dependencies = [ + "libc", +] + [[package]] name = "memchr" version = "2.7.1" @@ -1451,18 +1441,12 @@ dependencies = [ [[package]] name = "pathfinder_simd" -version = "0.5.2" -source = "git+https://github.com/servo/pathfinder?rev=e4fcda0d5259d0acf902aee6de7d2501f2bd6629#e4fcda0d5259d0acf902aee6de7d2501f2bd6629" +version = "0.5.3" +source = "git+https://github.com/servo/pathfinder?rev=30419d07660dc11a21e42ef4a7fa329600cff152#30419d07660dc11a21e42ef4a7fa329600cff152" dependencies = [ "rustc_version", ] -[[package]] -name = "percent-encoding" -version = "2.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" - [[package]] name = "pin-project-lite" version = "0.2.13" @@ -1570,9 +1554,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.78" +version = "1.0.79" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae" +checksum = "e835ff2298f5721608eb1a980ecaee1aef2c132bf95ecc026a11b7bf3c01c02e" dependencies = [ "unicode-ident", ] @@ -1620,9 +1604,9 @@ checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" [[package]] name = "rayon" -version = "1.8.1" +version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa7237101a77a10773db45d62004a272517633fbcc3df19d96455ede1122e051" +checksum = "b418a60154510ca1a002a752ca9714984e21e4241e804d32555251faf8b78ffa" dependencies = [ "either", "rayon-core", @@ -1672,9 +1656,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.10.3" +version = "1.10.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b62dbe01f0b06f9d8dc7d49e05a0785f153b00b2c227856282f671e0318c9b15" +checksum = "c117dbdfde9c8308975b6a18d71f3f385c89461f7b3fb054288ecf2a2058ba4c" dependencies = [ "aho-corasick", "memchr", @@ -1684,9 +1668,9 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.4.5" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5bb987efffd3c6d0d8f5f89510bb458559eab11e4f869acb20bf845e016259cd" +checksum = "86b83b8b9847f9bf95ef68afb0b8e6cdb80f498442f5179a29fad448fcc1eaea" dependencies = [ "aho-corasick", "memchr", @@ -1701,14 +1685,14 @@ checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" [[package]] name = "region" -version = "3.0.0" +version = "3.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76e189c2369884dce920945e2ddf79b3dff49e071a167dd1817fa9c4c00d512e" +checksum = "e6b6ebd13bc009aef9cd476c1310d49ac354d36e240cf1bd753290f3dc7199a7" dependencies = [ "bitflags 1.3.2", "libc", - "mach", - "winapi", + "mach2", + "windows-sys 0.52.0", ] [[package]] @@ -1770,7 +1754,7 @@ dependencies = [ "proc-macro2", "quote", "rust-embed-utils", - "syn 2.0.51", + "syn 2.0.55", "walkdir", ] @@ -1821,6 +1805,14 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" +[[package]] +name = "scripts" +version = "0.0.0" +dependencies = [ + "eyre", + "plotters", +] + [[package]] name = "seahash" version = "4.1.0" @@ -1867,14 +1859,14 @@ checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.51", + "syn 2.0.55", ] [[package]] name = "serde_json" -version = "1.0.114" +version = "1.0.115" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c5f09b1bd632ef549eaa9f60a1f8de742bdbc698e6cee2095fc84dde5f549ae0" +checksum = "12dc5c46daa8e9fdf4f5e71b6cf9a53f2487da0e86e55808e2d35539666497dd" dependencies = [ "itoa", "ryu", @@ -1931,9 +1923,9 @@ checksum = "826167069c09b99d56f31e9ae5c99049e932a98c9dc2dac47645b08dbbf76ba7" [[package]] name = "smallvec" -version = "1.13.1" +version = "1.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6ecd384b10a64542d77071bd64bd7b231f4ed5940fba55e98c3de13824cf3d7" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" [[package]] name = "spin" @@ -1966,9 +1958,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.51" +version = "2.0.55" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ab617d94515e94ae53b8406c628598680aa0c9587474ecbe58188f7b345d66c" +checksum = "002a1b3dbf967edfafc32655d0f377ab0bb7b994aa1d32c8cc7e9b8bf3ebb8f0" dependencies = [ "proc-macro2", "quote", @@ -1998,22 +1990,22 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.57" +version = "1.0.58" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e45bcbe8ed29775f228095caf2cd67af7a4ccf756ebff23a306bf3e8b47b24b" +checksum = "03468839009160513471e86a034bb2c5c0e4baae3b43f79ffc55c4a5427b3297" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.57" +version = "1.0.58" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a953cb265bef375dae3de6663da4d3804eee9682ea80d8e2542529b73c531c81" +checksum = "c61f3ba182994efc43764a46c018c347bc492c79f024e705f46567b418f6d4f7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.51", + "syn 2.0.55", ] [[package]] @@ -2062,37 +2054,36 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tinywasm" -version = "0.5.0" +version = "0.6.0" dependencies = [ "eyre", "libm", "log", "owo-colors 4.0.0", - "plotters", "pretty_env_logger", "serde", "serde_json", "tinywasm-parser", "tinywasm-types", "wasm-testsuite", - "wast 200.0.0", + "wast 202.0.0", ] [[package]] name = "tinywasm-cli" -version = "0.5.0" +version = "0.6.0" dependencies = [ "argh", "color-eyre", "log", "pretty_env_logger", "tinywasm", - "wast 200.0.0", + "wast 202.0.0", ] [[package]] name = "tinywasm-parser" -version = "0.5.0" +version = "0.6.0" dependencies = [ "log", "tinywasm-types", @@ -2111,7 +2102,7 @@ dependencies = [ [[package]] name = "tinywasm-types" -version = "0.5.0" +version = "0.6.0" dependencies = [ "bytecheck 0.7.0", "log", @@ -2120,14 +2111,14 @@ dependencies = [ [[package]] name = "tinywasm-wasmparser" -version = "0.200.3" +version = "0.202.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "365709f885b90cad71c71120414f99255e74d9d03f232618d9d1c6eb5db0ea99" +checksum = "b02b9566a3c8b98f29dd9821d0584de1ad0290cdc9132296f66fbf4015001bb1" dependencies = [ - "ahash 0.8.9", - "bitflags 2.4.2", + "ahash 0.8.11", + "bitflags 2.5.0", "hashbrown 0.14.3", - "indexmap 2.2.3", + "indexmap 2.2.6", "semver", ] @@ -2150,7 +2141,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.51", + "syn 2.0.55", ] [[package]] @@ -2196,49 +2187,23 @@ version = "1.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" -[[package]] -name = "unicode-bidi" -version = "0.3.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08f95100a766bf4f8f28f90d77e0a5461bbdb219042e7679bebe79004fed8d75" - [[package]] name = "unicode-ident" version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" -[[package]] -name = "unicode-normalization" -version = "0.1.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a56d1686db2308d901306f92a263857ef59ea39678a5458e7cb17f01415101f5" -dependencies = [ - "tinyvec", -] - [[package]] name = "unicode-width" version = "0.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e51733f11c9c4f72aa0c160008246859e340b00807569a0da0e7a1079b27ba85" -[[package]] -name = "url" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31e6302e3bb753d46e83516cae55ae196fc0c309407cf11ab35cc51a4c2a4633" -dependencies = [ - "form_urlencoded", - "idna", - "percent-encoding", -] - [[package]] name = "uuid" -version = "1.7.0" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f00cc9702ca12d3c81455259621e676d0f7251cec66a21e98fe2e9a37db93b2a" +checksum = "a183cf7feeba97b4dd1c0d46788634f6221d87fa961b305bed08c851829efcc0" [[package]] name = "valuable" @@ -2254,9 +2219,9 @@ checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" [[package]] name = "walkdir" -version = "2.4.0" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d71d857dc86794ca4c280d616f7da00d2dbfd8cd788846559a6813e6aa4b54ee" +checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b" dependencies = [ "same-file", "winapi-util", @@ -2270,9 +2235,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.91" +version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1e124130aee3fb58c5bdd6b639a0509486b0338acaaae0c84a5124b0f588b7f" +checksum = "4be2531df63900aeb2bca0daaaddec08491ee64ceecbee5076636a3b026795a8" dependencies = [ "cfg-if", "wasm-bindgen-macro", @@ -2280,24 +2245,24 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.91" +version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c9e7e1900c352b609c8488ad12639a311045f40a35491fb69ba8c12f758af70b" +checksum = "614d787b966d3989fa7bb98a654e369c762374fd3213d212cfc0251257e747da" dependencies = [ "bumpalo", "log", "once_cell", "proc-macro2", "quote", - "syn 2.0.51", + "syn 2.0.55", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-macro" -version = "0.2.91" +version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b30af9e2d358182b5c7449424f017eba305ed32a7010509ede96cdc4696c46ed" +checksum = "a1f8823de937b71b9460c0c34e25f3da88250760bec0ebac694b49997550d726" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -2305,22 +2270,22 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.91" +version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "642f325be6301eb8107a83d12a8ac6c1e1c54345a7ef1a9261962dfefda09e66" +checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.51", + "syn 2.0.55", "wasm-bindgen-backend", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-shared" -version = "0.2.91" +version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4f186bd2dcf04330886ce82d6f33dd75a7bfcf69ecf5763b89fcde53b6ac9838" +checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96" [[package]] name = "wasm-encoder" @@ -2333,25 +2298,25 @@ dependencies = [ [[package]] name = "wasm-encoder" -version = "0.200.0" +version = "0.202.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9e3fb0c8fbddd78aa6095b850dfeedbc7506cf5f81e633f69cf8f2333ab84b9" +checksum = "bfd106365a7f5f7aa3c1916a98cbb3ad477f5ff96ddb130285a91c6e7429e67a" dependencies = [ "leb128", ] [[package]] name = "wasm-testsuite" -version = "0.2.2" +version = "0.3.0" dependencies = [ "rust-embed", ] [[package]] name = "wasmer" -version = "4.2.5" +version = "4.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5467c7a23f9be04d5691590bea509dbea27e5ba5810d0020bef908456a495f33" +checksum = "5c15724dc25d1ee57962334aea8e41ade2675e5ea2ac6b8d42da6051b0face66" dependencies = [ "bytes", "cfg-if", @@ -2365,6 +2330,7 @@ dependencies = [ "shared-buffer", "target-lexicon", "thiserror", + "tracing", "wasm-bindgen", "wasmer-compiler", "wasmer-compiler-cranelift", @@ -2378,9 +2344,9 @@ dependencies = [ [[package]] name = "wasmer-compiler" -version = "4.2.5" +version = "4.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "510ad01a668d774f3a103a7c219bbc0970be93e8f1b27e2fdb48d1f4ccd1deff" +checksum = "55a7f3b3a96f8d844c25e2c032af9572306dd63fa93dc17bcca4c5458ac569bd" dependencies = [ "backtrace", "bytes", @@ -2405,9 +2371,9 @@ dependencies = [ [[package]] name = "wasmer-compiler-cranelift" -version = "4.2.5" +version = "4.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "54bf93078990d83960d798de3c5935bddaba771fc2fefb9ed6bab9c0bbdea5c1" +checksum = "102e2c5bacac69495c4025767e2fa26797ffb27f242dccb7cf57d9cefd944386" dependencies = [ "cranelift-codegen", "cranelift-entity", @@ -2424,9 +2390,9 @@ dependencies = [ [[package]] name = "wasmer-compiler-singlepass" -version = "4.2.5" +version = "4.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f4d6359d66a8bcefac26d48fcb0f3f0882bdf122b52121a1ae21f918706e040" +checksum = "2071db9b993508dac72d12f7a9372e0c095fbdc173e0009c4b75886bed4a855e" dependencies = [ "byteorder", "dynasm", @@ -2443,9 +2409,9 @@ dependencies = [ [[package]] name = "wasmer-derive" -version = "4.2.5" +version = "4.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b374fd34d97b1c091d8675f9bc472df52dc6787d139d3762d42c7dc84813a9b" +checksum = "0ea737fa08f95d6abc4459f42a70a9833e8974b814e74971d77ef473814f4d4c" dependencies = [ "proc-macro-error", "proc-macro2", @@ -2455,9 +2421,9 @@ dependencies = [ [[package]] name = "wasmer-types" -version = "4.2.5" +version = "4.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0caf1c87937b52aba8e9f920a278e1beda282f7439612c0b48f51a58e7a87bab" +checksum = "b0689110e291b0f07fc665f2824e5ff81df120848e8a9acfbf1a9bf7990773f9" dependencies = [ "bytecheck 0.6.12", "enum-iterator", @@ -2471,9 +2437,9 @@ dependencies = [ [[package]] name = "wasmer-vm" -version = "4.2.5" +version = "4.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "58315c25492bc72a33f47a7d7fb0869a0106fc0164ec051e349a9e1eddba9a01" +checksum = "4cd41f822a1ac4242d478754e8ceba2806a00ea5072803622e1fe91e8e28b2a1" dependencies = [ "backtrace", "cc", @@ -2530,12 +2496,13 @@ dependencies = [ [[package]] name = "wasmparser" -version = "0.95.0" +version = "0.121.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2ea896273ea99b15132414be1da01ab0d8836415083298ecaffbe308eaac87a" +checksum = "9dbe55c8f9d0dbd25d9447a5a889ff90c0cc3feaa7395310d3d826b2c703eaab" dependencies = [ - "indexmap 1.9.3", - "url", + "bitflags 2.5.0", + "indexmap 2.2.6", + "semver", ] [[package]] @@ -2561,15 +2528,15 @@ dependencies = [ [[package]] name = "wast" -version = "200.0.0" +version = "202.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d1810d14e6b03ebb8fb05eef4009ad5749c989b65197d83bce7de7172ed91366" +checksum = "1fbcb11204515c953c9b42ede0a46a1c5e17f82af05c4fae201a8efff1b0f4fe" dependencies = [ "bumpalo", "leb128", "memchr", "unicode-width", - "wasm-encoder 0.200.0", + "wasm-encoder 0.202.0", ] [[package]] @@ -2583,9 +2550,9 @@ dependencies = [ [[package]] name = "web-sys" -version = "0.3.68" +version = "0.3.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96565907687f7aceb35bc5fc03770a8a0471d82e479f25832f54a0e3f4b28446" +checksum = "77afa9a11836342370f4817622a2f0f418b134426d91a82dfb48f532d2ec13ef" dependencies = [ "js-sys", "wasm-bindgen", @@ -2634,7 +2601,7 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" dependencies = [ - "windows-targets 0.52.3", + "windows-targets 0.52.4", ] [[package]] @@ -2650,22 +2617,13 @@ dependencies = [ "windows_x86_64_msvc 0.33.0", ] -[[package]] -name = "windows-sys" -version = "0.48.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" -dependencies = [ - "windows-targets 0.48.5", -] - [[package]] name = "windows-sys" version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" dependencies = [ - "windows-targets 0.52.3", + "windows-targets 0.52.4", ] [[package]] @@ -2685,17 +2643,17 @@ dependencies = [ [[package]] name = "windows-targets" -version = "0.52.3" +version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d380ba1dc7187569a8a9e91ed34b8ccfc33123bbacb8c0aed2d1ad7f3ef2dc5f" +checksum = "7dd37b7e5ab9018759f893a1952c9420d060016fc19a472b4bb20d1bdd694d1b" dependencies = [ - "windows_aarch64_gnullvm 0.52.3", - "windows_aarch64_msvc 0.52.3", - "windows_i686_gnu 0.52.3", - "windows_i686_msvc 0.52.3", - "windows_x86_64_gnu 0.52.3", - "windows_x86_64_gnullvm 0.52.3", - "windows_x86_64_msvc 0.52.3", + "windows_aarch64_gnullvm 0.52.4", + "windows_aarch64_msvc 0.52.4", + "windows_i686_gnu 0.52.4", + "windows_i686_msvc 0.52.4", + "windows_x86_64_gnu 0.52.4", + "windows_x86_64_gnullvm 0.52.4", + "windows_x86_64_msvc 0.52.4", ] [[package]] @@ -2706,9 +2664,9 @@ checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" [[package]] name = "windows_aarch64_gnullvm" -version = "0.52.3" +version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68e5dcfb9413f53afd9c8f86e56a7b4d86d9a2fa26090ea2dc9e40fba56c6ec6" +checksum = "bcf46cf4c365c6f2d1cc93ce535f2c8b244591df96ceee75d8e83deb70a9cac9" [[package]] name = "windows_aarch64_msvc" @@ -2724,9 +2682,9 @@ checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" [[package]] name = "windows_aarch64_msvc" -version = "0.52.3" +version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8dab469ebbc45798319e69eebf92308e541ce46760b49b18c6b3fe5e8965b30f" +checksum = "da9f259dd3bcf6990b55bffd094c4f7235817ba4ceebde8e6d11cd0c5633b675" [[package]] name = "windows_i686_gnu" @@ -2742,9 +2700,9 @@ checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" [[package]] name = "windows_i686_gnu" -version = "0.52.3" +version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a4e9b6a7cac734a8b4138a4e1044eac3404d8326b6c0f939276560687a033fb" +checksum = "b474d8268f99e0995f25b9f095bc7434632601028cf86590aea5c8a5cb7801d3" [[package]] name = "windows_i686_msvc" @@ -2760,9 +2718,9 @@ checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" [[package]] name = "windows_i686_msvc" -version = "0.52.3" +version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28b0ec9c422ca95ff34a78755cfa6ad4a51371da2a5ace67500cf7ca5f232c58" +checksum = "1515e9a29e5bed743cb4415a9ecf5dfca648ce85ee42e15873c3cd8610ff8e02" [[package]] name = "windows_x86_64_gnu" @@ -2778,9 +2736,9 @@ checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" [[package]] name = "windows_x86_64_gnu" -version = "0.52.3" +version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "704131571ba93e89d7cd43482277d6632589b18ecf4468f591fbae0a8b101614" +checksum = "5eee091590e89cc02ad514ffe3ead9eb6b660aedca2183455434b93546371a03" [[package]] name = "windows_x86_64_gnullvm" @@ -2790,9 +2748,9 @@ checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" [[package]] name = "windows_x86_64_gnullvm" -version = "0.52.3" +version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42079295511643151e98d61c38c0acc444e52dd42ab456f7ccfd5152e8ecf21c" +checksum = "77ca79f2451b49fa9e2af39f0747fe999fcda4f5e241b2898624dca97a1f2177" [[package]] name = "windows_x86_64_msvc" @@ -2808,9 +2766,9 @@ checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" [[package]] name = "windows_x86_64_msvc" -version = "0.52.3" +version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0770833d60a970638e989b3fa9fd2bb1aaadcf88963d1659fd7d9990196ed2d6" +checksum = "32b752e52a2da0ddfbdbcc6fceadfeede4c939ed16d13e648833a61dfb611ed8" [[package]] name = "wio" @@ -2859,5 +2817,5 @@ checksum = "9ce1b18ccd8e73a9321186f97e46f9f04b778851177567b1975109d26a08d2a6" dependencies = [ "proc-macro2", "quote", - "syn 2.0.51", + "syn 2.0.55", ] diff --git a/Cargo.toml b/Cargo.toml index 41b7af0..c5fca68 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [workspace] -members=["crates/*"] +members=["crates/*", "benchmarks", "scripts"] default-members=[".", "crates/tinywasm", "crates/types", "crates/parser"] resolver="2" @@ -11,7 +11,7 @@ panic="abort" inherits="release" [workspace.package] -version="0.5.0" +version="0.6.0" edition="2021" license="MIT OR Apache-2.0" authors=["Henry Gressmann "] @@ -39,5 +39,5 @@ codegen-units=1 debug=true [patch.crates-io] -# https://github.com/servo/pathfinder/pull/548 -pathfinder_simd={git="https://github.com/servo/pathfinder", rev="e4fcda0d5259d0acf902aee6de7d2501f2bd6629"} +# https://github.com/servo/pathfinder/pull/548 & https://github.com/servo/pathfinder/issues/558 +pathfinder_simd={git="https://github.com/servo/pathfinder", rev="30419d07660dc11a21e42ef4a7fa329600cff152"} diff --git a/README.md b/README.md index c2abbf3..38000f4 100644 --- a/README.md +++ b/README.md @@ -13,14 +13,16 @@ ## Why TinyWasm? - **Tiny**: TinyWasm is designed to be as small as possible without significantly compromising performance or functionality (< 6000 lines of code). -- **Portable**: TinyWasm runs on any platform that Rust can target, including WebAssembly itself, with minimal external dependencies. +- **Portable**: TinyWasm runs on any platform that Rust can target, including other WebAssembly Runtimes, with minimal external dependencies. - **Lightweight**: TinyWasm is easy to integrate and has a low call overhead, making it suitable for scripting and embedding. ## Status -As of version `0.3.0`, TinyWasm successfully passes all the WebAssembly 1.0 tests in the [WebAssembly Test Suite](https://github.com/WebAssembly/testsuite). Work on the 2.0 tests is ongoing. This enables TinyWasm to run most WebAssembly programs, including versions of TinyWasm itself compiled to WebAssembly (see [examples/wasm-rust.rs](./examples/wasm-rust.rs)). The results of the testsuites are available [here](https://github.com/explodingcamera/tinywasm/tree/main/crates/tinywasm/tests/generated). +As of version `0.3.0`, TinyWasm successfully passes all the WebAssembly 1.0 tests in the [WebAssembly Test Suite](https://github.com/WebAssembly/testsuite). Work on the 2.0 tests is ongoing. This enables TinyWasm to run most WebAssembly programs, including executing TinyWasm itself compiled to WebAssembly (see [examples/wasm-rust.rs](./examples/wasm-rust.rs)). The results of the testsuites are available [here](https://github.com/explodingcamera/tinywasm/tree/main/crates/tinywasm/tests/generated). -The API is still unstable and may change at any time, so you probably don't want to use it in production _yet_. Note that TinyWasm isn't primarily designed for high performance; its focus lies more on simplicity, size, and portability. More details on its performance aspects can be found in [BENCHMARKS.md](./BENCHMARKS.md). +The API is still unstable and may change at any time, so you probably don't want to use it in production _yet_. TinyWasm isn't primarily designed for high performance; it focuses more on simplicity, size, and portability. More details on its performance can be found in [BENCHMARKS.md](./BENCHMARKS.md). + +**Future Development**: The first major version will focus on improving the API and adding support for [WASI](https://wasi.dev/). While doing so, I also want to further simplify and reduce the codebase's size and improve the parser's performance. ## Supported Proposals @@ -64,11 +66,22 @@ $ tinywasm-cli --help - **`archive`**\ Enables pre-parsing of archives. This is enabled by default. - **`unsafe`**\ - Uses `unsafe` code to improve performance, particularly in Memory access + Uses `unsafe` code to improve performance, particularly in Memory access. -With all these features disabled, TinyWasm only depends on `core`, `alloc` and `libm` and can be used in `no_std` environments. +With all these features disabled, TinyWasm only depends on `core`, `alloc` ,and `libm` and can be used in `no_std` environments. Since `libm` is not as performant as the compiler's math intrinsics, it is recommended to use the `std` feature if possible (at least [for now](https://github.com/rust-lang/rfcs/issues/2505)), especially on wasm32 targets. +## Inspiration + +Big thanks to the authors of the following projects, which have inspired and influenced TinyWasm: + +- [wasmi](https://github.com/wasmi-labs/wasmi) - an efficient and lightweight WebAssembly interpreter that also runs on `no_std` environments +- [wasm3](https://github.com/wasm3/wasm3) - a high performance WebAssembly interpreter written in C +- [wazero](https://wazero.io/) - a zero-dependency WebAssembly interpreter written in go +- [wain](https://github.com/rhysd/wain) - a zero-dependency WebAssembly interpreter written in Rust + +I encourage you to check these projects out if you're looking for a more mature and feature-complete WebAssembly interpreter. + ## License Licensed under either of [Apache License, Version 2.0](./LICENSE-APACHE) or [MIT license](./LICENSE-MIT) at your option. diff --git a/crates/benchmarks/Cargo.toml b/benchmarks/Cargo.toml similarity index 86% rename from crates/benchmarks/Cargo.toml rename to benchmarks/Cargo.toml index b9225c1..a374713 100644 --- a/crates/benchmarks/Cargo.toml +++ b/benchmarks/Cargo.toml @@ -5,7 +5,7 @@ edition.workspace=true [dependencies] criterion={version="0.5", features=["html_reports"]} -tinywasm={path="../../crates/tinywasm", features=["unsafe"]} +tinywasm={path="../crates/tinywasm", features=["unsafe"]} wat={version="1.0"} wasmi={version="0.31", features=["std"]} wasmer={version="4.2", features=["cranelift", "singlepass"]} diff --git a/crates/benchmarks/benches/argon2id.rs b/benchmarks/benches/argon2id.rs similarity index 96% rename from crates/benchmarks/benches/argon2id.rs rename to benchmarks/benches/argon2id.rs index 7c1ffc5..3046dee 100644 --- a/crates/benchmarks/benches/argon2id.rs +++ b/benchmarks/benches/argon2id.rs @@ -36,7 +36,7 @@ fn run_native(params: (i32, i32, i32)) { run_native(params.0, params.1, params.2) } -const ARGON2ID: &[u8] = include_bytes!("../../../examples/rust/out/argon2id.wasm"); +const ARGON2ID: &[u8] = include_bytes!("../../examples/rust/out/argon2id.wasm"); fn criterion_benchmark(c: &mut Criterion) { let twasm = wasm_to_twasm(ARGON2ID); let params = (1000, 2, 1); diff --git a/crates/benchmarks/benches/fibonacci.rs b/benchmarks/benches/fibonacci.rs similarity index 97% rename from crates/benchmarks/benches/fibonacci.rs rename to benchmarks/benches/fibonacci.rs index 8a4dab2..b391285 100644 --- a/crates/benchmarks/benches/fibonacci.rs +++ b/benchmarks/benches/fibonacci.rs @@ -45,7 +45,7 @@ fn run_native_recursive(n: i32) -> i32 { run_native_recursive(n - 1) + run_native_recursive(n - 2) } -const FIBONACCI: &[u8] = include_bytes!("../../../examples/rust/out/fibonacci.wasm"); +const FIBONACCI: &[u8] = include_bytes!("../../examples/rust/out/fibonacci.wasm"); fn criterion_benchmark(c: &mut Criterion) { let twasm = wasm_to_twasm(FIBONACCI); diff --git a/crates/benchmarks/benches/selfhosted.rs b/benchmarks/benches/selfhosted.rs similarity index 95% rename from crates/benchmarks/benches/selfhosted.rs rename to benchmarks/benches/selfhosted.rs index 94dfdce..02d44ac 100644 --- a/crates/benchmarks/benches/selfhosted.rs +++ b/benchmarks/benches/selfhosted.rs @@ -4,7 +4,7 @@ use criterion::{criterion_group, criterion_main, Criterion}; fn run_native() { use tinywasm::*; - let module = tinywasm::Module::parse_bytes(include_bytes!("../../../examples/rust/out/print.wasm")).expect("parse"); + let module = tinywasm::Module::parse_bytes(include_bytes!("../../examples/rust/out/print.wasm")).expect("parse"); let mut store = Store::default(); let mut imports = Imports::default(); imports.define("env", "printi32", Extern::typed_func(|_: FuncContext<'_>, _: i32| Ok(()))).expect("define"); @@ -51,7 +51,7 @@ fn run_wasmer(wasm: &[u8]) { hello.call(&mut store, &[]).expect("call"); } -const TINYWASM: &[u8] = include_bytes!("../../../examples/rust/out/tinywasm.wasm"); +const TINYWASM: &[u8] = include_bytes!("../../examples/rust/out/tinywasm.wasm"); fn criterion_benchmark(c: &mut Criterion) { { let mut group = c.benchmark_group("selfhosted-parse"); diff --git a/crates/benchmarks/benches/util/mod.rs b/benchmarks/benches/util/mod.rs similarity index 96% rename from crates/benchmarks/benches/util/mod.rs rename to benchmarks/benches/util/mod.rs index 0df2a52..f75ce66 100644 --- a/crates/benchmarks/benches/util/mod.rs +++ b/benchmarks/benches/util/mod.rs @@ -1,6 +1,6 @@ #![allow(dead_code)] -use tinywasm::{self, parser::Parser, types::TinyWasmModule}; +use tinywasm::{parser::Parser, types::TinyWasmModule}; pub fn parse_wasm(wasm: &[u8]) -> TinyWasmModule { let parser = Parser::new(); diff --git a/crates/cli/Cargo.toml b/crates/cli/Cargo.toml index f6105c8..0012483 100644 --- a/crates/cli/Cargo.toml +++ b/crates/cli/Cargo.toml @@ -14,12 +14,12 @@ path="src/bin.rs" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -tinywasm={version="0.5.0", path="../tinywasm", features=["std", "parser"]} +tinywasm={version="0.6.0", path="../tinywasm", features=["std", "parser"]} argh="0.1" color-eyre={version="0.6", default-features=false} log="0.4" pretty_env_logger="0.5" -wast={version="200.0", optional=true} +wast={version="202.0", optional=true} [features] default=["wat"] diff --git a/crates/cli/src/bin.rs b/crates/cli/src/bin.rs index 34d4bcd..6508c5f 100644 --- a/crates/cli/src/bin.rs +++ b/crates/cli/src/bin.rs @@ -4,7 +4,7 @@ use argh::FromArgs; use args::WasmArg; use color_eyre::eyre::Result; use log::{debug, info}; -use tinywasm::{self, types::WasmValue, Module}; +use tinywasm::{types::WasmValue, Module}; use crate::args::to_wasm_args; mod args; diff --git a/crates/parser/Cargo.toml b/crates/parser/Cargo.toml index b21c0ac..6057c30 100644 --- a/crates/parser/Cargo.toml +++ b/crates/parser/Cargo.toml @@ -9,12 +9,11 @@ repository.workspace=true [dependencies] # fork of wasmparser with no_std support, see https://github.com/bytecodealliance/wasmtime/issues/3495 -wasmparser={version="0.200.3", package="tinywasm-wasmparser", default-features=false} +wasmparser={version="0.202.0", package="tinywasm-wasmparser", default-features=false} log={version="0.4", optional=true} -tinywasm-types={version="0.5.0", path="../types", default-features=false} +tinywasm-types={version="0.6.0", path="../types", default-features=false} [features] default=["std", "logging"] logging=["log"] std=["tinywasm-types/std"] - diff --git a/crates/parser/src/conversion.rs b/crates/parser/src/conversion.rs index c13d08f..ccdc308 100644 --- a/crates/parser/src/conversion.rs +++ b/crates/parser/src/conversion.rs @@ -187,6 +187,7 @@ pub(crate) fn convert_module_type(ty: wasmparser::RecGroup) -> Result )); } let ty = types.next().unwrap().unwrap_func(); + let params = ty.params().iter().map(|p| Ok(convert_valtype(p))).collect::>>()?.into_boxed_slice(); @@ -197,11 +198,10 @@ pub(crate) fn convert_module_type(ty: wasmparser::RecGroup) -> Result } pub(crate) fn convert_blocktype(blocktype: wasmparser::BlockType) -> BlockArgs { - use wasmparser::BlockType::*; match blocktype { - Empty => BlockArgs::Empty, - Type(ty) => BlockArgs::Type(convert_valtype(&ty)), - FuncType(ty) => BlockArgs::FuncType(ty), + wasmparser::BlockType::Empty => BlockArgs::Empty, + wasmparser::BlockType::Type(ty) => BlockArgs::Type(convert_valtype(&ty)), + wasmparser::BlockType::FuncType(ty) => BlockArgs::FuncType(ty), } } diff --git a/crates/parser/src/lib.rs b/crates/parser/src/lib.rs index 7beb5f8..5fb3c48 100644 --- a/crates/parser/src/lib.rs +++ b/crates/parser/src/lib.rs @@ -8,9 +8,11 @@ #![cfg_attr(not(feature = "std"), feature(error_in_core))] //! See [`tinywasm`](https://docs.rs/tinywasm) for documentation. -mod std; extern crate alloc; +#[cfg(feature = "std")] +extern crate std; + // log for logging (optional). #[cfg(feature = "logging")] #[allow(clippy::single_component_path_imports)] @@ -32,7 +34,7 @@ mod visit; use alloc::{string::ToString, vec::Vec}; pub use error::*; use module::ModuleReader; -use tinywasm_types::{TypedWasmFunction, WasmFunction}; +use tinywasm_types::WasmFunction; use wasmparser::{Validator, WasmFeatures}; pub use tinywasm_types::TinyWasmModule; @@ -156,13 +158,10 @@ impl TryFrom for TinyWasmModule { .code .into_iter() .zip(code_type_addrs) - .map(|((instructions, locals), ty_idx)| TypedWasmFunction { - type_addr: ty_idx, - wasm_function: WasmFunction { - instructions, - locals, - ty: reader.func_types.get(ty_idx as usize).expect("No func type for func, this is a bug").clone(), - }, + .map(|((instructions, locals), ty_idx)| WasmFunction { + instructions, + locals, + ty: reader.func_types.get(ty_idx as usize).expect("No func type for func, this is a bug").clone(), }) .collect::>(); @@ -175,7 +174,6 @@ impl TryFrom for TinyWasmModule { globals: globals.into_boxed_slice(), table_types: table_types.into_boxed_slice(), imports: reader.imports.into_boxed_slice(), - version: reader.version, start_func: reader.start_func, data: reader.data.into_boxed_slice(), exports: reader.exports.into_boxed_slice(), diff --git a/crates/parser/src/std.rs b/crates/parser/src/std.rs deleted file mode 100644 index 16a7058..0000000 --- a/crates/parser/src/std.rs +++ /dev/null @@ -1,5 +0,0 @@ -#[cfg(feature = "std")] -extern crate std; - -#[cfg(feature = "std")] -pub(crate) use std::*; diff --git a/crates/parser/src/visit.rs b/crates/parser/src/visit.rs index cc9f0e2..c5743b8 100644 --- a/crates/parser/src/visit.rs +++ b/crates/parser/src/visit.rs @@ -10,7 +10,6 @@ struct ValidateThenVisit<'a, T, U>(T, &'a mut U); macro_rules! validate_then_visit { ($( @$proposal:ident $op:ident $({ $($arg:ident: $argty:ty),* })? => $visit:ident)*) => { $( - #[inline] fn $visit(&mut self $($(,$arg: $argty)*)?) -> Self::Output { self.0.$visit($($($arg.clone()),*)?)?; Ok(self.1.$visit($($($arg),*)?)) @@ -103,7 +102,7 @@ pub(crate) struct FunctionBuilder { impl FunctionBuilder { pub(crate) fn new(instr_capacity: usize) -> Self { - Self { instructions: Vec::with_capacity(instr_capacity), label_ptrs: Vec::with_capacity(128) } + Self { instructions: Vec::with_capacity(instr_capacity), label_ptrs: Vec::with_capacity(256) } } #[cold] @@ -391,10 +390,9 @@ impl<'a> wasmparser::VisitOperator<'a> for FunctionBuilder { self.visit(Instruction::Else(0)) } - #[inline] fn visit_end(&mut self) -> Self::Output { let Some(label_pointer) = self.label_ptrs.pop() else { - return self.visit(Instruction::EndFunc); + return self.visit(Instruction::Return); }; let current_instr_ptr = self.instructions.len(); @@ -422,11 +420,11 @@ impl<'a> wasmparser::VisitOperator<'a> for FunctionBuilder { *else_offset = (label_pointer - if_label_pointer) .try_into() - .expect("else_instr_end_offset is too large, tinywasm does not support blocks that large"); + .expect("else_instr_end_offset is too large, tinywasm does not support blocks that large"); *end_offset = (current_instr_ptr - if_label_pointer) .try_into() - .expect("else_instr_end_offset is too large, tinywasm does not support blocks that large"); + .expect("else_instr_end_offset is too large, tinywasm does not support blocks that large"); } Instruction::Block(_, ref mut end_offset) | Instruction::Loop(_, ref mut end_offset) diff --git a/crates/tinywasm/Cargo.toml b/crates/tinywasm/Cargo.toml index 406a82d..81d0eeb 100644 --- a/crates/tinywasm/Cargo.toml +++ b/crates/tinywasm/Cargo.toml @@ -13,33 +13,28 @@ name="tinywasm" path="src/lib.rs" [dependencies] -log={version="0.4", optional=true} -tinywasm-parser={version="0.5.0", path="../parser", default-features=false, optional=true} -tinywasm-types={version="0.5.0", path="../types", default-features=false} +_log={version="0.4", optional=true, package="log"} +tinywasm-parser={version="0.6.0", path="../parser", default-features=false, optional=true} +tinywasm-types={version="0.6.0", path="../types", default-features=false} libm={version="0.2", default-features=false} [dev-dependencies] wasm-testsuite={path="../wasm-testsuite"} -wast={version="200.0"} +wast={version="202.0"} owo-colors={version="4.0"} eyre={version="0.6"} serde_json={version="1.0"} serde={version="1.0", features=["derive"]} -plotters={version="0.3"} pretty_env_logger="0.5" [features] default=["std", "parser", "logging", "archive"] -logging=["log", "tinywasm-parser?/logging", "tinywasm-types/logging"] +logging=["_log", "tinywasm-parser?/logging", "tinywasm-types/logging"] std=["tinywasm-parser?/std", "tinywasm-types/std"] parser=["tinywasm-parser"] unsafe=["tinywasm-types/unsafe"] archive=["tinywasm-types/archive"] -[[test]] -name="generate-charts" -harness=false - [[test]] name="test-mvp" harness=false diff --git a/crates/tinywasm/src/imports.rs b/crates/tinywasm/src/imports.rs index 1c5ca98..67ac360 100644 --- a/crates/tinywasm/src/imports.rs +++ b/crates/tinywasm/src/imports.rs @@ -191,6 +191,7 @@ impl From<&Import> for ExternName { /// /// ## Example /// ```rust +/// # use _log as log; /// # fn main() -> tinywasm::Result<()> { /// use tinywasm::{Imports, Extern}; /// use tinywasm::types::{ValType, TableType, MemoryType, WasmValue}; @@ -218,6 +219,7 @@ impl From<&Import> for ExternName { /// /// Note that module instance addresses for [`Imports::link_module`] can be obtained from [`crate::ModuleInstance::id`]. /// Now, the imports object can be passed to [`crate::ModuleInstance::instantiate`]. +#[derive(Clone)] pub struct Imports { values: BTreeMap, modules: BTreeMap, diff --git a/crates/tinywasm/src/lib.rs b/crates/tinywasm/src/lib.rs index 583a68d..e2d57fc 100644 --- a/crates/tinywasm/src/lib.rs +++ b/crates/tinywasm/src/lib.rs @@ -79,7 +79,7 @@ extern crate alloc; // log for logging (optional). #[cfg(feature = "logging")] #[allow(clippy::single_component_path_imports)] -use log; +use _log as log; // noop fallback if logging is disabled. #[cfg(not(feature = "logging"))] diff --git a/crates/tinywasm/src/module.rs b/crates/tinywasm/src/module.rs index 08e76da..5b5f0c6 100644 --- a/crates/tinywasm/src/module.rs +++ b/crates/tinywasm/src/module.rs @@ -5,6 +5,7 @@ use tinywasm_types::TinyWasmModule; /// A WebAssembly Module /// /// See +#[derive(Clone)] pub struct Module { pub(crate) data: TinyWasmModule, } diff --git a/crates/tinywasm/src/runtime/interpreter/mod.rs b/crates/tinywasm/src/runtime/interpreter/mod.rs index 007acaa..2f0328b 100644 --- a/crates/tinywasm/src/runtime/interpreter/mod.rs +++ b/crates/tinywasm/src/runtime/interpreter/mod.rs @@ -80,7 +80,7 @@ enum ExecResult { fn exec_one(cf: &mut CallFrame, stack: &mut Stack, store: &mut Store, module: &ModuleInstance) -> Result { let instrs = &cf.func_instance.0.instructions; - if unlikely(cf.instr_ptr >= instrs.len() || instrs.is_empty()) { + if unlikely(cf.instr_ptr as usize >= instrs.len() || instrs.is_empty()) { log::error!("instr_ptr out of bounds: {} >= {}", cf.instr_ptr, instrs.len()); return Err(Error::Other(format!("instr_ptr out of bounds: {} >= {}", cf.instr_ptr, instrs.len()))); } @@ -94,7 +94,7 @@ fn exec_one(cf: &mut CallFrame, stack: &mut Stack, store: &mut Store, module: &M Unreachable => { cold(); return Err(crate::Trap::Unreachable.into()); - } // we don't need to include the call frame here because it's already on the stack + } Drop => stack.values.pop().map(|_| ())?, Select( @@ -128,7 +128,7 @@ fn exec_one(cf: &mut CallFrame, stack: &mut Stack, store: &mut Store, module: &M }; let params = stack.values.pop_n_rev(wasm_func.ty.params.len())?; - let call_frame = CallFrame::new(wasm_func, func_inst.owner, params, stack.blocks.len()); + let call_frame = CallFrame::new(wasm_func, func_inst.owner, params, stack.blocks.len() as u32); // push the call frame cf.instr_ptr += 1; // skip the call instruction @@ -181,7 +181,7 @@ fn exec_one(cf: &mut CallFrame, stack: &mut Stack, store: &mut Store, module: &M } let params = stack.values.pop_n_rev(wasm_func.ty.params.len())?; - let call_frame = CallFrame::new(wasm_func, func_inst.owner, params, stack.blocks.len()); + let call_frame = CallFrame::new(wasm_func, func_inst.owner, params, stack.blocks.len() as u32); // push the call frame cf.instr_ptr += 1; // skip the call instruction @@ -198,8 +198,8 @@ fn exec_one(cf: &mut CallFrame, stack: &mut Stack, store: &mut Store, module: &M cf.enter_block( BlockFrame::new( cf.instr_ptr, - cf.instr_ptr + *end_offset as usize, - stack.values.len(), + cf.instr_ptr + *end_offset, + stack.values.len() as u32, BlockType::If, &args.unpack(), module, @@ -213,17 +213,17 @@ fn exec_one(cf: &mut CallFrame, stack: &mut Stack, store: &mut Store, module: &M // falsy value is on the top of the stack if *else_offset != 0 { let label = BlockFrame::new( - cf.instr_ptr + *else_offset as usize, - cf.instr_ptr + *end_offset as usize, - stack.values.len(), + cf.instr_ptr + *else_offset, + cf.instr_ptr + *end_offset, + stack.values.len() as u32, BlockType::Else, &args.unpack(), module, ); - cf.instr_ptr += *else_offset as usize; + cf.instr_ptr += *else_offset; cf.enter_block(label, &mut stack.values, &mut stack.blocks); } else { - cf.instr_ptr += *end_offset as usize; + cf.instr_ptr += *end_offset; } } @@ -231,8 +231,8 @@ fn exec_one(cf: &mut CallFrame, stack: &mut Stack, store: &mut Store, module: &M cf.enter_block( BlockFrame::new( cf.instr_ptr, - cf.instr_ptr + *end_offset as usize, - stack.values.len(), + cf.instr_ptr + *end_offset, + stack.values.len() as u32, BlockType::Loop, args, module, @@ -246,8 +246,8 @@ fn exec_one(cf: &mut CallFrame, stack: &mut Stack, store: &mut Store, module: &M cf.enter_block( BlockFrame::new( cf.instr_ptr, - cf.instr_ptr + *end_offset as usize, - stack.values.len(), + cf.instr_ptr + *end_offset, + stack.values.len() as u32, BlockType::Block, args, module, @@ -258,7 +258,9 @@ fn exec_one(cf: &mut CallFrame, stack: &mut Stack, store: &mut Store, module: &M } BrTable(default, len) => { - let instr = cf.instructions()[cf.instr_ptr + 1..cf.instr_ptr + 1 + *len as usize] + let start = cf.instr_ptr + 1; + let end = cf.instr_ptr + 1 + *len; + let instr = cf.instructions()[start as usize..end as usize] .iter() .map(|i| match i { BrLabel(l) => Ok(*l), @@ -294,49 +296,31 @@ fn exec_one(cf: &mut CallFrame, stack: &mut Stack, store: &mut Store, module: &M false => return Ok(ExecResult::Call), }, - EndFunc => { - if stack.blocks.len() != cf.block_ptr { - cold(); - panic!("endfunc: block frames not empty, this should have been validated by the parser"); - } - - match stack.call_stack.is_empty() { - true => return Ok(ExecResult::Return), - false => return Ok(ExecResult::Call), - } - } - // We're essentially using else as a EndBlockFrame instruction for if blocks Else(end_offset) => { - let Some(block) = stack.blocks.pop() else { - cold(); - panic!("else: no label to end, this should have been validated by the parser"); - }; + let block = + stack.blocks.pop().expect("else: no label to end, this should have been validated by the parser"); - let res_count = block.results; - stack.values.truncate_keep(block.stack_ptr, res_count); - cf.instr_ptr += *end_offset as usize; + stack.values.truncate_keep(block.stack_ptr, block.results as u32); + cf.instr_ptr += *end_offset; } + // remove the label from the label stack EndBlockFrame => { - // remove the label from the label stack - let Some(block) = stack.blocks.pop() else { - cold(); - panic!("end blockframe: no label to end, this should have been validated by the parser"); - }; + let block = stack + .blocks + .pop() + .expect("end blockframe: no label to end, this should have been validated by the parser"); - stack.values.truncate_keep(block.stack_ptr, block.results); + stack.values.truncate_keep(block.stack_ptr, block.results as u32); } LocalGet(local_index) => stack.values.push(cf.get_local(*local_index as usize)), LocalSet(local_index) => cf.set_local(*local_index as usize, stack.values.pop()?), - LocalTee(local_index) => { - let local = stack.values.last(); - cf.set_local( - *local_index as usize, - *local.expect("localtee: stack is empty. this should have been validated by the parser"), - ); - } + LocalTee(local_index) => cf.set_local( + *local_index as usize, + *stack.values.last().expect("localtee: stack is empty. this should have been validated by the parser"), + ), GlobalGet(global_index) => { let idx = module.resolve_global_addr(*global_index); diff --git a/crates/tinywasm/src/runtime/stack/block_stack.rs b/crates/tinywasm/src/runtime/stack/block_stack.rs index cf7a0d4..719dc00 100644 --- a/crates/tinywasm/src/runtime/stack/block_stack.rs +++ b/crates/tinywasm/src/runtime/stack/block_stack.rs @@ -1,9 +1,9 @@ -use crate::{unlikely, ModuleInstance}; +use crate::{unlikely, Error, ModuleInstance, Result}; use alloc::vec::Vec; use tinywasm_types::BlockArgs; #[derive(Debug, Clone, Default)] -pub(crate) struct BlockStack(Vec); // TODO: maybe Box<[LabelFrame]> by analyzing the lable count when parsing the module? +pub(crate) struct BlockStack(Vec); // TODO: maybe Box<[LabelFrame]> by analyzing the label count when parsing the module? impl BlockStack { #[inline] @@ -18,49 +18,50 @@ impl BlockStack { #[inline] /// get the label at the given index, where 0 is the top of the stack - pub(crate) fn get_relative_to(&self, index: usize, offset: usize) -> Option<&BlockFrame> { - let len = self.0.len() - offset; + pub(crate) fn get_relative_to(&self, index: u32, offset: u32) -> Option<&BlockFrame> { + let len = (self.0.len() as u32) - offset; // the vast majority of wasm functions don't use break to return if unlikely(index >= len) { return None; } - Some(&self.0[self.0.len() - index - 1]) + Some(&self.0[self.0.len() - index as usize - 1]) } #[inline] - pub(crate) fn pop(&mut self) -> Option { - self.0.pop() + pub(crate) fn pop(&mut self) -> Result { + self.0.pop().ok_or(Error::BlockStackUnderflow) } /// keep the top `len` blocks and discard the rest #[inline] - pub(crate) fn truncate(&mut self, len: usize) { - self.0.truncate(len); + pub(crate) fn truncate(&mut self, len: u32) { + self.0.truncate(len as usize); } } #[derive(Debug, Clone)] pub(crate) struct BlockFrame { // position of the instruction pointer when the block was entered - pub(crate) instr_ptr: usize, + pub(crate) instr_ptr: u32, // position of the end instruction of the block - pub(crate) end_instr_ptr: usize, + pub(crate) end_instr_ptr: u32, // position of the stack pointer when the block was entered - pub(crate) stack_ptr: usize, - pub(crate) results: usize, - pub(crate) params: usize, + pub(crate) stack_ptr: u32, + + pub(crate) results: u8, + pub(crate) params: u8, pub(crate) ty: BlockType, } impl BlockFrame { #[inline] pub(crate) fn new( - instr_ptr: usize, - end_instr_ptr: usize, - stack_ptr: usize, + instr_ptr: u32, + end_instr_ptr: u32, + stack_ptr: u32, ty: BlockType, args: &BlockArgs, module: &ModuleInstance, @@ -70,7 +71,7 @@ impl BlockFrame { BlockArgs::Type(_) => (0, 1), BlockArgs::FuncType(t) => { let ty = module.func_ty(*t); - (ty.params.len(), ty.results.len()) + (ty.params.len() as u8, ty.results.len() as u8) } }; diff --git a/crates/tinywasm/src/runtime/stack/call_stack.rs b/crates/tinywasm/src/runtime/stack/call_stack.rs index 12270d1..c242b74 100644 --- a/crates/tinywasm/src/runtime/stack/call_stack.rs +++ b/crates/tinywasm/src/runtime/stack/call_stack.rs @@ -48,8 +48,8 @@ impl CallStack { #[derive(Debug, Clone)] pub(crate) struct CallFrame { - pub(crate) instr_ptr: usize, - pub(crate) block_ptr: usize, + pub(crate) instr_ptr: u32, + pub(crate) block_ptr: u32, pub(crate) func_instance: (Rc, ModuleInstanceAddr), pub(crate) locals: Box<[RawWasmValue]>, } @@ -63,7 +63,9 @@ impl CallFrame { blocks: &mut super::BlockStack, ) { if block_frame.params > 0 { - values.extend_from_within((block_frame.stack_ptr - block_frame.params)..block_frame.stack_ptr); + let start = (block_frame.stack_ptr - block_frame.params as u32) as usize; + let end = block_frame.stack_ptr as usize; + values.extend_from_within(start..end); } blocks.push(block_frame); @@ -77,7 +79,7 @@ impl CallFrame { values: &mut super::ValueStack, blocks: &mut super::BlockStack, ) -> Option<()> { - let break_to = blocks.get_relative_to(break_to_relative as usize, self.block_ptr)?; + let break_to = blocks.get_relative_to(break_to_relative, self.block_ptr)?; // instr_ptr points to the label instruction, but the next step // will increment it by 1 since we're changing the "current" instr_ptr @@ -92,7 +94,7 @@ impl CallFrame { // check if we're breaking to the loop if break_to_relative != 0 { // we also want to trim the label stack to the loop (but not including the loop) - blocks.truncate(blocks.len() - break_to_relative as usize); + blocks.truncate(blocks.len() as u32 - break_to_relative); return Some(()); } } @@ -106,7 +108,7 @@ impl CallFrame { self.instr_ptr = break_to.end_instr_ptr; // we also want to trim the label stack, including the block - blocks.truncate(blocks.len() - (break_to_relative as usize + 1)); + blocks.truncate(blocks.len() as u32 - (break_to_relative + 1)); } } @@ -118,8 +120,8 @@ impl CallFrame { pub(crate) fn new( wasm_func_inst: Rc, owner: ModuleInstanceAddr, - params: impl Iterator + ExactSizeIterator, - block_ptr: usize, + params: impl ExactSizeIterator, + block_ptr: u32, ) -> Self { let locals = { let local_types = &wasm_func_inst.locals; @@ -150,6 +152,6 @@ impl CallFrame { #[inline(always)] pub(crate) fn current_instruction(&self) -> &Instruction { - &self.func_instance.0.instructions[self.instr_ptr] + &self.func_instance.0.instructions[self.instr_ptr as usize] } } diff --git a/crates/tinywasm/src/runtime/stack/value_stack.rs b/crates/tinywasm/src/runtime/stack/value_stack.rs index 5903228..2fa03e9 100644 --- a/crates/tinywasm/src/runtime/stack/value_stack.rs +++ b/crates/tinywasm/src/runtime/stack/value_stack.rs @@ -5,6 +5,7 @@ use alloc::vec::Vec; use tinywasm_types::{ValType, WasmValue}; pub(crate) const MIN_VALUE_STACK_SIZE: usize = 1024; +// pub(crate) const MAX_VALUE_STACK_SIZE: usize = 1024 * 1024; #[derive(Debug)] pub(crate) struct ValueStack { @@ -48,9 +49,9 @@ impl ValueStack { self.stack.len() } - pub(crate) fn truncate_keep(&mut self, n: usize, end_keep: usize) { + pub(crate) fn truncate_keep(&mut self, n: u32, end_keep: u32) { let total_to_keep = n + end_keep; - let len = self.stack.len(); + let len = self.stack.len() as u32; assert!(len >= total_to_keep, "Total to keep should be less than or equal to self.top"); if len <= total_to_keep { @@ -58,8 +59,8 @@ impl ValueStack { } let items_to_remove = len - total_to_keep; - let remove_start_index = len - items_to_remove - end_keep; - let remove_end_index = len - end_keep; + let remove_start_index = (len - items_to_remove - end_keep) as usize; + let remove_end_index = (len - end_keep) as usize; self.stack.drain(remove_start_index..remove_end_index); } @@ -69,8 +70,14 @@ impl ValueStack { } #[inline] - pub(crate) fn last(&self) -> Option<&RawWasmValue> { - self.stack.last() + pub(crate) fn last(&self) -> Result<&RawWasmValue> { + match self.stack.last() { + Some(v) => Ok(v), + None => { + cold(); + Err(Error::ValueStackUnderflow) + } + } } #[inline] @@ -102,8 +109,10 @@ impl ValueStack { } #[inline] - pub(crate) fn break_to(&mut self, new_stack_size: usize, result_count: usize) { - self.stack.drain(new_stack_size..(self.stack.len() - result_count)); + pub(crate) fn break_to(&mut self, new_stack_size: u32, result_count: u8) { + let start = new_stack_size as usize; + let end = self.stack.len() - result_count as usize; + self.stack.drain(start..end); } #[inline] diff --git a/crates/tinywasm/src/runtime/value.rs b/crates/tinywasm/src/runtime/value.rs index 4835eab..2381657 100644 --- a/crates/tinywasm/src/runtime/value.rs +++ b/crates/tinywasm/src/runtime/value.rs @@ -92,7 +92,6 @@ type RawValue = u64; type RawValueRep = [u8; 8]; // This all looks like a lot of extra steps, but the compiler will optimize it all away. -// The `u128` is used to make the conversion easier to write. impl_from_raw_wasm_value!(i32, |x| x as RawValue, |x: RawValueRep| i32::from_ne_bytes(x[0..4].try_into().unwrap())); impl_from_raw_wasm_value!(i64, |x| x as RawValue, |x: RawValueRep| i64::from_ne_bytes(x[0..8].try_into().unwrap())); impl_from_raw_wasm_value!(f32, |x| f32::to_bits(x) as RawValue, |x: RawValueRep| f32::from_bits(u32::from_ne_bytes( diff --git a/crates/tinywasm/src/store/global.rs b/crates/tinywasm/src/store/global.rs index 1bcbad7..cbba1a2 100644 --- a/crates/tinywasm/src/store/global.rs +++ b/crates/tinywasm/src/store/global.rs @@ -40,3 +40,32 @@ impl GlobalInstance { Ok(()) } } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_global_instance_get_set() { + let global_type = GlobalType { ty: ValType::I32, mutable: true }; + let initial_value = RawWasmValue::from(10i32); + let owner = 0; + + let mut global_instance = GlobalInstance::new(global_type, initial_value, owner); + + // Test `get` + assert_eq!(global_instance.get(), WasmValue::I32(10), "global value should be 10"); + + // Test `set` with correct type + assert!(global_instance.set(WasmValue::I32(20)).is_ok(), "set should succeed"); + assert_eq!(global_instance.get(), WasmValue::I32(20), "global value should be 20"); + + // Test `set` with incorrect type + assert!(matches!(global_instance.set(WasmValue::F32(1.0)), Err(Error::Other(_))), "set should fail"); + + // Test `set` on immutable global + let immutable_global_type = GlobalType { ty: ValType::I32, mutable: false }; + let mut immutable_global_instance = GlobalInstance::new(immutable_global_type, initial_value, owner); + assert!(matches!(immutable_global_instance.set(WasmValue::I32(30)), Err(Error::Other(_)))); + } +} diff --git a/crates/tinywasm/src/store/memory.rs b/crates/tinywasm/src/store/memory.rs index ea820da..00bcc97 100644 --- a/crates/tinywasm/src/store/memory.rs +++ b/crates/tinywasm/src/store/memory.rs @@ -211,7 +211,7 @@ impl_mem_loadable_for_primitive!( #[cfg(test)] mod memory_instance_tests { use super::*; - use tinywasm_types::{MemoryArch, MemoryType, ModuleInstanceAddr}; + use tinywasm_types::MemoryArch; fn create_test_memory() -> MemoryInstance { let kind = MemoryType { arch: MemoryArch::I32, page_count_initial: 1, page_count_max: Some(2) }; @@ -275,4 +275,11 @@ mod memory_instance_tests { let mut memory = create_test_memory(); assert!(memory.grow(MAX_PAGES as i32 + 1).is_none()); } + + #[test] + fn test_memory_grow_max_pages() { + let mut memory = create_test_memory(); + assert_eq!(memory.grow(1), Some(1)); + assert_eq!(memory.grow(1), None); + } } diff --git a/crates/tinywasm/src/store/mod.rs b/crates/tinywasm/src/store/mod.rs index f4e0df9..1cdcff3 100644 --- a/crates/tinywasm/src/store/mod.rs +++ b/crates/tinywasm/src/store/mod.rs @@ -180,15 +180,11 @@ impl Store { // Linking related functions impl Store { /// Add functions to the store, returning their addresses in the store - pub(crate) fn init_funcs( - &mut self, - funcs: Vec, - idx: ModuleInstanceAddr, - ) -> Result> { + pub(crate) fn init_funcs(&mut self, funcs: Vec, idx: ModuleInstanceAddr) -> Result> { let func_count = self.data.funcs.len(); let mut func_addrs = Vec::with_capacity(func_count); for (i, func) in funcs.into_iter().enumerate() { - self.data.funcs.push(FunctionInstance::new_wasm(func.wasm_function, idx)); + self.data.funcs.push(FunctionInstance::new_wasm(func, idx)); func_addrs.push((i + func_count) as FuncAddr); } Ok(func_addrs) diff --git a/crates/tinywasm/src/store/table.rs b/crates/tinywasm/src/store/table.rs index d9dd9ad..52c35f6 100644 --- a/crates/tinywasm/src/store/table.rs +++ b/crates/tinywasm/src/store/table.rs @@ -116,3 +116,86 @@ impl TableElement { } } } + +#[cfg(test)] +mod tests { + use super::*; + + // Helper to create a dummy TableType + fn dummy_table_type() -> TableType { + TableType { element_type: ValType::RefFunc, size_initial: 10, size_max: Some(20) } + } + + #[test] + fn test_table_instance_creation() { + let kind = dummy_table_type(); + let table_instance = TableInstance::new(kind.clone(), 0); + assert_eq!(table_instance.size(), kind.size_initial as i32, "Table instance creation failed: size mismatch"); + } + + #[test] + fn test_get_wasm_val() { + let kind = dummy_table_type(); + let mut table_instance = TableInstance::new(kind, 0); + + table_instance.set(0, 0).expect("Setting table element failed"); + + match table_instance.get_wasm_val(0) { + Ok(WasmValue::RefFunc(_)) => {} + _ => assert!(false, "get_wasm_val failed to return the correct WasmValue"), + } + + match table_instance.get_wasm_val(999) { + Err(Error::Trap(Trap::UndefinedElement { .. })) => {} + _ => assert!(false, "get_wasm_val failed to handle undefined element correctly"), + } + } + + #[test] + fn test_set_and_get() { + let kind = dummy_table_type(); + let mut table_instance = TableInstance::new(kind, 0); + + let result = table_instance.set(0, 1); + assert!(result.is_ok(), "Setting table element failed"); + + let elem = table_instance.get(0); + assert!( + elem.is_ok() && matches!(elem.unwrap(), &TableElement::Initialized(1)), + "Getting table element failed or returned incorrect value" + ); + } + + #[test] + fn test_table_grow_and_fit() { + let kind = dummy_table_type(); + let mut table_instance = TableInstance::new(kind, 0); + + let result = table_instance.set(15, 1); + assert!(result.is_ok(), "Table grow on set failed"); + + let size = table_instance.size(); + assert!(size >= 16, "Table did not grow to expected size"); + } + + #[test] + fn test_table_init() { + let kind = dummy_table_type(); + let mut table_instance = TableInstance::new(kind, 0); + + let init_elements = vec![TableElement::Initialized(0); 5]; + let func_addrs = vec![0, 1, 2, 3, 4]; + let result = table_instance.init(&func_addrs, 0, &init_elements); + + assert!(result.is_ok(), "Initializing table with elements failed"); + + for i in 0..5 { + let elem = table_instance.get(i); + assert!( + elem.is_ok() && matches!(elem.unwrap(), &TableElement::Initialized(_)), + "Element not initialized correctly at index {}", + i + ); + } + } +} diff --git a/crates/tinywasm/tests/charts/mod.rs b/crates/tinywasm/tests/charts/mod.rs deleted file mode 100644 index fba287b..0000000 --- a/crates/tinywasm/tests/charts/mod.rs +++ /dev/null @@ -1,2 +0,0 @@ -mod progress; -pub use progress::create_progress_chart; diff --git a/crates/tinywasm/tests/generate-charts.rs b/crates/tinywasm/tests/generate-charts.rs deleted file mode 100644 index ec48703..0000000 --- a/crates/tinywasm/tests/generate-charts.rs +++ /dev/null @@ -1,31 +0,0 @@ -mod charts; -use eyre::Result; - -fn main() -> Result<()> { - generate_charts() -} - -fn generate_charts() -> Result<()> { - let args = std::env::args().collect::>(); - if args.len() < 2 || args[1] != "--enable" { - return Ok(()); - } - - charts::create_progress_chart( - "WebAssembly 1.0 Test Suite", - std::path::Path::new("./tests/generated/mvp.csv"), - std::path::Path::new("./tests/generated/progress-mvp.svg"), - )?; - - println!("created progress chart: ./tests/generated/progress-mvp.svg"); - - charts::create_progress_chart( - "WebAssembly 2.0 Test Suite", - std::path::Path::new("./tests/generated/2.0.csv"), - std::path::Path::new("./tests/generated/progress-2.0.svg"), - )?; - - println!("created progress chart: ./tests/generated/progress-2.0.svg"); - - Ok(()) -} diff --git a/crates/tinywasm/tests/generated/2.0.csv b/crates/tinywasm/tests/generated/2.0.csv index 40ef2ae..c97b58e 100644 --- a/crates/tinywasm/tests/generated/2.0.csv +++ b/crates/tinywasm/tests/generated/2.0.csv @@ -1,3 +1,4 @@ 0.3.0,26722,1161,[{"name":"address.wast","passed":260,"failed":0},{"name":"align.wast","passed":156,"failed":0},{"name":"binary-leb128.wast","passed":91,"failed":0},{"name":"binary.wast","passed":112,"failed":0},{"name":"block.wast","passed":223,"failed":0},{"name":"br.wast","passed":97,"failed":0},{"name":"br_if.wast","passed":118,"failed":0},{"name":"br_table.wast","passed":174,"failed":0},{"name":"bulk.wast","passed":8,"failed":109},{"name":"call.wast","passed":91,"failed":0},{"name":"call_indirect.wast","passed":170,"failed":0},{"name":"comments.wast","passed":8,"failed":0},{"name":"const.wast","passed":778,"failed":0},{"name":"conversions.wast","passed":619,"failed":0},{"name":"custom.wast","passed":11,"failed":0},{"name":"data.wast","passed":61,"failed":0},{"name":"elem.wast","passed":98,"failed":1},{"name":"endianness.wast","passed":69,"failed":0},{"name":"exports.wast","passed":96,"failed":0},{"name":"f32.wast","passed":2514,"failed":0},{"name":"f32_bitwise.wast","passed":364,"failed":0},{"name":"f32_cmp.wast","passed":2407,"failed":0},{"name":"f64.wast","passed":2514,"failed":0},{"name":"f64_bitwise.wast","passed":364,"failed":0},{"name":"f64_cmp.wast","passed":2407,"failed":0},{"name":"fac.wast","passed":8,"failed":0},{"name":"float_exprs.wast","passed":900,"failed":0},{"name":"float_literals.wast","passed":163,"failed":0},{"name":"float_memory.wast","passed":90,"failed":0},{"name":"float_misc.wast","passed":441,"failed":0},{"name":"forward.wast","passed":5,"failed":0},{"name":"func.wast","passed":172,"failed":0},{"name":"func_ptrs.wast","passed":36,"failed":0},{"name":"global.wast","passed":110,"failed":0},{"name":"i32.wast","passed":460,"failed":0},{"name":"i64.wast","passed":416,"failed":0},{"name":"if.wast","passed":241,"failed":0},{"name":"imports.wast","passed":171,"failed":12},{"name":"inline-module.wast","passed":1,"failed":0},{"name":"int_exprs.wast","passed":108,"failed":0},{"name":"int_literals.wast","passed":51,"failed":0},{"name":"labels.wast","passed":29,"failed":0},{"name":"left-to-right.wast","passed":96,"failed":0},{"name":"linking.wast","passed":132,"failed":0},{"name":"load.wast","passed":97,"failed":0},{"name":"local_get.wast","passed":36,"failed":0},{"name":"local_set.wast","passed":53,"failed":0},{"name":"local_tee.wast","passed":97,"failed":0},{"name":"loop.wast","passed":120,"failed":0},{"name":"memory.wast","passed":79,"failed":0},{"name":"memory_copy.wast","passed":3928,"failed":522},{"name":"memory_fill.wast","passed":64,"failed":36},{"name":"memory_grow.wast","passed":96,"failed":0},{"name":"memory_init.wast","passed":177,"failed":63},{"name":"memory_redundancy.wast","passed":8,"failed":0},{"name":"memory_size.wast","passed":42,"failed":0},{"name":"memory_trap.wast","passed":182,"failed":0},{"name":"names.wast","passed":486,"failed":0},{"name":"nop.wast","passed":88,"failed":0},{"name":"ref_func.wast","passed":9,"failed":8},{"name":"ref_is_null.wast","passed":4,"failed":12},{"name":"ref_null.wast","passed":1,"failed":2},{"name":"return.wast","passed":84,"failed":0},{"name":"select.wast","passed":148,"failed":0},{"name":"skip-stack-guard-page.wast","passed":11,"failed":0},{"name":"stack.wast","passed":7,"failed":0},{"name":"start.wast","passed":20,"failed":0},{"name":"store.wast","passed":68,"failed":0},{"name":"switch.wast","passed":28,"failed":0},{"name":"table-sub.wast","passed":2,"failed":0},{"name":"table.wast","passed":19,"failed":0},{"name":"table_copy.wast","passed":1613,"failed":115},{"name":"table_fill.wast","passed":23,"failed":22},{"name":"table_get.wast","passed":10,"failed":6},{"name":"table_grow.wast","passed":21,"failed":29},{"name":"table_init.wast","passed":594,"failed":186},{"name":"table_set.wast","passed":19,"failed":7},{"name":"table_size.wast","passed":8,"failed":31},{"name":"token.wast","passed":58,"failed":0},{"name":"traps.wast","passed":36,"failed":0},{"name":"type.wast","passed":3,"failed":0},{"name":"unreachable.wast","passed":64,"failed":0},{"name":"unreached-invalid.wast","passed":118,"failed":0},{"name":"unreached-valid.wast","passed":7,"failed":0},{"name":"unwind.wast","passed":50,"failed":0},{"name":"utf8-custom-section-id.wast","passed":176,"failed":0},{"name":"utf8-import-field.wast","passed":176,"failed":0},{"name":"utf8-import-module.wast","passed":176,"failed":0},{"name":"utf8-invalid-encoding.wast","passed":176,"failed":0}] 0.4.0,27549,334,[{"name":"address.wast","passed":260,"failed":0},{"name":"align.wast","passed":156,"failed":0},{"name":"binary-leb128.wast","passed":91,"failed":0},{"name":"binary.wast","passed":112,"failed":0},{"name":"block.wast","passed":223,"failed":0},{"name":"br.wast","passed":97,"failed":0},{"name":"br_if.wast","passed":118,"failed":0},{"name":"br_table.wast","passed":174,"failed":0},{"name":"bulk.wast","passed":75,"failed":42},{"name":"call.wast","passed":91,"failed":0},{"name":"call_indirect.wast","passed":170,"failed":0},{"name":"comments.wast","passed":8,"failed":0},{"name":"const.wast","passed":778,"failed":0},{"name":"conversions.wast","passed":619,"failed":0},{"name":"custom.wast","passed":11,"failed":0},{"name":"data.wast","passed":61,"failed":0},{"name":"elem.wast","passed":99,"failed":0},{"name":"endianness.wast","passed":69,"failed":0},{"name":"exports.wast","passed":96,"failed":0},{"name":"f32.wast","passed":2514,"failed":0},{"name":"f32_bitwise.wast","passed":364,"failed":0},{"name":"f32_cmp.wast","passed":2407,"failed":0},{"name":"f64.wast","passed":2514,"failed":0},{"name":"f64_bitwise.wast","passed":364,"failed":0},{"name":"f64_cmp.wast","passed":2407,"failed":0},{"name":"fac.wast","passed":8,"failed":0},{"name":"float_exprs.wast","passed":900,"failed":0},{"name":"float_literals.wast","passed":163,"failed":0},{"name":"float_memory.wast","passed":90,"failed":0},{"name":"float_misc.wast","passed":441,"failed":0},{"name":"forward.wast","passed":5,"failed":0},{"name":"func.wast","passed":172,"failed":0},{"name":"func_ptrs.wast","passed":36,"failed":0},{"name":"global.wast","passed":110,"failed":0},{"name":"i32.wast","passed":460,"failed":0},{"name":"i64.wast","passed":416,"failed":0},{"name":"if.wast","passed":241,"failed":0},{"name":"imports.wast","passed":183,"failed":0},{"name":"inline-module.wast","passed":1,"failed":0},{"name":"int_exprs.wast","passed":108,"failed":0},{"name":"int_literals.wast","passed":51,"failed":0},{"name":"labels.wast","passed":29,"failed":0},{"name":"left-to-right.wast","passed":96,"failed":0},{"name":"linking.wast","passed":132,"failed":0},{"name":"load.wast","passed":97,"failed":0},{"name":"local_get.wast","passed":36,"failed":0},{"name":"local_set.wast","passed":53,"failed":0},{"name":"local_tee.wast","passed":97,"failed":0},{"name":"loop.wast","passed":120,"failed":0},{"name":"memory.wast","passed":79,"failed":0},{"name":"memory_copy.wast","passed":4450,"failed":0},{"name":"memory_fill.wast","passed":100,"failed":0},{"name":"memory_grow.wast","passed":96,"failed":0},{"name":"memory_init.wast","passed":240,"failed":0},{"name":"memory_redundancy.wast","passed":8,"failed":0},{"name":"memory_size.wast","passed":42,"failed":0},{"name":"memory_trap.wast","passed":182,"failed":0},{"name":"names.wast","passed":486,"failed":0},{"name":"nop.wast","passed":88,"failed":0},{"name":"ref_func.wast","passed":9,"failed":8},{"name":"ref_is_null.wast","passed":4,"failed":12},{"name":"ref_null.wast","passed":1,"failed":2},{"name":"return.wast","passed":84,"failed":0},{"name":"select.wast","passed":148,"failed":0},{"name":"skip-stack-guard-page.wast","passed":11,"failed":0},{"name":"stack.wast","passed":7,"failed":0},{"name":"start.wast","passed":20,"failed":0},{"name":"store.wast","passed":68,"failed":0},{"name":"switch.wast","passed":28,"failed":0},{"name":"table-sub.wast","passed":2,"failed":0},{"name":"table.wast","passed":19,"failed":0},{"name":"table_copy.wast","passed":1613,"failed":115},{"name":"table_fill.wast","passed":23,"failed":22},{"name":"table_get.wast","passed":10,"failed":6},{"name":"table_grow.wast","passed":21,"failed":29},{"name":"table_init.wast","passed":720,"failed":60},{"name":"table_set.wast","passed":19,"failed":7},{"name":"table_size.wast","passed":8,"failed":31},{"name":"token.wast","passed":58,"failed":0},{"name":"traps.wast","passed":36,"failed":0},{"name":"type.wast","passed":3,"failed":0},{"name":"unreachable.wast","passed":64,"failed":0},{"name":"unreached-invalid.wast","passed":118,"failed":0},{"name":"unreached-valid.wast","passed":7,"failed":0},{"name":"unwind.wast","passed":50,"failed":0},{"name":"utf8-custom-section-id.wast","passed":176,"failed":0},{"name":"utf8-import-field.wast","passed":176,"failed":0},{"name":"utf8-import-module.wast","passed":176,"failed":0},{"name":"utf8-invalid-encoding.wast","passed":176,"failed":0}] 0.4.1,27551,335,[{"name":"address.wast","passed":260,"failed":0},{"name":"align.wast","passed":156,"failed":0},{"name":"binary-leb128.wast","passed":91,"failed":0},{"name":"binary.wast","passed":112,"failed":0},{"name":"block.wast","passed":223,"failed":0},{"name":"br.wast","passed":97,"failed":0},{"name":"br_if.wast","passed":118,"failed":0},{"name":"br_table.wast","passed":174,"failed":0},{"name":"bulk.wast","passed":75,"failed":42},{"name":"call.wast","passed":91,"failed":0},{"name":"call_indirect.wast","passed":170,"failed":0},{"name":"comments.wast","passed":8,"failed":0},{"name":"const.wast","passed":778,"failed":0},{"name":"conversions.wast","passed":619,"failed":0},{"name":"custom.wast","passed":11,"failed":0},{"name":"data.wast","passed":61,"failed":0},{"name":"elem.wast","passed":99,"failed":0},{"name":"endianness.wast","passed":69,"failed":0},{"name":"exports.wast","passed":96,"failed":0},{"name":"f32.wast","passed":2514,"failed":0},{"name":"f32_bitwise.wast","passed":364,"failed":0},{"name":"f32_cmp.wast","passed":2407,"failed":0},{"name":"f64.wast","passed":2514,"failed":0},{"name":"f64_bitwise.wast","passed":364,"failed":0},{"name":"f64_cmp.wast","passed":2407,"failed":0},{"name":"fac.wast","passed":8,"failed":0},{"name":"float_exprs.wast","passed":900,"failed":0},{"name":"float_literals.wast","passed":163,"failed":0},{"name":"float_memory.wast","passed":90,"failed":0},{"name":"float_misc.wast","passed":441,"failed":0},{"name":"forward.wast","passed":5,"failed":0},{"name":"func.wast","passed":172,"failed":0},{"name":"func_ptrs.wast","passed":36,"failed":0},{"name":"global.wast","passed":110,"failed":0},{"name":"i32.wast","passed":460,"failed":0},{"name":"i64.wast","passed":416,"failed":0},{"name":"if.wast","passed":241,"failed":0},{"name":"imports.wast","passed":186,"failed":0},{"name":"inline-module.wast","passed":1,"failed":0},{"name":"int_exprs.wast","passed":108,"failed":0},{"name":"int_literals.wast","passed":51,"failed":0},{"name":"labels.wast","passed":29,"failed":0},{"name":"left-to-right.wast","passed":96,"failed":0},{"name":"linking.wast","passed":132,"failed":0},{"name":"load.wast","passed":97,"failed":0},{"name":"local_get.wast","passed":36,"failed":0},{"name":"local_set.wast","passed":53,"failed":0},{"name":"local_tee.wast","passed":97,"failed":0},{"name":"loop.wast","passed":120,"failed":0},{"name":"memory.wast","passed":79,"failed":0},{"name":"memory_copy.wast","passed":4450,"failed":0},{"name":"memory_fill.wast","passed":100,"failed":0},{"name":"memory_grow.wast","passed":96,"failed":0},{"name":"memory_init.wast","passed":240,"failed":0},{"name":"memory_redundancy.wast","passed":8,"failed":0},{"name":"memory_size.wast","passed":42,"failed":0},{"name":"memory_trap.wast","passed":182,"failed":0},{"name":"names.wast","passed":486,"failed":0},{"name":"nop.wast","passed":88,"failed":0},{"name":"ref_func.wast","passed":9,"failed":8},{"name":"ref_is_null.wast","passed":4,"failed":12},{"name":"ref_null.wast","passed":1,"failed":2},{"name":"return.wast","passed":84,"failed":0},{"name":"select.wast","passed":148,"failed":0},{"name":"skip-stack-guard-page.wast","passed":11,"failed":0},{"name":"stack.wast","passed":7,"failed":0},{"name":"start.wast","passed":20,"failed":0},{"name":"store.wast","passed":68,"failed":0},{"name":"switch.wast","passed":28,"failed":0},{"name":"table-sub.wast","passed":2,"failed":0},{"name":"table.wast","passed":19,"failed":0},{"name":"table_copy.wast","passed":1613,"failed":115},{"name":"table_fill.wast","passed":23,"failed":22},{"name":"table_get.wast","passed":10,"failed":6},{"name":"table_grow.wast","passed":21,"failed":29},{"name":"table_init.wast","passed":719,"failed":61},{"name":"table_set.wast","passed":19,"failed":7},{"name":"table_size.wast","passed":8,"failed":31},{"name":"token.wast","passed":58,"failed":0},{"name":"traps.wast","passed":36,"failed":0},{"name":"type.wast","passed":3,"failed":0},{"name":"unreachable.wast","passed":64,"failed":0},{"name":"unreached-invalid.wast","passed":118,"failed":0},{"name":"unreached-valid.wast","passed":7,"failed":0},{"name":"unwind.wast","passed":50,"failed":0},{"name":"utf8-custom-section-id.wast","passed":176,"failed":0},{"name":"utf8-import-field.wast","passed":176,"failed":0},{"name":"utf8-import-module.wast","passed":176,"failed":0},{"name":"utf8-invalid-encoding.wast","passed":176,"failed":0}] +0.5.0,27551,335,[{"name":"address.wast","passed":260,"failed":0},{"name":"align.wast","passed":156,"failed":0},{"name":"binary-leb128.wast","passed":91,"failed":0},{"name":"binary.wast","passed":112,"failed":0},{"name":"block.wast","passed":223,"failed":0},{"name":"br.wast","passed":97,"failed":0},{"name":"br_if.wast","passed":118,"failed":0},{"name":"br_table.wast","passed":174,"failed":0},{"name":"bulk.wast","passed":75,"failed":42},{"name":"call.wast","passed":91,"failed":0},{"name":"call_indirect.wast","passed":170,"failed":0},{"name":"comments.wast","passed":8,"failed":0},{"name":"const.wast","passed":778,"failed":0},{"name":"conversions.wast","passed":619,"failed":0},{"name":"custom.wast","passed":11,"failed":0},{"name":"data.wast","passed":61,"failed":0},{"name":"elem.wast","passed":99,"failed":0},{"name":"endianness.wast","passed":69,"failed":0},{"name":"exports.wast","passed":96,"failed":0},{"name":"f32.wast","passed":2514,"failed":0},{"name":"f32_bitwise.wast","passed":364,"failed":0},{"name":"f32_cmp.wast","passed":2407,"failed":0},{"name":"f64.wast","passed":2514,"failed":0},{"name":"f64_bitwise.wast","passed":364,"failed":0},{"name":"f64_cmp.wast","passed":2407,"failed":0},{"name":"fac.wast","passed":8,"failed":0},{"name":"float_exprs.wast","passed":900,"failed":0},{"name":"float_literals.wast","passed":163,"failed":0},{"name":"float_memory.wast","passed":90,"failed":0},{"name":"float_misc.wast","passed":441,"failed":0},{"name":"forward.wast","passed":5,"failed":0},{"name":"func.wast","passed":172,"failed":0},{"name":"func_ptrs.wast","passed":36,"failed":0},{"name":"global.wast","passed":110,"failed":0},{"name":"i32.wast","passed":460,"failed":0},{"name":"i64.wast","passed":416,"failed":0},{"name":"if.wast","passed":241,"failed":0},{"name":"imports.wast","passed":186,"failed":0},{"name":"inline-module.wast","passed":1,"failed":0},{"name":"int_exprs.wast","passed":108,"failed":0},{"name":"int_literals.wast","passed":51,"failed":0},{"name":"labels.wast","passed":29,"failed":0},{"name":"left-to-right.wast","passed":96,"failed":0},{"name":"linking.wast","passed":132,"failed":0},{"name":"load.wast","passed":97,"failed":0},{"name":"local_get.wast","passed":36,"failed":0},{"name":"local_set.wast","passed":53,"failed":0},{"name":"local_tee.wast","passed":97,"failed":0},{"name":"loop.wast","passed":120,"failed":0},{"name":"memory.wast","passed":79,"failed":0},{"name":"memory_copy.wast","passed":4450,"failed":0},{"name":"memory_fill.wast","passed":100,"failed":0},{"name":"memory_grow.wast","passed":96,"failed":0},{"name":"memory_init.wast","passed":240,"failed":0},{"name":"memory_redundancy.wast","passed":8,"failed":0},{"name":"memory_size.wast","passed":42,"failed":0},{"name":"memory_trap.wast","passed":182,"failed":0},{"name":"names.wast","passed":486,"failed":0},{"name":"nop.wast","passed":88,"failed":0},{"name":"ref_func.wast","passed":9,"failed":8},{"name":"ref_is_null.wast","passed":4,"failed":12},{"name":"ref_null.wast","passed":1,"failed":2},{"name":"return.wast","passed":84,"failed":0},{"name":"select.wast","passed":148,"failed":0},{"name":"skip-stack-guard-page.wast","passed":11,"failed":0},{"name":"stack.wast","passed":7,"failed":0},{"name":"start.wast","passed":20,"failed":0},{"name":"store.wast","passed":68,"failed":0},{"name":"switch.wast","passed":28,"failed":0},{"name":"table-sub.wast","passed":2,"failed":0},{"name":"table.wast","passed":19,"failed":0},{"name":"table_copy.wast","passed":1613,"failed":115},{"name":"table_fill.wast","passed":23,"failed":22},{"name":"table_get.wast","passed":10,"failed":6},{"name":"table_grow.wast","passed":21,"failed":29},{"name":"table_init.wast","passed":719,"failed":61},{"name":"table_set.wast","passed":19,"failed":7},{"name":"table_size.wast","passed":8,"failed":31},{"name":"token.wast","passed":58,"failed":0},{"name":"traps.wast","passed":36,"failed":0},{"name":"type.wast","passed":3,"failed":0},{"name":"unreachable.wast","passed":64,"failed":0},{"name":"unreached-invalid.wast","passed":118,"failed":0},{"name":"unreached-valid.wast","passed":7,"failed":0},{"name":"unwind.wast","passed":50,"failed":0},{"name":"utf8-custom-section-id.wast","passed":176,"failed":0},{"name":"utf8-import-field.wast","passed":176,"failed":0},{"name":"utf8-import-module.wast","passed":176,"failed":0},{"name":"utf8-invalid-encoding.wast","passed":176,"failed":0}] diff --git a/crates/tinywasm/tests/generated/mvp.csv b/crates/tinywasm/tests/generated/mvp.csv index 2e151d5..90dfa04 100644 --- a/crates/tinywasm/tests/generated/mvp.csv +++ b/crates/tinywasm/tests/generated/mvp.csv @@ -5,3 +5,4 @@ 0.3.0,20254,0,[{"name":"address.wast","passed":260,"failed":0},{"name":"align.wast","passed":156,"failed":0},{"name":"binary-leb128.wast","passed":91,"failed":0},{"name":"binary.wast","passed":112,"failed":0},{"name":"block.wast","passed":223,"failed":0},{"name":"br.wast","passed":97,"failed":0},{"name":"br_if.wast","passed":118,"failed":0},{"name":"br_table.wast","passed":174,"failed":0},{"name":"call.wast","passed":91,"failed":0},{"name":"call_indirect.wast","passed":170,"failed":0},{"name":"comments.wast","passed":8,"failed":0},{"name":"const.wast","passed":778,"failed":0},{"name":"conversions.wast","passed":619,"failed":0},{"name":"custom.wast","passed":11,"failed":0},{"name":"data.wast","passed":61,"failed":0},{"name":"elem.wast","passed":99,"failed":0},{"name":"endianness.wast","passed":69,"failed":0},{"name":"exports.wast","passed":96,"failed":0},{"name":"f32.wast","passed":2514,"failed":0},{"name":"f32_bitwise.wast","passed":364,"failed":0},{"name":"f32_cmp.wast","passed":2407,"failed":0},{"name":"f64.wast","passed":2514,"failed":0},{"name":"f64_bitwise.wast","passed":364,"failed":0},{"name":"f64_cmp.wast","passed":2407,"failed":0},{"name":"fac.wast","passed":8,"failed":0},{"name":"float_exprs.wast","passed":900,"failed":0},{"name":"float_literals.wast","passed":163,"failed":0},{"name":"float_memory.wast","passed":90,"failed":0},{"name":"float_misc.wast","passed":441,"failed":0},{"name":"forward.wast","passed":5,"failed":0},{"name":"func.wast","passed":172,"failed":0},{"name":"func_ptrs.wast","passed":36,"failed":0},{"name":"global.wast","passed":110,"failed":0},{"name":"i32.wast","passed":460,"failed":0},{"name":"i64.wast","passed":416,"failed":0},{"name":"if.wast","passed":241,"failed":0},{"name":"imports.wast","passed":183,"failed":0},{"name":"inline-module.wast","passed":1,"failed":0},{"name":"int_exprs.wast","passed":108,"failed":0},{"name":"int_literals.wast","passed":51,"failed":0},{"name":"labels.wast","passed":29,"failed":0},{"name":"left-to-right.wast","passed":96,"failed":0},{"name":"linking.wast","passed":132,"failed":0},{"name":"load.wast","passed":97,"failed":0},{"name":"local_get.wast","passed":36,"failed":0},{"name":"local_set.wast","passed":53,"failed":0},{"name":"local_tee.wast","passed":97,"failed":0},{"name":"loop.wast","passed":120,"failed":0},{"name":"memory.wast","passed":79,"failed":0},{"name":"memory_grow.wast","passed":96,"failed":0},{"name":"memory_redundancy.wast","passed":8,"failed":0},{"name":"memory_size.wast","passed":42,"failed":0},{"name":"memory_trap.wast","passed":182,"failed":0},{"name":"names.wast","passed":486,"failed":0},{"name":"nop.wast","passed":88,"failed":0},{"name":"return.wast","passed":84,"failed":0},{"name":"select.wast","passed":148,"failed":0},{"name":"skip-stack-guard-page.wast","passed":11,"failed":0},{"name":"stack.wast","passed":7,"failed":0},{"name":"start.wast","passed":20,"failed":0},{"name":"store.wast","passed":68,"failed":0},{"name":"switch.wast","passed":28,"failed":0},{"name":"table.wast","passed":19,"failed":0},{"name":"token.wast","passed":58,"failed":0},{"name":"traps.wast","passed":36,"failed":0},{"name":"type.wast","passed":3,"failed":0},{"name":"unreachable.wast","passed":64,"failed":0},{"name":"unreached-invalid.wast","passed":118,"failed":0},{"name":"unreached-valid.wast","passed":7,"failed":0},{"name":"unwind.wast","passed":50,"failed":0},{"name":"utf8-custom-section-id.wast","passed":176,"failed":0},{"name":"utf8-import-field.wast","passed":176,"failed":0},{"name":"utf8-import-module.wast","passed":176,"failed":0},{"name":"utf8-invalid-encoding.wast","passed":176,"failed":0}] 0.4.0,20254,0,[{"name":"address.wast","passed":260,"failed":0},{"name":"align.wast","passed":156,"failed":0},{"name":"binary-leb128.wast","passed":91,"failed":0},{"name":"binary.wast","passed":112,"failed":0},{"name":"block.wast","passed":223,"failed":0},{"name":"br.wast","passed":97,"failed":0},{"name":"br_if.wast","passed":118,"failed":0},{"name":"br_table.wast","passed":174,"failed":0},{"name":"call.wast","passed":91,"failed":0},{"name":"call_indirect.wast","passed":170,"failed":0},{"name":"comments.wast","passed":8,"failed":0},{"name":"const.wast","passed":778,"failed":0},{"name":"conversions.wast","passed":619,"failed":0},{"name":"custom.wast","passed":11,"failed":0},{"name":"data.wast","passed":61,"failed":0},{"name":"elem.wast","passed":99,"failed":0},{"name":"endianness.wast","passed":69,"failed":0},{"name":"exports.wast","passed":96,"failed":0},{"name":"f32.wast","passed":2514,"failed":0},{"name":"f32_bitwise.wast","passed":364,"failed":0},{"name":"f32_cmp.wast","passed":2407,"failed":0},{"name":"f64.wast","passed":2514,"failed":0},{"name":"f64_bitwise.wast","passed":364,"failed":0},{"name":"f64_cmp.wast","passed":2407,"failed":0},{"name":"fac.wast","passed":8,"failed":0},{"name":"float_exprs.wast","passed":900,"failed":0},{"name":"float_literals.wast","passed":163,"failed":0},{"name":"float_memory.wast","passed":90,"failed":0},{"name":"float_misc.wast","passed":441,"failed":0},{"name":"forward.wast","passed":5,"failed":0},{"name":"func.wast","passed":172,"failed":0},{"name":"func_ptrs.wast","passed":36,"failed":0},{"name":"global.wast","passed":110,"failed":0},{"name":"i32.wast","passed":460,"failed":0},{"name":"i64.wast","passed":416,"failed":0},{"name":"if.wast","passed":241,"failed":0},{"name":"imports.wast","passed":183,"failed":0},{"name":"inline-module.wast","passed":1,"failed":0},{"name":"int_exprs.wast","passed":108,"failed":0},{"name":"int_literals.wast","passed":51,"failed":0},{"name":"labels.wast","passed":29,"failed":0},{"name":"left-to-right.wast","passed":96,"failed":0},{"name":"linking.wast","passed":132,"failed":0},{"name":"load.wast","passed":97,"failed":0},{"name":"local_get.wast","passed":36,"failed":0},{"name":"local_set.wast","passed":53,"failed":0},{"name":"local_tee.wast","passed":97,"failed":0},{"name":"loop.wast","passed":120,"failed":0},{"name":"memory.wast","passed":79,"failed":0},{"name":"memory_grow.wast","passed":96,"failed":0},{"name":"memory_redundancy.wast","passed":8,"failed":0},{"name":"memory_size.wast","passed":42,"failed":0},{"name":"memory_trap.wast","passed":182,"failed":0},{"name":"names.wast","passed":486,"failed":0},{"name":"nop.wast","passed":88,"failed":0},{"name":"return.wast","passed":84,"failed":0},{"name":"select.wast","passed":148,"failed":0},{"name":"skip-stack-guard-page.wast","passed":11,"failed":0},{"name":"stack.wast","passed":7,"failed":0},{"name":"start.wast","passed":20,"failed":0},{"name":"store.wast","passed":68,"failed":0},{"name":"switch.wast","passed":28,"failed":0},{"name":"table.wast","passed":19,"failed":0},{"name":"token.wast","passed":58,"failed":0},{"name":"traps.wast","passed":36,"failed":0},{"name":"type.wast","passed":3,"failed":0},{"name":"unreachable.wast","passed":64,"failed":0},{"name":"unreached-invalid.wast","passed":118,"failed":0},{"name":"unreached-valid.wast","passed":7,"failed":0},{"name":"unwind.wast","passed":50,"failed":0},{"name":"utf8-custom-section-id.wast","passed":176,"failed":0},{"name":"utf8-import-field.wast","passed":176,"failed":0},{"name":"utf8-import-module.wast","passed":176,"failed":0},{"name":"utf8-invalid-encoding.wast","passed":176,"failed":0}] 0.4.1,20257,0,[{"name":"address.wast","passed":260,"failed":0},{"name":"align.wast","passed":156,"failed":0},{"name":"binary-leb128.wast","passed":91,"failed":0},{"name":"binary.wast","passed":112,"failed":0},{"name":"block.wast","passed":223,"failed":0},{"name":"br.wast","passed":97,"failed":0},{"name":"br_if.wast","passed":118,"failed":0},{"name":"br_table.wast","passed":174,"failed":0},{"name":"call.wast","passed":91,"failed":0},{"name":"call_indirect.wast","passed":170,"failed":0},{"name":"comments.wast","passed":8,"failed":0},{"name":"const.wast","passed":778,"failed":0},{"name":"conversions.wast","passed":619,"failed":0},{"name":"custom.wast","passed":11,"failed":0},{"name":"data.wast","passed":61,"failed":0},{"name":"elem.wast","passed":99,"failed":0},{"name":"endianness.wast","passed":69,"failed":0},{"name":"exports.wast","passed":96,"failed":0},{"name":"f32.wast","passed":2514,"failed":0},{"name":"f32_bitwise.wast","passed":364,"failed":0},{"name":"f32_cmp.wast","passed":2407,"failed":0},{"name":"f64.wast","passed":2514,"failed":0},{"name":"f64_bitwise.wast","passed":364,"failed":0},{"name":"f64_cmp.wast","passed":2407,"failed":0},{"name":"fac.wast","passed":8,"failed":0},{"name":"float_exprs.wast","passed":900,"failed":0},{"name":"float_literals.wast","passed":163,"failed":0},{"name":"float_memory.wast","passed":90,"failed":0},{"name":"float_misc.wast","passed":441,"failed":0},{"name":"forward.wast","passed":5,"failed":0},{"name":"func.wast","passed":172,"failed":0},{"name":"func_ptrs.wast","passed":36,"failed":0},{"name":"global.wast","passed":110,"failed":0},{"name":"i32.wast","passed":460,"failed":0},{"name":"i64.wast","passed":416,"failed":0},{"name":"if.wast","passed":241,"failed":0},{"name":"imports.wast","passed":186,"failed":0},{"name":"inline-module.wast","passed":1,"failed":0},{"name":"int_exprs.wast","passed":108,"failed":0},{"name":"int_literals.wast","passed":51,"failed":0},{"name":"labels.wast","passed":29,"failed":0},{"name":"left-to-right.wast","passed":96,"failed":0},{"name":"linking.wast","passed":132,"failed":0},{"name":"load.wast","passed":97,"failed":0},{"name":"local_get.wast","passed":36,"failed":0},{"name":"local_set.wast","passed":53,"failed":0},{"name":"local_tee.wast","passed":97,"failed":0},{"name":"loop.wast","passed":120,"failed":0},{"name":"memory.wast","passed":79,"failed":0},{"name":"memory_grow.wast","passed":96,"failed":0},{"name":"memory_redundancy.wast","passed":8,"failed":0},{"name":"memory_size.wast","passed":42,"failed":0},{"name":"memory_trap.wast","passed":182,"failed":0},{"name":"names.wast","passed":486,"failed":0},{"name":"nop.wast","passed":88,"failed":0},{"name":"return.wast","passed":84,"failed":0},{"name":"select.wast","passed":148,"failed":0},{"name":"skip-stack-guard-page.wast","passed":11,"failed":0},{"name":"stack.wast","passed":7,"failed":0},{"name":"start.wast","passed":20,"failed":0},{"name":"store.wast","passed":68,"failed":0},{"name":"switch.wast","passed":28,"failed":0},{"name":"table.wast","passed":19,"failed":0},{"name":"token.wast","passed":58,"failed":0},{"name":"traps.wast","passed":36,"failed":0},{"name":"type.wast","passed":3,"failed":0},{"name":"unreachable.wast","passed":64,"failed":0},{"name":"unreached-invalid.wast","passed":118,"failed":0},{"name":"unreached-valid.wast","passed":7,"failed":0},{"name":"unwind.wast","passed":50,"failed":0},{"name":"utf8-custom-section-id.wast","passed":176,"failed":0},{"name":"utf8-import-field.wast","passed":176,"failed":0},{"name":"utf8-import-module.wast","passed":176,"failed":0},{"name":"utf8-invalid-encoding.wast","passed":176,"failed":0}] +0.5.0,20272,0,[{"name":"address.wast","passed":260,"failed":0},{"name":"align.wast","passed":156,"failed":0},{"name":"binary-leb128.wast","passed":91,"failed":0},{"name":"binary.wast","passed":112,"failed":0},{"name":"block.wast","passed":223,"failed":0},{"name":"br.wast","passed":97,"failed":0},{"name":"br_if.wast","passed":118,"failed":0},{"name":"br_table.wast","passed":174,"failed":0},{"name":"call.wast","passed":91,"failed":0},{"name":"call_indirect.wast","passed":170,"failed":0},{"name":"comments.wast","passed":8,"failed":0},{"name":"const.wast","passed":778,"failed":0},{"name":"conversions.wast","passed":619,"failed":0},{"name":"custom.wast","passed":11,"failed":0},{"name":"data.wast","passed":61,"failed":0},{"name":"elem.wast","passed":98,"failed":0},{"name":"endianness.wast","passed":69,"failed":0},{"name":"exports.wast","passed":96,"failed":0},{"name":"f32.wast","passed":2514,"failed":0},{"name":"f32_bitwise.wast","passed":364,"failed":0},{"name":"f32_cmp.wast","passed":2407,"failed":0},{"name":"f64.wast","passed":2514,"failed":0},{"name":"f64_bitwise.wast","passed":364,"failed":0},{"name":"f64_cmp.wast","passed":2407,"failed":0},{"name":"fac.wast","passed":8,"failed":0},{"name":"float_exprs.wast","passed":900,"failed":0},{"name":"float_literals.wast","passed":179,"failed":0},{"name":"float_memory.wast","passed":90,"failed":0},{"name":"float_misc.wast","passed":441,"failed":0},{"name":"forward.wast","passed":5,"failed":0},{"name":"func.wast","passed":172,"failed":0},{"name":"func_ptrs.wast","passed":36,"failed":0},{"name":"global.wast","passed":110,"failed":0},{"name":"i32.wast","passed":460,"failed":0},{"name":"i64.wast","passed":416,"failed":0},{"name":"if.wast","passed":241,"failed":0},{"name":"imports.wast","passed":186,"failed":0},{"name":"inline-module.wast","passed":1,"failed":0},{"name":"int_exprs.wast","passed":108,"failed":0},{"name":"int_literals.wast","passed":51,"failed":0},{"name":"labels.wast","passed":29,"failed":0},{"name":"left-to-right.wast","passed":96,"failed":0},{"name":"linking.wast","passed":132,"failed":0},{"name":"load.wast","passed":97,"failed":0},{"name":"local_get.wast","passed":36,"failed":0},{"name":"local_set.wast","passed":53,"failed":0},{"name":"local_tee.wast","passed":97,"failed":0},{"name":"loop.wast","passed":120,"failed":0},{"name":"memory.wast","passed":79,"failed":0},{"name":"memory_grow.wast","passed":96,"failed":0},{"name":"memory_redundancy.wast","passed":8,"failed":0},{"name":"memory_size.wast","passed":42,"failed":0},{"name":"memory_trap.wast","passed":182,"failed":0},{"name":"names.wast","passed":486,"failed":0},{"name":"nop.wast","passed":88,"failed":0},{"name":"return.wast","passed":84,"failed":0},{"name":"select.wast","passed":148,"failed":0},{"name":"skip-stack-guard-page.wast","passed":11,"failed":0},{"name":"stack.wast","passed":7,"failed":0},{"name":"start.wast","passed":20,"failed":0},{"name":"store.wast","passed":68,"failed":0},{"name":"switch.wast","passed":28,"failed":0},{"name":"table.wast","passed":19,"failed":0},{"name":"token.wast","passed":58,"failed":0},{"name":"traps.wast","passed":36,"failed":0},{"name":"type.wast","passed":3,"failed":0},{"name":"unreachable.wast","passed":64,"failed":0},{"name":"unreached-invalid.wast","passed":118,"failed":0},{"name":"unreached-valid.wast","passed":7,"failed":0},{"name":"unwind.wast","passed":50,"failed":0},{"name":"utf8-custom-section-id.wast","passed":176,"failed":0},{"name":"utf8-import-field.wast","passed":176,"failed":0},{"name":"utf8-import-module.wast","passed":176,"failed":0},{"name":"utf8-invalid-encoding.wast","passed":176,"failed":0}] diff --git a/crates/tinywasm/tests/generated/progress-2.0.svg b/crates/tinywasm/tests/generated/progress-2.0.svg index 6424367..f5562a1 100644 --- a/crates/tinywasm/tests/generated/progress-2.0.svg +++ b/crates/tinywasm/tests/generated/progress-2.0.svg @@ -41,19 +41,24 @@ TinyWasm Version - + v0.3.0 (26722) - - + + v0.4.0 (27549) - - -v0.4.1 (27552) + + +v0.4.1 (27551) - - - - + + +v0.5.0 (27551) + + + + + + diff --git a/crates/tinywasm/tests/generated/progress-mvp.svg b/crates/tinywasm/tests/generated/progress-mvp.svg index 2a26dd5..3501681 100644 --- a/crates/tinywasm/tests/generated/progress-mvp.svg +++ b/crates/tinywasm/tests/generated/progress-mvp.svg @@ -36,27 +36,20 @@ TinyWasm Version - + v0.0.4 (9258) - - -v0.1.0 (17630) - - - -v0.3.0 (20254) - - - -v0.4.1 (20257) - - - - - - - - - + + +v0.4.0 (20254) + + + + + + + + + + diff --git a/crates/tinywasm/tests/test-mvp.rs b/crates/tinywasm/tests/test-mvp.rs index 445b7fa..a1c2067 100644 --- a/crates/tinywasm/tests/test-mvp.rs +++ b/crates/tinywasm/tests/test-mvp.rs @@ -1,4 +1,5 @@ mod testsuite; +use _log as log; use eyre::{eyre, Result}; use owo_colors::OwoColorize; use testsuite::TestSuite; diff --git a/crates/tinywasm/tests/test-two.rs b/crates/tinywasm/tests/test-two.rs index e710d1a..b5ed9c8 100644 --- a/crates/tinywasm/tests/test-two.rs +++ b/crates/tinywasm/tests/test-two.rs @@ -1,4 +1,5 @@ mod testsuite; +use _log as log; use eyre::{eyre, Result}; use owo_colors::OwoColorize; use testsuite::TestSuite; diff --git a/crates/tinywasm/tests/test-wast.rs b/crates/tinywasm/tests/test-wast.rs index 1d3fbe3..fa3af91 100644 --- a/crates/tinywasm/tests/test-wast.rs +++ b/crates/tinywasm/tests/test-wast.rs @@ -1,5 +1,6 @@ use std::path::PathBuf; +use _log as log; use eyre::{bail, eyre, Result}; use owo_colors::OwoColorize; use testsuite::TestSuite; diff --git a/crates/tinywasm/tests/testsuite/mod.rs b/crates/tinywasm/tests/testsuite/mod.rs index 35f0607..6223982 100644 --- a/crates/tinywasm/tests/testsuite/mod.rs +++ b/crates/tinywasm/tests/testsuite/mod.rs @@ -1,5 +1,6 @@ #![allow(dead_code)] // rust analyzer doesn't recognize that code is used by tests without harness +use _log as log; use eyre::Result; use owo_colors::OwoColorize; use std::io::{BufRead, Seek, SeekFrom}; diff --git a/crates/tinywasm/tests/testsuite/run.rs b/crates/tinywasm/tests/testsuite/run.rs index 84efc3a..2b2bbc4 100644 --- a/crates/tinywasm/tests/testsuite/run.rs +++ b/crates/tinywasm/tests/testsuite/run.rs @@ -3,6 +3,7 @@ use crate::testsuite::util::*; use std::{borrow::Cow, collections::HashMap}; use super::TestSuite; +use _log as log; use eyre::{eyre, Result}; use log::{debug, error, info}; use tinywasm::{Extern, Imports, ModuleInstance}; diff --git a/crates/types/src/archive.rs b/crates/types/src/archive.rs index 273d6ed..9bf095b 100644 --- a/crates/types/src/archive.rs +++ b/crates/types/src/archive.rs @@ -47,6 +47,9 @@ impl Display for TwasmError { } } +#[cfg(feature = "std")] +extern crate std; + #[cfg(feature = "std")] impl std::error::Error for TwasmError {} diff --git a/crates/types/src/instructions.rs b/crates/types/src/instructions.rs index 9923116..402cc9a 100644 --- a/crates/types/src/instructions.rs +++ b/crates/types/src/instructions.rs @@ -72,9 +72,8 @@ pub enum ConstInstruction { /// Wasm Bytecode can map to multiple of these instructions. /// /// # Differences to the spec -/// * `br_table` stores the jump lables in the following `br_label` instructions to keep this enum small. -/// * Lables/Blocks: we store the label end offset in the instruction itself and -/// have seperate EndBlockFrame and EndFunc instructions to mark the end of a block or function. +/// * `br_table` stores the jump labels in the following `br_label` instructions to keep this enum small. +/// * Lables/Blocks: we store the label end offset in the instruction itself and use `EndBlockFrame` to mark the end of a block. /// This makes it easier to implement the label stack iteratively. /// /// See @@ -121,7 +120,6 @@ pub enum Instruction { If(BlockArgsPacked, ElseOffset, EndOffset), // If else offset is 0 if there is no else block Else(EndOffset), EndBlockFrame, - EndFunc, Br(LabelAddr), BrIf(LabelAddr), BrTable(BrTableDefault, BrTableLen), // has to be followed by multiple BrLabel instructions diff --git a/crates/types/src/lib.rs b/crates/types/src/lib.rs index d2da7d7..c5c8071 100644 --- a/crates/types/src/lib.rs +++ b/crates/types/src/lib.rs @@ -3,7 +3,7 @@ attr(deny(warnings, rust_2018_idioms), allow(dead_code, unused_assignments, unused_variables)) ))] #![warn(missing_debug_implementations, rust_2018_idioms, unreachable_pub)] -#![cfg_attr(not(feature = "std"), no_std)] +#![no_std] #![cfg_attr(not(feature = "unsafe"), forbid(unsafe_code))] #![cfg_attr(feature = "unsafe", deny(unused_unsafe))] @@ -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. diff --git a/crates/wasm-testsuite/Cargo.toml b/crates/wasm-testsuite/Cargo.toml index 97c1f58..3e12db5 100644 --- a/crates/wasm-testsuite/Cargo.toml +++ b/crates/wasm-testsuite/Cargo.toml @@ -1,6 +1,6 @@ [package] name="wasm-testsuite" -version="0.2.2" +version="0.3.0" description="Mirror of the WebAssembly core testsuite for use in testing WebAssembly implementations" license="Apache-2.0" readme="README.md" @@ -15,4 +15,4 @@ path="lib.rs" independent=true [dependencies] -rust-embed={version="8.1.0", features=["include-exclude"]} +rust-embed={version="8.3", features=["include-exclude"]} diff --git a/crates/wasm-testsuite/data b/crates/wasm-testsuite/data index 5a1a590..16a839d 160000 --- a/crates/wasm-testsuite/data +++ b/crates/wasm-testsuite/data @@ -1 +1 @@ -Subproject commit 5a1a590603d81f40ef471abba70a90a9ae5f4627 +Subproject commit 16a839d5601c283541a84572b47637f035b51437 diff --git a/examples/rust/rust-toolchain.toml b/examples/rust/rust-toolchain.toml index 6c22ba5..21a0cab 100644 --- a/examples/rust/rust-toolchain.toml +++ b/examples/rust/rust-toolchain.toml @@ -1,2 +1,3 @@ [toolchain] -channel="nightly-2024-02-11" +channel="nightly" +targets=["wasm32-unknown-unknown"] diff --git a/examples/wasm-rust.rs b/examples/wasm-rust.rs index cff38f5..921c4a3 100644 --- a/examples/wasm-rust.rs +++ b/examples/wasm-rust.rs @@ -1,4 +1,4 @@ -use color_eyre::eyre::Result; +use color_eyre::eyre::{eyre, Result}; use tinywasm::{Extern, FuncContext, Imports, MemoryStringExt, Module, Store}; /// Examples of using WebAssembly compiled from Rust with tinywasm. @@ -20,6 +20,10 @@ use tinywasm::{Extern, FuncContext, Imports, MemoryStringExt, Module, Store}; fn main() -> Result<()> { pretty_env_logger::init(); + if !std::path::Path::new("./examples/rust/out/").exists() { + return Err(eyre!("No WebAssembly files found. See examples/wasm-rust.rs for instructions.")); + } + let args = std::env::args().collect::>(); if args.len() < 2 { println!("Usage: cargo run --example wasm-rust "); @@ -36,6 +40,17 @@ fn main() -> Result<()> { "printi32" => printi32()?, "fibonacci" => fibonacci()?, "tinywasm" => tinywasm()?, + "all" => { + println!("Running all examples"); + println!("\nhello.wasm:"); + hello()?; + println!("\nprinti32.wasm:"); + printi32()?; + println!("\nfibonacci.wasm:"); + fibonacci()?; + println!("\ntinywasm.wasm:"); + tinywasm()?; + } _ => {} } @@ -43,8 +58,7 @@ fn main() -> Result<()> { } fn tinywasm() -> Result<()> { - const TINYWASM: &[u8] = include_bytes!("./rust/out/tinywasm.wasm"); - let module = Module::parse_bytes(TINYWASM)?; + let module = Module::parse_file("./examples/rust/out/tinywasm.wasm")?; let mut store = Store::default(); let mut imports = Imports::new(); @@ -65,8 +79,7 @@ fn tinywasm() -> Result<()> { } fn hello() -> Result<()> { - const HELLO_WASM: &[u8] = include_bytes!("./rust/out/hello.wasm"); - let module = Module::parse_bytes(HELLO_WASM)?; + let module = Module::parse_file("./examples/rust/out/hello.wasm")?; let mut store = Store::default(); let mut imports = Imports::new(); @@ -95,8 +108,7 @@ fn hello() -> Result<()> { } fn printi32() -> Result<()> { - const HELLO_WASM: &[u8] = include_bytes!("./rust/out/print.wasm"); - let module = Module::parse_bytes(HELLO_WASM)?; + let module = Module::parse_file("./examples/rust/out/print.wasm")?; let mut store = Store::default(); let mut imports = Imports::new(); @@ -117,8 +129,7 @@ fn printi32() -> Result<()> { } fn fibonacci() -> Result<()> { - const FIBONACCI_WASM: &[u8] = include_bytes!("./rust/out/fibonacci.wasm"); - let module = Module::parse_bytes(FIBONACCI_WASM)?; + let module = Module::parse_file("./examples/rust/out/fibonacci.wasm")?; let mut store = Store::default(); let instance = module.instantiate(&mut store, None)?; diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 6c22ba5..7d876a7 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,2 +1,2 @@ [toolchain] -channel="nightly-2024-02-11" +channel="nightly-2024-03-11" diff --git a/scripts/Cargo.toml b/scripts/Cargo.toml new file mode 100644 index 0000000..5217729 --- /dev/null +++ b/scripts/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name="scripts" +publish=false +edition.workspace=true + +[dependencies] +plotters={version="0.3"} +eyre={version="0.6"} diff --git a/scripts/src/bin/generate-charts/main.rs b/scripts/src/bin/generate-charts/main.rs new file mode 100644 index 0000000..1206e5f --- /dev/null +++ b/scripts/src/bin/generate-charts/main.rs @@ -0,0 +1,35 @@ +mod progress; +use std::{path::PathBuf, str::FromStr}; + +use eyre::Result; + +fn main() -> Result<()> { + generate_charts() +} + +fn generate_charts() -> Result<()> { + let results_dir = PathBuf::from_str("./crates/tinywasm/tests/generated")?; + + // check if the folder exists + if !results_dir.exists() { + return Err(eyre::eyre!( + "This script should be run from the root of the project, and the test results should be generated first." + )); + } + + progress::create_progress_chart( + "WebAssembly 1.0 Test Suite", + &results_dir.join("mvp.csv"), + &results_dir.join("progress-mvp.svg"), + )?; + println!("created progress chart: {}", results_dir.join("progress-mvp.svg").display()); + + progress::create_progress_chart( + "WebAssembly 2.0 Test Suite", + &results_dir.join("2.0.csv"), + &results_dir.join("progress-2.0.svg"), + )?; + println!("created progress chart: {}", results_dir.join("progress-2.0.svg").display()); + + Ok(()) +} diff --git a/crates/tinywasm/tests/charts/progress.rs b/scripts/src/bin/generate-charts/progress.rs similarity index 100% rename from crates/tinywasm/tests/charts/progress.rs rename to scripts/src/bin/generate-charts/progress.rs