refactor(viperc): 完全删除 T1 | T2 类型组合,语法糖改用标记下标
This commit is contained in:
1 parent
42b094a575
commit
82a735c367
12 files changed
+355
-463
No files matched your search
@@ -212,7 +212,20 @@ def _PyiTypeStr(buf: bytes, buf_size: sizet, pos: sizet, annot: ast.AST*, depth:
|
||||
if at.attr is not None: pos = _PyiEmit(buf, buf_size, pos, at.attr)
|
||||
return pos
|
||||
|
||||
# Subscript: subscripted type (e.g. list[int], t.CArray[elem, count])
|
||||
# Call: attribute marker with arguments (e.g. attr.aligned(16), attr.section(".x"))
|
||||
if k == ast.ASTKind.Call:
|
||||
cl_t: ast.Call* = ast.Call*(annot)
|
||||
if cl_t.func is None: return pos
|
||||
pos = _PyiTypeStr(buf, buf_size, pos, cl_t.func, depth + 1)
|
||||
pos = _PyiEmit(buf, buf_size, pos, "(")
|
||||
if cl_t.args is not None:
|
||||
for ai_t in range(int(len(cl_t.args))):
|
||||
if ai_t > 0: pos = _PyiEmit(buf, buf_size, pos, ", ")
|
||||
pos = _PyiTypeStr(buf, buf_size, pos, cl_t.args.get(ai_t), depth + 1)
|
||||
pos = _PyiEmit(buf, buf_size, pos, ")")
|
||||
return pos
|
||||
|
||||
# Subscript: subscripted type (e.g. list[int], CArray[elem, count])
|
||||
if k == ast.ASTKind.Subscript:
|
||||
sub: ast.Subscript* = ast.Subscript*(annot)
|
||||
pos = _PyiTypeStr(buf, buf_size, pos, sub.value, depth + 1)
|
||||
|
||||
@@ -1631,6 +1631,49 @@ def _resolve_single_vpi_type_str(pool: memhub.MemBuddy*, seg: str) -> mlirlite.L
|
||||
# vpi caches `-> None` verbatim as "None"; map None to Void so cross-module
|
||||
# `-> None` methods do not fail fast with an unresolvable return type.
|
||||
if string.strcmp(seg, "None") == 0: return mlirlite.Void(pool)
|
||||
# Descriptor / storage / value-reference marker wrappers: CConst[T], State[T], CExport[T], ...
|
||||
# The marker carries no value type, so resolve the wrapped type.
|
||||
if seg_len_ps > 0 and seg[seg_len_ps - 1] == ']':
|
||||
lb_mk: str = string.strchr(seg, '[')
|
||||
if lb_mk is not None:
|
||||
lb_off: sizet = sizet(uint64(lb_mk) - uint64(seg))
|
||||
if lb_off > 0 and seg_len_ps > lb_off + 1:
|
||||
mk_len: sizet = lb_off
|
||||
mk_buf: bytes = stdlib.malloc(mk_len + 1)
|
||||
if mk_buf is not None:
|
||||
string.strncpy(mk_buf, seg, mk_len)
|
||||
mk_buf[mk_len] = '\0'
|
||||
mk_name: str = mk_buf
|
||||
# `attr.<name>` / `attr.<name>(...)` markers are builtin descriptors.
|
||||
is_attr_marker: int = 0
|
||||
if string.strncmp(mk_name, "attr.", 5) == 0 or string.strcmp(mk_name, "attr") == 0: is_attr_marker = 1
|
||||
dot_mk: str = string.strrchr(mk_name, '.')
|
||||
if dot_mk is not None: mk_name = dot_mk + 1
|
||||
is_marker: int = is_attr_marker
|
||||
if string.strcmp(mk_name, "CConst") == 0 or string.strcmp(mk_name, "CVolatile") == 0 \
|
||||
or string.strcmp(mk_name, "BigEndian") == 0 or string.strcmp(mk_name, "LittleEndian") == 0 \
|
||||
or string.strcmp(mk_name, "CStatic") == 0 or string.strcmp(mk_name, "CExport") == 0 \
|
||||
or string.strcmp(mk_name, "CExtern") == 0 or string.strcmp(mk_name, "State") == 0 \
|
||||
or string.strcmp(mk_name, "CDefine") == 0 or string.strcmp(mk_name, "CRef") == 0 \
|
||||
or string.strcmp(mk_name, "CTempRef") == 0 or string.strcmp(mk_name, "CAutoPtr") == 0 \
|
||||
or string.strcmp(mk_name, "attr") == 0:
|
||||
is_marker = 1
|
||||
if is_marker != 0:
|
||||
inner_len_mk: sizet = seg_len_ps - lb_off - 2
|
||||
inner_mk: bytes = stdlib.malloc(inner_len_mk + 1)
|
||||
if inner_mk is not None:
|
||||
string.strncpy(inner_mk, seg + lb_off + 1, inner_len_mk)
|
||||
inner_mk[inner_len_mk] = '\0'
|
||||
inner_ty_mk: mlirlite.LLVMType* = _resolve_single_vpi_type_str(pool, inner_mk)
|
||||
stdlib.free(inner_mk)
|
||||
# Value-reference parameters use the pointer ABI: &T / &temp T -> T*.
|
||||
if inner_ty_mk is not None and (string.strcmp(mk_name, "CRef") == 0 or string.strcmp(mk_name, "CTempRef") == 0):
|
||||
inner_ty_mk = mlirlite.Ptr(pool, inner_ty_mk)
|
||||
elif string.strcmp(mk_name, "CAutoPtr") == 0:
|
||||
inner_ty_mk = i8_ptr_ty
|
||||
stdlib.free(mk_buf)
|
||||
return inner_ty_mk
|
||||
stdlib.free(mk_buf)
|
||||
# rawptr[T] built-in raw pointer (equivalent to t.CPtr[T] -> Ptr(T)); vpi keeps the
|
||||
# Subscript form verbatim. Same as TypeGenResolve's rawptr branch: Ptr(resolve(T)).
|
||||
if string.strncmp(seg, "rawptr[", 7) == 0:
|
||||
@@ -1697,6 +1740,8 @@ def _resolve_single_vpi_type_str(pool: memhub.MemBuddy*, seg: str) -> mlirlite.L
|
||||
def _resolve_vpi_ret_annot_str(pool: memhub.MemBuddy*, ret_annot: str, i32_ty: mlirlite.LLVMType*, i8_ptr_ty: mlirlite.LLVMType*) -> mlirlite.LLVMType*:
|
||||
"""Resolve a vpi return-annotation string directly to LLVMType without building AST nodes."""
|
||||
if ret_annot is None or pool is None: return None
|
||||
# `T1 | T2` unions were retired; a stub containing one must be regenerated.
|
||||
if string.strchr(ret_annot, '|') is not None: return None
|
||||
|
||||
# tuple[T1, T2, ...] -> anonymous struct {T1, T2, ...} (multi-return packing),
|
||||
# matching TypeGenMixin._resolve_generic_subscript_ty's tuple branch.
|
||||
|
||||
Reference in new issue
Block a user