Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
bytecodealliance
GitHub Repository: bytecodealliance/wasmtime
Path: blob/main/tests/all/import_indexes.rs
1692 views
1
#![cfg(not(miri))]
2
3
use wasmtime::*;
4
5
#[test]
6
fn same_import_names_still_distinct() -> anyhow::Result<()> {
7
const WAT: &str = r#"
8
(module
9
(import "" "" (func $a (result i32)))
10
(import "" "" (func $b (result f32)))
11
(func (export "foo") (result i32)
12
call $a
13
call $b
14
i32.trunc_f32_u
15
i32.add)
16
)
17
"#;
18
19
let mut store = Store::<()>::default();
20
let engine = store.engine().clone();
21
let module = Module::new(&engine, WAT)?;
22
23
let imports = [
24
Func::new(
25
&mut store,
26
FuncType::new(&engine, None, Some(ValType::I32)),
27
|_, params, results| {
28
assert!(params.is_empty());
29
assert_eq!(results.len(), 1);
30
results[0] = 1i32.into();
31
Ok(())
32
},
33
)
34
.into(),
35
Func::new(
36
&mut store,
37
FuncType::new(&engine, None, Some(ValType::F32)),
38
|_, params, results| {
39
assert!(params.is_empty());
40
assert_eq!(results.len(), 1);
41
results[0] = 2.0f32.into();
42
Ok(())
43
},
44
)
45
.into(),
46
];
47
let instance = Instance::new(&mut store, &module, &imports)?;
48
49
let func = instance.get_typed_func::<(), i32>(&mut store, "foo")?;
50
let result = func.call(&mut store, ())?;
51
assert_eq!(result, 3);
52
Ok(())
53
}
54
55