From d227bee139592975f60542357f07d35a76034fbe Mon Sep 17 00:00:00 2001 From: TermiNexus Date: Thu, 30 Jul 2026 16:34:50 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=86=20.py=20=E5=92=8C=20.pyi=20=E5=90=8E?= =?UTF-8?q?=E7=BC=80=E5=90=8D=E6=94=B9=E4=B8=BA=E4=BA=86=20.vp=20=E5=92=8C?= =?UTF-8?q?=20.vpi=20=E5=90=8E=E7=BC=80=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- App/lib/Projectrans/{Config.py => Config.vp} | 0 App/lib/Projectrans/{Utils.py => Utils.vp} | 0 .../Projectrans/{__init__.py => __init__.vp} | 0 .../StubGen/{Converter.py => Converter.vp} | 0 App/lib/StubGen/{__init__.py => __init__.vp} | 0 App/lib/{__init__.py => __init__.vp} | 0 .../{BuildPipeline.py => BuildPipeline.vp} | 0 ...andlesAnnAssign.py => HandlesAnnAssign.vp} | 0 .../{HandlesAssign.py => HandlesAssign.vp} | 0 ...andlesAugAssign.py => HandlesAugAssign.vp} | 0 .../{HandlesBase.py => HandlesBase.vp} | 0 .../{HandlesBody.py => HandlesBody.vp} | 0 ...{HandlesClassDef.py => HandlesClassDef.vp} | 0 .../{HandlesEnum.py => HandlesEnum.vp} | 0 .../{HandlesExpr.py => HandlesExpr.vp} | 10 ++++---- ...{HandlesExprCall.py => HandlesExprCall.vp} | 0 .../{HandlesExprOps.py => HandlesExprOps.vp} | 0 .../Handles/{HandlesFor.py => HandlesFor.vp} | 0 ...andlesFunctions.py => HandlesFunctions.vp} | 0 .../Handles/{HandlesIf.py => HandlesIf.vp} | 0 .../{HandlesImports.py => HandlesImports.vp} | 0 .../{HandlesMain.py => HandlesMain.vp} | 0 ...{HandlesNonlocal.py => HandlesNonlocal.vp} | 0 .../{HandlesReturn.py => HandlesReturn.vp} | 0 .../{HandlesStruct.py => HandlesStruct.vp} | 0 ...dlesTranslator.py => HandlesTranslator.vp} | 0 .../{HandlesType.py => HandlesType.vp} | 0 .../Handles/{HandlesVar.py => HandlesVar.vp} | 0 .../{HandlesWhile.py => HandlesWhile.vp} | 0 .../core/Handles/{__init__.py => __init__.vp} | 0 ...{IncludesScanner.py => IncludesScanner.vp} | 8 +++---- App/lib/core/{Phase1.py => Phase1.vp} | 4 ++-- App/lib/core/{Phase2.py => Phase2.vp} | 10 ++++---- App/lib/core/{StubMerger.py => StubMerger.vp} | 24 +++++++++++++------ App/lib/core/{VLogger.py => VLogger.vp} | 0 App/lib/core/{__init__.py => __init__.vp} | 0 App/{main.py => main.vp} | 11 +++++++-- Test/App/{asm_test.py => asm_test.vp} | 0 Test/App/{attr_test.py => attr_test.vp} | 0 .../{augassign_test.py => augassign_test.vp} | 0 Test/App/{circ_a.py => circ_a.vp} | 0 Test/App/{circ_b.py => circ_b.vp} | 0 Test/App/{circ_test.py => circ_test.vp} | 0 Test/App/{closure_test.py => closure_test.vp} | 0 Test/App/{deco_test.py => deco_test.vp} | 0 .../{deref_min_test.py => deref_min_test.vp} | 0 Test/App/{deref_test.py => deref_test.vp} | 0 Test/App/{eq_test.py => eq_test.vp} | 0 Test/App/{float_test.py => float_test.vp} | 0 Test/App/{flow_test.py => flow_test.vp} | 0 Test/App/{for_test.py => for_test.vp} | 0 Test/App/{func_test.py => func_test.vp} | 0 ...unc_vtable_test.py => func_vtable_test.vp} | 0 Test/App/{inherit_test.py => inherit_test.vp} | 0 Test/App/{llvmir_test.py => llvmir_test.vp} | 0 .../{namespace_defs.py => namespace_defs.vp} | 0 .../{namespace_test.py => namespace_test.vp} | 0 Test/App/{new_test.py => new_test.vp} | 0 Test/App/{oop_test.py => oop_test.vp} | 0 Test/App/{opovl_test.py => opovl_test.vp} | 0 .../{ptr_only_test.py => ptr_only_test.vp} | 0 Test/App/{ptr_test.py => ptr_test.vp} | 0 Test/App/{simple_test.py => simple_test.vp} | 0 ...{string_min_test.py => string_min_test.vp} | 0 Test/App/{string_test.py => string_test.vp} | 0 Test/App/{struct_test.py => struct_test.vp} | 0 Test/App/{test_main.py => test_main.vp} | 0 .../{testcheck_test.py => testcheck_test.vp} | 0 .../{type_bit_test.py => type_bit_test.vp} | 0 ...patch_test.py => virtual_dispatch_test.vp} | 0 Test/App/{vtable_test.py => vtable_test.vp} | 0 Test/NegativeTest/App/{defs.py => defs.vp} | 0 Test/NegativeTest/App/{main.py => main.vp} | 0 Test/Sha1Test/App/{main.py => main.vp} | 0 74 files changed, 42 insertions(+), 25 deletions(-) rename App/lib/Projectrans/{Config.py => Config.vp} (100%) rename App/lib/Projectrans/{Utils.py => Utils.vp} (100%) rename App/lib/Projectrans/{__init__.py => __init__.vp} (100%) rename App/lib/StubGen/{Converter.py => Converter.vp} (100%) rename App/lib/StubGen/{__init__.py => __init__.vp} (100%) rename App/lib/{__init__.py => __init__.vp} (100%) rename App/lib/core/{BuildPipeline.py => BuildPipeline.vp} (100%) rename App/lib/core/Handles/{HandlesAnnAssign.py => HandlesAnnAssign.vp} (100%) rename App/lib/core/Handles/{HandlesAssign.py => HandlesAssign.vp} (100%) rename App/lib/core/Handles/{HandlesAugAssign.py => HandlesAugAssign.vp} (100%) rename App/lib/core/Handles/{HandlesBase.py => HandlesBase.vp} (100%) rename App/lib/core/Handles/{HandlesBody.py => HandlesBody.vp} (100%) rename App/lib/core/Handles/{HandlesClassDef.py => HandlesClassDef.vp} (100%) rename App/lib/core/Handles/{HandlesEnum.py => HandlesEnum.vp} (100%) rename App/lib/core/Handles/{HandlesExpr.py => HandlesExpr.vp} (99%) rename App/lib/core/Handles/{HandlesExprCall.py => HandlesExprCall.vp} (100%) rename App/lib/core/Handles/{HandlesExprOps.py => HandlesExprOps.vp} (100%) rename App/lib/core/Handles/{HandlesFor.py => HandlesFor.vp} (100%) rename App/lib/core/Handles/{HandlesFunctions.py => HandlesFunctions.vp} (100%) rename App/lib/core/Handles/{HandlesIf.py => HandlesIf.vp} (100%) rename App/lib/core/Handles/{HandlesImports.py => HandlesImports.vp} (100%) rename App/lib/core/Handles/{HandlesMain.py => HandlesMain.vp} (100%) rename App/lib/core/Handles/{HandlesNonlocal.py => HandlesNonlocal.vp} (100%) rename App/lib/core/Handles/{HandlesReturn.py => HandlesReturn.vp} (100%) rename App/lib/core/Handles/{HandlesStruct.py => HandlesStruct.vp} (100%) rename App/lib/core/Handles/{HandlesTranslator.py => HandlesTranslator.vp} (100%) rename App/lib/core/Handles/{HandlesType.py => HandlesType.vp} (100%) rename App/lib/core/Handles/{HandlesVar.py => HandlesVar.vp} (100%) rename App/lib/core/Handles/{HandlesWhile.py => HandlesWhile.vp} (100%) rename App/lib/core/Handles/{__init__.py => __init__.vp} (100%) rename App/lib/core/{IncludesScanner.py => IncludesScanner.vp} (95%) rename App/lib/core/{Phase1.py => Phase1.vp} (99%) rename App/lib/core/{Phase2.py => Phase2.vp} (98%) rename App/lib/core/{StubMerger.py => StubMerger.vp} (98%) rename App/lib/core/{VLogger.py => VLogger.vp} (100%) rename App/lib/core/{__init__.py => __init__.vp} (100%) rename App/{main.py => main.vp} (98%) rename Test/App/{asm_test.py => asm_test.vp} (100%) rename Test/App/{attr_test.py => attr_test.vp} (100%) rename Test/App/{augassign_test.py => augassign_test.vp} (100%) rename Test/App/{circ_a.py => circ_a.vp} (100%) rename Test/App/{circ_b.py => circ_b.vp} (100%) rename Test/App/{circ_test.py => circ_test.vp} (100%) rename Test/App/{closure_test.py => closure_test.vp} (100%) rename Test/App/{deco_test.py => deco_test.vp} (100%) rename Test/App/{deref_min_test.py => deref_min_test.vp} (100%) rename Test/App/{deref_test.py => deref_test.vp} (100%) rename Test/App/{eq_test.py => eq_test.vp} (100%) rename Test/App/{float_test.py => float_test.vp} (100%) rename Test/App/{flow_test.py => flow_test.vp} (100%) rename Test/App/{for_test.py => for_test.vp} (100%) rename Test/App/{func_test.py => func_test.vp} (100%) rename Test/App/{func_vtable_test.py => func_vtable_test.vp} (100%) rename Test/App/{inherit_test.py => inherit_test.vp} (100%) rename Test/App/{llvmir_test.py => llvmir_test.vp} (100%) rename Test/App/{namespace_defs.py => namespace_defs.vp} (100%) rename Test/App/{namespace_test.py => namespace_test.vp} (100%) rename Test/App/{new_test.py => new_test.vp} (100%) rename Test/App/{oop_test.py => oop_test.vp} (100%) rename Test/App/{opovl_test.py => opovl_test.vp} (100%) rename Test/App/{ptr_only_test.py => ptr_only_test.vp} (100%) rename Test/App/{ptr_test.py => ptr_test.vp} (100%) rename Test/App/{simple_test.py => simple_test.vp} (100%) rename Test/App/{string_min_test.py => string_min_test.vp} (100%) rename Test/App/{string_test.py => string_test.vp} (100%) rename Test/App/{struct_test.py => struct_test.vp} (100%) rename Test/App/{test_main.py => test_main.vp} (100%) rename Test/App/{testcheck_test.py => testcheck_test.vp} (100%) rename Test/App/{type_bit_test.py => type_bit_test.vp} (100%) rename Test/App/{virtual_dispatch_test.py => virtual_dispatch_test.vp} (100%) rename Test/App/{vtable_test.py => vtable_test.vp} (100%) rename Test/NegativeTest/App/{defs.py => defs.vp} (100%) rename Test/NegativeTest/App/{main.py => main.vp} (100%) rename Test/Sha1Test/App/{main.py => main.vp} (100%) diff --git a/App/lib/Projectrans/Config.py b/App/lib/Projectrans/Config.vp similarity index 100% rename from App/lib/Projectrans/Config.py rename to App/lib/Projectrans/Config.vp diff --git a/App/lib/Projectrans/Utils.py b/App/lib/Projectrans/Utils.vp similarity index 100% rename from App/lib/Projectrans/Utils.py rename to App/lib/Projectrans/Utils.vp diff --git a/App/lib/Projectrans/__init__.py b/App/lib/Projectrans/__init__.vp similarity index 100% rename from App/lib/Projectrans/__init__.py rename to App/lib/Projectrans/__init__.vp diff --git a/App/lib/StubGen/Converter.py b/App/lib/StubGen/Converter.vp similarity index 100% rename from App/lib/StubGen/Converter.py rename to App/lib/StubGen/Converter.vp diff --git a/App/lib/StubGen/__init__.py b/App/lib/StubGen/__init__.vp similarity index 100% rename from App/lib/StubGen/__init__.py rename to App/lib/StubGen/__init__.vp diff --git a/App/lib/__init__.py b/App/lib/__init__.vp similarity index 100% rename from App/lib/__init__.py rename to App/lib/__init__.vp diff --git a/App/lib/core/BuildPipeline.py b/App/lib/core/BuildPipeline.vp similarity index 100% rename from App/lib/core/BuildPipeline.py rename to App/lib/core/BuildPipeline.vp diff --git a/App/lib/core/Handles/HandlesAnnAssign.py b/App/lib/core/Handles/HandlesAnnAssign.vp similarity index 100% rename from App/lib/core/Handles/HandlesAnnAssign.py rename to App/lib/core/Handles/HandlesAnnAssign.vp diff --git a/App/lib/core/Handles/HandlesAssign.py b/App/lib/core/Handles/HandlesAssign.vp similarity index 100% rename from App/lib/core/Handles/HandlesAssign.py rename to App/lib/core/Handles/HandlesAssign.vp diff --git a/App/lib/core/Handles/HandlesAugAssign.py b/App/lib/core/Handles/HandlesAugAssign.vp similarity index 100% rename from App/lib/core/Handles/HandlesAugAssign.py rename to App/lib/core/Handles/HandlesAugAssign.vp diff --git a/App/lib/core/Handles/HandlesBase.py b/App/lib/core/Handles/HandlesBase.vp similarity index 100% rename from App/lib/core/Handles/HandlesBase.py rename to App/lib/core/Handles/HandlesBase.vp diff --git a/App/lib/core/Handles/HandlesBody.py b/App/lib/core/Handles/HandlesBody.vp similarity index 100% rename from App/lib/core/Handles/HandlesBody.py rename to App/lib/core/Handles/HandlesBody.vp diff --git a/App/lib/core/Handles/HandlesClassDef.py b/App/lib/core/Handles/HandlesClassDef.vp similarity index 100% rename from App/lib/core/Handles/HandlesClassDef.py rename to App/lib/core/Handles/HandlesClassDef.vp diff --git a/App/lib/core/Handles/HandlesEnum.py b/App/lib/core/Handles/HandlesEnum.vp similarity index 100% rename from App/lib/core/Handles/HandlesEnum.py rename to App/lib/core/Handles/HandlesEnum.vp diff --git a/App/lib/core/Handles/HandlesExpr.py b/App/lib/core/Handles/HandlesExpr.vp similarity index 99% rename from App/lib/core/Handles/HandlesExpr.py rename to App/lib/core/Handles/HandlesExpr.vp index 8bbda11..9b950a9 100644 --- a/App/lib/core/Handles/HandlesExpr.py +++ b/App/lib/core/Handles/HandlesExpr.vp @@ -1267,13 +1267,13 @@ def _lookup_cross_module_cdefine(pool: memhub.MemBuddy | t.CPtr, if temp_dir is None: return -1 - # 6. 构建 pyi 文件路径 + # 6. 构建 vpi 文件路径 td_len: t.CSizeT = string.strlen(temp_dir) - pyi_path: str = StubMerger._sliced_path(temp_dir, td_len, sha1, "pyi") + pyi_path: str = StubMerger._sliced_path(temp_dir, td_len, sha1, "vpi") if pyi_path is None: return -1 - # 7. 读取 pyi 文件;若不存在或内容过短(空 stub)则回退读取源 .py 文件 + # 7. 读取 vpi 文件;若不存在或内容过短(空 stub)则回退读取源 .py 文件 PYI_READ_BUF_SIZE: t.CSizeT = 65536 pyi_buf: bytes = stdlib.malloc(PYI_READ_BUF_SIZE) if pyi_buf is None: @@ -1283,12 +1283,12 @@ def _lookup_cross_module_cdefine(pool: memhub.MemBuddy | t.CPtr, need_py_fallback: int = 0 bytes_read: LONG = 0 if pf.closed: - # .pyi 文件不存在:回退读取源 .py 文件 + # .vpi 文件不存在:回退读取源 .py 文件 need_py_fallback = 1 else: bytes_read = pf.read_all(pyi_buf, PYI_READ_BUF_SIZE) pf.close() - # pyi 内容过短(< 10 字节)视为空 stub,回退 .py + # vpi 内容过短(< 10 字节)视为空 stub,回退 .py if bytes_read < 10: need_py_fallback = 1 else: diff --git a/App/lib/core/Handles/HandlesExprCall.py b/App/lib/core/Handles/HandlesExprCall.vp similarity index 100% rename from App/lib/core/Handles/HandlesExprCall.py rename to App/lib/core/Handles/HandlesExprCall.vp diff --git a/App/lib/core/Handles/HandlesExprOps.py b/App/lib/core/Handles/HandlesExprOps.vp similarity index 100% rename from App/lib/core/Handles/HandlesExprOps.py rename to App/lib/core/Handles/HandlesExprOps.vp diff --git a/App/lib/core/Handles/HandlesFor.py b/App/lib/core/Handles/HandlesFor.vp similarity index 100% rename from App/lib/core/Handles/HandlesFor.py rename to App/lib/core/Handles/HandlesFor.vp diff --git a/App/lib/core/Handles/HandlesFunctions.py b/App/lib/core/Handles/HandlesFunctions.vp similarity index 100% rename from App/lib/core/Handles/HandlesFunctions.py rename to App/lib/core/Handles/HandlesFunctions.vp diff --git a/App/lib/core/Handles/HandlesIf.py b/App/lib/core/Handles/HandlesIf.vp similarity index 100% rename from App/lib/core/Handles/HandlesIf.py rename to App/lib/core/Handles/HandlesIf.vp diff --git a/App/lib/core/Handles/HandlesImports.py b/App/lib/core/Handles/HandlesImports.vp similarity index 100% rename from App/lib/core/Handles/HandlesImports.py rename to App/lib/core/Handles/HandlesImports.vp diff --git a/App/lib/core/Handles/HandlesMain.py b/App/lib/core/Handles/HandlesMain.vp similarity index 100% rename from App/lib/core/Handles/HandlesMain.py rename to App/lib/core/Handles/HandlesMain.vp diff --git a/App/lib/core/Handles/HandlesNonlocal.py b/App/lib/core/Handles/HandlesNonlocal.vp similarity index 100% rename from App/lib/core/Handles/HandlesNonlocal.py rename to App/lib/core/Handles/HandlesNonlocal.vp diff --git a/App/lib/core/Handles/HandlesReturn.py b/App/lib/core/Handles/HandlesReturn.vp similarity index 100% rename from App/lib/core/Handles/HandlesReturn.py rename to App/lib/core/Handles/HandlesReturn.vp diff --git a/App/lib/core/Handles/HandlesStruct.py b/App/lib/core/Handles/HandlesStruct.vp similarity index 100% rename from App/lib/core/Handles/HandlesStruct.py rename to App/lib/core/Handles/HandlesStruct.vp diff --git a/App/lib/core/Handles/HandlesTranslator.py b/App/lib/core/Handles/HandlesTranslator.vp similarity index 100% rename from App/lib/core/Handles/HandlesTranslator.py rename to App/lib/core/Handles/HandlesTranslator.vp diff --git a/App/lib/core/Handles/HandlesType.py b/App/lib/core/Handles/HandlesType.vp similarity index 100% rename from App/lib/core/Handles/HandlesType.py rename to App/lib/core/Handles/HandlesType.vp diff --git a/App/lib/core/Handles/HandlesVar.py b/App/lib/core/Handles/HandlesVar.vp similarity index 100% rename from App/lib/core/Handles/HandlesVar.py rename to App/lib/core/Handles/HandlesVar.vp diff --git a/App/lib/core/Handles/HandlesWhile.py b/App/lib/core/Handles/HandlesWhile.vp similarity index 100% rename from App/lib/core/Handles/HandlesWhile.py rename to App/lib/core/Handles/HandlesWhile.vp diff --git a/App/lib/core/Handles/__init__.py b/App/lib/core/Handles/__init__.vp similarity index 100% rename from App/lib/core/Handles/__init__.py rename to App/lib/core/Handles/__init__.vp diff --git a/App/lib/core/IncludesScanner.py b/App/lib/core/IncludesScanner.vp similarity index 95% rename from App/lib/core/IncludesScanner.py rename to App/lib/core/IncludesScanner.vp index 8d317e3..c03793c 100644 --- a/App/lib/core/IncludesScanner.py +++ b/App/lib/core/IncludesScanner.vp @@ -101,9 +101,9 @@ def add_file_entry(result: ScanResult | t.CPtr, ch: t.CChar = mod_buf[i] if ch == '/' or ch == '\\': mod_buf[i] = '.' - # 去掉 .py 扩展名 + # 去掉 .vp 或 .py 扩展名(.vp 为 Viper 源,.py 向后兼容) if rel_len >= 3: - if mod_buf[rel_len - 3] == '.' and mod_buf[rel_len - 2] == 'p' and mod_buf[rel_len - 1] == 'y': + if (mod_buf[rel_len - 3] == '.' and mod_buf[rel_len - 2] == 'v' and mod_buf[rel_len - 1] == 'p') or (mod_buf[rel_len - 3] == '.' and mod_buf[rel_len - 2] == 'p' and mod_buf[rel_len - 1] == 'y'): mod_buf[rel_len - 3] = '\0' # 获取条目地址 @@ -295,10 +295,10 @@ def scan_directory_recursive(pool: memhub.MemBuddy | t.CPtr, # 递归扫描子目录 scan_directory_recursive(pool, full_path, rel_path, result) else: - # 检查是否为 .py 文件 + # 检查是否为 .vp 或 .py 文件(.vp 为 Viper 源,.py 向后兼容) is_py: int = 0 if fname_len >= 3: - if fname[fname_len - 3] == '.' and fname[fname_len - 2] == 'p' and fname[fname_len - 1] == 'y': + if (fname[fname_len - 3] == '.' and fname[fname_len - 2] == 'v' and fname[fname_len - 1] == 'p') or (fname[fname_len - 3] == '.' and fname[fname_len - 2] == 'p' and fname[fname_len - 1] == 'y'): is_py = 1 if is_py != 0: diff --git a/App/lib/core/Phase1.py b/App/lib/core/Phase1.vp similarity index 99% rename from App/lib/core/Phase1.py rename to App/lib/core/Phase1.vp index c741a8d..899a864 100644 --- a/App/lib/core/Phase1.py +++ b/App/lib/core/Phase1.vp @@ -1082,12 +1082,12 @@ def RunPhase1(mb: memhub.MemBuddy | t.CPtr, includes_dir: str, temp_dir: str, failed += 1 continue - # 生成 .pyi 存根文件(直接遍历 AST,不依赖 PythonToStubConverter) + # 生成 .vpi 存根文件(直接遍历 AST,不依赖 PythonToStubConverter) pyi_buf: bytes = stdlib.malloc(PYI_BUF_SIZE) if pyi_buf is not None: pyi_pos: t.CSizeT = StubConverter._GeneratePyiFromAst(mb, tree, entry.RelPath, pyi_buf, PYI_BUF_SIZE) if pyi_pos > 0: - pyi_path: str = StubMerger._sliced_path(temp_dir, dir_len, sha1, "pyi") + pyi_path: str = StubMerger._sliced_path(temp_dir, dir_len, sha1, "vpi") if pyi_path is not None: pf: fileio.File | t.CPtr = fileio.File(pyi_path, fileio.MODE.W) if not pf.closed: diff --git a/App/lib/core/Phase2.py b/App/lib/core/Phase2.vp similarity index 98% rename from App/lib/core/Phase2.py rename to App/lib/core/Phase2.vp index 0b1593a..567f08b 100644 --- a/App/lib/core/Phase2.py +++ b/App/lib/core/Phase2.vp @@ -117,9 +117,9 @@ def _ScanDirForPyFiles(mb: memhub.MemBuddy | t.CPtr, file_count = _ScanDirForPyFiles(mb, sub_dir, entries, entry_size, file_count, max_files) stdlib.free(sub_dir) else: - # 检查是否是 .py 文件 + # 检查是否是 .vp 或 .py 文件(.vp 为 Viper 源,.py 向后兼容) if fname_len > 3: - if fname[fname_len - 3] == '.' and fname[fname_len - 2] == 'p' and fname[fname_len - 1] == 'y': + if (fname[fname_len - 3] == '.' and fname[fname_len - 2] == 'v' and fname[fname_len - 1] == 'p') or (fname[fname_len - 3] == '.' and fname[fname_len - 2] == 'p' and fname[fname_len - 1] == 'y'): if file_count < max_files: full_path: bytes = stdlib.malloc(dir_len + fname_len + 2) if full_path is not None: @@ -556,12 +556,12 @@ def RunMultiFileProject(mb: memhub.MemBuddy | t.CPtr, if fb_comp is not None: viperlib.snprintf(fb_comp, 1024, "[%d/%d] 编译完成: %s", i + 1, file_count, ent.Path) VLogger.info(fb_comp, "PhaseB") - # 构造 .obj 路径,检测是否是 main 模块(test_main.py 或 main.py) + # 构造 .obj 路径,检测是否是 main 模块(test_main.vp/.py 或 main.vp/.py) od_len: t.CSizeT = string.strlen(output_dir) is_main_mod: int = 0 - if string.strstr(ent.Path, "test_main.py") is not None: + if string.strstr(ent.Path, "test_main.vp") is not None or string.strstr(ent.Path, "test_main.py") is not None: is_main_mod = 1 - elif string.strstr(ent.Path, "main.py") is not None: + elif string.strstr(ent.Path, "main.vp") is not None or string.strstr(ent.Path, "main.py") is not None: is_main_mod = 1 # 切片路径: output_dir/{sha1前缀}/{sha1}.obj diff --git a/App/lib/core/StubMerger.py b/App/lib/core/StubMerger.vp similarity index 98% rename from App/lib/core/StubMerger.py rename to App/lib/core/StubMerger.vp index 04e8ccc..3833d3a 100644 --- a/App/lib/core/StubMerger.py +++ b/App/lib/core/StubMerger.vp @@ -1219,9 +1219,10 @@ def _PathToModuleName(path: str) -> str: if psep_ch == '/' or psep_ch == '\\': path_start = prefix_len plen = plen - prefix_len - # 去掉 .py 后缀 - if plen > 3 and path[path_start + plen - 3] == '.' and path[path_start + plen - 2] == 'p' and path[path_start + plen - 1] == 'y': - plen -= 3 + # 去掉 .vp 或 .py 后缀(.vp 为 Viper 源,.py 向后兼容) + if plen > 3: + if (path[path_start + plen - 3] == '.' and path[path_start + plen - 2] == 'v' and path[path_start + plen - 1] == 'p') or (path[path_start + plen - 3] == '.' and path[path_start + plen - 2] == 'p' and path[path_start + plen - 1] == 'y'): + plen -= 3 if plen == 0: return None # 检查是否以 /__init__ 或 \__init__ 结尾(包的 __init__.py) @@ -1446,7 +1447,7 @@ def _BuildReachableSha1Set(mb: memhub.MemBuddy | t.CPtr, source_dir: str, stdlib.free(mod_arr) stdlib.free(worklist) return -1 - viperlib.snprintf(pattern, dir_len + 8, "%s/*.py", source_dir) + viperlib.snprintf(pattern, dir_len + 8, "%s/*", source_dir) find_data_size: t.CSizeT = win32file.WIN32_FIND_DATAA.__sizeof__() find_data: win32file.WIN32_FIND_DATAA | t.CPtr = stdlib.malloc(find_data_size + 16) @@ -1462,7 +1463,7 @@ def _BuildReachableSha1Set(mb: memhub.MemBuddy | t.CPtr, source_dir: str, if handle == win32base.INVALID_HANDLE_VALUE: fb_fd: t.CChar | t.CPtr = VLogger.fmt_buf() if fb_fd is not None: - viperlib.snprintf(fb_fd, 1024, "未找到 .py 文件: %s", pattern) + viperlib.snprintf(fb_fd, 1024, "未找到源文件(.vp/.py): %s", pattern) VLogger.warning(fb_fd, "Reachable") stdlib.free(pattern) stdlib.free(find_data) @@ -1477,7 +1478,8 @@ def _BuildReachableSha1Set(mb: memhub.MemBuddy | t.CPtr, source_dir: str, fname_len: t.CSizeT = string.strlen(fname) if fname_len > 3: is_py: int = 0 - if fname[fname_len - 3] == '.' and fname[fname_len - 2] == 'p' and fname[fname_len - 1] == 'y': + # 检查 .vp 或 .py 扩展名(.vp 为 Viper 源,.py 向后兼容) + if (fname[fname_len - 3] == '.' and fname[fname_len - 2] == 'v' and fname[fname_len - 1] == 'p') or (fname[fname_len - 3] == '.' and fname[fname_len - 2] == 'p' and fname[fname_len - 1] == 'y'): is_py = 1 if is_py != 0: full_path: bytes = stdlib.malloc(dir_len + fname_len + 2) @@ -1677,11 +1679,19 @@ def _BuildReachableSha1Set(mb: memhub.MemBuddy | t.CPtr, source_dir: str, app_mod_path: bytes = stdlib.malloc(sd_len_ff + mb_len_ff + 6) is_app_src: int = 0 if app_mod_path is not None: - viperlib.snprintf(app_mod_path, sd_len_ff + mb_len_ff + 6, "%s/%s.py", source_dir, mod_buf) + # 优先尝试 .vp,向后兼容 .py + viperlib.snprintf(app_mod_path, sd_len_ff + mb_len_ff + 6, "%s/%s.vp", source_dir, mod_buf) af: fileio.File | t.CPtr = fileio.File(app_mod_path, fileio.MODE.R) if not af.closed: is_app_src = 1 af.close() + else: + # .vp 不存在,回退 .py + viperlib.snprintf(app_mod_path, sd_len_ff + mb_len_ff + 6, "%s/%s.py", source_dir, mod_buf) + af = fileio.File(app_mod_path, fileio.MODE.R) + if not af.closed: + is_app_src = 1 + af.close() stdlib.free(app_mod_path) if is_app_src != 0: # App 源文件,跳过(不 fast-fail) diff --git a/App/lib/core/VLogger.py b/App/lib/core/VLogger.vp similarity index 100% rename from App/lib/core/VLogger.py rename to App/lib/core/VLogger.vp diff --git a/App/lib/core/__init__.py b/App/lib/core/__init__.vp similarity index 100% rename from App/lib/core/__init__.py rename to App/lib/core/__init__.vp diff --git a/App/main.py b/App/main.vp similarity index 98% rename from App/main.py rename to App/main.vp index 10ac1db..b747af3 100644 --- a/App/main.py +++ b/App/main.vp @@ -315,11 +315,18 @@ def main() -> int: # === 单文件模式:--src 指定时使用指定文件;--project 但无 SourceDir 时回退 === if src_path is None and project is not None: if Config.SourceDir is not None: - # 构造入口路径: SourceDir/main.py + # 构造入口路径: 优先 SourceDir/main.vp,回退 SourceDir/main.py sd_len: t.CSizeT = string.strlen(Config.SourceDir) path_buf: bytes = stdlib.malloc(sd_len + 16) if path_buf is not None: - viperlib.snprintf(path_buf, sd_len + 16, "%s/main.py", Config.SourceDir) + # 优先尝试 main.vp + viperlib.snprintf(path_buf, sd_len + 16, "%s/main.vp", Config.SourceDir) + ef: fileio.File | t.CPtr = fileio.File(path_buf, fileio.MODE.R) + if ef.closed: + # .vp 不存在,回退 main.py + viperlib.snprintf(path_buf, sd_len + 16, "%s/main.py", Config.SourceDir) + else: + ef.close() src_path = path_buf if log is not None: fb4: t.CChar | t.CPtr = VLogger.fmt_buf() diff --git a/Test/App/asm_test.py b/Test/App/asm_test.vp similarity index 100% rename from Test/App/asm_test.py rename to Test/App/asm_test.vp diff --git a/Test/App/attr_test.py b/Test/App/attr_test.vp similarity index 100% rename from Test/App/attr_test.py rename to Test/App/attr_test.vp diff --git a/Test/App/augassign_test.py b/Test/App/augassign_test.vp similarity index 100% rename from Test/App/augassign_test.py rename to Test/App/augassign_test.vp diff --git a/Test/App/circ_a.py b/Test/App/circ_a.vp similarity index 100% rename from Test/App/circ_a.py rename to Test/App/circ_a.vp diff --git a/Test/App/circ_b.py b/Test/App/circ_b.vp similarity index 100% rename from Test/App/circ_b.py rename to Test/App/circ_b.vp diff --git a/Test/App/circ_test.py b/Test/App/circ_test.vp similarity index 100% rename from Test/App/circ_test.py rename to Test/App/circ_test.vp diff --git a/Test/App/closure_test.py b/Test/App/closure_test.vp similarity index 100% rename from Test/App/closure_test.py rename to Test/App/closure_test.vp diff --git a/Test/App/deco_test.py b/Test/App/deco_test.vp similarity index 100% rename from Test/App/deco_test.py rename to Test/App/deco_test.vp diff --git a/Test/App/deref_min_test.py b/Test/App/deref_min_test.vp similarity index 100% rename from Test/App/deref_min_test.py rename to Test/App/deref_min_test.vp diff --git a/Test/App/deref_test.py b/Test/App/deref_test.vp similarity index 100% rename from Test/App/deref_test.py rename to Test/App/deref_test.vp diff --git a/Test/App/eq_test.py b/Test/App/eq_test.vp similarity index 100% rename from Test/App/eq_test.py rename to Test/App/eq_test.vp diff --git a/Test/App/float_test.py b/Test/App/float_test.vp similarity index 100% rename from Test/App/float_test.py rename to Test/App/float_test.vp diff --git a/Test/App/flow_test.py b/Test/App/flow_test.vp similarity index 100% rename from Test/App/flow_test.py rename to Test/App/flow_test.vp diff --git a/Test/App/for_test.py b/Test/App/for_test.vp similarity index 100% rename from Test/App/for_test.py rename to Test/App/for_test.vp diff --git a/Test/App/func_test.py b/Test/App/func_test.vp similarity index 100% rename from Test/App/func_test.py rename to Test/App/func_test.vp diff --git a/Test/App/func_vtable_test.py b/Test/App/func_vtable_test.vp similarity index 100% rename from Test/App/func_vtable_test.py rename to Test/App/func_vtable_test.vp diff --git a/Test/App/inherit_test.py b/Test/App/inherit_test.vp similarity index 100% rename from Test/App/inherit_test.py rename to Test/App/inherit_test.vp diff --git a/Test/App/llvmir_test.py b/Test/App/llvmir_test.vp similarity index 100% rename from Test/App/llvmir_test.py rename to Test/App/llvmir_test.vp diff --git a/Test/App/namespace_defs.py b/Test/App/namespace_defs.vp similarity index 100% rename from Test/App/namespace_defs.py rename to Test/App/namespace_defs.vp diff --git a/Test/App/namespace_test.py b/Test/App/namespace_test.vp similarity index 100% rename from Test/App/namespace_test.py rename to Test/App/namespace_test.vp diff --git a/Test/App/new_test.py b/Test/App/new_test.vp similarity index 100% rename from Test/App/new_test.py rename to Test/App/new_test.vp diff --git a/Test/App/oop_test.py b/Test/App/oop_test.vp similarity index 100% rename from Test/App/oop_test.py rename to Test/App/oop_test.vp diff --git a/Test/App/opovl_test.py b/Test/App/opovl_test.vp similarity index 100% rename from Test/App/opovl_test.py rename to Test/App/opovl_test.vp diff --git a/Test/App/ptr_only_test.py b/Test/App/ptr_only_test.vp similarity index 100% rename from Test/App/ptr_only_test.py rename to Test/App/ptr_only_test.vp diff --git a/Test/App/ptr_test.py b/Test/App/ptr_test.vp similarity index 100% rename from Test/App/ptr_test.py rename to Test/App/ptr_test.vp diff --git a/Test/App/simple_test.py b/Test/App/simple_test.vp similarity index 100% rename from Test/App/simple_test.py rename to Test/App/simple_test.vp diff --git a/Test/App/string_min_test.py b/Test/App/string_min_test.vp similarity index 100% rename from Test/App/string_min_test.py rename to Test/App/string_min_test.vp diff --git a/Test/App/string_test.py b/Test/App/string_test.vp similarity index 100% rename from Test/App/string_test.py rename to Test/App/string_test.vp diff --git a/Test/App/struct_test.py b/Test/App/struct_test.vp similarity index 100% rename from Test/App/struct_test.py rename to Test/App/struct_test.vp diff --git a/Test/App/test_main.py b/Test/App/test_main.vp similarity index 100% rename from Test/App/test_main.py rename to Test/App/test_main.vp diff --git a/Test/App/testcheck_test.py b/Test/App/testcheck_test.vp similarity index 100% rename from Test/App/testcheck_test.py rename to Test/App/testcheck_test.vp diff --git a/Test/App/type_bit_test.py b/Test/App/type_bit_test.vp similarity index 100% rename from Test/App/type_bit_test.py rename to Test/App/type_bit_test.vp diff --git a/Test/App/virtual_dispatch_test.py b/Test/App/virtual_dispatch_test.vp similarity index 100% rename from Test/App/virtual_dispatch_test.py rename to Test/App/virtual_dispatch_test.vp diff --git a/Test/App/vtable_test.py b/Test/App/vtable_test.vp similarity index 100% rename from Test/App/vtable_test.py rename to Test/App/vtable_test.vp diff --git a/Test/NegativeTest/App/defs.py b/Test/NegativeTest/App/defs.vp similarity index 100% rename from Test/NegativeTest/App/defs.py rename to Test/NegativeTest/App/defs.vp diff --git a/Test/NegativeTest/App/main.py b/Test/NegativeTest/App/main.vp similarity index 100% rename from Test/NegativeTest/App/main.py rename to Test/NegativeTest/App/main.vp diff --git a/Test/Sha1Test/App/main.py b/Test/Sha1Test/App/main.vp similarity index 100% rename from Test/Sha1Test/App/main.py rename to Test/Sha1Test/App/main.vp