Files
ViperC/App/lib/core/CompilerFactory.vp
T

44 lines
2.1 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import t, c
import memhub
# ============================================================
# CompilerFactory - 编译器结构体工厂(对齐 TPC Translator 装配模式)
#
# TPC 的 Translator 在 __init__ 集中创建编译器各子对象(Handler/
# SymbolTable/Exportable 等),是编译器的"装配器/工厂";TPV 的 main
# 目前手动创建 mb/gen 并逐模块注入(_mbuddy/set_global_gen),装配
# 逻辑散落。本工厂集中持有编译器级共享内存对象:
#
# - Pool :主内存池(MemBuddy,瞬时数据,受 mark/reset_to 回收)
# - PermPool :永久内存池(MemBuddy,跨 mark 持久数据专用,从不 reset)
#
# 各模块经模块级委托 CompilerFactory.PermPool 获取永久池,
# 避免把编译器专属单例塞进通用内存库 memhub(memhub 保持通用)。
# includes 层(llvmlite/__types.vp 的 DeepCopyType)不依赖本工厂:
# 深拷贝的分配源由调用方以 pool 参数传入(传 PermPool 即持久)。
# 类名与模块名同名(均为 CompilerFactory):合法场景,TPC 已支持
# 模块别名优先解析——`X.func()` 中 X 是 import 别名(IsModuleAlias)
# 时按模块函数处理,`X.X(args)` 的类构造按 FuncAttr==类名 走 struct
# 路径,二者互不冲突(勿再改类名规避,见用户明确要求)。
# ============================================================
@t.NoVTable
class CompilerFactory:
"""编译器结构体工厂(持有主池/永久池等共享对象)"""
Pool: memhub.MemBuddy | t.CPtr # 主内存池(瞬时数据,mark/reset 回收)
PermPool: memhub.MemBuddy | t.CPtr # 永久内存池(持久数据,从不 reset)
def __init__(self, pool: memhub.MemBuddy | t.CPtr,
perm_pool: memhub.MemBuddy | t.CPtr):
if self is None:
return
self.Pool = pool
self.PermPool = perm_pool
# ============================================================
# 全局工厂单例
# ============================================================
factory: CompilerFactory | t.CPtr = None