Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce support for environments where the standard library is not available (#![no_std]) but a global allocator is #59

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
121 changes: 116 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ binary = ["wain-syntax-binary"]
text = ["wain-syntax-text"]

[dependencies]
wain-ast = { path = "./wain-ast", version = "0.2" }
wain-syntax-text = { path = "./wain-syntax-text", version = "0.2", optional = true }
wain-syntax-binary = { path = "./wain-syntax-binary", version = "0.1", optional = true }
wain-validate = { path = "./wain-validate", version = "0.1" }
wain-exec = { path = "./wain-exec", version = "0.3" }
wain-ast = { path = "./wain-ast", version = "0.3" }
wain-syntax-text = { path = "./wain-syntax-text", version = "0.3", optional = true }
wain-syntax-binary = { path = "./wain-syntax-binary", version = "0.2", optional = true }
wain-validate = { path = "./wain-validate", version = "0.2" }
wain-exec = { path = "./wain-exec", version = "0.4" }

[dev-dependencies]
cargo-husky = { version = "1", features = ["run-cargo-clippy", "run-cargo-fmt"] }
Expand Down
9 changes: 7 additions & 2 deletions spec-test/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -634,8 +634,13 @@ impl<'s> Parse<'s> for Script<'s> {
while !parser.is_done()? {
commands.push(parser.parse()?);
}
let start = commands.first().map(Command::start_pos).unwrap_or(0);
Ok(Script { start, commands })
// The name and id fields appear to be dead code, which is causing Clippy to fail and thus I can't `git push` without the post-commit hooks failing.
// I'm not sure if this is intended, but I've commented it out to remove the dead code and please Clippy.
// let start = commands.first().map(Command::start_pos).unwrap_or(0);
Ok(Script {
//start,
commands,
})
}
}

Expand Down
6 changes: 4 additions & 2 deletions spec-test/src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ mod color {
pub const BLUE: &[u8] = b"";
}

struct Discard;
// The Discard struct appears to be dead code, which is causing Clippy to fail and thus I can't `git push` without the post-commit hooks failing.
// I'm not sure if this is intended, but I've commented it out to remove the dead code and please Clippy.
/* struct Discard;

impl io::Read for Discard {
fn read(&mut self, _buf: &mut [u8]) -> io::Result<usize> {
Expand All @@ -58,7 +60,7 @@ impl io::Write for Discard {
fn flush(&mut self) -> io::Result<()> {
Ok(())
}
}
} */

#[derive(Default)]
pub struct Summary {
Expand Down
23 changes: 20 additions & 3 deletions spec-test/src/wast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ impl Const {
}

pub struct Script<'source> {
pub start: usize,
// The start field appears to be dead code, which is causing Clippy to fail and thus I can't `git push` without the post-commit hooks failing.
// I'm not sure if this is intended, but I've commented it out to remove the dead code and please Clippy.
// pub start: usize,
pub commands: Vec<Command<'source>>,
}

Expand All @@ -89,7 +91,10 @@ pub enum Command<'source> {
EmbeddedModule(EmbeddedModule),
InlineModule(ast::Root<'source, TextSource<'source>>),
}
impl<'s> Command<'s> {

// This impl appears to be dead code, which is causing Clippy to fail and thus I can't `git push` without the post-commit hooks failing.
// I'm not sure if this is intended, but I've commented it out to remove the dead code and please Clippy.
/*impl<'s> Command<'s> {
pub fn start_pos(&self) -> usize {
match self {
Command::AssertReturn(AssertReturn::Invoke { start, .. }) => *start,
Expand All @@ -105,7 +110,7 @@ impl<'s> Command<'s> {
Command::InlineModule(r) => r.module.start,
}
}
}
}*/

// (invoke {id}? {name} {constant}*)
pub struct Invoke<'source> {
Expand All @@ -118,12 +123,19 @@ pub struct Invoke<'source> {
// (register {name} {id}?)
pub struct Register<'source> {
pub start: usize,
// The name and id fields appear to be dead code, which is causing Clippy to fail and thus I can't `git push` without the post-commit hooks failing.
// However, they are used for assert! in the tests, so I've told clippy to ignore this.
#[allow(dead_code)]
pub name: String,
#[allow(dead_code)]
pub id: Option<&'source str>,
}

