Files
Viper_VRTE/_withcontent.vp
T
TermiNexus e71daeea0e docs(includes): R11 注释英文化——75 个文件的中文注释改写为英文短注释
按规范「注释只讲解作用,不掺杂历史原因,尽量英文」:把 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 顺序回归通过。
2026-10-05 16:18:44 +08:00

76 lines
3.0 KiB
Plaintext

import t, c
from stdint import *
from w32.win32process import TlsAlloc, TlsGetValue, TlsSetValue
import stdlib
import stdio
import string
# Maximum provider stack depth (compiler verifies sufficiency; increase if needed)
define _MAX_PROVIDER_DEPTH = 32
class _ProviderStack:
"""Provider stack, stores pairs of field names and pointers."""
# Field names are stored as string pointers: a `char` element would hold a
# single byte, truncating the name and breaking every provider lookup.
names: [32]str
ptrs: [32]rawptr
top: uint64
# TLS index (global; all threads share the same index)
_tls_index: ulong = 0
@t.TLS
def _init_tls():
"""Initialize TLS index (executes once; subsequent calls are skipped)."""
global _tls_index
# Double guard: TPV now implements @t.TLS (a per-function one-shot guard setting __tls_init_done), but this re-check is kept for compatibility with older TPV.exe builds.
# _tls_index starts at 0 (TlsAlloc never returns 0 on success).
if _tls_index == 0:
_tls_index = TlsAlloc()
def _get_stack() -> _ProviderStack*:
"""Obtain current thread's provider stack. Allocate one if none exists."""
_init_tls()
stack: _ProviderStack* = TlsGetValue(_tls_index)
if stack == None:
stack = stdlib.malloc(_ProviderStack.__sizeof__())
string.memset(stack, 0, _ProviderStack.__sizeof__())
TlsSetValue(_tls_index, stack)
return stack
def _push_provider(field_name: str, ptr: rawptr):
"""Push a provider (field_name, ptr) onto the stack."""
stack: _ProviderStack* = _get_stack()
if stack.top >= _MAX_PROVIDER_DEPTH:
stdio.printf("[with] ERROR: provider stack overflow (depth=%lu, max=%d), field '%s' not injected\n", stack.top, _MAX_PROVIDER_DEPTH, field_name)
return
stack.names[stack.top] = field_name
stack.ptrs[stack.top] = ptr
stack.top = stack.top + 1
def _pop_provider():
"""Pop the top provider entry from the stack."""
stack: _ProviderStack* = _get_stack()
if stack.top > 0:
stack.top = stack.top - 1
def _find_provider(field_name: str) -> rawptr:
"""Search for matching field_name starting from stack top.
Return associated pointer, or NULL if no match found."""
stack: _ProviderStack* = _get_stack()
# Upper bound explicitly cast to t.CInt (signed): the loop is "decrement, stop at -1". If the bound were unsigned (stack.top is a uint64 field), the predicate would degrade to ugt and -1 (= UINT32_MAX unsigned) would make it always false, so the loop body is unreachable and this function always returns NULL (all with-injections break, and _str.upper crashes taking a vtable from NULL).
# The explicit cast keeps the signed domain consistent with the decrement semantics.
for i in range(int(stack.top) - 1, -1, -1):
# Content comparison: every string literal gets its own constant, so the
# push/find pointers differ and pointer equality never matches.
if string.strcmp(stack.names[i], field_name) == 0: return stack.ptrs[i]
return None