修正了种子编译器的错误

This commit is contained in:
2026-07-22 21:55:36 +08:00
parent 135aa05485
commit ca7c2120b8
1185 changed files with 12056 additions and 2673 deletions

View File

@@ -18,8 +18,9 @@ _mbuddy: memhub.MemManager | t.CPtr
# 配置值(从 project.vpj 加载)
SourceDir: str
TempDir: str
OutputDir: str
BuildDir: str
TempDir: str # = {BuildDir}/temp自动计算
OutputDir: str # = {BuildDir}/output自动计算
ProjectName: str
ProjectVersion: str
CompilerCmd: str
@@ -29,7 +30,7 @@ LinkerFlags: str # 链接器参数(空格分隔,从 linker.flags
LinkerOutput: str
TargetTriple: str
TargetDataLayout: str
SliceLevel: t.CInt
Sha1SliceLevel: t.CInt # SHA1 切片层数(目录分散等级)
StrictMode: t.CInt
IncludesDir: str # includes 目录路径(从 includes 数组首元素)
@@ -43,9 +44,9 @@ def Load_project_config(path: str) -> int:
Returns:
0 表示成功,非 0 表示失败
"""
global SourceDir, TempDir, OutputDir, ProjectName, ProjectVersion
global SourceDir, BuildDir, TempDir, OutputDir, ProjectName, ProjectVersion
global CompilerCmd, CompilerFlags, LinkerCmd, LinkerFlags, LinkerOutput
global TargetTriple, TargetDataLayout, SliceLevel, StrictMode
global TargetTriple, TargetDataLayout, Sha1SliceLevel, StrictMode
global IncludesDir
if path is None:
@@ -79,8 +80,12 @@ def Load_project_config(path: str) -> int:
# 读取顶层字段
SourceDir = root["source_dir"].as_string() if root["source_dir"] is not None else None
TempDir = root["temp_dir"].as_string() if root["temp_dir"] is not None else None
OutputDir = root["output_dir"].as_string() if root["output_dir"] is not None else None
# build_dir: 统一构建目录(默认 ./.tpv_buildtemp 和 output 作为其子目录
bd_val: JsonValue | t.CPtr = root["build_dir"]
if bd_val is not None and bd_val.is_string():
BuildDir = bd_val.as_string()
else:
BuildDir = "./.tpv_build"
ProjectName = root["name"].as_string() if root["name"] is not None else None
ProjectVersion = root["version"].as_string() if root["version"] is not None else None
@@ -108,11 +113,17 @@ def Load_project_config(path: str) -> int:
TargetDataLayout = target["datalayout"].as_string() if target["datalayout"] is not None else None
# 读取 options 子对象
# Sha1SliceLevel: SHA1 切片层数(默认 1每层取 SHA1 前 2 字符作为子目录)
# level=0 → 不切片,文件直接放 base_dir
# level=1 → b7/{sha1}.ext
# level=2 → b7/90/{sha1}.ext
options: JsonValue | t.CPtr = root["options"]
Sha1SliceLevel = 1
StrictMode = 1
if options is not None and options.is_object():
sl: JsonValue | t.CPtr = options["slice_level"]
sl: JsonValue | t.CPtr = options["sha1_slice_level"]
if sl is not None and sl.is_int():
SliceLevel = sl.as_int()
Sha1SliceLevel = sl.as_int()
sm: JsonValue | t.CPtr = options["strict_mode"]
if sm is not None and sm.is_bool():
StrictMode = 1 if sm.as_bool() else 0
@@ -241,9 +252,10 @@ def _join_path(rel: str, project_dir: str) -> str:
def resolve_paths(project_dir: str) -> int:
"""解析并规范化工程路径src/temp/output/includes
"""解析并规范化工程路径src/build/includes
将 project.vpj 中的相对路径(以 ./ 开头)转换为基于 project_dir 的路径。
BuildDir 解析后TempDir = {BuildDir}/tempOutputDir = {BuildDir}/output。
Args:
project_dir: 工程根目录project.vpj 所在目录)
@@ -251,15 +263,28 @@ def resolve_paths(project_dir: str) -> int:
Returns:
0 表示成功,非 0 表示失败
"""
global SourceDir, TempDir, OutputDir, IncludesDir
global SourceDir, BuildDir, TempDir, OutputDir, IncludesDir
if project_dir is None:
return 1
if _mbuddy is None:
return 1
SourceDir = _join_path(SourceDir, project_dir)
TempDir = _join_path(TempDir, project_dir)
OutputDir = _join_path(OutputDir, project_dir)
BuildDir = _join_path(BuildDir, project_dir)
# TempDir = {BuildDir}/temp
if BuildDir is not None:
bd_len: t.CSizeT = string.strlen(BuildDir)
temp_buf: str = _mbuddy.alloc(bd_len + 8)
if temp_buf is not None:
viperlib.snprintf(temp_buf, bd_len + 8, "%s/temp", BuildDir)
TempDir = temp_buf
# OutputDir = {BuildDir}/output
output_buf: str = _mbuddy.alloc(bd_len + 8)
if output_buf is not None:
viperlib.snprintf(output_buf, bd_len + 8, "%s/output", BuildDir)
OutputDir = output_buf
# includes 路径可能是 ../includes 形式,需要基于 project_dir 解析
if IncludesDir is not None:
IncludesDir = _join_path(IncludesDir, project_dir)
@@ -287,6 +312,8 @@ def print_config():
stdio.printf(" project: %s v%s\n", ProjectName, ProjectVersion if ProjectVersion is not None else "?")
if SourceDir is not None:
stdio.printf(" source_dir: %s\n", SourceDir)
if BuildDir is not None:
stdio.printf(" build_dir: %s\n", BuildDir)
if TempDir is not None:
stdio.printf(" temp_dir: %s\n", TempDir)
if OutputDir is not None:
@@ -296,4 +323,48 @@ def print_config():
if LinkerCmd is not None:
stdio.printf(" linker: %s -> %s\n", LinkerCmd, LinkerOutput if LinkerOutput is not None else "?")
if IncludesDir is not None:
stdio.printf(" includes: %s\n", IncludesDir)
stdio.printf(" includes: %s\n", IncludesDir)
stdio.printf(" sha1_slice_level: %d\n", Sha1SliceLevel)
# ============================================================
# slice_subdir - 根据 SHA1 和切片层数返回子目录路径
#
# 每层取 SHA1 的 2 个字符作为子目录名:
# level=0 → None不切片
# level=1 → "b7"
# level=2 → "b7/90"
# level=3 → "b7/90/23"
#
# Args:
# sha1: SHA1 字符串(至少 2*level 字符)
# level: 切片层数
#
# Returns:
# 子目录路径字符串mbuddy 分配无需释放level<=0 时返回 None
# ============================================================
def slice_subdir(sha1: str, level: int) -> str:
"""根据 SHA1 和切片层数返回子目录路径"""
if level <= 0 or sha1 is None:
return None
if _mbuddy is None:
return None
# 每层 2 字符 + 分隔符,最后无分隔符 + null
# buf 大小: level * 2 + (level - 1) + 1 = level * 3
buf_len: t.CSizeT = t.CSizeT(level * 3)
buf: str = _mbuddy.alloc(buf_len)
if buf is None:
return None
pos: int = 0
i: int = 0
while i < level:
if i > 0:
buf[pos] = '/'
pos += 1
idx: int = i * 2
buf[pos] = sha1[idx]
buf[pos + 1] = sha1[idx + 1]
pos += 2
i += 1
buf[pos] = '\0'
return buf