1804060c8SJoel Dice #![expect(unsafe_op_in_unsafe_fn, reason = "old code, not worth updating yet")]
2804060c8SJoel Dice
3804060c8SJoel Dice mod bindings {
4804060c8SJoel Dice wit_bindgen::generate!({
5804060c8SJoel Dice path: "../misc/component-async-tests/wit",
6804060c8SJoel Dice world: "yield-callee",
7804060c8SJoel Dice });
8804060c8SJoel Dice }
9804060c8SJoel Dice
10804060c8SJoel Dice use {
11804060c8SJoel Dice bindings::local::local::continue_,
12c1551308SJoel Dice test_programs::async_::{CALLBACK_CODE_EXIT, CALLBACK_CODE_YIELD, EVENT_CANCELLED, EVENT_NONE},
13804060c8SJoel Dice };
14804060c8SJoel Dice
15804060c8SJoel Dice #[cfg(target_arch = "wasm32")]
16804060c8SJoel Dice #[link(wasm_import_module = "[export]local:local/run")]
17804060c8SJoel Dice unsafe extern "C" {
18*020727d0SAlex Crichton #[link_name = "[task-return]run"]
task_return_run()19804060c8SJoel Dice fn task_return_run();
20804060c8SJoel Dice }
21804060c8SJoel Dice #[cfg(not(target_arch = "wasm32"))]
task_return_run()22804060c8SJoel Dice unsafe extern "C" fn task_return_run() {
23804060c8SJoel Dice unreachable!()
24804060c8SJoel Dice }
25804060c8SJoel Dice
26*020727d0SAlex Crichton #[unsafe(export_name = "[async-lift]local:local/run#run")]
export_run() -> u3227804060c8SJoel Dice unsafe extern "C" fn export_run() -> u32 {
28804060c8SJoel Dice callback_run(EVENT_NONE, 0, 0)
29804060c8SJoel Dice }
30804060c8SJoel Dice
31*020727d0SAlex Crichton #[unsafe(export_name = "[callback][async-lift]local:local/run#run")]
callback_run(event0: u32, _event1: u32, _event2: u32) -> u3232804060c8SJoel Dice unsafe extern "C" fn callback_run(event0: u32, _event1: u32, _event2: u32) -> u32 {
33c1551308SJoel Dice assert!(event0 == EVENT_NONE || event0 == EVENT_CANCELLED);
34804060c8SJoel Dice
35c1551308SJoel Dice if continue_::get_continue() && event0 == EVENT_NONE {
36804060c8SJoel Dice CALLBACK_CODE_YIELD
37804060c8SJoel Dice } else {
38804060c8SJoel Dice task_return_run();
39804060c8SJoel Dice CALLBACK_CODE_EXIT
40804060c8SJoel Dice }
41804060c8SJoel Dice }
42804060c8SJoel Dice
43804060c8SJoel Dice // Unused function; required since this file is built as a `bin`:
main()44804060c8SJoel Dice fn main() {}
45