chore(comments): Test 仓注释英文化(R11)

把 81 个 .vp 文件的中文 # 注释与三引号文档串改写为简洁英文,每个连续注释块 <=2 行;运行时中文字符串字面量(testcheck.begin/print 等用户可见消息)保持原样。骨架比对 HEAD 与工作区 112 文件漂移 0,全量 77/77 顺序回归通过。
This commit is contained in:
TermiNexus committed 2026-10-05 22:43:38 +08:00
1 parent aa5a7e7250
commit ee6461be46
81 files changed
+1231 -1925

No files matched your search

+16 -25
View File
@@ -4,20 +4,11 @@ from t import CPtr, CInt, CExport
import testcheck
# ============================================================
# super() 语义专项测试(由 TransPyV.exe 编译)
#
# 覆盖场景:
# 1. super().__init__(args) — 子类构造调父类构造(字段由父类设置)
# 2. super().method() 静态绑定父类实现(不触发子类 override / 虚分派)
# 3. super() 调未覆盖的父类方法(父类字段区前缀对齐,this 无需调整)
# 4. 三层继承链 super().__init__(Leaf → Mid → Grand 逐层传递,
# 每个中间类的 super() 沿各自 CurClassName 的 MRO 跳自身找父类)
# 5. super().method 沿 MRO 找实际定义类(Mid 未定义 Base → 找到 Grand.Base)
# ============================================================
# ===== super() semantics test =====
# Covers super().__init__ chaining, static method binding, MRO lookup, 3-level chains.
# ========== 单继承:super().__init__ + super().method ==========
# ========== Single inheritance: super().__init__ + super().method ==========
@t.CVTable
class Animal:
@@ -38,21 +29,21 @@ class Dog(Animal):
Breed: CInt
def __init__(self, tag: CInt, breed: CInt):
super().__init__(tag) # 调 Animal.__init__ 设置 Tag
super().__init__(tag) # Call Animal.__init__ to set Tag
self.Breed = breed
def Speak(self) -> CInt:
return 1
def ParentSpeak(self) -> CInt:
return super().Speak() # 静态绑定 Animal.Speak → 0(不走虚分派)
return super().Speak() # Statically bind Animal.Speak -> 0 (no virtual dispatch)
def FullGreet(self) -> CInt:
# super() 调父类 Greet(Dog 未覆盖),再加自身字段
# Call parent Greet (not overridden by Dog), then add own field
return super().Greet() + self.Breed
# ========== 三层继承链:Grand → Mid → Leaf ==========
# ========== Three-level chain: Grand -> Mid -> Leaf ==========
@t.CVTable
class Grand:
@@ -70,7 +61,7 @@ class Mid(Grand):
M: CInt
def __init__(self, v: CInt):
super().__init__(v + 1) # 调 Grand.__init__
super().__init__(v + 1) # Call Grand.__init__
self.M = v
def MidOnly(self) -> CInt:
@@ -80,39 +71,39 @@ class Mid(Grand):
@t.CVTable
class Leaf(Mid):
def __init__(self, v: CInt):
super().__init__(v + 2) # 调 Mid.__init__(Mid 内部再 super 到 Grand)
super().__init__(v + 2) # Call Mid.__init__ (which supers to Grand)
def GetBase(self) -> CInt:
return super().Base() # Mid 未定义 Base → 沿 MRO 找 Grand.Base
return super().Base() # Mid has no Base -> find Grand.Base along MRO
def CallMidOnly(self) -> CInt:
return super().MidOnly() # 调 Mid.MidOnly
return super().MidOnly() # Call Mid.MidOnly
def main() -> CInt | CExport:
testcheck.begin("SuperTest: super() 语义测试")
# --- 1. super().__init__ 设置父类字段 ---
# --- 1. super().__init__ sets parent fields ---
d: Dog | CPtr = Dog(42, 7)
testcheck.check(d.Tag == 42, "super().__init__ 设置父类字段 OK",
"super().__init__ FAILED")
testcheck.check(d.Breed == 7, "子类字段 OK", "子类字段 FAILED")
# --- 2. super().method 静态绑定(不虚分派到子类 override) ---
# --- 2. super().method static binding (no dispatch to child override) ---
testcheck.check(d.ParentSpeak() == 0, "super().Speak() 静态绑定父类 OK",
"super().Speak() FAILED")
testcheck.check(d.Speak() == 1, "子类 Speak() override OK", "Speak() FAILED")
# --- 3. super() 调未覆盖的父类方法(42+1000+7 = 1049) ---
# --- 3. super() calls uncovered parent method (42+1000+7 = 1049) ---
testcheck.check(d.FullGreet() == 1049, "super() 调未覆盖父类方法 OK",
"FullGreet() FAILED")
# --- 4. 三层继承链 super().__init__(Leaf(10) → Mid(12) → Grand(13)) ---
# --- 4. three-level super().__init__ chain (Leaf(10) -> Mid(12) -> Grand(13)) ---
lf: Leaf | CPtr = Leaf(10)
testcheck.check(lf.G == 13, "三层 super().__init__ 链 G OK", "三层 G FAILED")
testcheck.check(lf.M == 12, "中间类 M OK", "中间类 M FAILED")
# --- 5. super().method 沿 MRO 找实际定义类 ---
# --- 5. super().method finds the defining class along MRO ---
testcheck.check(lf.GetBase() == 13, "super().Base() 沿 MRO OK", "GetBase() FAILED")
testcheck.check(lf.CallMidOnly() == 12, "super().MidOnly() OK", "CallMidOnly() FAILED")