尝试进行 Qt 测试,增加了 AI 人机调试工具 _console,以及 TransPyV 进行修正

This commit is contained in:
2026-07-21 14:41:22 +08:00
parent a277ded8d4
commit 135aa05485
311 changed files with 7084 additions and 2131 deletions

View File

@@ -165,6 +165,39 @@ class ExprBuiltinHandle(BaseHandle):
return ir.Constant(ir.IntType(8).as_pointer(), None)
elif FuncName == 'input':
return self._HandleInputLlvm(Node)
elif FuncName == 'isinstance':
# isinstance(obj, Type) — 静态类型系统下编译时解析
# TransPyC 是静态类型系统,运行时无 RTTI。
# 对于编译时已知类型,若变量类型是目标类型的子类则生成 true否则 false。
# 若无法确定(如基类指针指向子类),保守生成 false。
# 注意:这主要让编译时辅助方法(如 c.py 中的 Asm._parse_asm_descr能通过编译
# 这些方法不在运行时被调用,行为不正确不影响程序。
if len(Node.args) >= 2:
ObjVal: ir.Value | None = self.HandleExprLlvm(Node.args[0])
TypeNode: ast.expr = Node.args[1]
TargetClassName: str = ''
if isinstance(TypeNode, ast.Name):
TargetClassName = TypeNode.id
elif isinstance(TypeNode, ast.Attribute):
TargetClassName = TypeNode.attr
if ObjVal is not None and TargetClassName:
ObjType: ir.Type = ObjVal.type
# 解引用指针获取 pointee 类型
if isinstance(ObjType, ir.PointerType):
ObjType = ObjType.pointee
# 检查 pointee 是否是目标结构体类型
if isinstance(ObjType, ir.IdentifiedStructType):
ObjStructName: str = getattr(ObjType, 'name', '')
ShortName: str = ObjStructName.split('.')[-1] if '.' in ObjStructName else ObjStructName
if ShortName == TargetClassName:
return ir.Constant(ir.IntType(1), 1)
# 检查 Gen.var_struct_class
if isinstance(Node.args[0], ast.Name):
VarClassName: str | None = Gen.var_struct_class.get(Node.args[0].id)
if VarClassName == TargetClassName:
return ir.Constant(ir.IntType(1), 1)
return ir.Constant(ir.IntType(1), 0)
return ir.Constant(ir.IntType(1), 0)
elif FuncName == 'ord':
if Node.args:
return self._HandleOrdLlvm(Node.args[0])