mirror of
https://github.com/fluencelabs/wasmer
synced 2025-06-19 20:01:20 +00:00
Modify imports macro to work with all things that are exports
This commit is contained in:
@ -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))
|
||||
"#;
|
||||
|
Reference in New Issue
Block a user