fix(transpyv): 槽视图统一 cast 到声明类型(47 处,含 codegen 自身)
同 includes 的同类修正:把一级指针 i8* 隐式塞进二级注解(i8** / str*)。 TransPyV 侧 coerce(ExprGenBase._ptr_cast_reason)没有 TPC 那样的「值侧是显式 指针 cast ⇒ 按 bitcast 重解释」豁免,故一旦用新构建的 TransPyV 编到这些文件 必然 fail-fast(回归测试首爆点在 includes/llvmlite 侧,本仓同形态站点随后必然 同样触发)。 涉及的两种形态: · `slot: str | t.CPtr = (t.CPtr)(addr)` —— cast 目标是一级 t.CPtr · `nm_slot: str* = (t.CPtr)(addr)` —— 注解 str* 即 i8** 统一改为 cast 到声明类型:`(str | t.CPtr)(addr)` / `str*(addr)`(后者与 includes/sys.vp `argv_arr: str* = str*(...)` 同一写法)。 本仓 47 处 / 6 文件: App/lib/core/Gen/VarGenMixin.vp 3 App/lib/core/Gen/TranslatorGenMixin.vp 8 App/lib/core/Gen/Func/FuncGenMixin.vp 13 App/lib/core/Gen/AsyncGenMixin.vp 15 App/lib/core/Gen/DebugInfoGen.vp 6 App/lib/Stub/StubGen/Converter.vp 2 Converter.vp:107 的 `_g_pyi_cdef_names: str | t.CPtr = None` 保持原样 (None 即空指针,任何指针类型均可,不属本类问题)。 只提交本 6 个文件;本仓其余未提交改动(CallGenBase/CallGenDispatch/CallGenFd/ CallGenProp/Generator/Translator/VLogger)与本迁移无关,保持不动。
This commit is contained in:
1 parent
07f2f2e9fc
commit
c2d7480f3d
6 files changed
+47
-47
No files matched your search
@@ -117,7 +117,7 @@ def _lookup_cdefine_for_pyi(name: str) -> int64:
|
||||
# 循环上限用 _g_pyi_cdef_count,且绝不能用 len()/.get:i8** 指针数组上 len() 回退 strlen(基址当字符串算长度 → 垃圾小值 → 靠后注册项查不到),.get 会被误分派为 HashTable.get(索引 inttoptr 成 key 指针 → 零页崩溃);用 t.CPtr(base + i*8) + e[0] 依次取名。
|
||||
pn: sizet = sizet(_g_pyi_cdef_count)
|
||||
for pi in range(pn):
|
||||
entry_pc: str | t.CPtr = t.CPtr(uint64(_g_pyi_cdef_names) + pi * 8)
|
||||
entry_pc: str | t.CPtr = (str | t.CPtr)(uint64(_g_pyi_cdef_names) + pi * 8)
|
||||
pnm: str = entry_pc[0]
|
||||
if pnm is not None and string.strcmp(pnm, name) == 0:
|
||||
_g_pyi_cdefine_found = 1
|
||||
@@ -842,7 +842,7 @@ def _GeneratePyiFromAst(mb: memhub.MemBuddy*, tree: ast.AST*,
|
||||
ann_pc: ast.Attribute* = ast.Attribute*(aa_pc.annotation)
|
||||
if ann_pc.attr is not None and string.strcmp(ann_pc.attr, "CDefine") == 0:
|
||||
if _g_pyi_cdef_names is not None and _g_pyi_cdef_vals is not None:
|
||||
slot_pc: str | t.CPtr = t.CPtr(uint64(_g_pyi_cdef_names) + cdi * 8)
|
||||
slot_pc: str | t.CPtr = (str | t.CPtr)(uint64(_g_pyi_cdef_names) + cdi * 8)
|
||||
slot_pc[0] = tgt_pc.id
|
||||
_g_pyi_cdef_vals[cdi] = _eval_cdefine_value_cache(aa_pc.value)
|
||||
cdi += 1
|
||||
|
||||
@@ -135,7 +135,7 @@ novirtual class AsyncGenMixin(CallGenBase.CallGenBase):
|
||||
if cnt >= HT.MAX_CORO_VARS:
|
||||
break
|
||||
addr: uint64 = uint64(trans._coro_params) + cnt * 8
|
||||
slot: str | t.CPtr = (t.CPtr)(addr)
|
||||
slot: str | t.CPtr = (str | t.CPtr)(addr)
|
||||
slot[0] = aname
|
||||
cnt = cnt + 1
|
||||
trans._coro_param_count = cnt
|
||||
@@ -678,7 +678,7 @@ novirtual class AsyncGenMixin(CallGenBase.CallGenBase):
|
||||
if cnt >= HT.MAX_CORO_VARS:
|
||||
return
|
||||
addr: uint64 = uint64(trans._coro_locals) + cnt * 8
|
||||
slot: str | t.CPtr = (t.CPtr)(addr)
|
||||
slot: str | t.CPtr = (str | t.CPtr)(addr)
|
||||
slot[0] = name
|
||||
trans._coro_local_count = cnt + 1
|
||||
|
||||
@@ -896,7 +896,7 @@ novirtual class AsyncGenMixin(CallGenBase.CallGenBase):
|
||||
if cnt >= HT.MAX_CORO_FUNCS:
|
||||
return
|
||||
addr: uint64 = uint64(trans._coro_wake_names) + cnt * 8
|
||||
slot: str | t.CPtr = (t.CPtr)(addr)
|
||||
slot: str | t.CPtr = (str | t.CPtr)(addr)
|
||||
slot[0] = name
|
||||
trans._coro_wake_idxs[cnt] = wake_idx
|
||||
trans._coro_wake_count = cnt + 1
|
||||
@@ -909,7 +909,7 @@ novirtual class AsyncGenMixin(CallGenBase.CallGenBase):
|
||||
i: int = 0
|
||||
for i in range(trans._coro_wake_count):
|
||||
addr: uint64 = uint64(trans._coro_wake_names) + i * 8
|
||||
slot: str | t.CPtr = (t.CPtr)(addr)
|
||||
slot: str | t.CPtr = (str | t.CPtr)(addr)
|
||||
if slot[0] is not None and string.strcmp(slot[0], name) == 0:
|
||||
return trans._coro_wake_idxs[i]
|
||||
return -1
|
||||
@@ -1635,7 +1635,7 @@ novirtual class AsyncGenMixin(CallGenBase.CallGenBase):
|
||||
if trans is None or trans._coro_params is None:
|
||||
return None
|
||||
addr: uint64 = uint64(trans._coro_params) + idx * 8
|
||||
slot: str | t.CPtr = (t.CPtr)(addr)
|
||||
slot: str | t.CPtr = (str | t.CPtr)(addr)
|
||||
return slot[0]
|
||||
|
||||
# ============================================================
|
||||
@@ -2424,7 +2424,7 @@ novirtual class AsyncGenMixin(CallGenBase.CallGenBase):
|
||||
i: int = 0
|
||||
for i in range(cnt):
|
||||
addr: uint64 = uint64(trans._async_funcs) + i * 8
|
||||
slot: str | t.CPtr = (t.CPtr)(addr)
|
||||
slot: str | t.CPtr = (str | t.CPtr)(addr)
|
||||
if slot[0] is not None and string.strcmp(slot[0], name) == 0:
|
||||
return 1
|
||||
return 0
|
||||
@@ -2441,13 +2441,13 @@ novirtual class AsyncGenMixin(CallGenBase.CallGenBase):
|
||||
i: int = 0
|
||||
for i in range(cnt):
|
||||
addr: uint64 = uint64(trans._coro_var_async) + i * 16
|
||||
pair: str | t.CPtr = (t.CPtr)(addr)
|
||||
pair: str | t.CPtr = (str | t.CPtr)(addr)
|
||||
if pair[0] is not None and string.strcmp(pair[0], var_name) == 0:
|
||||
return 0
|
||||
if cnt >= HT.MAX_CORO_VARS:
|
||||
return 1
|
||||
pair2_addr: uint64 = uint64(trans._coro_var_async) + cnt * 16
|
||||
pair2: str | t.CPtr = (t.CPtr)(pair2_addr)
|
||||
pair2: str | t.CPtr = (str | t.CPtr)(pair2_addr)
|
||||
pair2[0] = var_name
|
||||
pair2[1] = func_name
|
||||
trans._coro_var_async_count = cnt + 1
|
||||
@@ -2462,13 +2462,13 @@ novirtual class AsyncGenMixin(CallGenBase.CallGenBase):
|
||||
i: int = 0
|
||||
for i in range(cnt):
|
||||
addr: uint64 = uint64(trans._async_funcs) + i * 8
|
||||
slot: str | t.CPtr = (t.CPtr)(addr)
|
||||
slot: str | t.CPtr = (str | t.CPtr)(addr)
|
||||
if slot[0] is not None and string.strcmp(slot[0], name) == 0:
|
||||
return 0
|
||||
if cnt >= HT.MAX_CORO_FUNCS:
|
||||
return 1
|
||||
addr2: uint64 = uint64(trans._async_funcs) + cnt * 8
|
||||
slot2: str | t.CPtr = (t.CPtr)(addr2)
|
||||
slot2: str | t.CPtr = (str | t.CPtr)(addr2)
|
||||
slot2[0] = name
|
||||
trans._async_func_count = cnt + 1
|
||||
return 0
|
||||
@@ -2485,14 +2485,14 @@ novirtual class AsyncGenMixin(CallGenBase.CallGenBase):
|
||||
i: int = 0
|
||||
for i in range(cnt):
|
||||
addr: uint64 = uint64(trans._coro_frames) + i * 16
|
||||
pair: str | t.CPtr = (t.CPtr)(addr)
|
||||
pair: str | t.CPtr = (str | t.CPtr)(addr)
|
||||
if pair[0] is not None and string.strcmp(pair[0], name) == 0:
|
||||
pair[1] = str(frame_ty)
|
||||
return 0
|
||||
if cnt >= HT.MAX_CORO_FUNCS:
|
||||
return 1
|
||||
pair2_addr: uint64 = uint64(trans._coro_frames) + cnt * 16
|
||||
pair2: str | t.CPtr = (t.CPtr)(pair2_addr)
|
||||
pair2: str | t.CPtr = (str | t.CPtr)(pair2_addr)
|
||||
pair2[0] = name
|
||||
pair2[1] = str(frame_ty)
|
||||
trans._coro_frame_count = cnt + 1
|
||||
@@ -2507,7 +2507,7 @@ novirtual class AsyncGenMixin(CallGenBase.CallGenBase):
|
||||
i: int = 0
|
||||
for i in range(cnt):
|
||||
addr: uint64 = uint64(trans._coro_frames) + i * 16
|
||||
pair: str | t.CPtr = (t.CPtr)(addr)
|
||||
pair: str | t.CPtr = (str | t.CPtr)(addr)
|
||||
if pair[0] is not None and string.strcmp(pair[0], name) == 0:
|
||||
if pair[1] is not None:
|
||||
ty_addr: sizet = sizet(pair[1])
|
||||
@@ -2524,7 +2524,7 @@ novirtual class AsyncGenMixin(CallGenBase.CallGenBase):
|
||||
i: int = 0
|
||||
for i in range(cnt):
|
||||
addr: uint64 = uint64(trans._coro_var_async) + i * 16
|
||||
pair: str | t.CPtr = (t.CPtr)(addr)
|
||||
pair: str | t.CPtr = (str | t.CPtr)(addr)
|
||||
if pair[0] is not None and string.strcmp(pair[0], var_name) == 0:
|
||||
return pair[1]
|
||||
return None
|
||||
@@ -2655,5 +2655,5 @@ novirtual class AsyncGenMixin(CallGenBase.CallGenBase):
|
||||
if trans is None or trans._coro_locals is None:
|
||||
return None
|
||||
addr: uint64 = uint64(trans._coro_locals) + idx * 8
|
||||
slot: str | t.CPtr = (t.CPtr)(addr)
|
||||
slot: str | t.CPtr = (str | t.CPtr)(addr)
|
||||
return slot[0]
|
||||
@@ -253,7 +253,7 @@ def _EnsureModuleNodes(pool: memhub.MemBuddy*) -> int:
|
||||
# _LocRefAt - read a cached DILocation ref string pointer
|
||||
# ============================================================
|
||||
def _LocRefAt(slot: int) -> str:
|
||||
slotp: str | t.CPtr = (t.CPtr)(uint64(_g_loc_ref) + sizet(slot) * 8)
|
||||
slotp: str | t.CPtr = (str | t.CPtr)(uint64(_g_loc_ref) + sizet(slot) * 8)
|
||||
r: str = slotp[0]
|
||||
return r
|
||||
|
||||
@@ -298,7 +298,7 @@ def _EnsureLocation(pool: memhub.MemBuddy*, sp: int, line: int, col: int) -> str
|
||||
_g_loc_key[kbase2] = sizet(sp)
|
||||
_g_loc_key[kbase2 + 1] = sizet(line)
|
||||
_g_loc_key[kbase2 + 2] = sizet(c)
|
||||
rslot: str | t.CPtr = (t.CPtr)(uint64(_g_loc_ref) + sizet(slot2) * 8)
|
||||
rslot: str | t.CPtr = (str | t.CPtr)(uint64(_g_loc_ref) + sizet(slot2) * 8)
|
||||
rslot[0] = lref
|
||||
_g_loc_used[slot2] = 1
|
||||
return lref
|
||||
@@ -354,9 +354,9 @@ def PushFunction(pool: memhub.MemBuddy*, builder: llvmlite.IRBuilder*,
|
||||
llvmlite.function_set_dbg(func, sp_ref)
|
||||
# save the enclosing function's DI context (LIFO), then switch to this one
|
||||
_g_stk_sp[_g_depth] = sizet(_g_cur_sp + 1)
|
||||
rslot: str | t.CPtr = (t.CPtr)(uint64(_g_stk_ref) + sizet(_g_depth) * 8)
|
||||
rslot: str | t.CPtr = (str | t.CPtr)(uint64(_g_stk_ref) + sizet(_g_depth) * 8)
|
||||
rslot[0] = _g_cur_entry_ref
|
||||
bslot: str | t.CPtr = (t.CPtr)(uint64(_g_stk_bld) + sizet(_g_depth) * 8)
|
||||
bslot: str | t.CPtr = (str | t.CPtr)(uint64(_g_stk_bld) + sizet(_g_depth) * 8)
|
||||
bslot[0] = _g_cur_builder
|
||||
_g_depth += 1
|
||||
_g_cur_sp = sp_id
|
||||
@@ -381,9 +381,9 @@ def PopFunction(builder: llvmlite.IRBuilder*) -> int:
|
||||
return 0
|
||||
_g_depth -= 1
|
||||
_g_cur_sp = int(_g_stk_sp[_g_depth]) - 1
|
||||
rslot: str | t.CPtr = (t.CPtr)(uint64(_g_stk_ref) + sizet(_g_depth) * 8)
|
||||
rslot: str | t.CPtr = (str | t.CPtr)(uint64(_g_stk_ref) + sizet(_g_depth) * 8)
|
||||
_g_cur_entry_ref = rslot[0]
|
||||
bslot: str | t.CPtr = (t.CPtr)(uint64(_g_stk_bld) + sizet(_g_depth) * 8)
|
||||
bslot: str | t.CPtr = (str | t.CPtr)(uint64(_g_stk_bld) + sizet(_g_depth) * 8)
|
||||
_g_cur_builder = (llvmlite.IRBuilder*)(bslot[0])
|
||||
if builder is not None:
|
||||
llvmlite.builder_clear_debug_location(builder)
|
||||
|
||||
@@ -93,7 +93,7 @@ novirtual class FuncGenMixin(CallGenBase.CallGenBase):
|
||||
case _:
|
||||
pty_n = resolved_n
|
||||
if param_count < 64 and param_tys is not None:
|
||||
pty_slot_n: str | t.CPtr = (t.CPtr)(uint64(param_tys) + param_count * 8)
|
||||
pty_slot_n: str | t.CPtr = (str | t.CPtr)(uint64(param_tys) + param_count * 8)
|
||||
pty_slot_n[0] = pty_n
|
||||
pname_n: str = pool.alloc(32)
|
||||
if pname_n is not None:
|
||||
@@ -142,7 +142,7 @@ novirtual class FuncGenMixin(CallGenBase.CallGenBase):
|
||||
pty2_n: llvmlite.LLVMType* = i32_ty
|
||||
if param_tys is not None:
|
||||
ty_addr_n: uint64 = uint64(param_tys) + idx_p * 8
|
||||
ty_slot_n: str | t.CPtr = (t.CPtr)(ty_addr_n)
|
||||
ty_slot_n: str | t.CPtr = (str | t.CPtr)(ty_addr_n)
|
||||
pty2_n = (llvmlite.LLVMType*)(ty_slot_n[0])
|
||||
if pty2_n is None:
|
||||
pty2_n = i32_ty
|
||||
@@ -295,7 +295,7 @@ novirtual class FuncGenMixin(CallGenBase.CallGenBase):
|
||||
for ni in range(nested_nonlocal_count):
|
||||
# 从 _nonlocal_names 缓冲区读取名称
|
||||
name_addr: uint64 = uint64(trans._nonlocal_names) + ni * 8
|
||||
nl_slot: str | t.CPtr = (t.CPtr)(name_addr)
|
||||
nl_slot: str | t.CPtr = (str | t.CPtr)(name_addr)
|
||||
nl_name: str = nl_slot[0]
|
||||
if nl_name is None:
|
||||
continue
|
||||
@@ -919,7 +919,7 @@ novirtual class FuncGenMixin(CallGenBase.CallGenBase):
|
||||
dup = 1
|
||||
break
|
||||
if dup == 0 and count < 64:
|
||||
nm_slot: str* = (t.CPtr)(uint64(names) + count * 8)
|
||||
nm_slot: str* = str*(uint64(names) + count * 8)
|
||||
nm_slot[0] = nm_x.id
|
||||
count += 1
|
||||
return count
|
||||
@@ -954,7 +954,7 @@ novirtual class FuncGenMixin(CallGenBase.CallGenBase):
|
||||
trans._nl_chain_count = self._collect_chain_nonlocals(trans, node, trans._nl_chain_names, 0)
|
||||
trans._nl_chain_done = 1
|
||||
for ci in range(trans._nl_chain_count):
|
||||
nm_slot: str* = (t.CPtr)(uint64(trans._nl_chain_names) + ci * 8)
|
||||
nm_slot: str* = str*(uint64(trans._nl_chain_names) + ci * 8)
|
||||
nl_name: str = nm_slot[0]
|
||||
if nl_name is None: continue
|
||||
# 只在"定义它的函数"(当前顶层作用域有 alloca)中建堆
|
||||
@@ -1084,7 +1084,7 @@ novirtual class FuncGenMixin(CallGenBase.CallGenBase):
|
||||
p_ty = llvmlite.Ptr(pool, aelem_ty_l)
|
||||
case _:
|
||||
p_ty = resolved
|
||||
ty_slot_p: str* = (t.CPtr)(uint64(param_tys) + param_count * 8)
|
||||
ty_slot_p: str* = str*(uint64(param_tys) + param_count * 8)
|
||||
ty_slot_p[0] = p_ty
|
||||
param_count += 1
|
||||
|
||||
@@ -1109,7 +1109,7 @@ novirtual class FuncGenMixin(CallGenBase.CallGenBase):
|
||||
llvmlite.add_param(pool, func, i8_ptr_ty, "%env")
|
||||
for pi2 in range(param_count):
|
||||
ty_addr2: uint64 = uint64(param_tys) + pi2 * 8
|
||||
ty_slot2: str* = (t.CPtr)(ty_addr2)
|
||||
ty_slot2: str* = str*(ty_addr2)
|
||||
p_ty2: llvmlite.LLVMType* = (llvmlite.LLVMType*)(ty_slot2[0])
|
||||
if p_ty2 is None:
|
||||
p_ty2 = i32_ty
|
||||
@@ -1161,7 +1161,7 @@ novirtual class FuncGenMixin(CallGenBase.CallGenBase):
|
||||
cap_slot: str = cap_names + ci * 64
|
||||
if cap_slot[0] == '\0': continue
|
||||
ty_addr3: uint64 = uint64(cap_tys) + ci * 8
|
||||
ty_slot3: str | t.CPtr = (t.CPtr)(ty_addr3)
|
||||
ty_slot3: str | t.CPtr = (str | t.CPtr)(ty_addr3)
|
||||
cap_ty: llvmlite.LLVMType* = (llvmlite.LLVMType*)(ty_slot3[0])
|
||||
if cap_ty is None: continue
|
||||
off_val: llvmlite.Value* = llvmlite.const_int32(pool, ci * 8)
|
||||
@@ -1181,7 +1181,7 @@ novirtual class FuncGenMixin(CallGenBase.CallGenBase):
|
||||
# 10. 参数 alloca
|
||||
for pi3 in range(param_count):
|
||||
ty_addr4: uint64 = uint64(param_tys) + pi3 * 8
|
||||
ty_slot4: str | t.CPtr = (t.CPtr)(ty_addr4)
|
||||
ty_slot4: str | t.CPtr = (str | t.CPtr)(ty_addr4)
|
||||
p_ty3: llvmlite.LLVMType* = (llvmlite.LLVMType*)(ty_slot4[0])
|
||||
if p_ty3 is None:
|
||||
# fail-fast:lambda 参数类型槽缺失(内部状态不一致),不再静默保持 i32
|
||||
@@ -1238,11 +1238,11 @@ novirtual class FuncGenMixin(CallGenBase.CallGenBase):
|
||||
if cap_slot3[0] == '\0':
|
||||
continue
|
||||
al_addr: uint64 = uint64(cap_allocas) + ci3 * 8
|
||||
al_slot: str | t.CPtr = (t.CPtr)(al_addr)
|
||||
al_slot: str | t.CPtr = (str | t.CPtr)(al_addr)
|
||||
var_alloca2: llvmlite.Value* = (llvmlite.Value*)(al_slot[0])
|
||||
if var_alloca2 is None: continue
|
||||
ty_addr5: uint64 = uint64(cap_tys) + ci3 * 8
|
||||
ty_slot5: str | t.CPtr = (t.CPtr)(ty_addr5)
|
||||
ty_slot5: str | t.CPtr = (str | t.CPtr)(ty_addr5)
|
||||
cap_ty2: llvmlite.LLVMType* = (llvmlite.LLVMType*)(ty_slot5[0])
|
||||
if cap_ty2 is None: continue
|
||||
# 堆存储大小:位宽/8,至少 8 字节(容纳指针/标量)
|
||||
@@ -1352,9 +1352,9 @@ novirtual class FuncGenMixin(CallGenBase.CallGenBase):
|
||||
if cap_count >= 64:
|
||||
return cap_count
|
||||
string.strncpy(cap_names + cap_count * 64, nm.id, 63)
|
||||
al_slot: str | t.CPtr = (t.CPtr)(uint64(cap_allocas) + cap_count * 8)
|
||||
al_slot: str | t.CPtr = (str | t.CPtr)(uint64(cap_allocas) + cap_count * 8)
|
||||
al_slot[0] = alloca
|
||||
ty_slot: str | t.CPtr = (t.CPtr)(uint64(cap_tys) + cap_count * 8)
|
||||
ty_slot: str | t.CPtr = (str | t.CPtr)(uint64(cap_tys) + cap_count * 8)
|
||||
ty_slot[0] = pointee
|
||||
return cap_count + 1
|
||||
# 递归遍历常见表达式子节点
|
||||
|
||||
@@ -1271,7 +1271,7 @@ novirtual class TranslatorGenMixin:
|
||||
VLogger.error("global 变量数量超过上限,请减少 global 声明或增大 MAX_GLOBAL_NAMES", "ScopeDecl")
|
||||
return
|
||||
entry_addr: uint64 = uint64(trans._global_names) + trans._global_name_count * 8
|
||||
slot_ptr: str | t.CPtr = (t.CPtr)(entry_addr)
|
||||
slot_ptr: str | t.CPtr = (str | t.CPtr)(entry_addr)
|
||||
slot_ptr[0] = name
|
||||
trans._global_name_count += 1
|
||||
|
||||
@@ -1281,7 +1281,7 @@ novirtual class TranslatorGenMixin:
|
||||
return 0
|
||||
for i in range(trans._global_name_count):
|
||||
entry_addr: uint64 = uint64(trans._global_names) + i * 8
|
||||
slot_ptr: str | t.CPtr = (t.CPtr)(entry_addr)
|
||||
slot_ptr: str | t.CPtr = (str | t.CPtr)(entry_addr)
|
||||
entry: str = slot_ptr[0]
|
||||
if entry is not None:
|
||||
if string.strcmp(entry, name) == 0:
|
||||
@@ -1310,7 +1310,7 @@ novirtual class TranslatorGenMixin:
|
||||
idx: int = self.get_nonlocal_index(trans, name)
|
||||
if idx >= 0:
|
||||
ty_addr: uint64 = uint64(trans._nonlocal_types) + idx * 8
|
||||
ty_slot: str | t.CPtr = (t.CPtr)(ty_addr)
|
||||
ty_slot: str | t.CPtr = (str | t.CPtr)(ty_addr)
|
||||
ty_slot[0] = var_ty
|
||||
return
|
||||
if trans._nonlocal_name_count >= HT.MAX_GLOBAL_NAMES:
|
||||
@@ -1325,12 +1325,12 @@ novirtual class TranslatorGenMixin:
|
||||
VLogger.error("nonlocal 变量数量超过上限,请减少 nonlocal 声明或增大 MAX_GLOBAL_NAMES", "ScopeDecl")
|
||||
return
|
||||
entry_addr: uint64 = uint64(trans._nonlocal_names) + trans._nonlocal_name_count * 8
|
||||
slot_ptr: str | t.CPtr = (t.CPtr)(entry_addr)
|
||||
slot_ptr: str | t.CPtr = (str | t.CPtr)(entry_addr)
|
||||
slot_ptr[0] = name
|
||||
# 存储类型信息(用 str|t.CPtr = i8** 二级指针,与 _nonlocal_names 一致)
|
||||
if trans._nonlocal_types is not None:
|
||||
ty_addr2: uint64 = uint64(trans._nonlocal_types) + trans._nonlocal_name_count * 8
|
||||
ty_slot2: str | t.CPtr = (t.CPtr)(ty_addr2)
|
||||
ty_slot2: str | t.CPtr = (str | t.CPtr)(ty_addr2)
|
||||
# var_ty 为 None 时直接报错终止(fail-fast),不再默认 i32
|
||||
stored_ty: llvmlite.LLVMType* = var_ty
|
||||
if stored_ty is None:
|
||||
@@ -1352,7 +1352,7 @@ novirtual class TranslatorGenMixin:
|
||||
if idx < 0:
|
||||
return None
|
||||
ty_addr: uint64 = uint64(trans._nonlocal_types) + idx * 8
|
||||
ty_slot: str | t.CPtr = (t.CPtr)(ty_addr)
|
||||
ty_slot: str | t.CPtr = (str | t.CPtr)(ty_addr)
|
||||
return (llvmlite.LLVMType*)(ty_slot[0])
|
||||
|
||||
def is_nonlocal_name(self, trans: HT.Translator*, name: str) -> int:
|
||||
@@ -1361,7 +1361,7 @@ novirtual class TranslatorGenMixin:
|
||||
return 0
|
||||
for i in range(trans._nonlocal_name_count):
|
||||
entry_addr: uint64 = uint64(trans._nonlocal_names) + i * 8
|
||||
slot_ptr: str | t.CPtr = (t.CPtr)(entry_addr)
|
||||
slot_ptr: str | t.CPtr = (str | t.CPtr)(entry_addr)
|
||||
entry: str = slot_ptr[0]
|
||||
if entry is not None:
|
||||
if string.strcmp(entry, name) == 0:
|
||||
@@ -1374,7 +1374,7 @@ novirtual class TranslatorGenMixin:
|
||||
return -1
|
||||
for i in range(trans._nonlocal_name_count):
|
||||
entry_addr: uint64 = uint64(trans._nonlocal_names) + i * 8
|
||||
slot_ptr: str | t.CPtr = (t.CPtr)(entry_addr)
|
||||
slot_ptr: str | t.CPtr = (str | t.CPtr)(entry_addr)
|
||||
entry: str = slot_ptr[0]
|
||||
if entry is not None:
|
||||
if string.strcmp(entry, name) == 0:
|
||||
|
||||
@@ -754,7 +754,7 @@ novirtual class VarGenMixin:
|
||||
if pty_chk is None:
|
||||
self.Gen.TypeGenErr.fatal_error(node, f"REPL: 会话函数 '{func_name}' 第 {ai_chk + 1} 个形参的类型 token 不受支持(M3 支持 iN/float/double/i8*)", "TypeError")
|
||||
return None
|
||||
pty_slot: str | t.CPtr = (t.CPtr)(uint64(ptypes) + ai_chk * 8)
|
||||
pty_slot: str | t.CPtr = (str | t.CPtr)(uint64(ptypes) + ai_chk * 8)
|
||||
pty_slot[0] = pty_chk
|
||||
# ③ 实参:首实参 = 本片段 ctx,其后按签名类型逐个翻译并 coerce
|
||||
head: llvmlite.Value* = ctx_val
|
||||
@@ -767,7 +767,7 @@ novirtual class VarGenMixin:
|
||||
if arg is None:
|
||||
self.Gen.TypeGenErr.fatal_error(node, f"REPL: 会话函数 '{func_name}' 的第 {ai + 1} 个实参缺失", "SyntaxError")
|
||||
return None
|
||||
pty_slot2: str | t.CPtr = (t.CPtr)(uint64(ptypes) + ai * 8)
|
||||
pty_slot2: str | t.CPtr = (str | t.CPtr)(uint64(ptypes) + ai * 8)
|
||||
pty: llvmlite.LLVMType* = (llvmlite.LLVMType*)(pty_slot2[0])
|
||||
arg_val: llvmlite.Value* = self.Gen.ExprGen.translate_value(builder, pool, mod, arg, None, 0, trans, pty)
|
||||
if arg_val is None:
|
||||
@@ -797,7 +797,7 @@ novirtual class VarGenMixin:
|
||||
for pi in range(arg_count):
|
||||
cur_ty: llvmlite.LLVMType* = i8_ptr_ty
|
||||
if pi > 0:
|
||||
pty_slot3: str | t.CPtr = (t.CPtr)(uint64(ptypes) + (pi - 1) * 8)
|
||||
pty_slot3: str | t.CPtr = (str | t.CPtr)(uint64(ptypes) + (pi - 1) * 8)
|
||||
cur_ty = (llvmlite.LLVMType*)(pty_slot3[0])
|
||||
pn: llvmlite.ParamNode* = llvmlite.new_param_node(pool, cur_ty)
|
||||
if pn is not None:
|
||||
|
||||
Reference in new issue
Block a user