(style: ApiStyle)
| 3338 | } |
| 3339 | |
| 3340 | async fn thread_index_via_guest_call(style: ApiStyle) -> Result<()> { |
| 3341 | let component = r#" |
| 3342 | (component |
| 3343 | (component $c |
| 3344 | (core module $m |
| 3345 | (import "" "thread.index" (func $thread-index (result i32))) |
| 3346 | (func (export "run") (result i32) |
| 3347 | (call $thread-index) |
| 3348 | ) |
| 3349 | ) |
| 3350 | (core func $thread-index (canon thread.index)) |
| 3351 | (core instance $m (instantiate $m (with "" (instance |
| 3352 | (export "thread.index" (func $thread-index)) |
| 3353 | )))) |
| 3354 | (func (export "run") (result u32) (canon lift (core func $m "run"))) |
| 3355 | ) |
| 3356 | (instance $c (instantiate $c)) |
| 3357 | |
| 3358 | (component $d |
| 3359 | (import "c" (instance $c |
| 3360 | (export "run" (func (result u32))) |
| 3361 | )) |
| 3362 | (core func $run (canon lower (func $c "run"))) |
| 3363 | (core module $m |
| 3364 | (import "" "thread.index" (func $thread-index (result i32))) |
| 3365 | (import "" "run" (func $run (result i32))) |
| 3366 | (func (export "run") |
| 3367 | (local $mine i32) |
| 3368 | (local $theirs i32) |
| 3369 | (local.set $mine (call $thread-index)) |
| 3370 | (if (i32.eqz (local.get $mine)) (then unreachable)) |
| 3371 | (local.set $theirs (call $run)) |
| 3372 | (if (i32.eqz (local.get $theirs)) (then unreachable)) |
| 3373 | ) |
| 3374 | ) |
| 3375 | (core func $thread-index (canon thread.index)) |
| 3376 | (core instance $m (instantiate $m (with "" (instance |
| 3377 | (export "thread.index" (func $thread-index)) |
| 3378 | (export "run" (func $run)) |
| 3379 | )))) |
| 3380 | (func (export "run") (canon lift (core func $m "run"))) |
| 3381 | ) |
| 3382 | (instance $d (instantiate $d (with "c" (instance $c)))) |
| 3383 | (func (export "run") (alias export $d "run")) |
| 3384 | ) |
| 3385 | "#; |
| 3386 | let engine = Engine::new(&style.config())?; |
| 3387 | let component = Component::new(&engine, component)?; |
| 3388 | let mut store = Store::new(&engine, ()); |
| 3389 | let linker = Linker::new(&engine); |
| 3390 | let instance = style.instantiate(&mut store, &linker, &component).await?; |
| 3391 | let run = instance.get_typed_func::<(), ()>(&mut store, "run")?; |
| 3392 | style.call(&mut store, run, ()).await?; |
| 3393 | Ok(()) |
| 3394 | } |
| 3395 | |
| 3396 | fn with_new_instance<T>( |
| 3397 | engine: &Engine, |
no test coverage detected