From 1b6f5dfc63e2f64aa1c1fed1a6b4c3e1e32db1b9 Mon Sep 17 00:00:00 2001 From: Henry Gressmann Date: Sun, 21 Jan 2024 20:50:27 +0100 Subject: wip: refactoring imports Signed-off-by: Henry Gressmann --- Cargo.lock | 4 +- crates/tinywasm/src/imports.rs | 223 ++++++++++++++++++++------------ crates/tinywasm/src/instance.rs | 16 ++- crates/tinywasm/src/store.rs | 137 +++++++++----------- crates/tinywasm/tests/generated/mvp.csv | 2 +- crates/tinywasm/tests/testsuite/run.rs | 9 +- crates/types/src/lib.rs | 2 +- 7 files changed, 219 insertions(+), 174 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 67a12d6..0b4e95c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1272,9 +1272,9 @@ checksum = "e51733f11c9c4f72aa0c160008246859e340b00807569a0da0e7a1079b27ba85" [[package]] name = "uuid" -version = "1.6.1" +version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e395fcf16a7a3d8127ec99782007af141946b4795001f876d54fb0d55978560" +checksum = "f00cc9702ca12d3c81455259621e676d0f7251cec66a21e98fe2e9a37db93b2a" [[package]] name = "version_check" diff --git a/crates/tinywasm/src/imports.rs b/crates/tinywasm/src/imports.rs index 41dd1a2..e7f9b81 100644 --- a/crates/tinywasm/src/imports.rs +++ b/crates/tinywasm/src/imports.rs @@ -11,12 +11,17 @@ use alloc::{ vec::Vec, }; use tinywasm_types::{ - ExternVal, ExternalKind, GlobalType, MemoryType, ModuleInstanceAddr, TableType, WasmFunction, WasmValue, + ExternVal, ExternalKind, FuncAddr, GlobalAddr, GlobalType, Import, MemAddr, MemoryType, ModuleInstanceAddr, + TableAddr, TableType, WasmFunction, WasmValue, }; +/// The internal representation of a function #[derive(Debug)] -pub(crate) enum Function { +pub enum Function { + /// A host function Host(HostFunction), + + /// A function defined in WebAssembly Wasm(WasmFunction), } @@ -49,14 +54,12 @@ pub enum Extern { Memory(ExternMemory), /// A function - Func(HostFunction), + Func(Function), } /// A function #[derive(Debug)] -pub struct ExternFunc { - pub(crate) inner: HostFunction, -} +pub struct ExternFunc(pub(crate) HostFunction); /// A global value #[derive(Debug)] @@ -110,10 +113,10 @@ impl Extern { func(store, &args) }; - Self::Func(HostFunction { + Self::Func(Function::Host(HostFunction { func: Arc::new(inner_func), ty: ty.clone(), - }) + })) } /// Create a new typed function import @@ -133,10 +136,10 @@ impl Extern { results: R::val_types(), }; - Self::Func(HostFunction { + Self::Func(Function::Host(HostFunction { func: Arc::new(inner_func), - ty: ty.clone(), - }) + ty, + })) } pub(crate) fn kind(&self) -> ExternalKind { @@ -156,6 +159,15 @@ pub struct ExternName { name: String, } +impl From<&Import> for ExternName { + fn from(import: &Import) -> Self { + Self { + module: import.module.to_string(), + name: import.name.to_string(), + } + } +} + #[derive(Debug, Default)] /// Imports for a module instance pub struct Imports { @@ -163,20 +175,77 @@ pub struct Imports { modules: BTreeMap, } -pub(crate) struct LinkedImports { - // externs that were defined and need to be instantiated - pub(crate) externs: BTreeMap, +pub(crate) enum ResolvedExtern { + // already in the store + Store(S), - // externs that were linked to other modules and already exist in the store - pub(crate) linked_externs: BTreeMap, + // needs to be added to the store, provided value + Extern(V), } -impl LinkedImports { - pub(crate) fn get(&self, module: &str, name: &str) -> Option<&Extern> { - self.externs.get(&ExternName { - module: module.to_string(), - name: name.to_string(), - }) +pub(crate) enum ResolvedImport { + Extern(Extern), + Store(ExternVal), +} + +impl ResolvedImport { + fn initialize(self, store: &mut crate::Store, idx: ModuleInstanceAddr) -> Result { + match self { + Self::Extern(extern_) => match extern_ { + Extern::Global(global) => { + let addr = store.add_global(global.ty, global.val.into(), idx)?; + Ok(ExternVal::Global(addr)) + } + Extern::Table(table) => { + // todo: do something with the initial value + let addr = store.add_table(table.ty, idx)?; + Ok(ExternVal::Table(addr)) + } + Extern::Memory(memory) => { + let addr = store.add_mem(memory.ty, idx)?; + Ok(ExternVal::Mem(addr)) + } + Extern::Func(func) => { + let addr = store.add_func(func, idx)?; + Ok(ExternVal::Func(addr)) + } + }, + Self::Store(extern_val) => Ok(extern_val.clone()), + } + } +} + +pub(crate) struct ResolvedImports { + pub(crate) globals: Vec>, + pub(crate) tables: Vec>, + pub(crate) mems: Vec>, + pub(crate) funcs: Vec>, +} + +impl ResolvedImports { + pub(crate) fn new() -> Self { + Self { + globals: Vec::new(), + tables: Vec::new(), + mems: Vec::new(), + funcs: Vec::new(), + } + } + + pub(crate) fn globals(&self) -> &[ResolvedExtern] { + &self.globals + } + + pub(crate) fn tables(&self) -> &[ResolvedExtern] { + &self.tables + } + + pub(crate) fn mems(&self) -> &[ResolvedExtern] { + &self.mems + } + + pub(crate) fn funcs(&self) -> &[ResolvedExtern] { + &self.funcs } } @@ -209,77 +278,63 @@ impl Imports { Ok(self) } - pub(crate) fn link(self, store: &mut crate::Store, module: &crate::Module) -> Result { - let mut links = BTreeMap::new(); + pub(crate) fn take(&mut self, store: &mut crate::Store, import: &Import) -> Option { + // TODO: compare types - for import in module.data.imports.iter() { - if let Some(i) = self.values.get(&ExternName { - module: import.module.to_string(), - name: import.name.to_string(), - }) { - if i.kind() != (&import.kind).into() { - return Err(crate::Error::InvalidImportType { - module: import.module.to_string(), - name: import.name.to_string(), - }); - } + let name = ExternName::from(import); + if let Some(v) = self.values.remove(&name) { + return Some(ResolvedImport::Extern(v)); + } - continue; - } - - let module_addr = - self.modules - .get(&import.module.to_string()) - .ok_or_else(|| crate::Error::MissingImport { - module: import.module.to_string(), - name: import.name.to_string(), - })?; - - let module = - store - .get_module_instance(*module_addr) - .ok_or_else(|| crate::Error::CouldNotResolveImport { - module: import.module.to_string(), - name: import.name.to_string(), - })?; - - let export = - module - .exports() - .get_untyped(&import.name) - .ok_or_else(|| crate::Error::CouldNotResolveImport { - module: import.module.to_string(), - name: import.name.to_string(), - })?; + return None; - // validate import - if export.kind != (&import.kind).into() { - return Err(crate::Error::InvalidImportType { + // TODO: allow linking to other modules + // if let Some(module_addr) = self.modules.get(&name.module) { + // let Some(module) = store.get_module_instance(*module_addr) else { + // return None; + // }; + + // let export = module.exports().get_untyped(&name.name)?; + // }; + + // then check if the import is defined + } + + pub(crate) fn link(mut self, store: &mut crate::Store, module: &crate::Module) -> Result { + let mut imports = ResolvedImports::new(); + + for import in module.data.imports.iter() { + let Some(val) = self.take(store, import) else { + return Err(crate::Error::MissingImport { module: import.module.to_string(), name: import.name.to_string(), }); - } - - let val = match export.kind { - ExternalKind::Func => ExternVal::Func(export.index), - ExternalKind::Global => ExternVal::Global(export.index), - ExternalKind::Table => ExternVal::Table(export.index), - ExternalKind::Memory => ExternVal::Mem(export.index), }; - links.insert( - ExternName { - module: import.module.to_string(), - name: import.name.to_string(), - }, - val, - ); + // validate import + // if export.kind != (&import.kind).into() { + // return Err(crate::Error::InvalidImportType { + // module: import.module.to_string(), + // name: import.name.to_string(), + // }); + // } + + // let val = match export.kind { + // ExternalKind::Func => ExternVal::Func(export.index), + // ExternalKind::Global => ExternVal::Global(export.index), + // ExternalKind::Table => ExternVal::Table(export.index), + // ExternalKind::Memory => ExternVal::Mem(export.index), + // }; + + // imports.0.insert( + // ExternName { + // module: import.module.to_string(), + // name: import.name.to_string(), + // }, + // ResolvedImport::Store(val), + // ); } - // TODO: link to other modules (currently only direct imports are supported) - Ok(LinkedImports { - externs: self.values, - linked_externs: links, - }) + Ok(imports) } } diff --git a/crates/tinywasm/src/instance.rs b/crates/tinywasm/src/instance.rs index ad1b53c..b8f87d7 100644 --- a/crates/tinywasm/src/instance.rs +++ b/crates/tinywasm/src/instance.rs @@ -52,14 +52,13 @@ impl ModuleInstance { let idx = store.next_module_instance_idx(); let imports = imports.unwrap_or_default(); - // TODO: doesn't link other modules yet let linked_imports = imports.link(store, &module)?; - let global_addrs = store.add_globals(module.data.globals.into(), &module.data.imports, &linked_imports, idx)?; + let global_addrs = store.add_globals(module.data.globals.into(), idx)?; // TODO: imported functions missing - let func_addrs = store.add_funcs(module.data.funcs.into(), idx); + let func_addrs = store.add_funcs(module.data.funcs.into(), idx)?; - let table_addrs = store.add_tables(module.data.table_types.into(), idx); + let table_addrs = store.add_tables(module.data.table_types.into(), idx)?; let mem_addrs = store.add_mems(module.data.memory_types.into(), idx)?; // TODO: active/declared elems need to be initialized @@ -152,8 +151,13 @@ impl ModuleInstance { .get(name, ExternalKind::Func) .ok_or_else(|| Error::Other(format!("Export not found: {}", name)))?; - let func_addr = self.0.func_addrs[export.index as usize]; - let func_inst = store.get_func(func_addr as usize)?; + let func_addr = self + .0 + .func_addrs + .get(export.index as usize) + .expect("No func addr for export, this is a bug"); + + let func_inst = store.get_func(*func_addr as usize)?; let func = func_inst.assert_wasm()?; let ty = self.0.types[func.ty_addr as usize].clone(); diff --git a/crates/tinywasm/src/store.rs b/crates/tinywasm/src/store.rs index 6293cca..9b2f711 100644 --- a/crates/tinywasm/src/store.rs +++ b/crates/tinywasm/src/store.rs @@ -7,13 +7,13 @@ use core::{ use alloc::{format, rc::Rc, string::ToString, vec, vec::Vec}; use tinywasm_types::{ - Addr, Data, Element, ElementKind, FuncAddr, Global, GlobalType, Import, Instruction, MemAddr, MemoryArch, - MemoryType, ModuleInstanceAddr, TableAddr, TableType, TypeAddr, ValType, WasmFunction, + Addr, Data, DataAddr, ElemAddr, Element, ElementKind, FuncAddr, Global, GlobalType, Import, MemAddr, MemoryArch, + MemoryType, ModuleInstanceAddr, TableAddr, TableType, WasmFunction, }; use crate::{ runtime::{self, DefaultRuntime}, - Error, Extern, Function, LinkedImports, ModuleInstance, RawWasmValue, Result, Trap, + Error, Function, ModuleInstance, RawWasmValue, Result, Trap, }; // global store id counter @@ -114,31 +114,23 @@ impl Store { } /// Add functions to the store, returning their addresses in the store - pub(crate) fn add_funcs(&mut self, funcs: Vec, idx: ModuleInstanceAddr) -> Vec { + pub(crate) fn add_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(Rc::new(FunctionInstance { - func: Function::Wasm(func), - owner: idx, - })); - func_addrs.push((i + func_count) as FuncAddr); + for func in funcs.into_iter() { + func_addrs.push(self.add_func(Function::Wasm(func), idx)?); } - func_addrs + Ok(func_addrs) } /// Add tables to the store, returning their addresses in the store - pub(crate) fn add_tables(&mut self, tables: Vec, idx: ModuleInstanceAddr) -> Vec { + pub(crate) fn add_tables(&mut self, tables: Vec, idx: ModuleInstanceAddr) -> Result> { let table_count = self.data.tables.len(); let mut table_addrs = Vec::with_capacity(table_count); for (i, table) in tables.into_iter().enumerate() { - self.data - .tables - .push(Rc::new(RefCell::new(TableInstance::new(table, idx)))); - - table_addrs.push((i + table_count) as TableAddr); + table_addrs.push(self.add_table(table, idx)?); } - table_addrs + Ok(table_addrs) } /// Add memories to the store, returning their addresses in the store @@ -146,78 +138,71 @@ impl Store { let mem_count = self.data.mems.len(); let mut mem_addrs = Vec::with_capacity(mem_count); for (i, mem) in mems.into_iter().enumerate() { - if let MemoryArch::I64 = mem.arch { - return Err(Error::UnsupportedFeature("64-bit memories".to_string())); - } - self.data - .mems - .push(Rc::new(RefCell::new(MemoryInstance::new(mem, idx)))); - - mem_addrs.push((i + mem_count) as MemAddr); + mem_addrs.push(self.add_mem(mem, idx)?); } Ok(mem_addrs) } /// Add globals to the store, returning their addresses in the store - pub(crate) fn add_globals( - &mut self, - globals: Vec, - wasm_imports: &[Import], - user_imports: &LinkedImports, - idx: ModuleInstanceAddr, - ) -> Result> { - // TODO: initialize imported globals - #![allow(clippy::unnecessary_filter_map)] // this is cleaner - let imported_globals = wasm_imports - .iter() - .filter_map(|import| match &import.kind { - tinywasm_types::ImportKind::Global(_) => Some(import), - _ => None, - }) - .map(|import| { - let Some(global) = user_imports.get(&import.module, &import.name) else { - return Err(Error::Other(format!( - "global import not found for {}::{}", - import.module, import.name - ))); - }; - match global { - Extern::Global(global) => Ok(global), - _ => Err(Error::Other(format!( - "expected global import for {}::{}", - import.module, import.name - ))), - } - }) - .collect::>>()?; - + pub(crate) fn add_globals(&mut self, globals: Vec, idx: ModuleInstanceAddr) -> Result> { let global_count = self.data.globals.len(); let mut global_addrs = Vec::with_capacity(global_count); - log::debug!("globals: {:?}", globals); - - // first add the imported globals - for (i, global) in imported_globals.iter().enumerate() { - self.data.globals.push(Rc::new(RefCell::new(GlobalInstance::new( - global.ty, - global.val.into(), - idx, - )))); - global_addrs.push((i + global_count) as Addr); - } - // then add the module globals for (i, global) in globals.iter().enumerate() { - self.data.globals.push(Rc::new(RefCell::new(GlobalInstance::new( - global.ty, - self.eval_const(&global.init)?, - idx, - )))); - global_addrs.push((i + global_count) as Addr); + global_addrs.push(self.add_global(global.ty, self.eval_const(&global.init)?, idx)?.into()); } Ok(global_addrs) } + pub(crate) fn add_global(&mut self, ty: GlobalType, value: RawWasmValue, idx: ModuleInstanceAddr) -> Result { + self.data + .globals + .push(Rc::new(RefCell::new(GlobalInstance::new(ty, value, idx)))); + Ok(self.data.globals.len() as Addr - 1) + } + + pub(crate) fn add_table(&mut self, table: TableType, idx: ModuleInstanceAddr) -> Result { + self.data + .tables + .push(Rc::new(RefCell::new(TableInstance::new(table, idx)))); + Ok(self.data.tables.len() as TableAddr - 1) + } + + pub(crate) fn add_mem(&mut self, mem: MemoryType, idx: ModuleInstanceAddr) -> Result { + if let MemoryArch::I64 = mem.arch { + return Err(Error::UnsupportedFeature("64-bit memories".to_string())); + } + self.data + .mems + .push(Rc::new(RefCell::new(MemoryInstance::new(mem, idx)))); + Ok(self.data.mems.len() as MemAddr - 1) + } + + pub(crate) fn add_elem(&mut self, elem: Element, idx: ModuleInstanceAddr) -> Result { + let init = elem + .items + .iter() + .map(|item| { + item.addr() + .ok_or_else(|| Error::UnsupportedFeature(format!("const expression other than ref: {:?}", item))) + }) + .collect::>>()?; + + self.data.elems.push(ElemInstance::new(elem.kind, idx, Some(init))); + Ok(self.data.elems.len() as ElemAddr - 1) + } + + pub(crate) fn add_data(&mut self, data: Data, idx: ModuleInstanceAddr) -> Result { + self.data.datas.push(DataInstance::new(data.data.to_vec(), idx)); + Ok(self.data.datas.len() as DataAddr - 1) + } + + pub(crate) fn add_func(&mut self, func: Function, idx: ModuleInstanceAddr) -> Result { + self.data.funcs.push(Rc::new(FunctionInstance { func, owner: idx })); + Ok(self.data.funcs.len() as FuncAddr - 1) + } + pub(crate) fn eval_i32_const(&self, const_instr: &tinywasm_types::ConstInstruction) -> Result { use tinywasm_types::ConstInstruction::*; let val = match const_instr { diff --git a/crates/tinywasm/tests/generated/mvp.csv b/crates/tinywasm/tests/generated/mvp.csv index 7749a65..e175639 100644 --- a/crates/tinywasm/tests/generated/mvp.csv +++ b/crates/tinywasm/tests/generated/mvp.csv @@ -2,4 +2,4 @@ 0.0.5,11135,9093,[{"name":"address.wast","passed":1,"failed":259},{"name":"align.wast","passed":108,"failed":48},{"name":"binary-leb128.wast","passed":78,"failed":13},{"name":"binary.wast","passed":107,"failed":5},{"name":"block.wast","passed":170,"failed":53},{"name":"br.wast","passed":20,"failed":77},{"name":"br_if.wast","passed":29,"failed":89},{"name":"br_table.wast","passed":24,"failed":150},{"name":"call.wast","passed":18,"failed":73},{"name":"call_indirect.wast","passed":34,"failed":136},{"name":"comments.wast","passed":5,"failed":3},{"name":"const.wast","passed":778,"failed":0},{"name":"conversions.wast","passed":25,"failed":594},{"name":"custom.wast","passed":10,"failed":1},{"name":"data.wast","passed":22,"failed":39},{"name":"elem.wast","passed":27,"failed":72},{"name":"endianness.wast","passed":1,"failed":68},{"name":"exports.wast","passed":90,"failed":6},{"name":"f32.wast","passed":1018,"failed":1496},{"name":"f32_bitwise.wast","passed":4,"failed":360},{"name":"f32_cmp.wast","passed":2407,"failed":0},{"name":"f64.wast","passed":1018,"failed":1496},{"name":"f64_bitwise.wast","passed":4,"failed":360},{"name":"f64_cmp.wast","passed":2407,"failed":0},{"name":"fac.wast","passed":1,"failed":7},{"name":"float_exprs.wast","passed":275,"failed":625},{"name":"float_literals.wast","passed":112,"failed":51},{"name":"float_memory.wast","passed":0,"failed":90},{"name":"float_misc.wast","passed":138,"failed":303},{"name":"forward.wast","passed":1,"failed":4},{"name":"func.wast","passed":81,"failed":91},{"name":"func_ptrs.wast","passed":7,"failed":29},{"name":"global.wast","passed":50,"failed":60},{"name":"i32.wast","passed":85,"failed":375},{"name":"i64.wast","passed":31,"failed":385},{"name":"if.wast","passed":116,"failed":125},{"name":"imports.wast","passed":23,"failed":160},{"name":"inline-module.wast","passed":1,"failed":0},{"name":"int_exprs.wast","passed":38,"failed":70},{"name":"int_literals.wast","passed":25,"failed":26},{"name":"labels.wast","passed":13,"failed":16},{"name":"left-to-right.wast","passed":0,"failed":96},{"name":"linking.wast","passed":5,"failed":127},{"name":"load.wast","passed":59,"failed":38},{"name":"local_get.wast","passed":18,"failed":18},{"name":"local_set.wast","passed":38,"failed":15},{"name":"local_tee.wast","passed":41,"failed":56},{"name":"loop.wast","passed":42,"failed":78},{"name":"memory.wast","passed":30,"failed":49},{"name":"memory_grow.wast","passed":11,"failed":85},{"name":"memory_redundancy.wast","passed":1,"failed":7},{"name":"memory_size.wast","passed":6,"failed":36},{"name":"memory_trap.wast","passed":1,"failed":181},{"name":"names.wast","passed":484,"failed":2},{"name":"nop.wast","passed":4,"failed":84},{"name":"return.wast","passed":20,"failed":64},{"name":"select.wast","passed":28,"failed":120},{"name":"skip-stack-guard-page.wast","passed":1,"failed":10},{"name":"stack.wast","passed":2,"failed":5},{"name":"start.wast","passed":4,"failed":16},{"name":"store.wast","passed":59,"failed":9},{"name":"switch.wast","passed":2,"failed":26},{"name":"token.wast","passed":39,"failed":19},{"name":"traps.wast","passed":4,"failed":32},{"name":"type.wast","passed":3,"failed":0},{"name":"unreachable.wast","passed":0,"failed":64},{"name":"unreached-invalid.wast","passed":118,"failed":0},{"name":"unwind.wast","passed":9,"failed":41},{"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.1.0,17630,2598,[{"name":"address.wast","passed":5,"failed":255},{"name":"align.wast","passed":108,"failed":48},{"name":"binary-leb128.wast","passed":91,"failed":0},{"name":"binary.wast","passed":110,"failed":2},{"name":"block.wast","passed":193,"failed":30},{"name":"br.wast","passed":84,"failed":13},{"name":"br_if.wast","passed":90,"failed":28},{"name":"br_table.wast","passed":25,"failed":149},{"name":"call.wast","passed":29,"failed":62},{"name":"call_indirect.wast","passed":36,"failed":134},{"name":"comments.wast","passed":7,"failed":1},{"name":"const.wast","passed":778,"failed":0},{"name":"conversions.wast","passed":371,"failed":248},{"name":"custom.wast","passed":11,"failed":0},{"name":"data.wast","passed":47,"failed":14},{"name":"elem.wast","passed":50,"failed":49},{"name":"endianness.wast","passed":1,"failed":68},{"name":"exports.wast","passed":92,"failed":4},{"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":2,"failed":6},{"name":"float_exprs.wast","passed":761,"failed":139},{"name":"float_literals.wast","passed":163,"failed":0},{"name":"float_memory.wast","passed":6,"failed":84},{"name":"float_misc.wast","passed":437,"failed":4},{"name":"forward.wast","passed":1,"failed":4},{"name":"func.wast","passed":124,"failed":48},{"name":"func_ptrs.wast","passed":10,"failed":26},{"name":"global.wast","passed":51,"failed":59},{"name":"i32.wast","passed":460,"failed":0},{"name":"i64.wast","passed":416,"failed":0},{"name":"if.wast","passed":120,"failed":121},{"name":"imports.wast","passed":74,"failed":109},{"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":14,"failed":15},{"name":"left-to-right.wast","passed":1,"failed":95},{"name":"linking.wast","passed":21,"failed":111},{"name":"load.wast","passed":60,"failed":37},{"name":"local_get.wast","passed":32,"failed":4},{"name":"local_set.wast","passed":50,"failed":3},{"name":"local_tee.wast","passed":68,"failed":29},{"name":"loop.wast","passed":93,"failed":27},{"name":"memory.wast","passed":34,"failed":45},{"name":"memory_grow.wast","passed":12,"failed":84},{"name":"memory_redundancy.wast","passed":1,"failed":7},{"name":"memory_size.wast","passed":6,"failed":36},{"name":"memory_trap.wast","passed":2,"failed":180},{"name":"names.wast","passed":485,"failed":1},{"name":"nop.wast","passed":46,"failed":42},{"name":"return.wast","passed":73,"failed":11},{"name":"select.wast","passed":86,"failed":62},{"name":"skip-stack-guard-page.wast","passed":1,"failed":10},{"name":"stack.wast","passed":2,"failed":5},{"name":"start.wast","passed":9,"failed":11},{"name":"store.wast","passed":59,"failed":9},{"name":"switch.wast","passed":2,"failed":26},{"name":"token.wast","passed":58,"failed":0},{"name":"traps.wast","passed":22,"failed":14},{"name":"type.wast","passed":3,"failed":0},{"name":"unreachable.wast","passed":50,"failed":14},{"name":"unreached-invalid.wast","passed":118,"failed":0},{"name":"unwind.wast","passed":35,"failed":15},{"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.2.0,19344,884,[{"name":"address.wast","passed":181,"failed":79},{"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":220,"failed":3},{"name":"br.wast","passed":97,"failed":0},{"name":"br_if.wast","passed":118,"failed":0},{"name":"br_table.wast","passed":171,"failed":3},{"name":"call.wast","passed":73,"failed":18},{"name":"call_indirect.wast","passed":50,"failed":120},{"name":"comments.wast","passed":7,"failed":1},{"name":"const.wast","passed":778,"failed":0},{"name":"conversions.wast","passed":439,"failed":180},{"name":"custom.wast","passed":11,"failed":0},{"name":"data.wast","passed":47,"failed":14},{"name":"elem.wast","passed":56,"failed":43},{"name":"endianness.wast","passed":29,"failed":40},{"name":"exports.wast","passed":92,"failed":4},{"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":6,"failed":2},{"name":"float_exprs.wast","passed":890,"failed":10},{"name":"float_literals.wast","passed":163,"failed":0},{"name":"float_memory.wast","passed":78,"failed":12},{"name":"float_misc.wast","passed":437,"failed":4},{"name":"forward.wast","passed":5,"failed":0},{"name":"func.wast","passed":168,"failed":4},{"name":"func_ptrs.wast","passed":10,"failed":26},{"name":"global.wast","passed":103,"failed":7},{"name":"i32.wast","passed":460,"failed":0},{"name":"i64.wast","passed":416,"failed":0},{"name":"if.wast","passed":231,"failed":10},{"name":"imports.wast","passed":80,"failed":103},{"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":26,"failed":3},{"name":"left-to-right.wast","passed":92,"failed":4},{"name":"linking.wast","passed":29,"failed":103},{"name":"load.wast","passed":93,"failed":4},{"name":"local_get.wast","passed":36,"failed":0},{"name":"local_set.wast","passed":53,"failed":0},{"name":"local_tee.wast","passed":93,"failed":4},{"name":"loop.wast","passed":116,"failed":4},{"name":"memory.wast","passed":78,"failed":1},{"name":"memory_grow.wast","passed":91,"failed":5},{"name":"memory_redundancy.wast","passed":8,"failed":0},{"name":"memory_size.wast","passed":35,"failed":7},{"name":"memory_trap.wast","passed":180,"failed":2},{"name":"names.wast","passed":485,"failed":1},{"name":"nop.wast","passed":78,"failed":10},{"name":"return.wast","passed":84,"failed":0},{"name":"select.wast","passed":114,"failed":34},{"name":"skip-stack-guard-page.wast","passed":1,"failed":10},{"name":"stack.wast","passed":7,"failed":0},{"name":"start.wast","passed":11,"failed":9},{"name":"store.wast","passed":68,"failed":0},{"name":"switch.wast","passed":28,"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":"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.3.0-alpha.0,19806,422,[{"name":"address.wast","passed":260,"failed":0},{"name":"align.wast","passed":156,"failed":0},{"name":"binary-leb128.wast","passed":88,"failed":3},{"name":"binary.wast","passed":112,"failed":0},{"name":"block.wast","passed":220,"failed":3},{"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":76,"failed":15},{"name":"call_indirect.wast","passed":159,"failed":11},{"name":"comments.wast","passed":7,"failed":1},{"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":48,"failed":13},{"name":"elem.wast","passed":76,"failed":23},{"name":"endianness.wast","passed":29,"failed":40},{"name":"exports.wast","passed":92,"failed":4},{"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":7,"failed":1},{"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":437,"failed":4},{"name":"forward.wast","passed":5,"failed":0},{"name":"func.wast","passed":172,"failed":0},{"name":"func_ptrs.wast","passed":31,"failed":5},{"name":"global.wast","passed":96,"failed":14},{"name":"i32.wast","passed":460,"failed":0},{"name":"i64.wast","passed":416,"failed":0},{"name":"if.wast","passed":232,"failed":9},{"name":"imports.wast","passed":50,"failed":133},{"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":26,"failed":3},{"name":"left-to-right.wast","passed":96,"failed":0},{"name":"linking.wast","passed":18,"failed":114},{"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":116,"failed":4},{"name":"memory.wast","passed":79,"failed":0},{"name":"memory_grow.wast","passed":95,"failed":1},{"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":484,"failed":2},{"name":"nop.wast","passed":78,"failed":10},{"name":"return.wast","passed":84,"failed":0},{"name":"select.wast","passed":143,"failed":5},{"name":"skip-stack-guard-page.wast","passed":11,"failed":0},{"name":"stack.wast","passed":7,"failed":0},{"name":"start.wast","passed":17,"failed":3},{"name":"store.wast","passed":68,"failed":0},{"name":"switch.wast","passed":28,"failed":0},{"name":"token.wast","passed":57,"failed":1},{"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":"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.3.0-alpha.0,19816,412,[{"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":220,"failed":3},{"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":76,"failed":15},{"name":"call_indirect.wast","passed":159,"failed":11},{"name":"comments.wast","passed":7,"failed":1},{"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":48,"failed":13},{"name":"elem.wast","passed":76,"failed":23},{"name":"endianness.wast","passed":29,"failed":40},{"name":"exports.wast","passed":92,"failed":4},{"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":7,"failed":1},{"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":437,"failed":4},{"name":"forward.wast","passed":5,"failed":0},{"name":"func.wast","passed":172,"failed":0},{"name":"func_ptrs.wast","passed":32,"failed":4},{"name":"global.wast","passed":96,"failed":14},{"name":"i32.wast","passed":460,"failed":0},{"name":"i64.wast","passed":416,"failed":0},{"name":"if.wast","passed":232,"failed":9},{"name":"imports.wast","passed":52,"failed":131},{"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":26,"failed":3},{"name":"left-to-right.wast","passed":96,"failed":0},{"name":"linking.wast","passed":20,"failed":112},{"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":116,"failed":4},{"name":"memory.wast","passed":79,"failed":0},{"name":"memory_grow.wast","passed":95,"failed":1},{"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":485,"failed":1},{"name":"nop.wast","passed":78,"failed":10},{"name":"return.wast","passed":84,"failed":0},{"name":"select.wast","passed":143,"failed":5},{"name":"skip-stack-guard-page.wast","passed":11,"failed":0},{"name":"stack.wast","passed":7,"failed":0},{"name":"start.wast","passed":17,"failed":3},{"name":"store.wast","passed":68,"failed":0},{"name":"switch.wast","passed":28,"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":"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/testsuite/run.rs b/crates/tinywasm/tests/testsuite/run.rs index 5dd42ee..d2eab6c 100644 --- a/crates/tinywasm/tests/testsuite/run.rs +++ b/crates/tinywasm/tests/testsuite/run.rs @@ -57,8 +57,8 @@ impl TestSuite { Ok(()) }); - let print_i64_f64 = Extern::typed_func(|_: &mut tinywasm::Store, args: (i64, f64)| { - log::debug!("print_i64_f64: {}, {}", args.0, args.1); + let print_f64_f64 = Extern::typed_func(|_: &mut tinywasm::Store, args: (f64, f64)| { + log::debug!("print_f64_f64: {}, {}", args.0, args.1); Ok(()) }); @@ -75,9 +75,10 @@ impl TestSuite { .define("spectest", "print_f32", print_f32)? .define("spectest", "print_f64", print_f64)? .define("spectest", "print_i32_f32", print_i32_f32)? - .define("spectest", "print_i64_f64", print_i64_f64)?; + .define("spectest", "print_f64_f64", print_f64_f64)?; for (name, addr) in registered_modules { + log::debug!("registering module: {}", name); imports.link_module(&name, addr)?; } @@ -137,7 +138,7 @@ impl TestSuite { Wat(mut module) => { // TODO: modules are not properly isolated from each other - tests fail because of this otherwise - store = tinywasm::Store::default(); + // store = tinywasm::Store::default(); debug!("got wat module"); let result = catch_unwind_silent(|| { let m = parse_module_bytes(&module.encode().expect("failed to encode module")) diff --git a/crates/types/src/lib.rs b/crates/types/src/lib.rs index 069f134..ac7f854 100644 --- a/crates/types/src/lib.rs +++ b/crates/types/src/lib.rs @@ -306,7 +306,7 @@ pub type ModuleInstanceAddr = Addr; /// A WebAssembly External Value. /// /// See -#[derive(Debug)] +#[derive(Debug, Clone)] pub enum ExternVal { Func(FuncAddr), Table(TableAddr), -- cgit v1.3.1