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

memory imports #124

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/core/reader/types/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::core::reader::{WasmReadable, WasmReader};
use crate::execution::assert_validated::UnwrapValidatedExt;
use crate::{unreachable_validated, Error, Result};

use super::TableType;
use super::{MemType, TableType};

#[derive(Debug)]
pub struct Import {
Expand Down Expand Up @@ -52,7 +52,7 @@ pub enum ImportDesc {
Table(TableType),
// TODO TableType
#[allow(dead_code)]
Mem(()),
Mem(MemType),
// TODO MemType
#[allow(dead_code)]
Global(()), // TODO GlobalType
Expand All @@ -64,7 +64,7 @@ impl WasmReadable for ImportDesc {
0x00 => Self::Func(wasm.read_var_u32()? as TypeIdx),
// https://webassembly.github.io/spec/core/binary/types.html#table-types
0x01 => Self::Table(TableType::read(wasm)?),
0x02 => todo!("read MemType"),
0x02 => Self::Mem(MemType::read(wasm)?),
0x03 => todo!("read GlobalType"),
other => return Err(Error::InvalidImportDesc(other)),
};
Expand All @@ -76,7 +76,7 @@ impl WasmReadable for ImportDesc {
match wasm.read_u8().unwrap_validated() {
0x00 => Self::Func(wasm.read_var_u32().unwrap_validated() as TypeIdx),
0x01 => Self::Table(TableType::read_unvalidated(wasm)),
0x02 => todo!("read MemType"),
0x02 => Self::Mem(MemType::read_unvalidated(wasm)),
0x03 => todo!("read GlobalType"),
_ => unreachable_validated!(),
}
Expand Down
27 changes: 20 additions & 7 deletions src/execution/execution_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,40 @@ use alloc::vec::Vec;

use crate::core::reader::types::FuncType;
use crate::core::reader::WasmReader;
use crate::core::sidetable::Sidetable;
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 struct ExecutionInfo {
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 {
impl ExecutionInfo {
pub fn new(name: &str, fn_types: Vec<FuncType>, store: Store) -> Self {
ExecutionInfo {
name: name.to_string(),
wasm_bytecode,
wasm_reader: WasmReader::new(wasm_bytecode),
fn_types,
store,
}
}
}

pub struct StateData<'r> {
pub wasm_bytecode: &'r [u8],
pub wasm_reader: WasmReader<'r>,
pub sidetables: Vec<Sidetable>,
}

impl<'r> StateData<'r> {
pub fn new(wasm_bytecode: &'r [u8], sidetables: Vec<Sidetable>) -> Self {
StateData {
wasm_bytecode,
wasm_reader: WasmReader::new(wasm_bytecode),
sidetables,
}
}
}
Loading