diff --git a/lib/core/Handles/HandlesAsyncFunctions.py b/lib/core/Handles/HandlesAsyncFunctions.py index 00699c7..110a6af 100644 --- a/lib/core/Handles/HandlesAsyncFunctions.py +++ b/lib/core/Handles/HandlesAsyncFunctions.py @@ -261,6 +261,7 @@ class AsyncFunctionHandle(BaseHandle): uses_sleep: list[bool] = [False] def _walk(stmts: list[ast.stmt]) -> None: + nonlocal await_counter, for_counter for stmt in stmts: if isinstance(stmt, (ast.If, ast.While)): _walk(stmt.body) @@ -951,8 +952,16 @@ class AsyncFunctionHandle(BaseHandle): Gen.builder.cbranch(done_cond, after_bb, check_bb) # SUSPEND:若 coro_sleep 唤醒槽存在且未到点,Sleep(1) 后继续轮询 Gen.builder.position_at_start(check_bb) - wake_ptr: ir.Value | None = getattr(Gen, '_coro_wake_ptr', None) - if wake_ptr is not None: + wake_idx: int | None = None + slot_vars: list[str] = getattr(Gen, '_coro_slot_vars', {}).get(async_name, []) + if '__coro_wake_us' in slot_vars: + wake_idx = 3 + slot_vars.index('__coro_wake_us') + if wake_idx is not None: + wake_ptr: ir.Value = Gen.builder.gep( + frame_ptr, + [ir.Constant(ir.IntType(32), 0), ir.Constant(ir.IntType(32), wake_idx)], + name='coro_wake_ptr', + ) wake_val: ir.Value = Gen._load(wake_ptr, name='coro_wake') now_fn: ir.Function = self._GetWinFunc('GetTickCount64', Gen, ir.IntType(64)) now_val: ir.Value = Gen.builder.call(now_fn, [], name='tick_now') @@ -965,6 +974,7 @@ class AsyncFunctionHandle(BaseHandle): Gen.builder.call(sleep_fn, [ir.Constant(ir.IntType(32), 1)]) Gen.builder.branch(loop_bb) Gen.builder.position_at_start(wake_due_bb) + Gen.builder.branch(loop_bb) else: Gen.builder.branch(loop_bb) Gen.builder.position_at_start(after_bb)