// (get {id}? {name})
pub struct GetGlobal<'source> {
// The start field appears to be dead code, which is causing Clippy to fail and thus I can't `git push` without the post-commit hooks failing.
// This is used in the tests, so I've told clippy to ignore this.
#[allow(dead_code)]
pub start: usize,
pub id: Option<&'source str>,
pub name: String,
Expand Down Expand Up @@ -176,7 +188,12 @@ pub struct AssertInvalid<'source> {
pub struct AssertUnlinkable<'source> {
pub start: usize,
// module is put inline. The source is always text

// The wat and expected fields appear to be dead code, which is causing Clippy to fail and thus I can't `git push` without the post-commit hooks failing.
// However, they are used for assert! in the tests, so I've told clippy to ignore this.
#[allow(dead_code)]
pub wat: ast::Root<'source, TextSource<'source>>,
#[allow(dead_code)]
pub expected: String,
}

Expand Down
2 changes: 1 addition & 1 deletion wain-ast/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "wain-ast"
version = "0.2.2"
version = "0.3.0"
authors = ["rhysd <[email protected]>"]
edition = "2021"
description = "WebAssembly abstract syntax tree definition used by both binary format and text format for wain project"
Expand Down
8 changes: 5 additions & 3 deletions wain-ast/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#![no_std]
#![forbid(unsafe_code)]
#![warn(clippy::dbg_macro)]

pub mod source;
extern crate alloc;

use alloc::{borrow::Cow, fmt, vec::Vec};

use std::borrow::Cow;
use std::fmt;
pub mod source;

// Root of the tree
#[derive(Clone, Debug, PartialEq)]
Expand Down
2 changes: 1 addition & 1 deletion wain-ast/src/source.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::fmt;
use alloc::fmt;

// Trait to handle source for better error message. Wasm has two format text and binary.
// This trait handles them with one generics.
Expand Down
13 changes: 9 additions & 4 deletions wain-exec/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "wain-exec"
version = "0.3.1"
version = "0.4.0"
authors = ["rhysd <[email protected]>"]
edition = "2021"
description = "WebAssembly syntax tree executor for wain project"
Expand All @@ -19,11 +19,16 @@ consolidate-commits = false
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
wain-ast = { path = "../wain-ast", version = "0.2" }
libm = { version = "0.2.8", optional = true }
wain-ast = { path = "../wain-ast", version = "0.3" }

[dev-dependencies]
wain-syntax-text = { path = "../wain-syntax-text", version = "0.2" }
wain-validate = { path = "../wain-validate", version = "0.1" }
wain-syntax-text = { path = "../wain-syntax-text", version = "0.3" }
wain-validate = { path = "../wain-validate", version = "0.2" }

[badges]
maintenance = { status = "actively-developed" }

[features]
default = []
no_std = ["libm"]
1 change: 0 additions & 1 deletion wain-exec/src/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ float_to_int_sat!(f64_to_i64_sat, f64, i64);
#[cfg(test)]
mod tests {
use super::*;
use std::{f32, f64};

trait NextAfter {
fn next_after(self, _: Self) -> Self;
Expand Down
4 changes: 3 additions & 1 deletion wain-exec/src/globals.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use crate::trap::{Result, Trap};
use crate::value::{LittleEndian, Value};
use alloc::boxed::Box;
use alloc::{vec, vec::Vec};
use wain_ast::{Global, GlobalKind, InsnKind, ValType};

// Fixed-size any values store indexed in advance
Expand Down Expand Up @@ -102,7 +104,7 @@ impl Globals {
mod tests {
use super::*;
use crate::trap::TrapReason;
use std::borrow::Cow;
use alloc::borrow::Cow;
use wain_ast::{Import, InsnKind, Instruction, Name, ValType};

#[test]
Expand Down
Loading