| 91 | } |
| 92 | |
| 93 | fn test_many_call_module(mut store: Store<()>) -> Result<()> { |
| 94 | const N: i32 = 200; |
| 95 | |
| 96 | let mut wat = String::new(); |
| 97 | wat.push_str("(module\n"); |
| 98 | wat.push_str("(func $first (result i32) (i32.const 1))\n"); |
| 99 | for i in 0..N { |
| 100 | wat.push_str(&format!("(func (export \"{i}\") (result i32 i32)\n")); |
| 101 | wat.push_str("call $first\n"); |
| 102 | wat.push_str(&format!("i32.const {i}\n")); |
| 103 | wat.push_str("i32.add\n"); |
| 104 | wat.push_str("call $last\n"); |
| 105 | wat.push_str(&format!("i32.const {i}\n")); |
| 106 | wat.push_str("i32.add)\n"); |
| 107 | } |
| 108 | wat.push_str("(func $last (result i32) (i32.const 2))\n"); |
| 109 | wat.push_str(")\n"); |
| 110 | |
| 111 | let module = Module::new(store.engine(), &wat)?; |
| 112 | |
| 113 | let instance = Instance::new(&mut store, &module, &[])?; |
| 114 | |
| 115 | for i in 0..N { |
| 116 | let name = i.to_string(); |
| 117 | let func = instance.get_typed_func::<(), (i32, i32)>(&mut store, &name)?; |
| 118 | let (a, b) = func.call(&mut store, ())?; |
| 119 | assert_eq!(a, i + 1); |
| 120 | assert_eq!(b, i + 2); |
| 121 | } |
| 122 | Ok(()) |
| 123 | } |