Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 461126c

Browse files
feat: full no_std support
Signed-off-by: Henry Gressmann <[email protected]>
1 parent b9a4e87 commit 461126c

File tree

24 files changed

+363
-31
lines changed

24 files changed

+363
-31
lines changed

.github/workflows/test.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ jobs:
4141
run: rustup update nightly
4242

4343
- name: Build (nightly, no default features)
44-
run: cargo +nightly build --workspace --exclude wasm-testsuite --no-default-features
44+
run: cargo +nightly build --workspace --exclude wasm-testsuite --exclude rust-wasm-examples --no-default-features
4545

4646
- name: Run tests (nightly, no default features)
47-
run: cargo +nightly test --workspace --exclude wasm-testsuite --no-default-features
47+
run: cargo +nightly test --workspace --exclude wasm-testsuite --exclude rust-wasm-examples --no-default-features
4848

4949
- name: Run MVP testsuite (nightly)
5050
run: cargo +nightly test-mvp

Cargo.lock

Lines changed: 101 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
[workspace]
22
members=["crates/*"]
3-
default-members=["crates/cli"]
43
resolver="2"
54

65
[workspace.package]
@@ -9,3 +8,12 @@ edition="2021"
98
license="MIT OR Apache-2.0"
109
authors=["Henry Gressmann <[email protected]>"]
1110
repository="https://github.com/explodingcamera/tinywasm"
11+
12+
[package]
13+
name="tinywasm-root"
14+
publish=false
15+
edition="2021"
16+
17+
[dev-dependencies]
18+
color-eyre="0.6"
19+
tinywasm={path="crates/tinywasm"}

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ $ cargo add tinywasm
5555
- **`parser`**\
5656
Enables the `tinywasm-parser` crate. This is enabled by default.
5757

58-
With all these features disabled, TinyWasm does not depend on any external crates and can be used in `no_std` environments.
58+
With all these features disabled, TinyWasm only depends on `core`, `alloc` and `libm` and can be used in `no_std` environments.
5959

6060
<!-- # 🎯 Goals
6161

crates/parser/src/conversion.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
use crate::log;
12
use alloc::{boxed::Box, format, string::ToString, vec::Vec};
2-
use log::debug;
33
use tinywasm_types::*;
44
use wasmparser::{FuncValidator, OperatorsReader, ValidatorResources};
55

@@ -239,7 +239,7 @@ pub fn process_operators<'a>(
239239
let mut labels_ptrs = Vec::new(); // indexes into the instructions array
240240

