Some simple information syncing
This commit is contained in:
@@ -49,127 +49,70 @@ SRC_BUF_SIZE: t.CDefine = 1048576
|
||||
def main() -> int:
|
||||
w32cmd.SetConsoleOutputCP(CODE_PAGE)
|
||||
w32cmd.SetConsoleCP(CODE_PAGE)
|
||||
# 用 fflush(0) 刷新所有流,确保崩溃前输出可见(0=NULL 刷新所有输出流)
|
||||
stdio.printf("[DBG] main enter\n")
|
||||
stdio.fflush(0)
|
||||
# 初始化 mbuddy 内存池
|
||||
stdio.printf("[DBG] before malloc\n")
|
||||
stdio.fflush(0)
|
||||
arena: bytes = stdlib.malloc(POOL_SIZE)
|
||||
stdio.printf("[DBG] after malloc arena=%p\n", arena)
|
||||
stdio.fflush(0)
|
||||
if arena is None:
|
||||
stdio.printf("FAIL: malloc for arena failed\n")
|
||||
return 1
|
||||
stdio.printf("[DBG] before MemBuddy\n")
|
||||
stdio.fflush(0)
|
||||
mb: memhub.MemBuddy | t.CPtr = memhub.MemBuddy(arena, POOL_SIZE)
|
||||
stdio.printf("[DBG] after MemBuddy mb=%p\n", mb)
|
||||
stdio.fflush(0)
|
||||
if mb is None:
|
||||
stdio.printf("FAIL: MemBuddy init failed\n")
|
||||
return 1
|
||||
|
||||
# 设置全局 mbuddy 指针(sys 和 argparse 都需要)
|
||||
stdio.printf("[DBG] before _mbuddy setup\n")
|
||||
stdio.fflush(0)
|
||||
sys._mbuddy = mb
|
||||
stdio.printf("[DBG] sys._mbuddy ok\n")
|
||||
stdio.fflush(0)
|
||||
argparse._mbuddy = mb
|
||||
ast._mbuddy = mb
|
||||
lib._mbuddy = (memhub.MemManager | t.CPtr)(mb)
|
||||
Config._mbuddy = (memhub.MemManager | t.CPtr)(mb)
|
||||
Utils._mbuddy = (memhub.MemManager | t.CPtr)(mb)
|
||||
lib._mbuddy = (memhub.MemBuddy | t.CPtr)(mb)
|
||||
Config._mbuddy = (memhub.MemBuddy | t.CPtr)(mb)
|
||||
Utils._mbuddy = (memhub.MemBuddy | t.CPtr)(mb)
|
||||
HandlesTranslator._mbuddy = mb
|
||||
BuildPipeline._mbuddy = (memhub.MemManager | t.CPtr)(mb)
|
||||
IncludesScanner._mbuddy = (memhub.MemManager | t.CPtr)(mb)
|
||||
StubMerger._mbuddy = (memhub.MemManager | t.CPtr)(mb)
|
||||
Phase1._mbuddy = (memhub.MemManager | t.CPtr)(mb)
|
||||
Phase2._mbuddy = (memhub.MemManager | t.CPtr)(mb)
|
||||
BuildPipeline._mbuddy = (memhub.MemBuddy | t.CPtr)(mb)
|
||||
IncludesScanner._mbuddy = (memhub.MemBuddy | t.CPtr)(mb)
|
||||
StubMerger._mbuddy = (memhub.MemBuddy | t.CPtr)(mb)
|
||||
Phase1._mbuddy = (memhub.MemBuddy | t.CPtr)(mb)
|
||||
Phase2._mbuddy = (memhub.MemBuddy | t.CPtr)(mb)
|
||||
subprocess._mbuddy = mb
|
||||
hashlib._mbuddy = (memhub.MemManager | t.CPtr)(mb)
|
||||
VLogger._mbuddy = (memhub.MemManager | t.CPtr)(mb)
|
||||
stdio.printf("[DBG] before InitLib\n")
|
||||
stdio.fflush(0)
|
||||
lib.InitLib((memhub.MemManager | t.CPtr)(mb))
|
||||
stdio.printf("[DBG] after InitLib\n")
|
||||
stdio.fflush(0)
|
||||
hashlib._mbuddy = (memhub.MemBuddy | t.CPtr)(mb)
|
||||
VLogger._mbuddy = (memhub.MemBuddy | t.CPtr)(mb)
|
||||
lib.InitLib((memhub.MemBuddy | t.CPtr)(mb))
|
||||
|
||||
# 初始化 VLogger 并打印启动日志
|
||||
log: VLogger.Logger | t.CPtr = VLogger.get_logger()
|
||||
stdio.printf("[DBG] after get_logger log=%p\n", log)
|
||||
stdio.fflush(0)
|
||||
if log is not None:
|
||||
log.info("TransPyV 启动")
|
||||
stdio.printf("[DBG] after log.info\n")
|
||||
stdio.fflush(0)
|
||||
|
||||
# 初始化命令行参数(Windows: GetCommandLineA, POSIX: /proc/self/cmdline)
|
||||
stdio.printf("[DBG] before _init_argv\n")
|
||||
stdio.fflush(0)
|
||||
sys._init_argv()
|
||||
stdio.printf("[DBG] after _init_argv\n")
|
||||
stdio.fflush(0)
|
||||
|
||||
# 创建参数解析器
|
||||
stdio.printf("[DBG] before ArgumentParser\n")
|
||||
stdio.fflush(0)
|
||||
parser: argparse.ArgumentParser | t.CPtr = argparse.ArgumentParser(
|
||||
"TransPyV", "TransPyV 命令行参数解析", pool=mb)
|
||||
stdio.printf("[DBG] after ArgumentParser parser=%p\n", parser)
|
||||
stdio.fflush(0)
|
||||
|
||||
# 注册参数(与 Projectrans.py main() 一致)
|
||||
stdio.printf("[DBG] before add_argument --project\n")
|
||||
stdio.fflush(0)
|
||||
parser.add_argument("--project", None, argparse.STRING, 0, None, False,
|
||||
argparse.STORE, "project.json 路径(默认查找当前目录)")
|
||||
stdio.printf("[DBG] after add_argument --project\n")
|
||||
stdio.fflush(0)
|
||||
parser.add_argument("--src", None, argparse.STRING, 0, None, False,
|
||||
argparse.STORE, "源文件目录(覆盖 project.json)")
|
||||
stdio.printf("[DBG] after --src\n")
|
||||
stdio.fflush(0)
|
||||
parser.add_argument("--temp", None, argparse.STRING, 0, None, False,
|
||||
argparse.STORE, "声明接口临时目录(覆盖 project.json)")
|
||||
stdio.printf("[DBG] after --temp\n")
|
||||
stdio.fflush(0)
|
||||
parser.add_argument("--output", None, argparse.STRING, 0, None, False,
|
||||
argparse.STORE, "输出目录(覆盖 project.json)")
|
||||
stdio.printf("[DBG] after --output\n")
|
||||
stdio.fflush(0)
|
||||
parser.add_argument("--phase", None, argparse.STRING, 0, None, False,
|
||||
argparse.STORE, "阶段: 1=生成声明, 2=翻译+编译, all=全部")
|
||||
stdio.printf("[DBG] after --phase\n")
|
||||
stdio.fflush(0)
|
||||
parser.add_argument("--cc", None, argparse.STRING, 0, None, False,
|
||||
argparse.STORE, "LLVM 编译器命令(覆盖 project.json)")
|
||||
stdio.printf("[DBG] after --cc\n")
|
||||
stdio.fflush(0)
|
||||
parser.add_argument("--clean", None, argparse.BOOL, 0, None, False,
|
||||
argparse.STORE_TRUE, "清理 output 和 temp 目录")
|
||||
stdio.printf("[DBG] after --clean\n")
|
||||
stdio.fflush(0)
|
||||
parser.add_argument("--run", None, argparse.BOOL, 0, None, False,
|
||||
argparse.STORE_TRUE, "编译成功后立即执行生成的可执行文件")
|
||||
stdio.printf("[DBG] after --run\n")
|
||||
stdio.fflush(0)
|
||||
parser.add_argument("--rebuild-includes", None, argparse.BOOL, 0, None, False,
|
||||
argparse.STORE_TRUE, "删除 includes.binary 预编译缓存并重新编译所有 includes")
|
||||
stdio.printf("[DBG] after --rebuild-includes\n")
|
||||
stdio.fflush(0)
|
||||
parser.add_argument("--clear-cache", None, argparse.BOOL, 0, None, False,
|
||||
argparse.STORE_TRUE, "清除 .transpyc_cache 全局缓存")
|
||||
stdio.printf("[DBG] after --clear-cache\n")
|
||||
stdio.fflush(0)
|
||||
|
||||
# 解析命令行参数
|
||||
stdio.printf("[DBG] before parse_args\n")
|
||||
stdio.fflush(0)
|
||||
args: argparse.ParsedArgs | t.CPtr = parser.parse_args(sys._argc, sys._argv)
|
||||
stdio.printf("[DBG] after parse_args args=%p\n", args)
|
||||
stdio.fflush(0)
|
||||
if args is None:
|
||||
if log is not None:
|
||||
log.error("参数解析失败", "argparse")
|
||||
@@ -244,13 +187,10 @@ def main() -> int:
|
||||
proj_loaded: int = 0
|
||||
proj_path: str = project
|
||||
if proj_path is not None:
|
||||
stdio.printf("[DBG] before Load_project_config path=%s\n", proj_path)
|
||||
stdio.fflush(0)
|
||||
if log is not None:
|
||||
log.banner("工程配置")
|
||||
if Config.Load_project_config(proj_path) == 0:
|
||||
stdio.printf("[DBG] Load_project_config OK\n")
|
||||
stdio.fflush(0)
|
||||
cfg_ret: int = Config.Load_project_config(proj_path)
|
||||
if cfg_ret == 0:
|
||||
proj_loaded = 1
|
||||
else:
|
||||
if log is not None:
|
||||
@@ -284,14 +224,8 @@ def main() -> int:
|
||||
if proj_dir is not None:
|
||||
string.memcpy(proj_dir, proj_path, slash_pos)
|
||||
proj_dir[slash_pos] = '\0'
|
||||
stdio.printf("[DBG] before resolve_paths dir=%s\n", proj_dir)
|
||||
stdio.fflush(0)
|
||||
Config.resolve_paths(proj_dir)
|
||||
stdio.printf("[DBG] resolve_paths OK\n")
|
||||
stdio.fflush(0)
|
||||
Config.print_config()
|
||||
stdio.printf("[DBG] print_config OK\n")
|
||||
stdio.fflush(0)
|
||||
|
||||
# === --clean: 清理 temp 和 output 目录 ===
|
||||
if _gb_clean:
|
||||
@@ -321,9 +255,10 @@ def main() -> int:
|
||||
phase_mode = "all"
|
||||
do_phase1: int = 0
|
||||
do_phase2: int = 0
|
||||
if phase_mode == "1" or phase_mode == "all":
|
||||
# 注意: 使用 string.strcmp 而非 ==,避免编译器 == 语义 bug
|
||||
if string.strcmp(phase_mode, "1") == 0 or string.strcmp(phase_mode, "all") == 0:
|
||||
do_phase1 = 1
|
||||
if phase_mode == "2" or phase_mode == "all":
|
||||
if string.strcmp(phase_mode, "2") == 0 or string.strcmp(phase_mode, "all") == 0:
|
||||
do_phase2 = 1
|
||||
if log is not None:
|
||||
fb3: t.CChar | t.CPtr = VLogger.fmt_buf()
|
||||
@@ -337,11 +272,7 @@ def main() -> int:
|
||||
ph1_temp: str = Config.TempDir
|
||||
if ph1_temp is None:
|
||||
ph1_temp = "."
|
||||
stdio.printf("[DBG] before Phase1.RunPhase1 inc=%s temp=%s\n", Config.IncludesDir, ph1_temp)
|
||||
stdio.fflush(0)
|
||||
Phase1.RunPhase1(mb, Config.IncludesDir, ph1_temp, log)
|
||||
stdio.printf("[DBG] Phase1.RunPhase1 OK\n")
|
||||
stdio.fflush(0)
|
||||
# 如果仅 Phase1(不执行 Phase2),直接退出
|
||||
if do_phase2 == 0:
|
||||
if log is not None:
|
||||
@@ -363,14 +294,10 @@ def main() -> int:
|
||||
mf_linker_out: str = Config.LinkerOutput if Config.LinkerOutput is not None else "app.exe"
|
||||
mf_includes_bin: str = Config.get_includes_binary_dir()
|
||||
|
||||
stdio.printf("[DBG] before Phase2.RunMultiFileProject src=%s temp=%s out=%s\n", Config.SourceDir, mf_temp, mf_output)
|
||||
stdio.fflush(0)
|
||||
mf_ret: int = Phase2.RunMultiFileProject(
|
||||
mb, Config.SourceDir, mf_temp, mf_output,
|
||||
mf_cc, mf_cc_flags, mf_linker, mf_linker_flags, mf_linker_out,
|
||||
mf_includes_bin, Config.IncludesDir, do_phase1, do_phase2, log, args)
|
||||
stdio.printf("[DBG] Phase2.RunMultiFileProject OK ret=%d\n", mf_ret)
|
||||
stdio.fflush(0)
|
||||
argparse.release(args)
|
||||
if log is not None:
|
||||
log.success("TransPyV 完成")
|
||||
|
||||
Reference in New Issue
Block a user