refactor(gen): R12/R13 同步——下标 while 循环改 for range、去 c.Set

与 includes 同步执行两批源改写:R12 把「i: int = 0 与 while i < N: … i += 1」形式的计数循环改写为「for i in range(N):」;R13 把 c.Set(*p, v) 迁移为 *p = v、c.Set(a, b) 迁移为 a = b(c.Set 是正在退化的路径)。

验证:bootstrap 三重重编 SUCCESS(无 vast_c 解析回退);全量 77/77 顺序回归通过(WebTest 首轮网络超时,单独重跑通过)。
This commit is contained in:
TermiNexus committed 2026-10-05 15:33:58 +08:00
1 parent a7b8118ce8
commit fb53f88893
25 files changed
+133 -345

No files matched your search

+19 -57
View File
@@ -131,11 +131,9 @@ def _BaseNameOf(path: str) -> str:
if path is None: return None
n: sizet = string.strlen(path)
start: sizet = 0
i: sizet = 0
while i < n:
for i in range(n):
ch: char = path[i]
if ch == '/' or ch == '\\': start = i + 1
i += 1
return _DupStd(path + start)
@@ -168,12 +166,10 @@ def _FindInList(names: list[str]*, name: str) -> int:
"""Linear-search names for name; return its index, or -1 if not found."""
if names is None or name is None: return -1
n: sizet = names.__len__()
i: sizet = 0
while i < n:
for i in range(n):
s: str = names.get(i)
if s is not None:
if string.strcmp(s, name) == 0: return int(i)
i += 1
return -1
@@ -203,8 +199,7 @@ def _SplitInto(out: list[str]*, joined: str) -> int:
n: sizet = string.strlen(joined)
if n == 0: return 1
start: sizet = 0
i: sizet = 0
while i <= n:
for i in range(n + 1):
if i == n or joined[i] == char(VB_SEP_CODE):
seg: str = stdlib.malloc(i - start + 1)
if seg is None: return 0
@@ -213,7 +208,6 @@ def _SplitInto(out: list[str]*, joined: str) -> int:
out.append(_DupScratch(seg))
stdlib.free(seg)
start = i + 1
i += 1
return 1
@@ -233,8 +227,7 @@ def _JoinSep(lst: list[str]*) -> str:
buf: str = _scratch.alloc(total + 1)
if buf is None: return None
pos: sizet = 0
i = 0
while i < n:
for i in range(n):
s = lst.get(i)
if s is not None:
sl: sizet = string.strlen(s)
@@ -243,7 +236,6 @@ def _JoinSep(lst: list[str]*) -> str:
pos += 1
string.strcpy(buf + pos, s)
pos += sl
i += 1
buf[pos] = '\0'
return buf
@@ -263,8 +255,7 @@ def _JoinSpace(lst: list[str]*) -> str:
buf: str = stdlib.malloc(total + 1)
if buf is None: return None
pos: sizet = 0
i = 0
while i < n:
for i in range(n):
s = lst.get(i)
if s is not None:
sl: sizet = string.strlen(s)
@@ -273,7 +264,6 @@ def _JoinSpace(lst: list[str]*) -> str:
pos += 1
string.strcpy(buf + pos, s)
pos += sl
i += 1
buf[pos] = '\0'
return buf
@@ -284,12 +274,10 @@ def _FirstSpaceTok(joined: str) -> str:
n: sizet = string.strlen(joined)
if n == 0: return None
sp: sizet = n
i: sizet = 0
while i < n:
for i in range(n):
if joined[i] == ' ':
sp = i
break
i += 1
seg: str = stdlib.malloc(sp + 1)
if seg is None: return None
string.strncpy(seg, joined, sp)
@@ -349,8 +337,7 @@ def _EvalList(node: ast.AST*, out: list[str]*) -> int:
lst: ast.List* = ast.List*(node)
if lst is None or lst.elts is None: return 0
n: sizet = lst.elts.__len__()
i: sizet = 0
while i < n:
for i in range(n):
e: ast.AST* = lst.elts.get(i)
if e is None: return 0
if e.kind() == ast.ASTKind.Starred:
@@ -360,7 +347,6 @@ def _EvalList(node: ast.AST*, out: list[str]*) -> int:
else:
if _EvalStr(e) == 0: return 0
out.append(_DupScratch(_g_out_str))
i += 1
return 1
if k == ast.ASTKind.BinOp:
bop: ast.BinOp* = ast.BinOp*(node)
@@ -423,8 +409,7 @@ def _HandleImport(stmt: ast.Import*) -> int:
global _alias, _saw_viperbuild
if stmt is None or stmt.names is None: return 0
n: sizet = stmt.names.__len__()
i: sizet = 0
while i < n:
for i in range(n):
al: ast.Alias* = ast.Alias*(stmt.names.get(i))
if al is not None and al.name is not None:
if string.strcmp(al.name, "viperbuild") == 0:
@@ -432,7 +417,6 @@ def _HandleImport(stmt: ast.Import*) -> int:
if al.asname is not None: _alias = _DupScratch(al.asname)
else: _alias = _DupScratch("viperbuild")
else: _AddPending(al.name)
i += 1
return 0
@@ -450,14 +434,12 @@ def _HandleImportFrom(stmt: ast.ImportFrom*) -> int:
_saw_viperbuild = 1
if stmt.names is None: return 0
n: sizet = stmt.names.__len__()
i: sizet = 0
while i < n:
for i in range(n):
al: ast.Alias* = ast.Alias*(stmt.names.get(i))
if al is not None and al.name is not None:
if string.strcmp(al.name, "Project") == 0:
if al.asname is not None: _ctor_name = _DupScratch(al.asname)
else: _ctor_name = _DupScratch("Project")
i += 1
return 0
@@ -505,8 +487,7 @@ def _ApplyCtorArgs(cl: ast.Call*) -> int:
_c_version = _DupStd(_g_out_str)
if cl.keywords is None: return 0
n: sizet = cl.keywords.__len__()
i: sizet = 0
while i < n:
for i in range(n):
kw: ast.Keyword* = ast.Keyword*(cl.keywords.get(i))
if kw is not None and kw.arg is not None and kw.value is not None:
if string.strcmp(kw.arg, "name") == 0:
@@ -522,7 +503,6 @@ def _ApplyCtorArgs(cl: ast.Call*) -> int:
else:
VLogger.error(f"viperbuild: Project(...) 不支持的关键字 {kw.arg}", "viperbuild")
return 1
i += 1
return 0
@@ -660,12 +640,10 @@ def _HandleConfigCall(cl: ast.Call*) -> int:
"""Handle a proj.config(kw=...) call."""
if cl is None or cl.keywords is None: return 0
n: sizet = cl.keywords.__len__()
i: sizet = 0
while i < n:
for i in range(n):
kw: ast.Keyword* = ast.Keyword*(cl.keywords.get(i))
if kw is not None and kw.arg is not None and kw.value is not None:
if _SetField(kw.arg, kw.value) != 0: return 1
i += 1
return 0
@@ -679,8 +657,7 @@ def _HandleBuildCall(cl: ast.Call*) -> int:
_c_has_build = 1
if cl.keywords is None: return 0
n: sizet = cl.keywords.__len__()
i: sizet = 0
while i < n:
for i in range(n):
kw: ast.Keyword* = ast.Keyword*(cl.keywords.get(i))
if kw is not None and kw.arg is not None and kw.value is not None:
if string.strcmp(kw.arg, "triple") == 0:
@@ -702,7 +679,6 @@ def _HandleBuildCall(cl: ast.Call*) -> int:
else:
VLogger.error(f"viperbuild: build(...) 不支持的关键字 {kw.arg}", "viperbuild")
return 1
i += 1
return 0
@@ -711,18 +687,14 @@ def _CallArgsHaveProjRef(cl: ast.Call*) -> int:
if cl is None: return 0
if cl.args is not None:
n: sizet = cl.args.__len__()
i: sizet = 0
while i < n:
for i in range(n):
if _IsProjRef(cl.args.get(i)) != 0: return 1
i += 1
if cl.keywords is not None:
n = cl.keywords.__len__()
i = 0
while i < n:
for i in range(n):
kw: ast.Keyword* = ast.Keyword*(cl.keywords.get(i))
if kw is not None and kw.value is not None:
if _IsProjRef(kw.value) != 0: return 1
i += 1
return 0
@@ -803,8 +775,7 @@ def _ScanFile(pool: memhub.MemBuddy*, path: str) -> int:
rc: int = 0
if body is not None:
cn: sizet = len(body)
ci: sizet = 0
while ci < cn:
for ci in range(cn):
child: ast.AST* = body.get(ci)
if child is not None:
kd: int = child.kind()
@@ -814,7 +785,6 @@ def _ScanFile(pool: memhub.MemBuddy*, path: str) -> int:
elif kd == ast.ASTKind.AnnAssign: rc = _HandleAnnAssign(ast.AnnAssign*(child))
elif kd == ast.ASTKind.Expr: rc = _HandleExprStmt(ast.Expr*(child))
if rc != 0: break
ci += 1
pool.reset_to(mark)
stdlib.free(src_buf)
@@ -883,13 +853,11 @@ def _RunBfs(pool: memhub.MemBuddy*, entry_path: str) -> int:
if rc == 1: return 1
# Resolve module names collected from this file
pn: sizet = _pending.__len__()
pi: sizet = 0
while pi < pn:
for pi in range(pn):
mod: str = _pending.get(pi)
if mod is not None:
dep: str = _ResolveModuleToFile(mod)
if dep is not None: _Enqueue(dep)
pi += 1
return 0
@@ -939,10 +907,8 @@ def _ProbeIncludes() -> str:
k: int = 0
while k <= 3:
base: str = _DupStd(exe_dir)
j: int = 0
while j < k:
for j in range(k):
base = _Join2(base, "..")
j += 1
cand: str = _Join2(base, "includes")
if _IsDir(cand) != 0: return cand
k += 1
@@ -955,12 +921,10 @@ def _DeriveOutputFromEntry(entry_path: str) -> str:
if base is None: return "app.exe"
n: sizet = string.strlen(base)
cut: sizet = n
i: sizet = 0
while i < n:
for i in range(n):
if base[i] == '.':
cut = i
break
i += 1
head: str = stdlib.malloc(cut + 5)
if head is None: return "app.exe"
string.strncpy(head, base, cut)
@@ -1047,12 +1011,10 @@ def _SplitToolCmd(joined: str, which: int) -> None:
if joined is None: return
n: sizet = string.strlen(joined)
sp: sizet = n
i: sizet = 0
while i < n:
for i in range(n):
if joined[i] == ' ':
sp = i
break
i += 1
cmd: str = stdlib.malloc(sp + 1)
if cmd is not None:
string.strncpy(cmd, joined, sp)