按规范「注释只讲解作用,不掺杂历史原因,尽量英文」:把 includes 下 75 个 .vp 的中文 # 注释与三引号 docstring 改写为英文,每个注释块压到 2 行以内。 保留要点:作用、约束、危险警告(不得/必须/注意)、ABI 与类型约定(如 BYTEPTR | t.CPtr = i8** 的跨模块坍缩坑)、位宽/长度约定、fail-fast 要求、内存与句柄所有权。 未动:文件头注释(规范豁免,仍是中文)、运行时中文字符串常量(printf / fatal_error / MlirFail 等用户可见消息,属代码字面量)。 验证:独立脚本比对 HEAD 与工作区的代码骨架(剥离 # 注释与三引号 docstring 后的非空行)——75 个文件逐字节一致;行尾 CRLF/LF 未被改动;全文剩余中文仅 547 行头注释、0 条行尾注释。bootstrap 三重重编 SUCCESS;全量 77/77 顺序回归通过。
50 lines
1.8 KiB
Plaintext
50 lines
1.8 KiB
Plaintext
import t, c
|
|
from stdint import *
|
|
import stdlib
|
|
|
|
|
|
novirtual class Coroutine:
|
|
"""Coroutine frame handle (M1: __ptr__ holds the frame pointer returned by create_<name>()).
|
|
Pure handle semantics: never instantiated or polymorphically dispatched, the compiler intercepts all coro.* calls; user code uses t.CPtr as the handle."""
|
|
__ptr__: rawptr
|
|
|
|
|
|
def coro_resume(c: Coroutine) -> int:
|
|
# M1 placeholder: the compiler inlines coro.coro_run into a resume_<name> loop; this function is never actually called (it only keeps the module compilable).
|
|
return 0
|
|
|
|
|
|
def coro_result(c: Coroutine) -> int:
|
|
# M1 placeholder: coro_run's inline translation reads the result directly from the frame ret slot.
|
|
return 0
|
|
|
|
|
|
def coro_run(c: Coroutine) -> int:
|
|
# M1 placeholder: the compiler inlines coro.coro_run at the call site (resume loop).
|
|
s: int = 0
|
|
while s == 0:
|
|
s = coro_resume(c)
|
|
return coro_result(c)
|
|
|
|
def coro_sleep(ms: int) -> int:
|
|
# M3 placeholder: the compiler inlines await coro_sleep(ms) into a frame wake-slot suspend; this function is never actually called (it only keeps the module compilable).
|
|
return 0
|
|
|
|
|
|
def coro_destroy(c: Coroutine):
|
|
# M3 placeholder: the compiler inlines coro.coro_destroy(frame) into free.
|
|
return
|
|
|
|
def coro_exception(c: Coroutine) -> int:
|
|
# M4 placeholder: the compiler inlines coro.coro_exception(frame) into a frame exc-slot read.
|
|
return 0
|
|
|
|
def coro_gather(a: Coroutine) -> int:
|
|
# M4 placeholder: the compiler inlines coro.coro_gather(frames...) into a concurrent-advance loop.
|
|
return 0
|
|
|
|
def coro_exception_msg(c: Coroutine) -> t.CPtr:
|
|
# M7 placeholder: the compiler inlines coro.coro_exception_msg(frame) into a frame msg-slot read.
|
|
# Note: TPV (Viper) does not support bare null; use t.CPtr(0) to build a null pointer (compatible with both compilers).
|
|
return None
|