diff --git a/lib/core/Handles/HandlesExprBuiltin.py b/lib/core/Handles/HandlesExprBuiltin.py index bab40b9..848ce25 100644 --- a/lib/core/Handles/HandlesExprBuiltin.py +++ b/lib/core/Handles/HandlesExprBuiltin.py @@ -737,6 +737,14 @@ class ExprBuiltinHandle(BaseHandle): result = self.Trans.ExprUtils._try_operator_overLoad(_matched_cn, '__len__', val, Gen) if result is not None: return result + if _matched_cn.startswith('list['): + _count_off: int | None = Gen._get_member_offset('__count__', _matched_cn, pointee) + if _count_off is not None: + _count_ptr = Gen.builder.gep( + val, + [ir.Constant(ir.IntType(32), 0), ir.Constant(ir.IntType(32), _count_off)], + name='list_count_ptr') + return Gen._load(_count_ptr, name='list_count') self._FailFastLenUnsupported(arg_node, Gen, val, f"len() 参数类型 '{_matched_cn}' 没有 __len__ 方法") else: # 未在 Gen.structs 登记的 struct(opaque/匿名)→ fail-fast。 diff --git a/lib/core/Handles/HandlesExprCall.py b/lib/core/Handles/HandlesExprCall.py index 00b7b0a..b5107ad 100644 --- a/lib/core/Handles/HandlesExprCall.py +++ b/lib/core/Handles/HandlesExprCall.py @@ -4120,6 +4120,14 @@ class ExprCallHandle(BaseHandle): result = self.Trans.ExprUtils._try_operator_overLoad(_matched_cn, '__len__', val, Gen) if result is not None: return result + if _matched_cn.startswith('list['): + _count_off: int | None = Gen._get_member_offset('__count__', _matched_cn, pointee) + if _count_off is not None: + _count_ptr = Gen.builder.gep( + val, + [ir.Constant(ir.IntType(32), 0), ir.Constant(ir.IntType(32), _count_off)], + name='list_count_ptr') + return Gen._load(_count_ptr, name='list_count') self._FailFastLenUnsupported(arg_node, Gen, val, f"len() 参数类型 '{_matched_cn}' 没有 __len__ 方法") else: # 未在 Gen.structs 登记的 struct(opaque/匿名)→ fail-fast。