From ce88be36191044f157ad0eeee5ce5bfa74f9bf7c Mon Sep 17 00:00:00 2001 From: Nerry <108566+neri@users.noreply.github.com> Date: Mon, 4 Mar 2024 00:56:48 +0900 Subject: [PATCH] minir fix --- Cargo.toml | 1 - src/tests.rs | 62 +++++++++++++++++++++++++++++++++------------------- src/wasm.rs | 4 ++-- 3 files changed, 41 insertions(+), 26 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 1ae9c08..3d9b4e3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,5 +21,4 @@ smallvec = {version = "1.13.1", default-features = false} [workspace] members = [ "cli", - "temp/test", ] diff --git a/src/tests.rs b/src/tests.rs index 51261ce..692ed2c 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -25,30 +25,31 @@ impl Env { #[test] fn instantiate() { let data = [0, 97, 115, 109, 1, 0, 0, 0]; - WebAssembly::instantiate(&data, Env {}).unwrap(); + WebAssembly::instantiate(&data, &Env {}).unwrap(); let data = [0, 97, 115, 109, 1, 0, 0]; assert_matches!( - CompileErrorKind::downcast_ref(&WebAssembly::instantiate(&data, Env {}).unwrap_err()) + CompileErrorKind::downcast_ref(&WebAssembly::instantiate(&data, &Env {}).unwrap_err()) .unwrap(), CompileErrorKind::BadExecutable ); let data = [0, 97, 115, 109, 2, 0, 0, 0]; assert_matches!( - CompileErrorKind::downcast_ref(&WebAssembly::instantiate(&data, Env {}).unwrap_err()) + CompileErrorKind::downcast_ref(&WebAssembly::instantiate(&data, &Env {}).unwrap_err()) .unwrap(), CompileErrorKind::BadExecutable ); let data = [0, 97, 115, 109, 1, 0, 0, 0, 1]; assert_matches!( - CompileErrorKind::downcast_ref(&WebAssembly::instantiate(&data, Env {}).unwrap_err()) + CompileErrorKind::downcast_ref(&WebAssembly::instantiate(&data, &Env {}).unwrap_err()) .unwrap(), CompileErrorKind::UnexpectedEof ); - let instance = WebAssembly::instantiate(include_bytes!("../test/tester.wasm"), Env {}).unwrap(); + let instance = + WebAssembly::instantiate(include_bytes!("../test/tester.wasm"), &Env {}).unwrap(); let _ = instance.function("fib").unwrap(); } @@ -57,13 +58,13 @@ fn section_order() { let data = [ 0, 97, 115, 109, 1, 0, 0, 0, 1, 1, 0, 2, 1, 0, 2, 1, 0, 3, 1, 0, 4, 1, 0, 5, 1, 0, ]; - WebAssembly::instantiate(&data, Env {}).unwrap(); + WebAssembly::instantiate(&data, &Env {}).unwrap(); let data = [ 0, 97, 115, 109, 1, 0, 0, 0, 1, 1, 0, 2, 1, 0, 2, 1, 0, 3, 1, 0, 4, 1, 0, 3, 1, 0, ]; assert_matches!( - CompileErrorKind::downcast_ref(&WebAssembly::instantiate(&data, Env {}).unwrap_err()) + CompileErrorKind::downcast_ref(&WebAssembly::instantiate(&data, &Env {}).unwrap_err()) .unwrap(), CompileErrorKind::InvalidSectionOrder(WasmSectionId::Function) ); @@ -791,7 +792,8 @@ fn br_table() { #[test] fn app_fact() { - let instance = WebAssembly::instantiate(include_bytes!("../test/tester.wasm"), Env {}).unwrap(); + let instance = + WebAssembly::instantiate(include_bytes!("../test/tester.wasm"), &Env {}).unwrap(); let runnable = instance.function("fact").unwrap(); let result = runnable @@ -813,7 +815,8 @@ fn app_fact() { #[test] fn app_fib() { - let instance = WebAssembly::instantiate(include_bytes!("../test/tester.wasm"), Env {}).unwrap(); + let instance = + WebAssembly::instantiate(include_bytes!("../test/tester.wasm"), &Env {}).unwrap(); let runnable = instance.function("fib").unwrap(); let result = runnable @@ -843,7 +846,8 @@ fn app_fib() { #[test] fn opr_test_i32() { - let instance = WebAssembly::instantiate(include_bytes!("../test/tester.wasm"), Env {}).unwrap(); + let instance = + WebAssembly::instantiate(include_bytes!("../test/tester.wasm"), &Env {}).unwrap(); let memory = instance.memory(0).unwrap().try_borrow().unwrap(); @@ -1016,7 +1020,8 @@ fn opr_test_i32() { #[test] fn opr_test_i64() { - let instance = WebAssembly::instantiate(include_bytes!("../test/tester.wasm"), Env {}).unwrap(); + let instance = + WebAssembly::instantiate(include_bytes!("../test/tester.wasm"), &Env {}).unwrap(); let memory = instance.memory(0).unwrap().try_borrow().unwrap(); @@ -1193,7 +1198,8 @@ fn opr_test_i64() { #[test] fn call_test() { - let instance = WebAssembly::instantiate(include_bytes!("../test/tester.wasm"), Env {}).unwrap(); + let instance = + WebAssembly::instantiate(include_bytes!("../test/tester.wasm"), &Env {}).unwrap(); let memory = instance.memory(0).unwrap().try_borrow().unwrap(); @@ -1294,7 +1300,8 @@ fn call_test() { #[test] fn call_indirect_test() { - let instance = WebAssembly::instantiate(include_bytes!("../test/tester.wasm"), Env {}).unwrap(); + let instance = + WebAssembly::instantiate(include_bytes!("../test/tester.wasm"), &Env {}).unwrap(); // let memory = instance.memory(0).unwrap().try_borrow().unwrap(); @@ -1334,7 +1341,8 @@ fn call_indirect_test() { #[test] fn mem_load_store() { - let instance = WebAssembly::instantiate(include_bytes!("../test/tester.wasm"), Env {}).unwrap(); + let instance = + WebAssembly::instantiate(include_bytes!("../test/tester.wasm"), &Env {}).unwrap(); let mut src = Vec::new(); for i in 0..65536 { @@ -1622,7 +1630,8 @@ fn mem_load_store() { #[test] fn memory() { - let instance = WebAssembly::instantiate(include_bytes!("../test/tester.wasm"), Env {}).unwrap(); + let instance = + WebAssembly::instantiate(include_bytes!("../test/tester.wasm"), &Env {}).unwrap(); let mut src = Vec::new(); for i in 0..256 { @@ -1790,7 +1799,8 @@ fn memory() { #[test] fn global() { - let instance = WebAssembly::instantiate(include_bytes!("../test/tester.wasm"), Env {}).unwrap(); + let instance = + WebAssembly::instantiate(include_bytes!("../test/tester.wasm"), &Env {}).unwrap(); let runnable = instance.function("global_add").unwrap(); assert_eq!( @@ -1847,7 +1857,7 @@ fn name() { 0x61, 0x6D, 0x65, 0x00, 0x06, 0x05, 0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x01, 0x0E, 0x02, 0x01, 0x04, 0x77, 0x61, 0x73, 0x6D, 0xB4, 0x24, 0x04, 0x74, 0x65, 0x73, 0x74, 0x7F, 0x00, ]; - let instance = WebAssembly::instantiate(&slice, Env {}).unwrap(); + let instance = WebAssembly::instantiate(&slice, &Env {}).unwrap(); let names = instance.module().names().unwrap(); assert_eq!(names.module().unwrap(), "Hello"); @@ -1949,7 +1959,8 @@ fn float32() { #[test] fn float32_opr() { - let instance = WebAssembly::instantiate(include_bytes!("../test/tester.wasm"), Env {}).unwrap(); + let instance = + WebAssembly::instantiate(include_bytes!("../test/tester.wasm"), &Env {}).unwrap(); let memory = instance.memory(0).unwrap().try_borrow().unwrap(); @@ -2646,7 +2657,8 @@ fn float64() { #[test] fn float64_opr() { - let instance = WebAssembly::instantiate(include_bytes!("../test/tester.wasm"), Env {}).unwrap(); + let instance = + WebAssembly::instantiate(include_bytes!("../test/tester.wasm"), &Env {}).unwrap(); let memory = instance.memory(0).unwrap().try_borrow().unwrap(); @@ -3419,7 +3431,8 @@ fn block_nest() { #[test] fn block_test() { - let instance = WebAssembly::instantiate(include_bytes!("../test/tester.wasm"), Env {}).unwrap(); + let instance = + WebAssembly::instantiate(include_bytes!("../test/tester.wasm"), &Env {}).unwrap(); let runnable = instance.function("block_test").unwrap(); let result = runnable @@ -3482,7 +3495,8 @@ fn loop_nest() { #[test] fn loop_test() { - let instance = WebAssembly::instantiate(include_bytes!("../test/tester.wasm"), Env {}).unwrap(); + let instance = + WebAssembly::instantiate(include_bytes!("../test/tester.wasm"), &Env {}).unwrap(); let runnable = instance.function("loop_test").unwrap(); let result = runnable @@ -3544,7 +3558,8 @@ fn if_nest() { #[test] fn if_test() { - let instance = WebAssembly::instantiate(include_bytes!("../test/tester.wasm"), Env {}).unwrap(); + let instance = + WebAssembly::instantiate(include_bytes!("../test/tester.wasm"), &Env {}).unwrap(); let runnable = instance.function("if_test1").unwrap(); let result = runnable @@ -3600,7 +3615,8 @@ fn if_test() { #[test] fn import_test() { - let instance = WebAssembly::instantiate(include_bytes!("../test/tester.wasm"), Env {}).unwrap(); + let instance = + WebAssembly::instantiate(include_bytes!("../test/tester.wasm"), &Env {}).unwrap(); let runnable = instance.function("import_test1").unwrap(); let result = runnable diff --git a/src/wasm.rs b/src/wasm.rs index d1d0dfe..9dea15c 100644 --- a/src/wasm.rs +++ b/src/wasm.rs @@ -44,7 +44,7 @@ impl WebAssembly { /// Instantiate wasm module pub fn instantiate( bytes: &[u8], - env: Env, + env: &Env, ) -> Result> { Self::compile(bytes)?.instantiate(env) } @@ -239,7 +239,7 @@ impl WasmModule { Ok(module) } - pub fn instantiate(mut self, env: Env) -> Result> { + pub fn instantiate(mut self, env: &Env) -> Result> { let mut func_idx = 0; for import in &self.imports { match import.desc {