- 帧结构体增加参数槽与提升临时变量槽,create_<name> 带参数存入帧 - 嵌套 await(如 a = b + await f())提升为顶层临时赋值 __await_N,帧预留槽 - 协程版 If/While:条件求值 + 分支内 await 就地挂起/恢复(动态状态号恢复块) - For 循环委托现有 handler(仅支持无 await/return,M3 扩展) - CoroTest 用例覆盖参数/嵌套 await/while+await/if+await(期望 coro result = 30)
28 lines
515 B
Plaintext
28 lines
515 B
Plaintext
import t, c
|
|
from stdint import *
|
|
import stdio
|
|
import coro
|
|
|
|
|
|
async def leaf(x: int) -> int:
|
|
return x + 1
|
|
|
|
|
|
async def task(base: int) -> int:
|
|
a: int = await leaf(base)
|
|
b: int = a * 2 + await leaf(a)
|
|
s: int = 0
|
|
i: int = 0
|
|
while i < 3:
|
|
s = s + await leaf(i)
|
|
i = i + 1
|
|
if s > 5:
|
|
s = s + await leaf(10)
|
|
return s + a + b
|
|
|
|
|
|
def main() -> t.CInt:
|
|
tt: coro.Coroutine = task(2)
|
|
r: t.CInt = coro.coro_run(tt)
|
|
stdio.printf("coro result = %d\n", r)
|
|
return 0 |