Skip to content

Commit

Permalink
fix: fix nix flake check + non-exhaustive pattern for error
Browse files Browse the repository at this point in the history
Signed-off-by: nerodesu017 <[email protected]>
  • Loading branch information
nerodesu017 committed Jan 27, 2025
2 parents b7f554e + 05664f7 commit 6b4f96d
Show file tree
Hide file tree
Showing 31 changed files with 1,324 additions and 263 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ hooks = []

[[test]]
name = "wasm_spec_testsuite"
harness = false
harness = false
16 changes: 14 additions & 2 deletions src/core/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ pub enum RuntimeError {
UninitializedElement,
SignatureMismatch,
ExpectedAValueOnTheStack,
ModuleNotFound,
UnmetImport,
UndefinedTableIndex,
// "undefined element" <- as-call_indirect-last
// "unreachable"
}

#[derive(Debug, PartialEq, Eq, Clone)]
Expand Down Expand Up @@ -100,6 +100,8 @@ pub enum Error {
FunctionTypeIsNotDefined(TypeIdx),
StoreInstantiationError(StoreInstantiationError),
OnlyFuncRefIsAllowed,
TypeUnificationMismatch,
InvalidSelectTypeVector,
TooManyLocals(usize),
UnsupportedProposal(Proposal),
Overflow,
Expand Down Expand Up @@ -247,6 +249,12 @@ impl Display for Error {
)),
Error::StoreInstantiationError(err) => err.fmt(f),
Error::OnlyFuncRefIsAllowed => f.write_str("Only FuncRef is allowed"),
Error::TypeUnificationMismatch => {
f.write_str("cannot unify types")
}
Error::InvalidSelectTypeVector => {
f.write_str("SELECT T* (0x1C) instruction must have exactly one type in the subsequent type vector")
},
Error::TooManyLocals(x) => {
f.write_fmt(format_args!("Too many locals (more than 2^32-1): {}", x))
}
Expand Down Expand Up @@ -274,6 +282,10 @@ impl Display for RuntimeError {
RuntimeError::ExpectedAValueOnTheStack => {
f.write_str("Expected a value on the stack, but None was found")
}
RuntimeError::ModuleNotFound => f.write_str("No such module exists"),
RuntimeError::UnmetImport => {
f.write_str("There is at least one import which has no corresponding export")
}
RuntimeError::UndefinedTableIndex => {
f.write_str("Indirect call: table index out of bounds")
}
Expand Down
2 changes: 2 additions & 0 deletions src/core/reader/types/opcode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ pub const BR_TABLE: u8 = 0x0E;
pub const RETURN: u8 = 0x0F;
pub const CALL: u8 = 0x10;
pub const DROP: u8 = 0x1A;
pub const SELECT: u8 = 0x1B;
pub const SELECT_T: u8 = 0x1C;
pub const CALL_INDIRECT: u8 = 0x11;
pub const LOCAL_GET: u8 = 0x20;
pub const LOCAL_SET: u8 = 0x21;
Expand Down
2 changes: 1 addition & 1 deletion src/core/sidetable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub type Sidetable = Vec<SidetableEntry>;
/// - else
// TODO hide implementation
// TODO Remove Clone trait from sidetables
#[derive(Clone)]
#[derive(Debug, Clone)]
pub struct SidetableEntry {
/// Δpc: the amount to adjust the instruction pointer by if the branch is taken
pub delta_pc: isize,
Expand Down
29 changes: 29 additions & 0 deletions src/execution/execution_info.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
use alloc::string::{String, ToString};
use alloc::vec::Vec;

use crate::core::reader::types::FuncType;
use crate::core::reader::WasmReader;
use crate::execution::Store;

/// ExecutionInfo is a compilation of relevant information needed by the [interpreter loop](
/// crate::execution::interpreter_loop::run). The lifetime annotation `'r` represents that this structure needs to be
/// valid at least as long as the [RuntimeInstance](crate::execution::RuntimeInstance) that creates it.
pub struct ExecutionInfo<'r> {
pub name: String,
pub wasm_bytecode: &'r [u8],
pub wasm_reader: WasmReader<'r>,
pub fn_types: Vec<FuncType>,
pub store: Store,
}

impl<'r> ExecutionInfo<'r> {
pub fn new(name: &str, wasm_bytecode: &'r [u8], fn_types: Vec<FuncType>, store: Store) -> Self {
ExecutionInfo {
name: name.to_string(),
wasm_bytecode,
wasm_reader: WasmReader::new(wasm_bytecode),
fn_types,
store,
}
}
}
Loading

0 comments on commit 6b4f96d

Please sign in to comment.