fix(match,sizeof): 修复 MatchClass 属性名与 LLVM 基本类型 sizeof

Match 分支改用 c.pattern;__sizeof__ 对 i1/i8/i16/i32/i64/f32/f64/ptr 直接返回字节数。
This commit is contained in:
TermiNexus committed 2026-10-18 20:13:37 +08:00
1 parent 369afb5011
commit da638a018b
3 files changed
+14 -2

No files matched your search

+6
View File
@@ -820,6 +820,12 @@ class ExprBuiltinHandle(BaseHandle):
f"({ast.unparse(Node)})不是类型名(Name/Attribute),拒绝静默返回 0"
)
_LLVM_BASIC_SIZES: dict[str, int] = {
'i1': 1, 'i8': 1, 'i16': 2, 'i32': 4, 'i64': 8,
'f32': 4, 'f64': 8, 'ptr': 8,
}
if type_name in _LLVM_BASIC_SIZES:
return ir.Constant(ir.IntType(64), _LLVM_BASIC_SIZES[type_name])
if type_name not in Gen.structs:
# str/bytes 是指针类型 (char*/void*),sizeof = 指针大小
if type_name in ('str', 'bytes'):
+6
View File
@@ -4479,6 +4479,12 @@ class ExprCallHandle(BaseHandle):
f"拒绝静默返回 0(会导致 alloc(0))"
)
_LLVM_BASIC_SIZES: dict[str, int] = {
'i1': 1, 'i8': 1, 'i16': 2, 'i32': 4, 'i64': 8,
'f32': 4, 'f64': 8, 'ptr': 8,
}
if type_name in _LLVM_BASIC_SIZES:
return ir.Constant(ir.IntType(64), _LLVM_BASIC_SIZES[type_name])
if type_name not in Gen.structs:
# SHA1 前缀查找:如 ClassDef → 657e182b27c2a022.ClassDef
struct_sha1_map = getattr(Gen, '_struct_sha1_map', {})
+2 -2
View File
@@ -350,7 +350,7 @@ class MatchHandle(BaseHandle):
if not HasDefault:
Gen.builder.position_at_start(DefaultBB)
Gen.builder.branch(AfterBB)
elif not any(isinstance(pattern, ast.MatchAs) and c.pattern.pattern is None for c in Node.cases) and not any(isinstance(pattern, ast.MatchSequence) for c in Node.cases):
elif not any(isinstance(c.pattern, ast.MatchAs) and c.pattern.pattern is None for c in Node.cases) and not any(isinstance(c.pattern, ast.MatchSequence) for c in Node.cases):
Gen.builder.position_at_start(DefaultBB)
Gen.builder.branch(AfterBB)
Gen.builder.position_at_start(AfterBB)
@@ -600,7 +600,7 @@ class MatchHandle(BaseHandle):
if not HasDefault:
Gen.builder.position_at_start(DefaultBB)
Gen.builder.branch(AfterBB)
elif not any(isinstance(pattern, ast.MatchAs) and c.pattern.pattern is None for c in Node.cases) and not any(isinstance(pattern, ast.MatchSequence) for c in Node.cases):
elif not any(isinstance(c.pattern, ast.MatchAs) and c.pattern.pattern is None for c in Node.cases) and not any(isinstance(c.pattern, ast.MatchSequence) for c in Node.cases):
Gen.builder.position_at_start(DefaultBB)
Gen.builder.branch(AfterBB)
Gen.builder.position_at_start(AfterBB)