diff --git a/lib/runtime-core/examples/simple/main.rs b/lib/runtime-core/examples/simple/main.rs index 0e697afbd..dcf016a81 100644 --- a/lib/runtime-core/examples/simple/main.rs +++ b/lib/runtime-core/examples/simple/main.rs @@ -1,6 +1,6 @@ use wabt::wat2wasm; use wasmer_clif_backend::CraneliftCompiler; -use wasmer_runtime_core::{error::Result, prelude::*}; +use wasmer_runtime_core::{error::Result, prelude::*, memory::Memory, types::MemoryDesc}; static EXAMPLE_WASM: &'static [u8] = include_bytes!("simple.wasm"); @@ -8,9 +8,18 @@ fn main() -> Result<()> { let wasm_binary = wat2wasm(IMPORT_MODULE.as_bytes()).expect("WAST not valid or malformed"); let inner_module = wasmer_runtime_core::compile_with(&wasm_binary, &CraneliftCompiler::new())?; + let mut memory = Memory::new(MemoryDesc { + min: 1, + max: Some(1), + shared: false, + }).unwrap(); + + memory.as_slice_mut()[0] = 42; + let import_object = imports! { "env" => { - "print_i32" => print_num<[i32] -> [i32]>, + "print_i32" => func!(print_num, [i32] -> [i32]), + "memory" => memory, }, }; @@ -36,9 +45,10 @@ extern "C" fn print_num(n: i32, _vmctx: &mut vm::Ctx) -> i32 { static IMPORT_MODULE: &str = r#" (module (type $t0 (func (param i32) (result i32))) - ;; (import "env" "memory" (memory 0 1)) + (import "env" "memory" (memory 1 1)) (import "env" "print_i32" (func $print_i32 (type $t0))) (func $print_num (export "print_num") (type $t0) (param $p0 i32) (result i32) - get_local $p0 + i32.const 0 + i32.load call $print_i32)) "#; diff --git a/lib/runtime-core/src/lib.rs b/lib/runtime-core/src/lib.rs index 261556116..2c9c1f0ac 100644 --- a/lib/runtime-core/src/lib.rs +++ b/lib/runtime-core/src/lib.rs @@ -39,7 +39,7 @@ pub mod prelude { MemoryIndex, TableIndex, Type, Value, }; pub use crate::vm; - pub use crate::{export_func, imports}; + pub use crate::{func, imports}; } /// Compile a [`Module`] using the provided compiler from diff --git a/lib/runtime-core/src/macros.rs b/lib/runtime-core/src/macros.rs index ad33321be..06a5fcdd1 100644 --- a/lib/runtime-core/src/macros.rs +++ b/lib/runtime-core/src/macros.rs @@ -6,8 +6,8 @@ macro_rules! debug { } #[macro_export] -macro_rules! export_func { - ($func:ident, [ $( $params:ident ),* ] -> [ $( $returns:ident ),* ]) => {{ +macro_rules! func { + ($func:ident, [ $( $params:ident ),* ] -> [ $( $returns:ident ),* ] ) => {{ use $crate::{ export::{Context, Export, FuncPointer}, types::{FuncSig, Type}, @@ -98,13 +98,10 @@ macro_rules! imports { #[macro_export] #[doc(hidden)] macro_rules! __imports_internal { - ( { $( $imp_name:expr => $func:ident < [ $( $params:ident ),* ] -> [ $( $returns:ident ),* ] >, )* } ) => {{ + ( { $( $imp_name:expr => $import_item:expr, )* } ) => {{ let mut ns = Namespace::new(); $( - ns.insert($imp_name, $crate::export_func!( - $func, - [ $( $params ),* ] -> [ $( $returns )* ] - )); + ns.insert($imp_name, $import_item); )* ns }}; diff --git a/lib/runtime-core/src/memory/dynamic.rs b/lib/runtime-core/src/memory/dynamic.rs index 0de43e4cc..7d9e9dbdc 100644 --- a/lib/runtime-core/src/memory/dynamic.rs +++ b/lib/runtime-core/src/memory/dynamic.rs @@ -43,7 +43,6 @@ impl DynamicMemory { local.base = storage.memory.as_ptr(); local.bound = desc.min as usize * WASM_PAGE_SIZE; local.memory = storage_ptr as *mut (); - println!("local: {:?}", local); Some(storage) } diff --git a/lib/runtime-core/src/memory/mod.rs b/lib/runtime-core/src/memory/mod.rs index f684f9d00..959692a18 100644 --- a/lib/runtime-core/src/memory/mod.rs +++ b/lib/runtime-core/src/memory/mod.rs @@ -37,7 +37,7 @@ impl Memory { MemoryType::Static => { MemoryStorage::Static(StaticMemory::new(desc, &mut vm_local_memory)?) } - MemoryType::SharedStatic => unimplemented!(), + MemoryType::SharedStatic => unimplemented!("shared memories are not yet implemented"), }; Some(Memory { diff --git a/lib/runtime/src/lib.rs b/lib/runtime/src/lib.rs index 797447736..43cf20d3e 100644 --- a/lib/runtime/src/lib.rs +++ b/lib/runtime/src/lib.rs @@ -83,7 +83,7 @@ pub use wasmer_runtime_core::vm::Ctx; pub use wasmer_runtime_core::{compile_with, validate}; pub use wasmer_runtime_core::error; -pub use wasmer_runtime_core::imports; +pub use wasmer_runtime_core::{imports, func}; pub mod wasm { pub use wasmer_runtime_core::instance::Function;