241241
for op in ops {
242-
debug!("op: {:?}", op);
242+
log::debug!("op: {:?}", op);
243243

244244
let op = op?;
245245
validator.op(offset, &op)?;
@@ -274,7 +274,7 @@ pub fn process_operators<'a>(
274274
}
275275
End => {
276276
if let Some(label_pointer) = labels_ptrs.pop() {
277-
debug!("ending block: {:?}", instructions[label_pointer]);
277+
log::debug!("ending block: {:?}", instructions[label_pointer]);
278278

279279
let current_instr_ptr = instructions.len();
280280

crates/parser/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ use log;
1414
#[cfg(not(feature = "logging"))]
1515
mod log {
1616
macro_rules! debug ( ($($tt:tt)*) => {{}} );
17+
macro_rules! error ( ($($tt:tt)*) => {{}} );
1718
pub(crate) use debug;
19+
pub(crate) use error;
1820
}
1921

2022
mod conversion;

crates/parser/src/module.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,9 @@ impl ModuleReader {
181181
validator.end(offset)?;
182182
self.end_reached = true;
183183
}
184-
CustomSection(reader) => {
184+
CustomSection(_reader) => {
185185
debug!("Found custom section");
186-
debug!("Skipping custom section: {:?}", reader.name());
186+
debug!("Skipping custom section: {:?}", _reader.name());
187187
}
188188
// TagSection(tag) => {
189189
// debug!("Found tag section");

crates/tinywasm/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ path="src/lib.rs"
1616
log={version="0.4", optional=true}
1717
tinywasm-parser={version="0.3.0-alpha.0", path="../parser", default-features=false, optional=true}
1818
tinywasm-types={version="0.3.0-alpha.0", path="../types", default-features=false}
19+
libm={version="0.2", default-features=false}
1920

2021
[dev-dependencies]
2122
wasm-testsuite={path="../wasm-testsuite"}

crates/tinywasm/src/func.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
use crate::log;
12
use alloc::{boxed::Box, format, string::String, string::ToString, vec, vec::Vec};
2-
use log::{debug, info};
33
use tinywasm_types::{FuncAddr, FuncType, ValType, WasmValue};
44

55
use crate::{
@@ -34,7 +34,7 @@ impl FuncHandle {
3434

3535
// 4. If the length of the provided argument values is different from the number of expected arguments, then fail
3636
if func_ty.params.len() != params.len() {
37-
info!("func_ty.params: {:?}", func_ty.params);
37+
log::info!("func_ty.params: {:?}", func_ty.params);
3838
return Err(Error::Other(format!(
3939
"param count mismatch: expected {}, got {}",
4040
func_ty.params.len(),
@@ -62,7 +62,7 @@ impl FuncHandle {
6262
};
6363

6464
// 6. Let f be the dummy frame
65-
debug!("locals: {:?}", locals);
65+
log::debug!("locals: {:?}", locals);
6666
let call_frame = CallFrame::new(func_inst, params, locals);
6767

6868
// 7. Push the frame f to the call stack

crates/tinywasm/src/imports.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use core::fmt::Debug;
44

55
use crate::{
66
func::{FromWasmValueTuple, IntoWasmValueTuple, ValTypesFromTuple},
7-
LinkingError, Result,
7+
log, LinkingError, Result,
88
};
99
use alloc::{
1010
collections::BTreeMap,

crates/tinywasm/src/instance.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use tinywasm_types::{
66

77
use crate::{
88
func::{FromWasmValueTuple, IntoWasmValueTuple},
9-
Error, FuncHandle, FuncHandleTyped, Imports, Module, Result, Store,
9+
log, Error, FuncHandle, FuncHandleTyped, Imports, Module, Result, Store,
1010
};
1111

1212
/// An instanciated WebAssembly module
@@ -123,7 +123,8 @@ impl ModuleInstance {
123123
&self.0.func_addrs
124124
}
125125

126-
pub(crate) fn func_tys(&self) -> &[FuncType] {
126+
/// Get the module's function types
127+
pub fn func_tys(&self) -> &[FuncType] {
127128
&self.0.types
128129
}
129130

crates/tinywasm/src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,13 @@ use log;
7878
#[cfg(not(feature = "logging"))]
7979
pub(crate) mod log {
8080
macro_rules! debug ( ($($tt:tt)*) => {{}} );
81+
macro_rules! info ( ($($tt:tt)*) => {{}} );
82+
macro_rules! trace ( ($($tt:tt)*) => {{}} );
83+
macro_rules! error ( ($($tt:tt)*) => {{}} );
8184
pub(crate) use debug;
85+
pub(crate) use error;
86+
pub(crate) use info;
87+
pub(crate) use trace;
8288
}
8389

8490
mod error;

crates/tinywasm/src/runtime/interpreter/mod.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,24 @@
1-
use core::ops::{BitAnd, BitOr, BitXor, Neg};
2-
31
use super::{InterpreterRuntime, Stack};
2+
use crate::log;
43
use crate::{
54
log::debug,
65
runtime::{BlockType, CallFrame, LabelArgs, LabelFrame},
76
Error, FuncContext, ModuleInstance, Result, Store, Trap,
87
};
98
use alloc::{string::ToString, vec::Vec};
9+
use core::ops::{BitAnd, BitOr, BitXor, Neg};
1010
use tinywasm_types::{ElementKind, Instruction, ValType};
1111

12+
#[cfg(not(feature = "std"))]
13+
mod no_std_floats;
14+
15+
#[cfg(not(feature = "std"))]
16+
#[allow(unused_imports)]
17+
use no_std_floats::FExt;
18+
1219
mod macros;
1320
mod traits;
21+
1422
use macros::*;
1523
use traits::*;
1624

0 commit comments

Comments
 (0)