| 1262 | #[wasmtime_test] |
| 1263 | #[cfg_attr(miri, ignore)] |
| 1264 | fn wrap_multiple_results(config: &mut Config) -> wasmtime::Result<()> { |
| 1265 | fn test<T>(store: &mut Store<()>, t: T) -> wasmtime::Result<()> |
| 1266 | where |
| 1267 | T: WasmRet |
| 1268 | + WasmResults |
| 1269 | + PartialEq |
| 1270 | + Copy |
| 1271 | + std::fmt::Debug |
| 1272 | + EqualToValues |
| 1273 | + 'static |
| 1274 | + Send |
| 1275 | + Sync, |
| 1276 | { |
| 1277 | let f = Func::wrap(&mut *store, move || t); |
| 1278 | let mut results = vec![Val::I32(0); f.ty(&store).results().len()]; |
| 1279 | assert_eq!(f.typed::<(), T>(&store)?.call(&mut *store, ())?, t); |
| 1280 | f.call(&mut *store, &[], &mut results)?; |
| 1281 | assert!(t.eq_values(&results)); |
| 1282 | |
| 1283 | let module = Module::new(store.engine(), &T::gen_wasm())?; |
| 1284 | let instance = Instance::new(&mut *store, &module, &[f.into()])?; |
| 1285 | let f = instance.get_func(&mut *store, "foo").unwrap(); |
| 1286 | |
| 1287 | assert_eq!(f.typed::<(), T>(&store)?.call(&mut *store, ())?, t); |
| 1288 | f.call(&mut *store, &[], &mut results)?; |
| 1289 | assert!(t.eq_values(&results)); |
| 1290 | Ok(()) |
| 1291 | } |
| 1292 | |
| 1293 | let engine = Engine::new(&config)?; |
| 1294 | let mut store = Store::new(&engine, ()); |
| 1295 | // 0 element |
| 1296 | test(&mut store, ())?; |
| 1297 | |
| 1298 | // 1 element |
| 1299 | test(&mut store, (1i32,))?; |
| 1300 | test(&mut store, (2u32,))?; |
| 1301 | test(&mut store, (3i64,))?; |
| 1302 | test(&mut store, (4u64,))?; |
| 1303 | test(&mut store, (5.0f32,))?; |
| 1304 | test(&mut store, (6.0f64,))?; |
| 1305 | |
| 1306 | // 2 element ... |
| 1307 | test(&mut store, (7i32, 8i32))?; |
| 1308 | test(&mut store, (7i32, 8i64))?; |
| 1309 | test(&mut store, (7i32, 8f32))?; |
| 1310 | test(&mut store, (7i32, 8f64))?; |
| 1311 | |
| 1312 | test(&mut store, (7i64, 8i32))?; |
| 1313 | test(&mut store, (7i64, 8i64))?; |
| 1314 | test(&mut store, (7i64, 8f32))?; |
| 1315 | test(&mut store, (7i64, 8f64))?; |
| 1316 | |
| 1317 | test(&mut store, (7f32, 8i32))?; |
| 1318 | test(&mut store, (7f32, 8i64))?; |
| 1319 | test(&mut store, (7f32, 8f32))?; |
| 1320 | test(&mut store, (7f32, 8f64))?; |
| 1321 | |