refactor: rawptr[T] -> T* 与 t.CConst 前缀迁移(R14/R16)
R14:rawptr[X] -> X*(41 文件 / 2037 行改动),X 含模块限定名与嵌套下标(rawptr[GSList[NameEntry]] -> GSList[NameEntry]*)。保留 6 处 rawptr[t.CPtr](规范例外:存纯裸指针);# 注释与字符串里的 rawptr[...] 属元语法描述,未动。 R16(保守子集):t.CConst | str/bytes -> const str/bytes,t.CConst | char | t.CPtr -> const str;typedef 右值位置豁免(const str 在该处无法注册,与 R1 同源)。 验证:TPC 自举三重重编 SUCCESS;TransPyV.exe 全量 77/77 顺序回归通过。
This commit is contained in:
1 parent
0ef4ba9634
commit
0055ab7ea7
41 files changed
+2031
-2031
No files matched your search
+1
-1
@@ -428,7 +428,7 @@ class ArgumentParser:
|
||||
# release — Release ParsedArgs and all internal resources
|
||||
# ============================================================
|
||||
|
||||
def release(args: rawptr[ParsedArgs]):
|
||||
def release(args: ParsedArgs*):
|
||||
"""Free ParsedArgs object and its inner HashTable resources."""
|
||||
if args is None: return
|
||||
if args.__mbuddy__ is None: return
|
||||
|
||||
+9
-9
@@ -69,7 +69,7 @@ _mbuddy: memhub.MemBuddy*
|
||||
# ============================================================
|
||||
# Common API: parse
|
||||
# ============================================================
|
||||
def parse(src: str, pool: rawptr[memhub.MemManager]) -> rawptr[AST]:
|
||||
def parse(src: str, pool: memhub.MemManager*) -> AST*:
|
||||
"""Parse Python source code, return the AST Module node.
|
||||
|
||||
Parameters:
|
||||
@@ -81,16 +81,16 @@ def parse(src: str, pool: rawptr[memhub.MemManager]) -> rawptr[AST]:
|
||||
"""
|
||||
if src is None or pool is None: return None
|
||||
_init_tables(pool)
|
||||
lx: rawptr[Lexer] = new_lexer(pool)
|
||||
lx: Lexer* = new_lexer(pool)
|
||||
if lx is None: return None
|
||||
_lexer_init(lx, src, pool)
|
||||
tokens: rawptr[Token] = tokenize(lx)
|
||||
tokens: Token* = tokenize(lx)
|
||||
if tokens is None: return None
|
||||
tree: rawptr[AST] = parse_tokens(pool, tokens)
|
||||
tree: AST* = parse_tokens(pool, tokens)
|
||||
return tree
|
||||
|
||||
|
||||
def parse_expression(src: str, pool: rawptr[memhub.MemManager]) -> rawptr[Expression]:
|
||||
def parse_expression(src: str, pool: memhub.MemManager*) -> Expression*:
|
||||
"""Parse a single expression, return the Expression node.
|
||||
|
||||
Parameters:
|
||||
@@ -102,13 +102,13 @@ def parse_expression(src: str, pool: rawptr[memhub.MemManager]) -> rawptr[Expres
|
||||
"""
|
||||
if src is None or pool is None: return None
|
||||
_init_tables(pool)
|
||||
lx: rawptr[Lexer] = new_lexer(pool)
|
||||
lx: Lexer* = new_lexer(pool)
|
||||
if lx is None: return None
|
||||
_lexer_init(lx, src, pool)
|
||||
tokens: rawptr[Token] = tokenize(lx)
|
||||
tokens: Token* = tokenize(lx)
|
||||
if tokens is None: return None
|
||||
ps: rawptr[Parser] = new_parser(pool)
|
||||
ps: Parser* = new_parser(pool)
|
||||
if ps is None: return None
|
||||
_parser_init(ps, tokens, pool)
|
||||
body: rawptr[AST] = _parse_test(ps)
|
||||
body: AST* = _parse_test(ps)
|
||||
return Expression(pool, body)
|
||||
+47
-47
@@ -14,15 +14,15 @@ from .base import (
|
||||
# ============================================================
|
||||
class ExceptHandler(AST):
|
||||
"""ExceptHandler(type: AST, name: str)"""
|
||||
type: rawptr[AST]
|
||||
type: AST*
|
||||
name: str
|
||||
|
||||
def __new__(self, pool: rawptr[memhub.MemManager], type: rawptr[AST], name: str):
|
||||
ptr: rawptr[ExceptHandler] = pool.alloc(ExceptHandler.__sizeof__())
|
||||
def __new__(self, pool: memhub.MemManager*, type: AST*, name: str):
|
||||
ptr: ExceptHandler* = pool.alloc(ExceptHandler.__sizeof__())
|
||||
if ptr: string.memset(ptr, 0, ExceptHandler.__sizeof__())
|
||||
return ptr
|
||||
|
||||
def __init__(self, pool: rawptr[memhub.MemManager], type: rawptr[AST], name: str):
|
||||
def __init__(self, pool: memhub.MemManager*, type: AST*, name: str):
|
||||
_init_ast(self, pool, 0, 0)
|
||||
self.type = type
|
||||
self.name = _copy_str(pool, name)
|
||||
@@ -53,26 +53,26 @@ class ExceptHandler(AST):
|
||||
class Arguments(AST):
|
||||
"""Arguments(args: list[AST | CPtr], vararg: AST, kwarg: AST,
|
||||
defaults: list[AST | CPtr], kw_defaults: list[AST | CPtr])"""
|
||||
args: rawptr[list[rawptr[AST]]]
|
||||
vararg: rawptr[AST]
|
||||
kwarg: rawptr[AST]
|
||||
defaults: rawptr[list[rawptr[AST]]]
|
||||
kw_defaults: rawptr[list[rawptr[AST]]]
|
||||
args: list[AST*]*
|
||||
vararg: AST*
|
||||
kwarg: AST*
|
||||
defaults: list[AST*]*
|
||||
kw_defaults: list[AST*]*
|
||||
|
||||
def __new__(self, pool: rawptr[memhub.MemManager],
|
||||
args: rawptr[list[rawptr[AST]]],
|
||||
vararg: rawptr[AST], kwarg: rawptr[AST],
|
||||
defaults: rawptr[list[rawptr[AST]]],
|
||||
kw_defaults: rawptr[list[rawptr[AST]]]):
|
||||
ptr: rawptr[Arguments] = pool.alloc(Arguments.__sizeof__())
|
||||
def __new__(self, pool: memhub.MemManager*,
|
||||
args: list[AST*]*,
|
||||
vararg: AST*, kwarg: AST*,
|
||||
defaults: list[AST*]*,
|
||||
kw_defaults: list[AST*]*):
|
||||
ptr: Arguments* = pool.alloc(Arguments.__sizeof__())
|
||||
if ptr: string.memset(ptr, 0, Arguments.__sizeof__())
|
||||
return ptr
|
||||
|
||||
def __init__(self, pool: rawptr[memhub.MemManager],
|
||||
args: rawptr[list[rawptr[AST]]],
|
||||
vararg: rawptr[AST], kwarg: rawptr[AST],
|
||||
defaults: rawptr[list[rawptr[AST]]],
|
||||
kw_defaults: rawptr[list[rawptr[AST]]]):
|
||||
def __init__(self, pool: memhub.MemManager*,
|
||||
args: list[AST*]*,
|
||||
vararg: AST*, kwarg: AST*,
|
||||
defaults: list[AST*]*,
|
||||
kw_defaults: list[AST*]*):
|
||||
_init_ast(self, pool, 0, 0)
|
||||
self.args = args
|
||||
self.vararg = vararg
|
||||
@@ -117,14 +117,14 @@ class Arguments(AST):
|
||||
class Arg(AST):
|
||||
"""Arg(arg: str, annotation: AST)"""
|
||||
arg: str
|
||||
annotation: rawptr[AST]
|
||||
annotation: AST*
|
||||
|
||||
def __new__(self, pool: rawptr[memhub.MemManager], arg: str, annotation: rawptr[AST]):
|
||||
ptr: rawptr[Arg] = pool.alloc(Arg.__sizeof__())
|
||||
def __new__(self, pool: memhub.MemManager*, arg: str, annotation: AST*):
|
||||
ptr: Arg* = pool.alloc(Arg.__sizeof__())
|
||||
if ptr: string.memset(ptr, 0, Arg.__sizeof__())
|
||||
return ptr
|
||||
|
||||
def __init__(self, pool: rawptr[memhub.MemManager], arg: str, annotation: rawptr[AST]):
|
||||
def __init__(self, pool: memhub.MemManager*, arg: str, annotation: AST*):
|
||||
_init_ast(self, pool, 0, 0)
|
||||
self.arg = _copy_str(pool, arg)
|
||||
self.annotation = annotation
|
||||
@@ -153,14 +153,14 @@ class Arg(AST):
|
||||
class Keyword(AST):
|
||||
"""Keyword(arg: str, value: AST)"""
|
||||
arg: str
|
||||
value: rawptr[AST]
|
||||
value: AST*
|
||||
|
||||
def __new__(self, pool: rawptr[memhub.MemManager], arg: str, value: rawptr[AST]):
|
||||
ptr: rawptr[Keyword] = pool.alloc(Keyword.__sizeof__())
|
||||
def __new__(self, pool: memhub.MemManager*, arg: str, value: AST*):
|
||||
ptr: Keyword* = pool.alloc(Keyword.__sizeof__())
|
||||
if ptr: string.memset(ptr, 0, Keyword.__sizeof__())
|
||||
return ptr
|
||||
|
||||
def __init__(self, pool: rawptr[memhub.MemManager], arg: str, value: rawptr[AST]):
|
||||
def __init__(self, pool: memhub.MemManager*, arg: str, value: AST*):
|
||||
_init_ast(self, pool, 0, 0)
|
||||
self.arg = _copy_str(pool, arg)
|
||||
self.value = value
|
||||
@@ -191,12 +191,12 @@ class Alias(AST):
|
||||
name: str
|
||||
asname: str
|
||||
|
||||
def __new__(self, pool: rawptr[memhub.MemManager], name: str, asname: str):
|
||||
ptr: rawptr[Alias] = pool.alloc(Alias.__sizeof__())
|
||||
def __new__(self, pool: memhub.MemManager*, name: str, asname: str):
|
||||
ptr: Alias* = pool.alloc(Alias.__sizeof__())
|
||||
if ptr: string.memset(ptr, 0, Alias.__sizeof__())
|
||||
return ptr
|
||||
|
||||
def __init__(self, pool: rawptr[memhub.MemManager],
|
||||
def __init__(self, pool: memhub.MemManager*,
|
||||
name: str, asname: str):
|
||||
_init_ast(self, pool, 0, 0)
|
||||
self.name = _copy_str(pool, name)
|
||||
@@ -223,16 +223,16 @@ class Alias(AST):
|
||||
|
||||
class WithItem(AST):
|
||||
"""WithItem(context_expr: AST, optional_vars: AST)"""
|
||||
context_expr: rawptr[AST]
|
||||
optional_vars: rawptr[AST]
|
||||
context_expr: AST*
|
||||
optional_vars: AST*
|
||||
|
||||
def __new__(self, pool: rawptr[memhub.MemManager], context_expr: rawptr[AST], optional_vars: rawptr[AST]):
|
||||
ptr: rawptr[WithItem] = pool.alloc(WithItem.__sizeof__())
|
||||
def __new__(self, pool: memhub.MemManager*, context_expr: AST*, optional_vars: AST*):
|
||||
ptr: WithItem* = pool.alloc(WithItem.__sizeof__())
|
||||
if ptr: string.memset(ptr, 0, WithItem.__sizeof__())
|
||||
return ptr
|
||||
|
||||
def __init__(self, pool: rawptr[memhub.MemManager],
|
||||
context_expr: rawptr[AST], optional_vars: rawptr[AST]):
|
||||
def __init__(self, pool: memhub.MemManager*,
|
||||
context_expr: AST*, optional_vars: AST*):
|
||||
_init_ast(self, pool, 0, 0)
|
||||
self.context_expr = context_expr
|
||||
self.optional_vars = optional_vars
|
||||
@@ -264,22 +264,22 @@ class WithItem(AST):
|
||||
|
||||
class Comprehension(AST):
|
||||
"""Comprehension(target: AST, iter: AST, ifs: list[AST | CPtr], is_async: CInt)"""
|
||||
target: rawptr[AST]
|
||||
iter: rawptr[AST]
|
||||
ifs: rawptr[list[rawptr[AST]]]
|
||||
target: AST*
|
||||
iter: AST*
|
||||
ifs: list[AST*]*
|
||||
is_async: int
|
||||
|
||||
def __new__(self, pool: rawptr[memhub.MemManager],
|
||||
target: rawptr[AST], iter: rawptr[AST],
|
||||
ifs: rawptr[list[rawptr[AST]]], is_async: int):
|
||||
ptr: rawptr[Comprehension] = pool.alloc(Comprehension.__sizeof__())
|
||||
def __new__(self, pool: memhub.MemManager*,
|
||||
target: AST*, iter: AST*,
|
||||
ifs: list[AST*]*, is_async: int):
|
||||
ptr: Comprehension* = pool.alloc(Comprehension.__sizeof__())
|
||||
if ptr:
|
||||
string.memset(ptr, 0, Comprehension.__sizeof__())
|
||||
return ptr
|
||||
|
||||
def __init__(self, pool: rawptr[memhub.MemManager],
|
||||
target: rawptr[AST], iter: rawptr[AST],
|
||||
ifs: rawptr[list[rawptr[AST]]], is_async: int):
|
||||
def __init__(self, pool: memhub.MemManager*,
|
||||
target: AST*, iter: AST*,
|
||||
ifs: list[AST*]*, is_async: int):
|
||||
_init_ast(self, pool, 0, 0)
|
||||
self.target = target
|
||||
self.iter = iter
|
||||
|
||||
+17
-17
@@ -104,7 +104,7 @@ enum ASTFlag:
|
||||
# ============================================================
|
||||
# Helper Functions
|
||||
# ============================================================
|
||||
def _copy_str(pool: rawptr[memhub.MemManager], src: str) -> str:
|
||||
def _copy_str(pool: memhub.MemManager*, src: str) -> str:
|
||||
"""Allocate and copy a C string from pool."""
|
||||
if src is None: return None
|
||||
slen: sizet = string.strlen(src)
|
||||
@@ -114,7 +114,7 @@ def _copy_str(pool: rawptr[memhub.MemManager], src: str) -> str:
|
||||
return buf
|
||||
|
||||
|
||||
def _set_pos(node: rawptr[AST], lineno: int, col_offset: int, end_lineno: int, end_col_offset: int):
|
||||
def _set_pos(node: AST*, lineno: int, col_offset: int, end_lineno: int, end_col_offset: int):
|
||||
if node is None: return
|
||||
node.lineno = lineno
|
||||
node.col_offset = col_offset
|
||||
@@ -122,7 +122,7 @@ def _set_pos(node: rawptr[AST], lineno: int, col_offset: int, end_lineno: int, e
|
||||
node.end_col_offset = end_col_offset
|
||||
|
||||
|
||||
def _inherit_pos(node: rawptr[AST], ref: rawptr[AST]):
|
||||
def _inherit_pos(node: AST*, ref: AST*):
|
||||
if node is None or ref is None: return
|
||||
node.lineno = ref.lineno
|
||||
node.col_offset = ref.col_offset
|
||||
@@ -130,7 +130,7 @@ def _inherit_pos(node: rawptr[AST], ref: rawptr[AST]):
|
||||
node.end_col_offset = ref.end_col_offset
|
||||
|
||||
|
||||
def _init_ast(node: rawptr[AST], pool: rawptr[memhub.MemManager], lineno: int, col: int):
|
||||
def _init_ast(node: AST*, pool: memhub.MemManager*, lineno: int, col: int):
|
||||
"""Initialize AST base fields."""
|
||||
node.parent = None
|
||||
node.pool = pool
|
||||
@@ -141,16 +141,16 @@ def _init_ast(node: rawptr[AST], pool: rawptr[memhub.MemManager], lineno: int, c
|
||||
node.children = None
|
||||
|
||||
|
||||
def _set_parent_list(lst: list[rawptr[AST]]*, parent: rawptr[AST]):
|
||||
def _set_parent_list(lst: list[AST*]*, parent: AST*):
|
||||
"""Set list children parent pointers."""
|
||||
if lst is None: return
|
||||
for i in range(lst.__len__()):
|
||||
child: rawptr[AST] = lst.get(i)
|
||||
child: AST* = lst.get(i)
|
||||
if child is not None: child.parent = parent
|
||||
|
||||
|
||||
def _append_child(lst: list[rawptr[AST]]*, node: rawptr[AST],
|
||||
pool: rawptr[memhub.MemManager]):
|
||||
def _append_child(lst: list[AST*]*, node: AST*,
|
||||
pool: memhub.MemManager*):
|
||||
"""Append child nodes to a list (module-level function, to avoid conflicts with the AST.append method name).
|
||||
|
||||
Call this function within the AST.append method to bypass the compiler mistaking list.append for a virtual function call to AST.append when doing type inference."""
|
||||
@@ -276,7 +276,7 @@ def _op_name(op: int) -> str:
|
||||
return "NoneOp"
|
||||
|
||||
|
||||
def _dump_list(lst: list[rawptr[AST]]*, buf: str, size: sizet, pos: sizet) -> sizet:
|
||||
def _dump_list(lst: list[AST*]*, buf: str, size: sizet, pos: sizet) -> sizet:
|
||||
"""Traverse a list[AST | CPtr] container, polymorphically dump each element."""
|
||||
if lst is None:
|
||||
pos = _emit(buf, size, pos, "[]")
|
||||
@@ -284,7 +284,7 @@ def _dump_list(lst: list[rawptr[AST]]*, buf: str, size: sizet, pos: sizet) -> si
|
||||
pos = _emit(buf, size, pos, "[")
|
||||
for i in range(lst.__len__()):
|
||||
if i > 0: pos = _emit(buf, size, pos, ", ")
|
||||
child: rawptr[AST] = lst.get(i)
|
||||
child: AST* = lst.get(i)
|
||||
if child is not None: pos = child.dump(buf, size, pos)
|
||||
pos = _emit(buf, size, pos, "]")
|
||||
return pos
|
||||
@@ -295,7 +295,7 @@ def _dump_op_list(lst: t.CPtr, buf: str, size: sizet, pos: sizet) -> sizet:
|
||||
if lst is None:
|
||||
pos = _emit(buf, size, pos, "[]")
|
||||
return pos
|
||||
ops_list: rawptr[list[int]] = (rawptr[list[int]])(lst)
|
||||
ops_list: list[int]* = (list[int]*)(lst)
|
||||
pos = _emit(buf, size, pos, "[")
|
||||
for i in range(ops_list.__len__()):
|
||||
if i > 0: pos = _emit(buf, size, pos, ", ")
|
||||
@@ -322,13 +322,13 @@ virtual class AST:
|
||||
end_lineno/end_col_offset: Ending position
|
||||
children: List of child nodes (body block, added via append)
|
||||
"""
|
||||
parent: rawptr[AST]
|
||||
pool: rawptr[memhub.MemManager]
|
||||
parent: AST*
|
||||
pool: memhub.MemManager*
|
||||
lineno: int
|
||||
col_offset: int
|
||||
end_lineno: int
|
||||
end_col_offset: int
|
||||
children: list[rawptr[AST]]*
|
||||
children: list[AST*]*
|
||||
|
||||
def kind(self) -> int:
|
||||
"""Returns the node type (ASTKind value), overridden by subclasses"""
|
||||
@@ -347,7 +347,7 @@ virtual class AST:
|
||||
Current implementation is empty. override this method to dispatch to visitor.visit_X(self)"""
|
||||
pass
|
||||
|
||||
def append(self, node: rawptr[AST]):
|
||||
def append(self, node: AST*):
|
||||
"""Append node to the children list.
|
||||
|
||||
Used for parser to build statement blocks: module.append(stmt), if_node.append(stmt), etc.
|
||||
@@ -356,7 +356,7 @@ virtual class AST:
|
||||
Note: list[AST|CPtr] is currently stored by value (compiler limitation), so you must set
|
||||
node.parent before appending, so the parent in the copy is correct."""
|
||||
if self is None or node is None: return
|
||||
if self.children is None: self.children = list[rawptr[AST]](self.pool, 8)
|
||||
if self.children is None: self.children = list[AST*](self.pool, 8)
|
||||
node.parent = self
|
||||
_append_child(self.children, node, self.pool)
|
||||
|
||||
@@ -386,7 +386,7 @@ virtual class ExprNode(AST):
|
||||
# ============================================================
|
||||
# Module dump function (for ast.dump(node, buf, size))
|
||||
# ============================================================
|
||||
def dump(node: rawptr[AST], buf: str, size: sizet):
|
||||
def dump(node: AST*, buf: str, size: sizet):
|
||||
"""Serialize AST node to buf (with capacity size)"""
|
||||
if node is None or buf is None or size == 0: return
|
||||
buf[0] = '\0'
|
||||
|
||||
+198
-198
@@ -20,12 +20,12 @@ class Name(ExprNode):
|
||||
id: str
|
||||
ctx: int
|
||||
|
||||
def __new__(self, pool: rawptr[memhub.MemManager], id: str, ctx: int):
|
||||
ptr: rawptr[Name] = pool.alloc(Name.__sizeof__())
|
||||
def __new__(self, pool: memhub.MemManager*, id: str, ctx: int):
|
||||
ptr: Name* = pool.alloc(Name.__sizeof__())
|
||||
if ptr: string.memset(ptr, 0, Name.__sizeof__())
|
||||
return ptr
|
||||
|
||||
def __init__(self, pool: rawptr[memhub.MemManager], id: str, ctx: int):
|
||||
def __init__(self, pool: memhub.MemManager*, id: str, ctx: int):
|
||||
_init_ast(self, pool, 0, 0)
|
||||
self.id = _copy_str(pool, id)
|
||||
self.ctx = ctx
|
||||
@@ -50,25 +50,25 @@ class Name(ExprNode):
|
||||
return pos
|
||||
|
||||
|
||||
def name_get_id(node: rawptr[Name]) -> str:
|
||||
def name_get_id(node: Name*) -> str:
|
||||
"""Get Name.id field (cross-module accessor; guards against stub field-access pitfalls)"""
|
||||
if node is None: return None
|
||||
return node.id
|
||||
|
||||
|
||||
def constant_get_str_val(node: rawptr[Constant]) -> str:
|
||||
def constant_get_str_val(node: Constant*) -> str:
|
||||
"""Get Constant.str_val field (cross-module accessor)"""
|
||||
if node is None: return None
|
||||
return node.str_val
|
||||
|
||||
|
||||
def binop_get_left(node: rawptr[BinOp]) -> rawptr[AST]:
|
||||
def binop_get_left(node: BinOp*) -> AST*:
|
||||
"""Get BinOp.left field (cross-module accessor)"""
|
||||
if node is None: return None
|
||||
return node.left
|
||||
|
||||
|
||||
def binop_get_right(node: rawptr[BinOp]) -> rawptr[AST]:
|
||||
def binop_get_right(node: BinOp*) -> AST*:
|
||||
"""Get BinOp.right field (cross-module accessor)"""
|
||||
if node is None: return None
|
||||
return node.right
|
||||
@@ -85,16 +85,16 @@ class Constant(ExprNode):
|
||||
str_val: str
|
||||
const_kind: int
|
||||
|
||||
def __new__(self, pool: rawptr[memhub.MemManager],
|
||||
def __new__(self, pool: memhub.MemManager*,
|
||||
const_kind: int, int_val: int64,
|
||||
float_val: double, str_val: str,
|
||||
lineno: int, col: int):
|
||||
ptr: rawptr[Constant] = pool.alloc(Constant.__sizeof__())
|
||||
ptr: Constant* = pool.alloc(Constant.__sizeof__())
|
||||
if ptr:
|
||||
string.memset(ptr, 0, Constant.__sizeof__())
|
||||
return ptr
|
||||
|
||||
def __init__(self, pool: rawptr[memhub.MemManager],
|
||||
def __init__(self, pool: memhub.MemManager*,
|
||||
const_kind: int, int_val: int64,
|
||||
float_val: double, str_val: str,
|
||||
lineno: int, col: int):
|
||||
@@ -148,18 +148,18 @@ class Constant(ExprNode):
|
||||
|
||||
class BinOp(ExprNode):
|
||||
"""BinOp(left: AST, op: OpKind, right: AST)"""
|
||||
left: rawptr[AST]
|
||||
left: AST*
|
||||
op: int
|
||||
right: rawptr[AST]
|
||||
right: AST*
|
||||
|
||||
def __new__(self, pool: rawptr[memhub.MemManager],
|
||||
left: rawptr[AST], op: int, right: rawptr[AST]):
|
||||
ptr: rawptr[BinOp] = pool.alloc(BinOp.__sizeof__())
|
||||
def __new__(self, pool: memhub.MemManager*,
|
||||
left: AST*, op: int, right: AST*):
|
||||
ptr: BinOp* = pool.alloc(BinOp.__sizeof__())
|
||||
if ptr: string.memset(ptr, 0, BinOp.__sizeof__())
|
||||
return ptr
|
||||
|
||||
def __init__(self, pool: rawptr[memhub.MemManager],
|
||||
left: rawptr[AST], op: int, right: rawptr[AST]):
|
||||
def __init__(self, pool: memhub.MemManager*,
|
||||
left: AST*, op: int, right: AST*):
|
||||
_init_ast(self, pool, 0, 0)
|
||||
self.left = left
|
||||
self.op = op
|
||||
@@ -195,16 +195,16 @@ class BinOp(ExprNode):
|
||||
class UnaryOp(ExprNode):
|
||||
"""UnaryOp(op: OpKind, operand: AST)"""
|
||||
op: int
|
||||
operand: rawptr[AST]
|
||||
operand: AST*
|
||||
|
||||
def __new__(self, pool: rawptr[memhub.MemManager],
|
||||
op: int, operand: rawptr[AST]):
|
||||
ptr: rawptr[UnaryOp] = pool.alloc(UnaryOp.__sizeof__())
|
||||
def __new__(self, pool: memhub.MemManager*,
|
||||
op: int, operand: AST*):
|
||||
ptr: UnaryOp* = pool.alloc(UnaryOp.__sizeof__())
|
||||
if ptr: string.memset(ptr, 0, UnaryOp.__sizeof__())
|
||||
return ptr
|
||||
|
||||
def __init__(self, pool: rawptr[memhub.MemManager],
|
||||
op: int, operand: rawptr[AST]):
|
||||
def __init__(self, pool: memhub.MemManager*,
|
||||
op: int, operand: AST*):
|
||||
_init_ast(self, pool, 0, 0)
|
||||
self.op = op
|
||||
self.operand = operand
|
||||
@@ -233,22 +233,22 @@ class UnaryOp(ExprNode):
|
||||
|
||||
class Compare(ExprNode):
|
||||
"""Compare(left: AST, ops: list[CInt], comparators: list[AST | CPtr])"""
|
||||
left: rawptr[AST]
|
||||
left: AST*
|
||||
ops: t.CPtr
|
||||
comparators: rawptr[list[rawptr[AST]]]
|
||||
comparators: list[AST*]*
|
||||
|
||||
def __new__(self, pool: rawptr[memhub.MemManager],
|
||||
left: rawptr[AST],
|
||||
def __new__(self, pool: memhub.MemManager*,
|
||||
left: AST*,
|
||||
ops: t.CPtr,
|
||||
comparators: rawptr[list[rawptr[AST]]]):
|
||||
ptr: rawptr[Compare] = pool.alloc(Compare.__sizeof__())
|
||||
comparators: list[AST*]*):
|
||||
ptr: Compare* = pool.alloc(Compare.__sizeof__())
|
||||
if ptr: string.memset(ptr, 0, Compare.__sizeof__())
|
||||
return ptr
|
||||
|
||||
def __init__(self, pool: rawptr[memhub.MemManager],
|
||||
left: rawptr[AST],
|
||||
def __init__(self, pool: memhub.MemManager*,
|
||||
left: AST*,
|
||||
ops: t.CPtr,
|
||||
comparators: rawptr[list[rawptr[AST]]]):
|
||||
comparators: list[AST*]*):
|
||||
_init_ast(self, pool, 0, 0)
|
||||
self.left = left
|
||||
self.ops = ops
|
||||
@@ -281,25 +281,25 @@ class Compare(ExprNode):
|
||||
|
||||
class Call(ExprNode):
|
||||
"""Call(func: AST, args: list[AST | CPtr], keywords: list[AST | CPtr])"""
|
||||
func: rawptr[AST]
|
||||
args: rawptr[list[rawptr[AST]]]
|
||||
keywords: rawptr[list[rawptr[AST]]]
|
||||
func: AST*
|
||||
args: list[AST*]*
|
||||
keywords: list[AST*]*
|
||||
# Value-position `volatile f()` / `volatile S()` prefix marker (see _IsVolatileCallPrefix):
|
||||
# 1 = result/temp slot accessed volatile (struct writes too). Appended last: offsets unchanged.
|
||||
IsVolatile: int
|
||||
|
||||
def __new__(self, pool: rawptr[memhub.MemManager],
|
||||
func: rawptr[AST],
|
||||
args: rawptr[list[rawptr[AST]]],
|
||||
keywords: rawptr[list[rawptr[AST]]]):
|
||||
ptr: rawptr[Call] = pool.alloc(Call.__sizeof__())
|
||||
def __new__(self, pool: memhub.MemManager*,
|
||||
func: AST*,
|
||||
args: list[AST*]*,
|
||||
keywords: list[AST*]*):
|
||||
ptr: Call* = pool.alloc(Call.__sizeof__())
|
||||
if ptr: string.memset(ptr, 0, Call.__sizeof__())
|
||||
return ptr
|
||||
|
||||
def __init__(self, pool: rawptr[memhub.MemManager],
|
||||
func: rawptr[AST],
|
||||
args: rawptr[list[rawptr[AST]]],
|
||||
keywords: rawptr[list[rawptr[AST]]]):
|
||||
def __init__(self, pool: memhub.MemManager*,
|
||||
func: AST*,
|
||||
args: list[AST*]*,
|
||||
keywords: list[AST*]*):
|
||||
_init_ast(self, pool, 0, 0)
|
||||
self.func = func
|
||||
self.args = args
|
||||
@@ -333,18 +333,18 @@ class Call(ExprNode):
|
||||
class BoolOp(ExprNode):
|
||||
"""BoolOp(op: CInt, values: list[AST | CPtr])"""
|
||||
op: int
|
||||
values: rawptr[list[rawptr[AST]]]
|
||||
values: list[AST*]*
|
||||
|
||||
def __new__(self, pool: rawptr[memhub.MemManager],
|
||||
def __new__(self, pool: memhub.MemManager*,
|
||||
op: int,
|
||||
values: rawptr[list[rawptr[AST]]]):
|
||||
ptr: rawptr[BoolOp] = pool.alloc(BoolOp.__sizeof__())
|
||||
values: list[AST*]*):
|
||||
ptr: BoolOp* = pool.alloc(BoolOp.__sizeof__())
|
||||
if ptr: string.memset(ptr, 0, BoolOp.__sizeof__())
|
||||
return ptr
|
||||
|
||||
def __init__(self, pool: rawptr[memhub.MemManager],
|
||||
def __init__(self, pool: memhub.MemManager*,
|
||||
op: int,
|
||||
values: rawptr[list[rawptr[AST]]]):
|
||||
values: list[AST*]*):
|
||||
_init_ast(self, pool, 0, 0)
|
||||
self.op = op
|
||||
self.values = values
|
||||
@@ -371,17 +371,17 @@ class BoolOp(ExprNode):
|
||||
|
||||
class Lambda(ExprNode):
|
||||
"""Lambda(args: AST, body: AST)"""
|
||||
args: rawptr[AST]
|
||||
body: rawptr[AST]
|
||||
args: AST*
|
||||
body: AST*
|
||||
|
||||
def __new__(self, pool: rawptr[memhub.MemManager],
|
||||
args: rawptr[AST], body: rawptr[AST]):
|
||||
ptr: rawptr[Lambda] = pool.alloc(Lambda.__sizeof__())
|
||||
def __new__(self, pool: memhub.MemManager*,
|
||||
args: AST*, body: AST*):
|
||||
ptr: Lambda* = pool.alloc(Lambda.__sizeof__())
|
||||
if ptr: string.memset(ptr, 0, Lambda.__sizeof__())
|
||||
return ptr
|
||||
|
||||
def __init__(self, pool: rawptr[memhub.MemManager],
|
||||
args: rawptr[AST], body: rawptr[AST]):
|
||||
def __init__(self, pool: memhub.MemManager*,
|
||||
args: AST*, body: AST*):
|
||||
_init_ast(self, pool, 0, 0)
|
||||
self.args = args
|
||||
self.body = body
|
||||
@@ -413,20 +413,20 @@ class Lambda(ExprNode):
|
||||
|
||||
class IfExp(ExprNode):
|
||||
"""IfExp(test: AST, body: AST, orelse: AST)"""
|
||||
test: rawptr[AST]
|
||||
body: rawptr[AST]
|
||||
orelse: rawptr[AST]
|
||||
test: AST*
|
||||
body: AST*
|
||||
orelse: AST*
|
||||
|
||||
def __new__(self, pool: rawptr[memhub.MemManager],
|
||||
test: rawptr[AST], body: rawptr[AST],
|
||||
orelse: rawptr[AST]):
|
||||
ptr: rawptr[IfExp] = pool.alloc(IfExp.__sizeof__())
|
||||
def __new__(self, pool: memhub.MemManager*,
|
||||
test: AST*, body: AST*,
|
||||
orelse: AST*):
|
||||
ptr: IfExp* = pool.alloc(IfExp.__sizeof__())
|
||||
if ptr: string.memset(ptr, 0, IfExp.__sizeof__())
|
||||
return ptr
|
||||
|
||||
def __init__(self, pool: rawptr[memhub.MemManager],
|
||||
test: rawptr[AST], body: rawptr[AST],
|
||||
orelse: rawptr[AST]):
|
||||
def __init__(self, pool: memhub.MemManager*,
|
||||
test: AST*, body: AST*,
|
||||
orelse: AST*):
|
||||
_init_ast(self, pool, 0, 0)
|
||||
self.test = test
|
||||
self.body = body
|
||||
@@ -464,19 +464,19 @@ class IfExp(ExprNode):
|
||||
|
||||
class Dict(ExprNode):
|
||||
"""Dict(keys: list[AST | CPtr], values: list[AST | CPtr])"""
|
||||
keys: rawptr[list[rawptr[AST]]]
|
||||
values: rawptr[list[rawptr[AST]]]
|
||||
keys: list[AST*]*
|
||||
values: list[AST*]*
|
||||
|
||||
def __new__(self, pool: rawptr[memhub.MemManager],
|
||||
keys: rawptr[list[rawptr[AST]]],
|
||||
values: rawptr[list[rawptr[AST]]]):
|
||||
ptr: rawptr[Dict] = pool.alloc(Dict.__sizeof__())
|
||||
def __new__(self, pool: memhub.MemManager*,
|
||||
keys: list[AST*]*,
|
||||
values: list[AST*]*):
|
||||
ptr: Dict* = pool.alloc(Dict.__sizeof__())
|
||||
if ptr: string.memset(ptr, 0, Dict.__sizeof__())
|
||||
return ptr
|
||||
|
||||
def __init__(self, pool: rawptr[memhub.MemManager],
|
||||
keys: rawptr[list[rawptr[AST]]],
|
||||
values: rawptr[list[rawptr[AST]]]):
|
||||
def __init__(self, pool: memhub.MemManager*,
|
||||
keys: list[AST*]*,
|
||||
values: list[AST*]*):
|
||||
_init_ast(self, pool, 0, 0)
|
||||
self.keys = keys
|
||||
self.values = values
|
||||
@@ -504,16 +504,16 @@ class Dict(ExprNode):
|
||||
|
||||
class Set(ExprNode):
|
||||
"""Set(elts: list[AST | CPtr])"""
|
||||
elts: rawptr[list[rawptr[AST]]]
|
||||
elts: list[AST*]*
|
||||
|
||||
def __new__(self, pool: rawptr[memhub.MemManager],
|
||||
elts: rawptr[list[rawptr[AST]]]):
|
||||
ptr: rawptr[Set] = pool.alloc(Set.__sizeof__())
|
||||
def __new__(self, pool: memhub.MemManager*,
|
||||
elts: list[AST*]*):
|
||||
ptr: Set* = pool.alloc(Set.__sizeof__())
|
||||
if ptr: string.memset(ptr, 0, Set.__sizeof__())
|
||||
return ptr
|
||||
|
||||
def __init__(self, pool: rawptr[memhub.MemManager],
|
||||
elts: rawptr[list[rawptr[AST]]]):
|
||||
def __init__(self, pool: memhub.MemManager*,
|
||||
elts: list[AST*]*):
|
||||
_init_ast(self, pool, 0, 0)
|
||||
self.elts = elts
|
||||
_set_parent_list(elts, self)
|
||||
@@ -537,19 +537,19 @@ class Set(ExprNode):
|
||||
|
||||
class ListComp(ExprNode):
|
||||
"""ListComp(elt: AST, generators: list[AST | CPtr])"""
|
||||
elt: rawptr[AST]
|
||||
generators: rawptr[list[rawptr[AST]]]
|
||||
elt: AST*
|
||||
generators: list[AST*]*
|
||||
|
||||
def __new__(self, pool: rawptr[memhub.MemManager],
|
||||
elt: rawptr[AST],
|
||||
generators: rawptr[list[rawptr[AST]]]):
|
||||
ptr: rawptr[ListComp] = pool.alloc(ListComp.__sizeof__())
|
||||
def __new__(self, pool: memhub.MemManager*,
|
||||
elt: AST*,
|
||||
generators: list[AST*]*):
|
||||
ptr: ListComp* = pool.alloc(ListComp.__sizeof__())
|
||||
if ptr: string.memset(ptr, 0, ListComp.__sizeof__())
|
||||
return ptr
|
||||
|
||||
def __init__(self, pool: rawptr[memhub.MemManager],
|
||||
elt: rawptr[AST],
|
||||
generators: rawptr[list[rawptr[AST]]]):
|
||||
def __init__(self, pool: memhub.MemManager*,
|
||||
elt: AST*,
|
||||
generators: list[AST*]*):
|
||||
_init_ast(self, pool, 0, 0)
|
||||
self.elt = elt
|
||||
self.generators = generators
|
||||
@@ -579,19 +579,19 @@ class ListComp(ExprNode):
|
||||
|
||||
class SetComp(ExprNode):
|
||||
"""SetComp(elt: AST, generators: list[AST | CPtr])"""
|
||||
elt: rawptr[AST]
|
||||
generators: rawptr[list[rawptr[AST]]]
|
||||
elt: AST*
|
||||
generators: list[AST*]*
|
||||
|
||||
def __new__(self, pool: rawptr[memhub.MemManager],
|
||||
elt: rawptr[AST],
|
||||
generators: rawptr[list[rawptr[AST]]]):
|
||||
ptr: rawptr[SetComp] = pool.alloc(SetComp.__sizeof__())
|
||||
def __new__(self, pool: memhub.MemManager*,
|
||||
elt: AST*,
|
||||
generators: list[AST*]*):
|
||||
ptr: SetComp* = pool.alloc(SetComp.__sizeof__())
|
||||
if ptr: string.memset(ptr, 0, SetComp.__sizeof__())
|
||||
return ptr
|
||||
|
||||
def __init__(self, pool: rawptr[memhub.MemManager],
|
||||
elt: rawptr[AST],
|
||||
generators: rawptr[list[rawptr[AST]]]):
|
||||
def __init__(self, pool: memhub.MemManager*,
|
||||
elt: AST*,
|
||||
generators: list[AST*]*):
|
||||
_init_ast(self, pool, 0, 0)
|
||||
self.elt = elt
|
||||
self.generators = generators
|
||||
@@ -621,20 +621,20 @@ class SetComp(ExprNode):
|
||||
|
||||
class DictComp(ExprNode):
|
||||
"""DictComp(key: AST, value: AST, generators: list[AST | CPtr])"""
|
||||
key: rawptr[AST]
|
||||
value: rawptr[AST]
|
||||
generators: rawptr[list[rawptr[AST]]]
|
||||
key: AST*
|
||||
value: AST*
|
||||
generators: list[AST*]*
|
||||
|
||||
def __new__(self, pool: rawptr[memhub.MemManager],
|
||||
key: rawptr[AST], value: rawptr[AST],
|
||||
generators: rawptr[list[rawptr[AST]]]):
|
||||
ptr: rawptr[DictComp] = pool.alloc(DictComp.__sizeof__())
|
||||
def __new__(self, pool: memhub.MemManager*,
|
||||
key: AST*, value: AST*,
|
||||
generators: list[AST*]*):
|
||||
ptr: DictComp* = pool.alloc(DictComp.__sizeof__())
|
||||
if ptr: string.memset(ptr, 0, DictComp.__sizeof__())
|
||||
return ptr
|
||||
|
||||
def __init__(self, pool: rawptr[memhub.MemManager],
|
||||
key: rawptr[AST], value: rawptr[AST],
|
||||
generators: rawptr[list[rawptr[AST]]]):
|
||||
def __init__(self, pool: memhub.MemManager*,
|
||||
key: AST*, value: AST*,
|
||||
generators: list[AST*]*):
|
||||
_init_ast(self, pool, 0, 0)
|
||||
self.key = key
|
||||
self.value = value
|
||||
@@ -670,19 +670,19 @@ class DictComp(ExprNode):
|
||||
|
||||
class GeneratorExp(ExprNode):
|
||||
"""GeneratorExp(elt: AST, generators: list[AST | CPtr])"""
|
||||
elt: rawptr[AST]
|
||||
generators: rawptr[list[rawptr[AST]]]
|
||||
elt: AST*
|
||||
generators: list[AST*]*
|
||||
|
||||
def __new__(self, pool: rawptr[memhub.MemManager],
|
||||
elt: rawptr[AST],
|
||||
generators: rawptr[list[rawptr[AST]]]):
|
||||
ptr: rawptr[GeneratorExp] = pool.alloc(GeneratorExp.__sizeof__())
|
||||
def __new__(self, pool: memhub.MemManager*,
|
||||
elt: AST*,
|
||||
generators: list[AST*]*):
|
||||
ptr: GeneratorExp* = pool.alloc(GeneratorExp.__sizeof__())
|
||||
if ptr: string.memset(ptr, 0, GeneratorExp.__sizeof__())
|
||||
return ptr
|
||||
|
||||
def __init__(self, pool: rawptr[memhub.MemManager],
|
||||
elt: rawptr[AST],
|
||||
generators: rawptr[list[rawptr[AST]]]):
|
||||
def __init__(self, pool: memhub.MemManager*,
|
||||
elt: AST*,
|
||||
generators: list[AST*]*):
|
||||
_init_ast(self, pool, 0, 0)
|
||||
self.elt = elt
|
||||
self.generators = generators
|
||||
@@ -712,14 +712,14 @@ class GeneratorExp(ExprNode):
|
||||
|
||||
class Await(ExprNode):
|
||||
"""Await(value: AST)"""
|
||||
value: rawptr[AST]
|
||||
value: AST*
|
||||
|
||||
def __new__(self, pool: rawptr[memhub.MemManager], value: rawptr[AST]):
|
||||
ptr: rawptr[Await] = pool.alloc(Await.__sizeof__())
|
||||
def __new__(self, pool: memhub.MemManager*, value: AST*):
|
||||
ptr: Await* = pool.alloc(Await.__sizeof__())
|
||||
if ptr: string.memset(ptr, 0, Await.__sizeof__())
|
||||
return ptr
|
||||
|
||||
def __init__(self, pool: rawptr[memhub.MemManager], value: rawptr[AST]):
|
||||
def __init__(self, pool: memhub.MemManager*, value: AST*):
|
||||
_init_ast(self, pool, 0, 0)
|
||||
self.value = value
|
||||
|
||||
@@ -745,14 +745,14 @@ class Await(ExprNode):
|
||||
|
||||
class Yield(ExprNode):
|
||||
"""Yield(value: AST)"""
|
||||
value: rawptr[AST]
|
||||
value: AST*
|
||||
|
||||
def __new__(self, pool: rawptr[memhub.MemManager], value: rawptr[AST]):
|
||||
ptr: rawptr[Yield] = pool.alloc(Yield.__sizeof__())
|
||||
def __new__(self, pool: memhub.MemManager*, value: AST*):
|
||||
ptr: Yield* = pool.alloc(Yield.__sizeof__())
|
||||
if ptr: string.memset(ptr, 0, Yield.__sizeof__())
|
||||
return ptr
|
||||
|
||||
def __init__(self, pool: rawptr[memhub.MemManager], value: rawptr[AST]):
|
||||
def __init__(self, pool: memhub.MemManager*, value: AST*):
|
||||
_init_ast(self, pool, 0, 0)
|
||||
self.value = value
|
||||
|
||||
@@ -778,14 +778,14 @@ class Yield(ExprNode):
|
||||
|
||||
class YieldFrom(ExprNode):
|
||||
"""YieldFrom(value: AST)"""
|
||||
value: rawptr[AST]
|
||||
value: AST*
|
||||
|
||||
def __new__(self, pool: rawptr[memhub.MemManager], value: rawptr[AST]):
|
||||
ptr: rawptr[YieldFrom] = pool.alloc(YieldFrom.__sizeof__())
|
||||
def __new__(self, pool: memhub.MemManager*, value: AST*):
|
||||
ptr: YieldFrom* = pool.alloc(YieldFrom.__sizeof__())
|
||||
if ptr: string.memset(ptr, 0, YieldFrom.__sizeof__())
|
||||
return ptr
|
||||
|
||||
def __init__(self, pool: rawptr[memhub.MemManager], value: rawptr[AST]):
|
||||
def __init__(self, pool: memhub.MemManager*, value: AST*):
|
||||
_init_ast(self, pool, 0, 0)
|
||||
self.value = value
|
||||
|
||||
@@ -811,20 +811,20 @@ class YieldFrom(ExprNode):
|
||||
|
||||
class FormattedValue(ExprNode):
|
||||
"""FormattedValue(value: AST, conversion: CInt, format_spec: AST)"""
|
||||
value: rawptr[AST]
|
||||
value: AST*
|
||||
conversion: int
|
||||
format_spec: rawptr[AST]
|
||||
format_spec: AST*
|
||||
|
||||
def __new__(self, pool: rawptr[memhub.MemManager],
|
||||
value: rawptr[AST], conversion: int,
|
||||
format_spec: rawptr[AST]):
|
||||
ptr: rawptr[FormattedValue] = pool.alloc(FormattedValue.__sizeof__())
|
||||
def __new__(self, pool: memhub.MemManager*,
|
||||
value: AST*, conversion: int,
|
||||
format_spec: AST*):
|
||||
ptr: FormattedValue* = pool.alloc(FormattedValue.__sizeof__())
|
||||
if ptr: string.memset(ptr, 0, FormattedValue.__sizeof__())
|
||||
return ptr
|
||||
|
||||
def __init__(self, pool: rawptr[memhub.MemManager],
|
||||
value: rawptr[AST], conversion: int,
|
||||
format_spec: rawptr[AST]):
|
||||
def __init__(self, pool: memhub.MemManager*,
|
||||
value: AST*, conversion: int,
|
||||
format_spec: AST*):
|
||||
_init_ast(self, pool, 0, 0)
|
||||
self.value = value
|
||||
self.conversion = conversion
|
||||
@@ -859,16 +859,16 @@ class FormattedValue(ExprNode):
|
||||
|
||||
class JoinedStr(ExprNode):
|
||||
"""JoinedStr(values: list[AST | CPtr])"""
|
||||
values: rawptr[list[rawptr[AST]]]
|
||||
values: list[AST*]*
|
||||
|
||||
def __new__(self, pool: rawptr[memhub.MemManager], values: rawptr[list[rawptr[AST]]]):
|
||||
ptr: rawptr[JoinedStr] = pool.alloc(JoinedStr.__sizeof__())
|
||||
def __new__(self, pool: memhub.MemManager*, values: list[AST*]*):
|
||||
ptr: JoinedStr* = pool.alloc(JoinedStr.__sizeof__())
|
||||
if ptr:
|
||||
string.memset(ptr, 0, JoinedStr.__sizeof__())
|
||||
return ptr
|
||||
|
||||
def __init__(self, pool: rawptr[memhub.MemManager],
|
||||
values: rawptr[list[rawptr[AST]]]):
|
||||
def __init__(self, pool: memhub.MemManager*,
|
||||
values: list[AST*]*):
|
||||
_init_ast(self, pool, 0, 0)
|
||||
self.values = values
|
||||
_set_parent_list(values, self)
|
||||
@@ -892,18 +892,18 @@ class JoinedStr(ExprNode):
|
||||
|
||||
class Attribute(ExprNode):
|
||||
"""Attribute(value: AST, attr: str, ctx: CInt)"""
|
||||
value: rawptr[AST]
|
||||
value: AST*
|
||||
attr: str
|
||||
ctx: int
|
||||
|
||||
def __new__(self, pool: rawptr[memhub.MemManager],
|
||||
value: rawptr[AST], attr: str, ctx: int):
|
||||
ptr: rawptr[Attribute] = pool.alloc(Attribute.__sizeof__())
|
||||
def __new__(self, pool: memhub.MemManager*,
|
||||
value: AST*, attr: str, ctx: int):
|
||||
ptr: Attribute* = pool.alloc(Attribute.__sizeof__())
|
||||
if ptr: string.memset(ptr, 0, Attribute.__sizeof__())
|
||||
return ptr
|
||||
|
||||
def __init__(self, pool: rawptr[memhub.MemManager],
|
||||
value: rawptr[AST], attr: str, ctx: int):
|
||||
def __init__(self, pool: memhub.MemManager*,
|
||||
value: AST*, attr: str, ctx: int):
|
||||
_init_ast(self, pool, 0, 0)
|
||||
self.value = value
|
||||
self.attr = _copy_str(pool, attr)
|
||||
@@ -933,13 +933,13 @@ class Attribute(ExprNode):
|
||||
# Field accessors (guard against cross-module stub field-access pitfalls): other modules reading
|
||||
# ast.Attribute fields directly may get a wrong stub GEP and crash, so they use these accessors.
|
||||
# ============================================================
|
||||
def attribute_get_value(node: rawptr[Attribute]) -> rawptr[AST]:
|
||||
def attribute_get_value(node: Attribute*) -> AST*:
|
||||
"""Get Attribute.value field (cross-module accessor)"""
|
||||
if node is None: return None
|
||||
return node.value
|
||||
|
||||
|
||||
def attribute_get_attr(node: rawptr[Attribute]) -> str:
|
||||
def attribute_get_attr(node: Attribute*) -> str:
|
||||
"""Get Attribute.attr field (cross-module accessor)"""
|
||||
if node is None: return None
|
||||
return node.attr
|
||||
@@ -951,18 +951,18 @@ def attribute_get_attr(node: rawptr[Attribute]) -> str:
|
||||
|
||||
class Subscript(ExprNode):
|
||||
"""Subscript(value: AST, slice: AST, ctx: CInt)"""
|
||||
value: rawptr[AST]
|
||||
slice: rawptr[AST]
|
||||
value: AST*
|
||||
slice: AST*
|
||||
ctx: int
|
||||
|
||||
def __new__(self, pool: rawptr[memhub.MemManager],
|
||||
value: rawptr[AST], slice: rawptr[AST], ctx: int):
|
||||
ptr: rawptr[Subscript] = pool.alloc(Subscript.__sizeof__())
|
||||
def __new__(self, pool: memhub.MemManager*,
|
||||
value: AST*, slice: AST*, ctx: int):
|
||||
ptr: Subscript* = pool.alloc(Subscript.__sizeof__())
|
||||
if ptr: string.memset(ptr, 0, Subscript.__sizeof__())
|
||||
return ptr
|
||||
|
||||
def __init__(self, pool: rawptr[memhub.MemManager],
|
||||
value: rawptr[AST], slice: rawptr[AST], ctx: int):
|
||||
def __init__(self, pool: memhub.MemManager*,
|
||||
value: AST*, slice: AST*, ctx: int):
|
||||
_init_ast(self, pool, 0, 0)
|
||||
self.value = value
|
||||
self.slice = slice
|
||||
@@ -997,17 +997,17 @@ class Subscript(ExprNode):
|
||||
|
||||
class Starred(ExprNode):
|
||||
"""Starred(value: AST, ctx: CInt)"""
|
||||
value: rawptr[AST]
|
||||
value: AST*
|
||||
ctx: int
|
||||
|
||||
def __new__(self, pool: rawptr[memhub.MemManager],
|
||||
value: rawptr[AST], ctx: int):
|
||||
ptr: rawptr[Starred] = pool.alloc(Starred.__sizeof__())
|
||||
def __new__(self, pool: memhub.MemManager*,
|
||||
value: AST*, ctx: int):
|
||||
ptr: Starred* = pool.alloc(Starred.__sizeof__())
|
||||
if ptr: string.memset(ptr, 0, Starred.__sizeof__())
|
||||
return ptr
|
||||
|
||||
def __init__(self, pool: rawptr[memhub.MemManager],
|
||||
value: rawptr[AST], ctx: int):
|
||||
def __init__(self, pool: memhub.MemManager*,
|
||||
value: AST*, ctx: int):
|
||||
_init_ast(self, pool, 0, 0)
|
||||
self.value = value
|
||||
self.ctx = ctx
|
||||
@@ -1036,17 +1036,17 @@ class Starred(ExprNode):
|
||||
|
||||
class List(ExprNode):
|
||||
"""List(elts: list[AST | CPtr], ctx: CInt)"""
|
||||
elts: rawptr[list[rawptr[AST]]]
|
||||
elts: list[AST*]*
|
||||
ctx: int
|
||||
|
||||
def __new__(self, pool: rawptr[memhub.MemManager],
|
||||
elts: rawptr[list[rawptr[AST]]], ctx: int):
|
||||
ptr: rawptr[List] = pool.alloc(List.__sizeof__())
|
||||
def __new__(self, pool: memhub.MemManager*,
|
||||
elts: list[AST*]*, ctx: int):
|
||||
ptr: List* = pool.alloc(List.__sizeof__())
|
||||
if ptr: string.memset(ptr, 0, List.__sizeof__())
|
||||
return ptr
|
||||
|
||||
def __init__(self, pool: rawptr[memhub.MemManager],
|
||||
elts: rawptr[list[rawptr[AST]]], ctx: int):
|
||||
def __init__(self, pool: memhub.MemManager*,
|
||||
elts: list[AST*]*, ctx: int):
|
||||
_init_ast(self, pool, 0, 0)
|
||||
self.elts = elts
|
||||
self.ctx = ctx
|
||||
@@ -1073,17 +1073,17 @@ class List(ExprNode):
|
||||
|
||||
class Tuple(ExprNode):
|
||||
"""Tuple(elts: list[AST | CPtr], ctx: CInt)"""
|
||||
elts: rawptr[list[rawptr[AST]]]
|
||||
elts: list[AST*]*
|
||||
ctx: int
|
||||
|
||||
def __new__(self, pool: rawptr[memhub.MemManager],
|
||||
elts: rawptr[list[rawptr[AST]]], ctx: int):
|
||||
ptr: rawptr[Tuple] = pool.alloc(Tuple.__sizeof__())
|
||||
def __new__(self, pool: memhub.MemManager*,
|
||||
elts: list[AST*]*, ctx: int):
|
||||
ptr: Tuple* = pool.alloc(Tuple.__sizeof__())
|
||||
if ptr: string.memset(ptr, 0, Tuple.__sizeof__())
|
||||
return ptr
|
||||
|
||||
def __init__(self, pool: rawptr[memhub.MemManager],
|
||||
elts: rawptr[list[rawptr[AST]]], ctx: int):
|
||||
def __init__(self, pool: memhub.MemManager*,
|
||||
elts: list[AST*]*, ctx: int):
|
||||
_init_ast(self, pool, 0, 0)
|
||||
self.elts = elts
|
||||
self.ctx = ctx
|
||||
@@ -1110,20 +1110,20 @@ class Tuple(ExprNode):
|
||||
|
||||
class Slice(ExprNode):
|
||||
"""Slice(lower: AST, upper: AST, step: AST)"""
|
||||
lower: rawptr[AST]
|
||||
upper: rawptr[AST]
|
||||
step: rawptr[AST]
|
||||
lower: AST*
|
||||
upper: AST*
|
||||
step: AST*
|
||||
|
||||
def __new__(self, pool: rawptr[memhub.MemManager],
|
||||
lower: rawptr[AST], upper: rawptr[AST],
|
||||
step: rawptr[AST]):
|
||||
ptr: rawptr[Slice] = pool.alloc(Slice.__sizeof__())
|
||||
def __new__(self, pool: memhub.MemManager*,
|
||||
lower: AST*, upper: AST*,
|
||||
step: AST*):
|
||||
ptr: Slice* = pool.alloc(Slice.__sizeof__())
|
||||
if ptr: string.memset(ptr, 0, Slice.__sizeof__())
|
||||
return ptr
|
||||
|
||||
def __init__(self, pool: rawptr[memhub.MemManager],
|
||||
lower: rawptr[AST], upper: rawptr[AST],
|
||||
step: rawptr[AST]):
|
||||
def __init__(self, pool: memhub.MemManager*,
|
||||
lower: AST*, upper: AST*,
|
||||
step: AST*):
|
||||
_init_ast(self, pool, 0, 0)
|
||||
self.lower = lower
|
||||
self.upper = upper
|
||||
@@ -1161,17 +1161,17 @@ class Slice(ExprNode):
|
||||
|
||||
class NamedExpr(ExprNode):
|
||||
"""NamedExpr(target: AST, value: AST)"""
|
||||
target: rawptr[AST]
|
||||
value: rawptr[AST]
|
||||
target: AST*
|
||||
value: AST*
|
||||
|
||||
def __new__(self, pool: rawptr[memhub.MemManager],
|
||||
target: rawptr[AST], value: rawptr[AST]):
|
||||
ptr: rawptr[NamedExpr] = pool.alloc(NamedExpr.__sizeof__())
|
||||
def __new__(self, pool: memhub.MemManager*,
|
||||
target: AST*, value: AST*):
|
||||
ptr: NamedExpr* = pool.alloc(NamedExpr.__sizeof__())
|
||||
if ptr: string.memset(ptr, 0, NamedExpr.__sizeof__())
|
||||
return ptr
|
||||
|
||||
def __init__(self, pool: rawptr[memhub.MemManager],
|
||||
target: rawptr[AST], value: rawptr[AST]):
|
||||
def __init__(self, pool: memhub.MemManager*,
|
||||
target: AST*, value: AST*):
|
||||
_init_ast(self, pool, 0, 0)
|
||||
self.target = target
|
||||
self.value = value
|
||||
@@ -1205,12 +1205,12 @@ class OpNode(AST):
|
||||
"""OpNode(op: CInt)"""
|
||||
op: int
|
||||
|
||||
def __new__(self, pool: rawptr[memhub.MemManager], op: int):
|
||||
ptr: rawptr[OpNode] = pool.alloc(OpNode.__sizeof__())
|
||||
def __new__(self, pool: memhub.MemManager*, op: int):
|
||||
ptr: OpNode* = pool.alloc(OpNode.__sizeof__())
|
||||
if ptr: string.memset(ptr, 0, OpNode.__sizeof__())
|
||||
return ptr
|
||||
|
||||
def __init__(self, pool: rawptr[memhub.MemManager], op: int):
|
||||
def __init__(self, pool: memhub.MemManager*, op: int):
|
||||
_init_ast(self, pool, 0, 0)
|
||||
self.op = op
|
||||
|
||||
|
||||
+35
-35
@@ -307,17 +307,17 @@ class Lexer:
|
||||
len: sizet # Source code length
|
||||
lineno: int # Current line number (1-based)
|
||||
col: int # Current column number (0-based)
|
||||
pool: rawptr[memhub.MemManager] # Memory pool
|
||||
indent_stack: rawptr[int] # Indent stack (int array, allocated from pool)
|
||||
pool: memhub.MemManager* # Memory pool
|
||||
indent_stack: int* # Indent stack (int array, allocated from pool)
|
||||
indent_top: int # Stack top (-1 for empty stack)
|
||||
paren_depth: int # Paren depth (>0 for no TokenType.NewLine)
|
||||
tokens_head: rawptr[Token] # token list head
|
||||
tokens_tail: rawptr[Token] # token list tail
|
||||
tokens_head: Token* # token list head
|
||||
tokens_tail: Token* # token list tail
|
||||
at_line_start: int # 1=line start (need indent)
|
||||
error_count: int # Error count
|
||||
|
||||
def __new__(self, pool: rawptr[memhub.MemManager]):
|
||||
ptr: rawptr[Lexer] = pool.alloc(Lexer.__sizeof__())
|
||||
def __new__(self, pool: memhub.MemManager*):
|
||||
ptr: Lexer* = pool.alloc(Lexer.__sizeof__())
|
||||
if ptr == None:
|
||||
# Pool exhausted: fail-fast instead of returning NULL (downstream would treat NULL as a valid Lexer)
|
||||
stdio.printf("[AST] Lexer 分配失败:内存池已耗尽(need=%zu 字节)\n",
|
||||
@@ -328,12 +328,12 @@ class Lexer:
|
||||
return ptr
|
||||
|
||||
|
||||
def new_lexer(pool: rawptr[memhub.MemManager]) -> rawptr[Lexer]:
|
||||
def new_lexer(pool: memhub.MemManager*) -> Lexer*:
|
||||
"""Allocate from the pool and return a Lexer (cross-module safe wrapper)"""
|
||||
return Lexer(pool)
|
||||
|
||||
|
||||
def _lexer_init(lx: rawptr[Lexer], src: str, pool: rawptr[memhub.MemManager]):
|
||||
def _lexer_init(lx: Lexer*, src: str, pool: memhub.MemManager*):
|
||||
"""Initialize Lexer"""
|
||||
if lx == None: return
|
||||
lx.src = src
|
||||
@@ -366,19 +366,19 @@ def _lexer_init(lx: rawptr[Lexer], src: str, pool: rawptr[memhub.MemManager]):
|
||||
# Auxiliary Functions
|
||||
# ============================================================
|
||||
|
||||
def _peek(lx: rawptr[Lexer], offset: sizet) -> char:
|
||||
def _peek(lx: Lexer*, offset: sizet) -> char:
|
||||
"""Peek character at position pos+offset, return '\0' if out of bounds"""
|
||||
p: sizet = lx.pos + offset
|
||||
if p >= lx.len: return '\0'
|
||||
return lx.src[p]
|
||||
|
||||
|
||||
def _peek_cur(lx: rawptr[Lexer]) -> char:
|
||||
def _peek_cur(lx: Lexer*) -> char:
|
||||
if lx.pos >= lx.len: return '\0'
|
||||
return lx.src[lx.pos]
|
||||
|
||||
|
||||
def _advance(lx: rawptr[Lexer]) -> char:
|
||||
def _advance(lx: Lexer*) -> char:
|
||||
"""Advance one character, return the character"""
|
||||
if lx.pos >= lx.len: return '\0'
|
||||
ch: char = lx.src[lx.pos]
|
||||
@@ -433,7 +433,7 @@ def _is_space(ch: char) -> int:
|
||||
return 0
|
||||
|
||||
|
||||
def _emit(lx: rawptr[Lexer], tok: rawptr[Token]):
|
||||
def _emit(lx: Lexer*, tok: Token*):
|
||||
"""Append token to token list"""
|
||||
if tok == None: return
|
||||
if lx.tokens_head == None:
|
||||
@@ -444,9 +444,9 @@ def _emit(lx: rawptr[Lexer], tok: rawptr[Token]):
|
||||
lx.tokens_tail = tok
|
||||
|
||||
|
||||
def _make_op_token(lx: rawptr[Lexer], op_id: int, length: int,
|
||||
lineno: int, col: int) -> rawptr[Token]:
|
||||
tok: rawptr[Token] = new_token(lx.pool, TokenType.Op, lineno, col)
|
||||
def _make_op_token(lx: Lexer*, op_id: int, length: int,
|
||||
lineno: int, col: int) -> Token*:
|
||||
tok: Token* = new_token(lx.pool, TokenType.Op, lineno, col)
|
||||
if tok == None: return None
|
||||
tok.op_subtype = op_id
|
||||
tok.end_col_offset = col + length
|
||||
@@ -457,7 +457,7 @@ def _make_op_token(lx: rawptr[Lexer], op_id: int, length: int,
|
||||
# Indent Handling
|
||||
# ============================================================
|
||||
|
||||
def _handle_indent(lx: rawptr[Lexer]):
|
||||
def _handle_indent(lx: Lexer*):
|
||||
"""Handle line start indent, generate TokenType.Indent/TokenType.Dedent.
|
||||
Skip empty lines and comment lines."""
|
||||
# Skip empty lines and comment lines
|
||||
@@ -544,12 +544,12 @@ def _handle_indent(lx: rawptr[Lexer]):
|
||||
return
|
||||
lx.indent_top += 1
|
||||
lx.indent_stack[lx.indent_top] = indent
|
||||
tok: rawptr[Token] = new_token(lx.pool, TokenType.Indent, lx.lineno, 0)
|
||||
tok: Token* = new_token(lx.pool, TokenType.Indent, lx.lineno, 0)
|
||||
_emit(lx, tok)
|
||||
else:
|
||||
while indent < lx.indent_stack[lx.indent_top] and lx.indent_top > 0:
|
||||
lx.indent_top -= 1
|
||||
tok: rawptr[Token] = new_token(lx.pool, TokenType.Dedent, lx.lineno, 0)
|
||||
tok: Token* = new_token(lx.pool, TokenType.Dedent, lx.lineno, 0)
|
||||
_emit(lx, tok)
|
||||
lx.at_line_start = 0
|
||||
|
||||
@@ -558,7 +558,7 @@ def _handle_indent(lx: rawptr[Lexer]):
|
||||
# Identifier/Keyword Handling
|
||||
# ============================================================
|
||||
|
||||
def _read_name(lx: rawptr[Lexer]):
|
||||
def _read_name(lx: Lexer*):
|
||||
start: sizet = lx.pos
|
||||
start_lineno: int = lx.lineno
|
||||
start_col: int = lx.col
|
||||
@@ -570,7 +570,7 @@ def _read_name(lx: rawptr[Lexer]):
|
||||
else:
|
||||
break
|
||||
length: sizet = lx.pos - start
|
||||
tok: rawptr[Token] = new_token(lx.pool, TokenType.Name, start_lineno, start_col)
|
||||
tok: Token* = new_token(lx.pool, TokenType.Name, start_lineno, start_col)
|
||||
if tok == None: return
|
||||
token_set_str(lx.pool, tok, lx.src, start, length)
|
||||
tok.end_lineno = lx.lineno
|
||||
@@ -585,7 +585,7 @@ def _read_name(lx: rawptr[Lexer]):
|
||||
# Number Handling
|
||||
# ============================================================
|
||||
|
||||
def _read_number(lx: rawptr[Lexer]):
|
||||
def _read_number(lx: Lexer*):
|
||||
start: sizet = lx.pos
|
||||
start_lineno: int = lx.lineno
|
||||
start_col: int = lx.col
|
||||
@@ -688,11 +688,11 @@ def _read_number(lx: rawptr[Lexer]):
|
||||
_emit_number(lx, start, start_lineno, start_col, is_float, is_complex, 0)
|
||||
|
||||
|
||||
def _emit_number(lx: rawptr[Lexer], start: sizet,
|
||||
def _emit_number(lx: Lexer*, start: sizet,
|
||||
start_lineno: int, start_col: int,
|
||||
is_float: int, is_complex: int, is_hex: int):
|
||||
length: sizet = lx.pos - start
|
||||
tok: rawptr[Token] = new_token(lx.pool, TokenType.Number, start_lineno, start_col)
|
||||
tok: Token* = new_token(lx.pool, TokenType.Number, start_lineno, start_col)
|
||||
if tok == None: return
|
||||
token_set_str(lx.pool, tok, lx.src, start, length)
|
||||
tok.is_float = is_float
|
||||
@@ -715,7 +715,7 @@ def _emit_number(lx: rawptr[Lexer], start: sizet,
|
||||
# String Handling
|
||||
# ============================================================
|
||||
|
||||
def _read_string(lx: rawptr[Lexer]):
|
||||
def _read_string(lx: Lexer*):
|
||||
"""Read string literal.
|
||||
Supports prefixes: r, b, u, f, rb, br, rf, fr (case insensitive)
|
||||
Supports quotes: ', ", ''',
|
||||
@@ -875,7 +875,7 @@ def _read_string(lx: rawptr[Lexer]):
|
||||
lx.col += 1
|
||||
|
||||
# Create token
|
||||
tok: rawptr[Token] = new_token(lx.pool, TokenType.String, start_lineno, start_col)
|
||||
tok: Token* = new_token(lx.pool, TokenType.String, start_lineno, start_col)
|
||||
if tok == None: return
|
||||
content_len: sizet = content_end - content_buf_start
|
||||
# esc_len: Actual bytes after escaping (used to check single character)
|
||||
@@ -968,16 +968,16 @@ def _read_string(lx: rawptr[Lexer]):
|
||||
# Operator Matching
|
||||
# ============================================================
|
||||
|
||||
def _read_operator(lx: rawptr[Lexer]):
|
||||
def _read_operator(lx: Lexer*):
|
||||
"""Greedy match operator"""
|
||||
start_lineno: int = lx.lineno
|
||||
start_col: int = lx.col
|
||||
remaining: sizet = lx.len - lx.pos
|
||||
|
||||
# Traverse operator table, find longest match
|
||||
best_entry: rawptr[OpEntry] = None
|
||||
best_entry: OpEntry* = None
|
||||
best_len: int = 0
|
||||
cur: rawptr[OpEntry] = _op_head
|
||||
cur: OpEntry* = _op_head
|
||||
while cur != None:
|
||||
if cur.length <= int(remaining):
|
||||
# Compare cur.name with src[pos:pos+cur.length]
|
||||
@@ -1006,7 +1006,7 @@ def _read_operator(lx: rawptr[Lexer]):
|
||||
if lx.paren_depth > 0:
|
||||
lx.paren_depth -= 1
|
||||
|
||||
tok: rawptr[Token] = _make_op_token(lx, best_entry.op_id, best_entry.length,
|
||||
tok: Token* = _make_op_token(lx, best_entry.op_id, best_entry.length,
|
||||
start_lineno, start_col)
|
||||
if tok == None: return
|
||||
token_set_str(lx.pool, tok, lx.src, lx.pos, sizet(best_len))
|
||||
@@ -1019,7 +1019,7 @@ def _read_operator(lx: rawptr[Lexer]):
|
||||
# Main Lexical Analysis Entry Point
|
||||
# ============================================================
|
||||
|
||||
def tokenize(lx: rawptr[Lexer]) -> rawptr[Token]:
|
||||
def tokenize(lx: Lexer*) -> Token*:
|
||||
"""Execute tokenization, return token list head"""
|
||||
if lx == None: return None
|
||||
while lx.pos < lx.len:
|
||||
@@ -1037,11 +1037,11 @@ def tokenize(lx: rawptr[Lexer]) -> rawptr[Token]:
|
||||
if ch == '\n':
|
||||
if lx.paren_depth > 0:
|
||||
# # In bi brackets, generates TokenType.Nl
|
||||
tok: rawptr[Token] = new_token(lx.pool, TokenType.Nl, lx.lineno, lx.col)
|
||||
tok: Token* = new_token(lx.pool, TokenType.Nl, lx.lineno, lx.col)
|
||||
_emit(lx, tok)
|
||||
else:
|
||||
# Logical new line
|
||||
tok: rawptr[Token] = new_token(lx.pool, TokenType.NewLine, lx.lineno, lx.col)
|
||||
tok: Token* = new_token(lx.pool, TokenType.NewLine, lx.lineno, lx.col)
|
||||
_emit(lx, tok)
|
||||
lx.at_line_start = 1
|
||||
lx.pos += 1
|
||||
@@ -1116,17 +1116,17 @@ def tokenize(lx: rawptr[Lexer]) -> rawptr[Token]:
|
||||
# End of file: generate TokenType.NewLine (if there's content)
|
||||
if lx.tokens_tail != None:
|
||||
if lx.tokens_tail.type != TokenType.NewLine and lx.tokens_tail.type != TokenType.Nl:
|
||||
tok: rawptr[Token] = new_token(lx.pool, TokenType.NewLine, lx.lineno, lx.col)
|
||||
tok: Token* = new_token(lx.pool, TokenType.NewLine, lx.lineno, lx.col)
|
||||
_emit(lx, tok)
|
||||
|
||||
# Generate remaining remaining TokenType.Dedent
|
||||
while lx.indent_top > 0:
|
||||
lx.indent_top -= 1
|
||||
tok: rawptr[Token] = new_token(lx.pool, TokenType.Dedent, lx.lineno, 0)
|
||||
tok: Token* = new_token(lx.pool, TokenType.Dedent, lx.lineno, 0)
|
||||
_emit(lx, tok)
|
||||
|
||||
# TokenType.EndMarker
|
||||
tok: rawptr[Token] = new_token(lx.pool, TokenType.EndMarker, lx.lineno, 0)
|
||||
tok: Token* = new_token(lx.pool, TokenType.EndMarker, lx.lineno, 0)
|
||||
_emit(lx, tok)
|
||||
|
||||
return lx.tokens_head
|
||||
+61
-61
@@ -14,17 +14,17 @@ from .base import (
|
||||
# ============================================================
|
||||
class MatchCase(AST):
|
||||
"""MatchCase(pattern: AST, guard: AST)"""
|
||||
pattern: rawptr[AST]
|
||||
guard: rawptr[AST]
|
||||
pattern: AST*
|
||||
guard: AST*
|
||||
|
||||
def __new__(self, pool: rawptr[memhub.MemManager],
|
||||
pattern: rawptr[AST], guard: rawptr[AST]):
|
||||
ptr: rawptr[MatchCase] = pool.alloc(MatchCase.__sizeof__())
|
||||
def __new__(self, pool: memhub.MemManager*,
|
||||
pattern: AST*, guard: AST*):
|
||||
ptr: MatchCase* = pool.alloc(MatchCase.__sizeof__())
|
||||
if ptr: string.memset(ptr, 0, MatchCase.__sizeof__())
|
||||
return ptr
|
||||
|
||||
def __init__(self, pool: rawptr[memhub.MemManager],
|
||||
pattern: rawptr[AST], guard: rawptr[AST]):
|
||||
def __init__(self, pool: memhub.MemManager*,
|
||||
pattern: AST*, guard: AST*):
|
||||
_init_ast(self, pool, 0, 0)
|
||||
self.pattern = pattern
|
||||
self.guard = guard
|
||||
@@ -53,14 +53,14 @@ class MatchCase(AST):
|
||||
# ============================================================
|
||||
class MatchValue(AST):
|
||||
"""MatchValue(value: AST)"""
|
||||
value: rawptr[AST]
|
||||
value: AST*
|
||||
|
||||
def __new__(self, pool: rawptr[memhub.MemManager], value: rawptr[AST]):
|
||||
ptr: rawptr[MatchValue] = pool.alloc(MatchValue.__sizeof__())
|
||||
def __new__(self, pool: memhub.MemManager*, value: AST*):
|
||||
ptr: MatchValue* = pool.alloc(MatchValue.__sizeof__())
|
||||
if ptr: string.memset(ptr, 0, MatchValue.__sizeof__())
|
||||
return ptr
|
||||
|
||||
def __init__(self, pool: rawptr[memhub.MemManager], value: rawptr[AST]):
|
||||
def __init__(self, pool: memhub.MemManager*, value: AST*):
|
||||
_init_ast(self, pool, 0, 0)
|
||||
self.value = value
|
||||
|
||||
@@ -83,14 +83,14 @@ class MatchValue(AST):
|
||||
# ============================================================
|
||||
class MatchSingleton(AST):
|
||||
"""MatchSingleton(value: AST)"""
|
||||
value: rawptr[AST]
|
||||
value: AST*
|
||||
|
||||
def __new__(self, pool: rawptr[memhub.MemManager], value: rawptr[AST]):
|
||||
ptr: rawptr[MatchSingleton] = pool.alloc(MatchSingleton.__sizeof__())
|
||||
def __new__(self, pool: memhub.MemManager*, value: AST*):
|
||||
ptr: MatchSingleton* = pool.alloc(MatchSingleton.__sizeof__())
|
||||
if ptr: string.memset(ptr, 0, MatchSingleton.__sizeof__())
|
||||
return ptr
|
||||
|
||||
def __init__(self, pool: rawptr[memhub.MemManager], value: rawptr[AST]):
|
||||
def __init__(self, pool: memhub.MemManager*, value: AST*):
|
||||
_init_ast(self, pool, 0, 0)
|
||||
self.value = value
|
||||
|
||||
@@ -113,16 +113,16 @@ class MatchSingleton(AST):
|
||||
# ============================================================
|
||||
class MatchSequence(AST):
|
||||
"""MatchSequence(patterns: list[rawptr[AST]])"""
|
||||
patterns: rawptr[list[rawptr[AST]]]
|
||||
patterns: list[AST*]*
|
||||
|
||||
def __new__(self, pool: rawptr[memhub.MemManager],
|
||||
patterns: rawptr[list[rawptr[AST]]]):
|
||||
ptr: rawptr[MatchSequence] = pool.alloc(MatchSequence.__sizeof__())
|
||||
def __new__(self, pool: memhub.MemManager*,
|
||||
patterns: list[AST*]*):
|
||||
ptr: MatchSequence* = pool.alloc(MatchSequence.__sizeof__())
|
||||
if ptr: string.memset(ptr, 0, MatchSequence.__sizeof__())
|
||||
return ptr
|
||||
|
||||
def __init__(self, pool: rawptr[memhub.MemManager],
|
||||
patterns: rawptr[list[rawptr[AST]]]):
|
||||
def __init__(self, pool: memhub.MemManager*,
|
||||
patterns: list[AST*]*):
|
||||
_init_ast(self, pool, 0, 0)
|
||||
self.patterns = patterns
|
||||
_set_parent_list(patterns, self)
|
||||
@@ -145,21 +145,21 @@ class MatchSequence(AST):
|
||||
# ============================================================
|
||||
class MatchMapping(AST):
|
||||
"""MatchMapping(keys: list[rawptr[AST]], patterns: list[rawptr[AST]], rest: str)"""
|
||||
keys: rawptr[list[rawptr[AST]]]
|
||||
patterns: rawptr[list[rawptr[AST]]]
|
||||
keys: list[AST*]*
|
||||
patterns: list[AST*]*
|
||||
rest: str
|
||||
|
||||
def __new__(self, pool: rawptr[memhub.MemManager],
|
||||
keys: rawptr[list[rawptr[AST]]],
|
||||
patterns: rawptr[list[rawptr[AST]]],
|
||||
def __new__(self, pool: memhub.MemManager*,
|
||||
keys: list[AST*]*,
|
||||
patterns: list[AST*]*,
|
||||
rest: str):
|
||||
ptr: rawptr[MatchMapping] = pool.alloc(MatchMapping.__sizeof__())
|
||||
ptr: MatchMapping* = pool.alloc(MatchMapping.__sizeof__())
|
||||
if ptr: string.memset(ptr, 0, MatchMapping.__sizeof__())
|
||||
return ptr
|
||||
|
||||
def __init__(self, pool: rawptr[memhub.MemManager],
|
||||
keys: rawptr[list[rawptr[AST]]],
|
||||
patterns: rawptr[list[rawptr[AST]]],
|
||||
def __init__(self, pool: memhub.MemManager*,
|
||||
keys: list[AST*]*,
|
||||
patterns: list[AST*]*,
|
||||
rest: str):
|
||||
_init_ast(self, pool, 0, 0)
|
||||
self.keys = keys
|
||||
@@ -191,26 +191,26 @@ class MatchMapping(AST):
|
||||
|
||||
class MatchClass(AST):
|
||||
"""MatchClass(cls: AST, patterns: list[rawptr[AST]],
|
||||
kwd_attrs: list[rawptr[AST]], kwd_patterns: list[rawptr[AST]])"""
|
||||
cls: rawptr[AST]
|
||||
patterns: rawptr[list[rawptr[AST]]]
|
||||
kwd_attrs: rawptr[list[rawptr[AST]]]
|
||||
kwd_patterns: rawptr[list[rawptr[AST]]]
|
||||
kwd_attrs: list[AST*], kwd_patterns: list[AST*])"""
|
||||
cls: AST*
|
||||
patterns: list[AST*]*
|
||||
kwd_attrs: list[AST*]*
|
||||
kwd_patterns: list[AST*]*
|
||||
|
||||
def __new__(self, pool: rawptr[memhub.MemManager],
|
||||
cls: rawptr[AST],
|
||||
patterns: rawptr[list[rawptr[AST]]],
|
||||
kwd_attrs: rawptr[list[rawptr[AST]]],
|
||||
kwd_patterns: rawptr[list[rawptr[AST]]]):
|
||||
ptr: rawptr[MatchClass] = pool.alloc(MatchClass.__sizeof__())
|
||||
def __new__(self, pool: memhub.MemManager*,
|
||||
cls: AST*,
|
||||
patterns: list[AST*]*,
|
||||
kwd_attrs: list[AST*]*,
|
||||
kwd_patterns: list[AST*]*):
|
||||
ptr: MatchClass* = pool.alloc(MatchClass.__sizeof__())
|
||||
if ptr: string.memset(ptr, 0, MatchClass.__sizeof__())
|
||||
return ptr
|
||||
|
||||
def __init__(self, pool: rawptr[memhub.MemManager],
|
||||
cls: rawptr[AST],
|
||||
patterns: rawptr[list[rawptr[AST]]],
|
||||
kwd_attrs: rawptr[list[rawptr[AST]]],
|
||||
kwd_patterns: rawptr[list[rawptr[AST]]]):
|
||||
def __init__(self, pool: memhub.MemManager*,
|
||||
cls: AST*,
|
||||
patterns: list[AST*]*,
|
||||
kwd_attrs: list[AST*]*,
|
||||
kwd_patterns: list[AST*]*):
|
||||
_init_ast(self, pool, 0, 0)
|
||||
self.cls = cls
|
||||
self.patterns = patterns
|
||||
@@ -247,12 +247,12 @@ class MatchStar(AST):
|
||||
"""MatchStar(name: str)"""
|
||||
name: str
|
||||
|
||||
def __new__(self, pool: rawptr[memhub.MemManager], name: str):
|
||||
ptr: rawptr[MatchStar] = pool.alloc(MatchStar.__sizeof__())
|
||||
def __new__(self, pool: memhub.MemManager*, name: str):
|
||||
ptr: MatchStar* = pool.alloc(MatchStar.__sizeof__())
|
||||
if ptr: string.memset(ptr, 0, MatchStar.__sizeof__())
|
||||
return ptr
|
||||
|
||||
def __init__(self, pool: rawptr[memhub.MemManager], name: str):
|
||||
def __init__(self, pool: memhub.MemManager*, name: str):
|
||||
_init_ast(self, pool, 0, 0)
|
||||
self.name = _copy_str(pool, name)
|
||||
|
||||
@@ -275,17 +275,17 @@ class MatchStar(AST):
|
||||
|
||||
class MatchAs(AST):
|
||||
"""MatchAs(pattern: AST, name: str)"""
|
||||
pattern: rawptr[AST]
|
||||
pattern: AST*
|
||||
name: str
|
||||
|
||||
def __new__(self, pool: rawptr[memhub.MemManager],
|
||||
pattern: rawptr[AST], name: str):
|
||||
ptr: rawptr[MatchAs] = pool.alloc(MatchAs.__sizeof__())
|
||||
def __new__(self, pool: memhub.MemManager*,
|
||||
pattern: AST*, name: str):
|
||||
ptr: MatchAs* = pool.alloc(MatchAs.__sizeof__())
|
||||
if ptr: string.memset(ptr, 0, MatchAs.__sizeof__())
|
||||
return ptr
|
||||
|
||||
def __init__(self, pool: rawptr[memhub.MemManager],
|
||||
pattern: rawptr[AST], name: str):
|
||||
def __init__(self, pool: memhub.MemManager*,
|
||||
pattern: AST*, name: str):
|
||||
_init_ast(self, pool, 0, 0)
|
||||
self.pattern = pattern
|
||||
self.name = _copy_str(pool, name)
|
||||
@@ -311,16 +311,16 @@ class MatchAs(AST):
|
||||
|
||||
class MatchOr(AST):
|
||||
"""MatchOr(patterns: list[rawptr[AST]])"""
|
||||
patterns: rawptr[list[rawptr[AST]]]
|
||||
patterns: list[AST*]*
|
||||
|
||||
def __new__(self, pool: rawptr[memhub.MemManager],
|
||||
patterns: rawptr[list[rawptr[AST]]]):
|
||||
ptr: rawptr[MatchOr] = pool.alloc(MatchOr.__sizeof__())
|
||||
def __new__(self, pool: memhub.MemManager*,
|
||||
patterns: list[AST*]*):
|
||||
ptr: MatchOr* = pool.alloc(MatchOr.__sizeof__())
|
||||
if ptr: string.memset(ptr, 0, MatchOr.__sizeof__())
|
||||
return ptr
|
||||
|
||||
def __init__(self, pool: rawptr[memhub.MemManager],
|
||||
patterns: rawptr[list[rawptr[AST]]]):
|
||||
def __init__(self, pool: memhub.MemManager*,
|
||||
patterns: list[AST*]*):
|
||||
_init_ast(self, pool, 0, 0)
|
||||
self.patterns = patterns
|
||||
_set_parent_list(patterns, self)
|
||||
|
||||
+628
-628
File diff suppressed because it is too large.
Load diff
+200
-200
@@ -16,12 +16,12 @@ from .base import (
|
||||
virtual class Module(AST):
|
||||
"""Module(children: list[rawptr[AST]])"""
|
||||
|
||||
def __new__(self, pool: rawptr[memhub.MemManager]):
|
||||
ptr: rawptr[Module] = pool.alloc(Module.__sizeof__())
|
||||
def __new__(self, pool: memhub.MemManager*):
|
||||
ptr: Module* = pool.alloc(Module.__sizeof__())
|
||||
if ptr: string.memset(ptr, 0, Module.__sizeof__())
|
||||
return ptr
|
||||
|
||||
def __init__(self, pool: rawptr[memhub.MemManager]):
|
||||
def __init__(self, pool: memhub.MemManager*):
|
||||
_init_ast(self, pool, 0, 0)
|
||||
|
||||
def kind(self) -> int:
|
||||
@@ -43,17 +43,17 @@ virtual class Module(AST):
|
||||
|
||||
class Assign(Stmt):
|
||||
"""Assign(targets: list[rawptr[AST]], value: AST)"""
|
||||
targets: rawptr[list[rawptr[AST]]]
|
||||
value: rawptr[AST]
|
||||
targets: list[AST*]*
|
||||
value: AST*
|
||||
|
||||
def __new__(self, pool: rawptr[memhub.MemManager],
|
||||
targets: rawptr[list[rawptr[AST]]], value: rawptr[AST]):
|
||||
ptr: rawptr[Assign] = pool.alloc(Assign.__sizeof__())
|
||||
def __new__(self, pool: memhub.MemManager*,
|
||||
targets: list[AST*]*, value: AST*):
|
||||
ptr: Assign* = pool.alloc(Assign.__sizeof__())
|
||||
if ptr: string.memset(ptr, 0, Assign.__sizeof__())
|
||||
return ptr
|
||||
|
||||
def __init__(self, pool: rawptr[memhub.MemManager],
|
||||
targets: rawptr[list[rawptr[AST]]], value: rawptr[AST]):
|
||||
def __init__(self, pool: memhub.MemManager*,
|
||||
targets: list[AST*]*, value: AST*):
|
||||
_init_ast(self, pool, 0, 0)
|
||||
self.targets = targets
|
||||
self.value = value
|
||||
@@ -83,19 +83,19 @@ class Assign(Stmt):
|
||||
|
||||
class If(Stmt):
|
||||
"""If(test: AST, orelse: list[rawptr[AST]])"""
|
||||
test: rawptr[AST]
|
||||
orelse: rawptr[list[rawptr[AST]]]
|
||||
test: AST*
|
||||
orelse: list[AST*]*
|
||||
|
||||
def __new__(self, pool: rawptr[memhub.MemManager],
|
||||
test: rawptr[AST],
|
||||
orelse: rawptr[list[rawptr[AST]]]):
|
||||
ptr: rawptr[If] = pool.alloc(If.__sizeof__())
|
||||
def __new__(self, pool: memhub.MemManager*,
|
||||
test: AST*,
|
||||
orelse: list[AST*]*):
|
||||
ptr: If* = pool.alloc(If.__sizeof__())
|
||||
if ptr: string.memset(ptr, 0, If.__sizeof__())
|
||||
return ptr
|
||||
|
||||
def __init__(self, pool: rawptr[memhub.MemManager],
|
||||
test: rawptr[AST],
|
||||
orelse: rawptr[list[rawptr[AST]]]):
|
||||
def __init__(self, pool: memhub.MemManager*,
|
||||
test: AST*,
|
||||
orelse: list[AST*]*):
|
||||
_init_ast(self, pool, 0, 0)
|
||||
self.test = test
|
||||
self.orelse = orelse
|
||||
@@ -127,22 +127,22 @@ class If(Stmt):
|
||||
|
||||
class For(Stmt):
|
||||
"""For(target: AST, iter: AST, orelse: list[rawptr[AST]], is_async: CInt)"""
|
||||
target: rawptr[AST]
|
||||
iter: rawptr[AST]
|
||||
orelse: rawptr[list[rawptr[AST]]]
|
||||
target: AST*
|
||||
iter: AST*
|
||||
orelse: list[AST*]*
|
||||
flags: int
|
||||
|
||||
def __new__(self, pool: rawptr[memhub.MemManager],
|
||||
target: rawptr[AST], iter: rawptr[AST],
|
||||
orelse: rawptr[list[rawptr[AST]]],
|
||||
def __new__(self, pool: memhub.MemManager*,
|
||||
target: AST*, iter: AST*,
|
||||
orelse: list[AST*]*,
|
||||
is_async: int):
|
||||
ptr: rawptr[For] = pool.alloc(For.__sizeof__())
|
||||
ptr: For* = pool.alloc(For.__sizeof__())
|
||||
if ptr: string.memset(ptr, 0, For.__sizeof__())
|
||||
return ptr
|
||||
|
||||
def __init__(self, pool: rawptr[memhub.MemManager],
|
||||
target: rawptr[AST], iter: rawptr[AST],
|
||||
orelse: rawptr[list[rawptr[AST]]],
|
||||
def __init__(self, pool: memhub.MemManager*,
|
||||
target: AST*, iter: AST*,
|
||||
orelse: list[AST*]*,
|
||||
is_async: int):
|
||||
_init_ast(self, pool, 0, 0)
|
||||
self.target = target
|
||||
@@ -183,19 +183,19 @@ class For(Stmt):
|
||||
|
||||
class While(Stmt):
|
||||
"""While(test: AST, orelse: list[rawptr[AST]])"""
|
||||
test: rawptr[AST]
|
||||
orelse: rawptr[list[rawptr[AST]]]
|
||||
test: AST*
|
||||
orelse: list[AST*]*
|
||||
|
||||
def __new__(self, pool: rawptr[memhub.MemManager],
|
||||
test: rawptr[AST],
|
||||
orelse: rawptr[list[rawptr[AST]]]):
|
||||
ptr: rawptr[While] = pool.alloc(While.__sizeof__())
|
||||
def __new__(self, pool: memhub.MemManager*,
|
||||
test: AST*,
|
||||
orelse: list[AST*]*):
|
||||
ptr: While* = pool.alloc(While.__sizeof__())
|
||||
if ptr: string.memset(ptr, 0, While.__sizeof__())
|
||||
return ptr
|
||||
|
||||
def __init__(self, pool: rawptr[memhub.MemManager],
|
||||
test: rawptr[AST],
|
||||
orelse: rawptr[list[rawptr[AST]]]):
|
||||
def __init__(self, pool: memhub.MemManager*,
|
||||
test: AST*,
|
||||
orelse: list[AST*]*):
|
||||
_init_ast(self, pool, 0, 0)
|
||||
self.test = test
|
||||
self.orelse = orelse
|
||||
@@ -225,14 +225,14 @@ class While(Stmt):
|
||||
|
||||
class Return(Stmt):
|
||||
"""Return(value: AST | None)"""
|
||||
value: rawptr[AST]
|
||||
value: AST*
|
||||
|
||||
def __new__(self, pool: rawptr[memhub.MemManager], value: rawptr[AST]):
|
||||
ptr: rawptr[Return] = pool.alloc(Return.__sizeof__())
|
||||
def __new__(self, pool: memhub.MemManager*, value: AST*):
|
||||
ptr: Return* = pool.alloc(Return.__sizeof__())
|
||||
if ptr: string.memset(ptr, 0, Return.__sizeof__())
|
||||
return ptr
|
||||
|
||||
def __init__(self, pool: rawptr[memhub.MemManager], value: rawptr[AST]):
|
||||
def __init__(self, pool: memhub.MemManager*, value: AST*):
|
||||
_init_ast(self, pool, 0, 0)
|
||||
self.value = value
|
||||
|
||||
@@ -258,14 +258,14 @@ class Return(Stmt):
|
||||
|
||||
class Expr(Stmt):
|
||||
"""Expr(value: AST)"""
|
||||
value: rawptr[AST]
|
||||
value: AST*
|
||||
|
||||
def __new__(self, pool: rawptr[memhub.MemManager], value: rawptr[AST]):
|
||||
ptr: rawptr[Expr] = pool.alloc(Expr.__sizeof__())
|
||||
def __new__(self, pool: memhub.MemManager*, value: AST*):
|
||||
ptr: Expr* = pool.alloc(Expr.__sizeof__())
|
||||
if ptr: string.memset(ptr, 0, Expr.__sizeof__())
|
||||
return ptr
|
||||
|
||||
def __init__(self, pool: rawptr[memhub.MemManager], value: rawptr[AST]):
|
||||
def __init__(self, pool: memhub.MemManager*, value: AST*):
|
||||
_init_ast(self, pool, 0, 0)
|
||||
self.value = value
|
||||
|
||||
@@ -291,31 +291,31 @@ class Expr(Stmt):
|
||||
|
||||
class FunctionDef(Stmt):
|
||||
"""FunctionDef(name: str, args: AST,
|
||||
decorator_list: list[rawptr[AST]], returns: AST, flags: CInt,
|
||||
type_params: rawptr[list[str]] = None)
|
||||
decorator_list: list[AST*], returns: AST, flags: CInt,
|
||||
type_params: list[str]* = None)
|
||||
|
||||
type_params: generic function type-parameter name list (the [T] in PEP 695 def f[T](...)),
|
||||
None means a non-generic function."""
|
||||
name: str
|
||||
args: rawptr[AST]
|
||||
decorator_list: rawptr[list[rawptr[AST]]]
|
||||
returns: rawptr[AST]
|
||||
args: AST*
|
||||
decorator_list: list[AST*]*
|
||||
returns: AST*
|
||||
flags: int
|
||||
type_params: rawptr[list[str]]
|
||||
type_params: list[str]*
|
||||
|
||||
def __new__(self, pool: rawptr[memhub.MemManager],
|
||||
name: str, args: rawptr[AST],
|
||||
decorator_list: rawptr[list[rawptr[AST]]],
|
||||
returns: rawptr[AST], is_async: int):
|
||||
ptr: rawptr[FunctionDef] = pool.alloc(FunctionDef.__sizeof__())
|
||||
def __new__(self, pool: memhub.MemManager*,
|
||||
name: str, args: AST*,
|
||||
decorator_list: list[AST*]*,
|
||||
returns: AST*, is_async: int):
|
||||
ptr: FunctionDef* = pool.alloc(FunctionDef.__sizeof__())
|
||||
if ptr: string.memset(ptr, 0, FunctionDef.__sizeof__())
|
||||
return ptr
|
||||
|
||||
def __init__(self, pool: rawptr[memhub.MemManager],
|
||||
name: str, args: rawptr[AST],
|
||||
decorator_list: rawptr[list[rawptr[AST]]],
|
||||
returns: rawptr[AST], is_async: int,
|
||||
type_params: rawptr[list[str]] = None):
|
||||
def __init__(self, pool: memhub.MemManager*,
|
||||
name: str, args: AST*,
|
||||
decorator_list: list[AST*]*,
|
||||
returns: AST*, is_async: int,
|
||||
type_params: list[str]* = None):
|
||||
_init_ast(self, pool, 0, 0)
|
||||
self.name = _copy_str(pool, name)
|
||||
self.args = args
|
||||
@@ -361,16 +361,16 @@ class FunctionDef(Stmt):
|
||||
|
||||
class Expression(AST):
|
||||
"""Expression(body: AST)"""
|
||||
body: rawptr[AST]
|
||||
body: AST*
|
||||
|
||||
def __new__(self, pool: rawptr[memhub.MemManager],
|
||||
body: rawptr[AST]):
|
||||
ptr: rawptr[Expression] = pool.alloc(Expression.__sizeof__())
|
||||
def __new__(self, pool: memhub.MemManager*,
|
||||
body: AST*):
|
||||
ptr: Expression* = pool.alloc(Expression.__sizeof__())
|
||||
if ptr: string.memset(ptr, 0, Expression.__sizeof__())
|
||||
return ptr
|
||||
|
||||
def __init__(self, pool: rawptr[memhub.MemManager],
|
||||
body: rawptr[AST]):
|
||||
def __init__(self, pool: memhub.MemManager*,
|
||||
body: AST*):
|
||||
_init_ast(self, pool, 0, 0)
|
||||
self.body = body
|
||||
|
||||
@@ -396,16 +396,16 @@ class Expression(AST):
|
||||
|
||||
class Interactive(AST):
|
||||
"""Interactive(body: AST)"""
|
||||
body: rawptr[AST]
|
||||
body: AST*
|
||||
|
||||
def __new__(self, pool: rawptr[memhub.MemManager],
|
||||
body: rawptr[AST]):
|
||||
ptr: rawptr[Interactive] = pool.alloc(Interactive.__sizeof__())
|
||||
def __new__(self, pool: memhub.MemManager*,
|
||||
body: AST*):
|
||||
ptr: Interactive* = pool.alloc(Interactive.__sizeof__())
|
||||
if ptr: string.memset(ptr, 0, Interactive.__sizeof__())
|
||||
return ptr
|
||||
|
||||
def __init__(self, pool: rawptr[memhub.MemManager],
|
||||
body: rawptr[AST]):
|
||||
def __init__(self, pool: memhub.MemManager*,
|
||||
body: AST*):
|
||||
_init_ast(self, pool, 0, 0)
|
||||
self.body = body
|
||||
|
||||
@@ -431,19 +431,19 @@ class Interactive(AST):
|
||||
|
||||
class FunctionType(AST):
|
||||
"""FunctionType(argtypes: list[rawptr[AST]], returns: AST)"""
|
||||
argtypes: rawptr[list[rawptr[AST]]]
|
||||
returns: rawptr[AST]
|
||||
argtypes: list[AST*]*
|
||||
returns: AST*
|
||||
|
||||
def __new__(self, pool: rawptr[memhub.MemManager],
|
||||
argtypes: rawptr[list[rawptr[AST]]],
|
||||
returns: rawptr[AST]):
|
||||
ptr: rawptr[FunctionType] = pool.alloc(FunctionType.__sizeof__())
|
||||
def __new__(self, pool: memhub.MemManager*,
|
||||
argtypes: list[AST*]*,
|
||||
returns: AST*):
|
||||
ptr: FunctionType* = pool.alloc(FunctionType.__sizeof__())
|
||||
if ptr: string.memset(ptr, 0, FunctionType.__sizeof__())
|
||||
return ptr
|
||||
|
||||
def __init__(self, pool: rawptr[memhub.MemManager],
|
||||
argtypes: rawptr[list[rawptr[AST]]],
|
||||
returns: rawptr[AST]):
|
||||
def __init__(self, pool: memhub.MemManager*,
|
||||
argtypes: list[AST*]*,
|
||||
returns: AST*):
|
||||
_init_ast(self, pool, 0, 0)
|
||||
self.argtypes = argtypes
|
||||
self.returns = returns
|
||||
@@ -472,32 +472,32 @@ class FunctionType(AST):
|
||||
|
||||
class ClassDef(Stmt):
|
||||
"""ClassDef(name: str, bases: list[rawptr[AST]], keywords: list[rawptr[AST]],
|
||||
decorator_list: list[rawptr[AST]], type_params: rawptr[list[str]])
|
||||
decorator_list: list[AST*], type_params: list[str]*)
|
||||
|
||||
type_params: generic type-parameter name list (the [T] in PEP 695 class list[T]:),
|
||||
None means a non-generic class."""
|
||||
name: str
|
||||
bases: rawptr[list[rawptr[AST]]]
|
||||
keywords: rawptr[list[rawptr[AST]]]
|
||||
decorator_list: rawptr[list[rawptr[AST]]]
|
||||
type_params: rawptr[list[str]]
|
||||
bases: list[AST*]*
|
||||
keywords: list[AST*]*
|
||||
decorator_list: list[AST*]*
|
||||
type_params: list[str]*
|
||||
|
||||
def __new__(self, pool: rawptr[memhub.MemManager],
|
||||
def __new__(self, pool: memhub.MemManager*,
|
||||
name: str,
|
||||
bases: rawptr[list[rawptr[AST]]],
|
||||
keywords: rawptr[list[rawptr[AST]]],
|
||||
decorator_list: rawptr[list[rawptr[AST]]],
|
||||
type_params: rawptr[list[str]] = None):
|
||||
ptr: rawptr[ClassDef] = pool.alloc(ClassDef.__sizeof__())
|
||||
bases: list[AST*]*,
|
||||
keywords: list[AST*]*,
|
||||
decorator_list: list[AST*]*,
|
||||
type_params: list[str]* = None):
|
||||
ptr: ClassDef* = pool.alloc(ClassDef.__sizeof__())
|
||||
if ptr: string.memset(ptr, 0, ClassDef.__sizeof__())
|
||||
return ptr
|
||||
|
||||
def __init__(self, pool: rawptr[memhub.MemManager],
|
||||
def __init__(self, pool: memhub.MemManager*,
|
||||
name: str,
|
||||
bases: rawptr[list[rawptr[AST]]],
|
||||
keywords: rawptr[list[rawptr[AST]]],
|
||||
decorator_list: rawptr[list[rawptr[AST]]],
|
||||
type_params: rawptr[list[str]] = None):
|
||||
bases: list[AST*]*,
|
||||
keywords: list[AST*]*,
|
||||
decorator_list: list[AST*]*,
|
||||
type_params: list[str]* = None):
|
||||
_init_ast(self, pool, 0, 0)
|
||||
self.name = _copy_str(pool, name)
|
||||
self.bases = bases
|
||||
@@ -533,16 +533,16 @@ class ClassDef(Stmt):
|
||||
|
||||
class Delete(Stmt):
|
||||
"""Delete(targets: list[rawptr[AST]])"""
|
||||
targets: rawptr[list[rawptr[AST]]]
|
||||
targets: list[AST*]*
|
||||
|
||||
def __new__(self, pool: rawptr[memhub.MemManager],
|
||||
targets: rawptr[list[rawptr[AST]]]):
|
||||
ptr: rawptr[Delete] = pool.alloc(Delete.__sizeof__())
|
||||
def __new__(self, pool: memhub.MemManager*,
|
||||
targets: list[AST*]*):
|
||||
ptr: Delete* = pool.alloc(Delete.__sizeof__())
|
||||
if ptr: string.memset(ptr, 0, Delete.__sizeof__())
|
||||
return ptr
|
||||
|
||||
def __init__(self, pool: rawptr[memhub.MemManager],
|
||||
targets: rawptr[list[rawptr[AST]]]):
|
||||
def __init__(self, pool: memhub.MemManager*,
|
||||
targets: list[AST*]*):
|
||||
_init_ast(self, pool, 0, 0)
|
||||
self.targets = targets
|
||||
_set_parent_list(targets, self)
|
||||
@@ -566,18 +566,18 @@ class Delete(Stmt):
|
||||
|
||||
class AugAssign(Stmt):
|
||||
"""AugAssign(target: AST, op: CInt, value: AST)"""
|
||||
target: rawptr[AST]
|
||||
target: AST*
|
||||
op: int
|
||||
value: rawptr[AST]
|
||||
value: AST*
|
||||
|
||||
def __new__(self, pool: rawptr[memhub.MemManager],
|
||||
target: rawptr[AST], op: int, value: rawptr[AST]):
|
||||
ptr: rawptr[AugAssign] = pool.alloc(AugAssign.__sizeof__())
|
||||
def __new__(self, pool: memhub.MemManager*,
|
||||
target: AST*, op: int, value: AST*):
|
||||
ptr: AugAssign* = pool.alloc(AugAssign.__sizeof__())
|
||||
if ptr: string.memset(ptr, 0, AugAssign.__sizeof__())
|
||||
return ptr
|
||||
|
||||
def __init__(self, pool: rawptr[memhub.MemManager],
|
||||
target: rawptr[AST], op: int, value: rawptr[AST]):
|
||||
def __init__(self, pool: memhub.MemManager*,
|
||||
target: AST*, op: int, value: AST*):
|
||||
_init_ast(self, pool, 0, 0)
|
||||
self.target = target
|
||||
self.op = op
|
||||
@@ -612,21 +612,21 @@ class AugAssign(Stmt):
|
||||
|
||||
class AnnAssign(Stmt):
|
||||
"""AnnAssign(target: AST, annotation: AST, value: AST, simple: CInt)"""
|
||||
target: rawptr[AST]
|
||||
annotation: rawptr[AST]
|
||||
value: rawptr[AST]
|
||||
target: AST*
|
||||
annotation: AST*
|
||||
value: AST*
|
||||
simple: int
|
||||
|
||||
def __new__(self, pool: rawptr[memhub.MemManager],
|
||||
target: rawptr[AST], annotation: rawptr[AST],
|
||||
value: rawptr[AST], simple: int):
|
||||
ptr: rawptr[AnnAssign] = pool.alloc(AnnAssign.__sizeof__())
|
||||
def __new__(self, pool: memhub.MemManager*,
|
||||
target: AST*, annotation: AST*,
|
||||
value: AST*, simple: int):
|
||||
ptr: AnnAssign* = pool.alloc(AnnAssign.__sizeof__())
|
||||
if ptr: string.memset(ptr, 0, AnnAssign.__sizeof__())
|
||||
return ptr
|
||||
|
||||
def __init__(self, pool: rawptr[memhub.MemManager],
|
||||
target: rawptr[AST], annotation: rawptr[AST],
|
||||
value: rawptr[AST], simple: int):
|
||||
def __init__(self, pool: memhub.MemManager*,
|
||||
target: AST*, annotation: AST*,
|
||||
value: AST*, simple: int):
|
||||
_init_ast(self, pool, 0, 0)
|
||||
self.target = target
|
||||
self.annotation = annotation
|
||||
@@ -667,18 +667,18 @@ class AnnAssign(Stmt):
|
||||
|
||||
class With(Stmt):
|
||||
"""With(items: list[rawptr[AST]], is_async: CInt)"""
|
||||
items: rawptr[list[rawptr[AST]]]
|
||||
items: list[AST*]*
|
||||
flags: int
|
||||
|
||||
def __new__(self, pool: rawptr[memhub.MemManager],
|
||||
items: rawptr[list[rawptr[AST]]],
|
||||
def __new__(self, pool: memhub.MemManager*,
|
||||
items: list[AST*]*,
|
||||
is_async: int):
|
||||
ptr: rawptr[With] = pool.alloc(With.__sizeof__())
|
||||
ptr: With* = pool.alloc(With.__sizeof__())
|
||||
if ptr: string.memset(ptr, 0, With.__sizeof__())
|
||||
return ptr
|
||||
|
||||
def __init__(self, pool: rawptr[memhub.MemManager],
|
||||
items: rawptr[list[rawptr[AST]]],
|
||||
def __init__(self, pool: memhub.MemManager*,
|
||||
items: list[AST*]*,
|
||||
is_async: int):
|
||||
_init_ast(self, pool, 0, 0)
|
||||
self.items = items
|
||||
@@ -709,17 +709,17 @@ class With(Stmt):
|
||||
|
||||
class Raise(Stmt):
|
||||
"""Raise(exc: AST, cause: AST)"""
|
||||
exc: rawptr[AST]
|
||||
cause: rawptr[AST]
|
||||
exc: AST*
|
||||
cause: AST*
|
||||
|
||||
def __new__(self, pool: rawptr[memhub.MemManager],
|
||||
exc: rawptr[AST], cause: rawptr[AST]):
|
||||
ptr: rawptr[Raise] = pool.alloc(Raise.__sizeof__())
|
||||
def __new__(self, pool: memhub.MemManager*,
|
||||
exc: AST*, cause: AST*):
|
||||
ptr: Raise* = pool.alloc(Raise.__sizeof__())
|
||||
if ptr: string.memset(ptr, 0, Raise.__sizeof__())
|
||||
return ptr
|
||||
|
||||
def __init__(self, pool: rawptr[memhub.MemManager],
|
||||
exc: rawptr[AST], cause: rawptr[AST]):
|
||||
def __init__(self, pool: memhub.MemManager*,
|
||||
exc: AST*, cause: AST*):
|
||||
_init_ast(self, pool, 0, 0)
|
||||
self.exc = exc
|
||||
self.cause = cause
|
||||
@@ -751,23 +751,23 @@ class Raise(Stmt):
|
||||
|
||||
class Try(Stmt):
|
||||
"""Try(handlers: list[rawptr[AST]],
|
||||
orelse: list[rawptr[AST]], finalbody: list[rawptr[AST]])"""
|
||||
handlers: rawptr[list[rawptr[AST]]]
|
||||
orelse: rawptr[list[rawptr[AST]]]
|
||||
finalbody: rawptr[list[rawptr[AST]]]
|
||||
orelse: list[AST*], finalbody: list[AST*])"""
|
||||
handlers: list[AST*]*
|
||||
orelse: list[AST*]*
|
||||
finalbody: list[AST*]*
|
||||
|
||||
def __new__(self, pool: rawptr[memhub.MemManager],
|
||||
handlers: rawptr[list[rawptr[AST]]],
|
||||
orelse: rawptr[list[rawptr[AST]]],
|
||||
finalbody: rawptr[list[rawptr[AST]]]):
|
||||
ptr: rawptr[Try] = pool.alloc(Try.__sizeof__())
|
||||
def __new__(self, pool: memhub.MemManager*,
|
||||
handlers: list[AST*]*,
|
||||
orelse: list[AST*]*,
|
||||
finalbody: list[AST*]*):
|
||||
ptr: Try* = pool.alloc(Try.__sizeof__())
|
||||
if ptr: string.memset(ptr, 0, Try.__sizeof__())
|
||||
return ptr
|
||||
|
||||
def __init__(self, pool: rawptr[memhub.MemManager],
|
||||
handlers: rawptr[list[rawptr[AST]]],
|
||||
orelse: rawptr[list[rawptr[AST]]],
|
||||
finalbody: rawptr[list[rawptr[AST]]]):
|
||||
def __init__(self, pool: memhub.MemManager*,
|
||||
handlers: list[AST*]*,
|
||||
orelse: list[AST*]*,
|
||||
finalbody: list[AST*]*):
|
||||
_init_ast(self, pool, 0, 0)
|
||||
self.handlers = handlers
|
||||
self.orelse = orelse
|
||||
@@ -801,17 +801,17 @@ class Try(Stmt):
|
||||
|
||||
class Assert(Stmt):
|
||||
"""Assert(test: AST, msg: AST)"""
|
||||
test: rawptr[AST]
|
||||
msg: rawptr[AST]
|
||||
test: AST*
|
||||
msg: AST*
|
||||
|
||||
def __new__(self, pool: rawptr[memhub.MemManager],
|
||||
test: rawptr[AST], msg: rawptr[AST]):
|
||||
ptr: rawptr[Assert] = pool.alloc(Assert.__sizeof__())
|
||||
def __new__(self, pool: memhub.MemManager*,
|
||||
test: AST*, msg: AST*):
|
||||
ptr: Assert* = pool.alloc(Assert.__sizeof__())
|
||||
if ptr: string.memset(ptr, 0, Assert.__sizeof__())
|
||||
return ptr
|
||||
|
||||
def __init__(self, pool: rawptr[memhub.MemManager],
|
||||
test: rawptr[AST], msg: rawptr[AST]):
|
||||
def __init__(self, pool: memhub.MemManager*,
|
||||
test: AST*, msg: AST*):
|
||||
_init_ast(self, pool, 0, 0)
|
||||
self.test = test
|
||||
self.msg = msg
|
||||
@@ -843,16 +843,16 @@ class Assert(Stmt):
|
||||
|
||||
class Global(Stmt):
|
||||
"""Global(names: list[rawptr[AST]])"""
|
||||
names: rawptr[list[rawptr[AST]]]
|
||||
names: list[AST*]*
|
||||
|
||||
def __new__(self, pool: rawptr[memhub.MemManager],
|
||||
names: rawptr[list[rawptr[AST]]]):
|
||||
ptr: rawptr[Global] = pool.alloc(Global.__sizeof__())
|
||||
def __new__(self, pool: memhub.MemManager*,
|
||||
names: list[AST*]*):
|
||||
ptr: Global* = pool.alloc(Global.__sizeof__())
|
||||
if ptr: string.memset(ptr, 0, Global.__sizeof__())
|
||||
return ptr
|
||||
|
||||
def __init__(self, pool: rawptr[memhub.MemManager],
|
||||
names: rawptr[list[rawptr[AST]]]):
|
||||
def __init__(self, pool: memhub.MemManager*,
|
||||
names: list[AST*]*):
|
||||
_init_ast(self, pool, 0, 0)
|
||||
self.names = names
|
||||
_set_parent_list(names, self)
|
||||
@@ -876,16 +876,16 @@ class Global(Stmt):
|
||||
|
||||
class Nonlocal(Stmt):
|
||||
"""Nonlocal(names: list[rawptr[AST]])"""
|
||||
names: rawptr[list[rawptr[AST]]]
|
||||
names: list[AST*]*
|
||||
|
||||
def __new__(self, pool: rawptr[memhub.MemManager],
|
||||
names: rawptr[list[rawptr[AST]]]):
|
||||
ptr: rawptr[Nonlocal] = pool.alloc(Nonlocal.__sizeof__())
|
||||
def __new__(self, pool: memhub.MemManager*,
|
||||
names: list[AST*]*):
|
||||
ptr: Nonlocal* = pool.alloc(Nonlocal.__sizeof__())
|
||||
if ptr: string.memset(ptr, 0, Nonlocal.__sizeof__())
|
||||
return ptr
|
||||
|
||||
def __init__(self, pool: rawptr[memhub.MemManager],
|
||||
names: rawptr[list[rawptr[AST]]]):
|
||||
def __init__(self, pool: memhub.MemManager*,
|
||||
names: list[AST*]*):
|
||||
_init_ast(self, pool, 0, 0)
|
||||
self.names = names
|
||||
_set_parent_list(names, self)
|
||||
@@ -910,12 +910,12 @@ class Nonlocal(Stmt):
|
||||
class Pass(Stmt):
|
||||
"""Pass()"""
|
||||
|
||||
def __new__(self, pool: rawptr[memhub.MemManager]):
|
||||
ptr: rawptr[Pass] = pool.alloc(Pass.__sizeof__())
|
||||
def __new__(self, pool: memhub.MemManager*):
|
||||
ptr: Pass* = pool.alloc(Pass.__sizeof__())
|
||||
if ptr: string.memset(ptr, 0, Pass.__sizeof__())
|
||||
return ptr
|
||||
|
||||
def __init__(self, pool: rawptr[memhub.MemManager]):
|
||||
def __init__(self, pool: memhub.MemManager*):
|
||||
_init_ast(self, pool, 0, 0)
|
||||
|
||||
def kind(self) -> int:
|
||||
@@ -936,12 +936,12 @@ class Pass(Stmt):
|
||||
class Break(Stmt):
|
||||
"""Break()"""
|
||||
|
||||
def __new__(self, pool: rawptr[memhub.MemManager]):
|
||||
ptr: rawptr[Break] = pool.alloc(Break.__sizeof__())
|
||||
def __new__(self, pool: memhub.MemManager*):
|
||||
ptr: Break* = pool.alloc(Break.__sizeof__())
|
||||
if ptr: string.memset(ptr, 0, Break.__sizeof__())
|
||||
return ptr
|
||||
|
||||
def __init__(self, pool: rawptr[memhub.MemManager]):
|
||||
def __init__(self, pool: memhub.MemManager*):
|
||||
_init_ast(self, pool, 0, 0)
|
||||
|
||||
def kind(self) -> int:
|
||||
@@ -962,12 +962,12 @@ class Break(Stmt):
|
||||
class Continue(Stmt):
|
||||
"""Continue()"""
|
||||
|
||||
def __new__(self, pool: rawptr[memhub.MemManager]):
|
||||
ptr: rawptr[Continue] = pool.alloc(Continue.__sizeof__())
|
||||
def __new__(self, pool: memhub.MemManager*):
|
||||
ptr: Continue* = pool.alloc(Continue.__sizeof__())
|
||||
if ptr: string.memset(ptr, 0, Continue.__sizeof__())
|
||||
return ptr
|
||||
|
||||
def __init__(self, pool: rawptr[memhub.MemManager]):
|
||||
def __init__(self, pool: memhub.MemManager*):
|
||||
_init_ast(self, pool, 0, 0)
|
||||
|
||||
def kind(self) -> int:
|
||||
@@ -988,12 +988,12 @@ class Continue(Stmt):
|
||||
class FallThrough(Stmt):
|
||||
"""FallThrough() - a switch case body does not auto-break, so it falls through to the next case"""
|
||||
|
||||
def __new__(self, pool: rawptr[memhub.MemManager]):
|
||||
ptr: rawptr[FallThrough] = pool.alloc(FallThrough.__sizeof__())
|
||||
def __new__(self, pool: memhub.MemManager*):
|
||||
ptr: FallThrough* = pool.alloc(FallThrough.__sizeof__())
|
||||
if ptr: string.memset(ptr, 0, FallThrough.__sizeof__())
|
||||
return ptr
|
||||
|
||||
def __init__(self, pool: rawptr[memhub.MemManager]):
|
||||
def __init__(self, pool: memhub.MemManager*):
|
||||
_init_ast(self, pool, 0, 0)
|
||||
|
||||
def kind(self) -> int:
|
||||
@@ -1013,16 +1013,16 @@ class FallThrough(Stmt):
|
||||
|
||||
class Import(Stmt):
|
||||
"""Import(names: list[rawptr[AST]])"""
|
||||
names: rawptr[list[rawptr[AST]]]
|
||||
names: list[AST*]*
|
||||
|
||||
def __new__(self, pool: rawptr[memhub.MemManager],
|
||||
names: rawptr[list[rawptr[AST]]]):
|
||||
ptr: rawptr[Import] = pool.alloc(Import.__sizeof__())
|
||||
def __new__(self, pool: memhub.MemManager*,
|
||||
names: list[AST*]*):
|
||||
ptr: Import* = pool.alloc(Import.__sizeof__())
|
||||
if ptr: string.memset(ptr, 0, Import.__sizeof__())
|
||||
return ptr
|
||||
|
||||
def __init__(self, pool: rawptr[memhub.MemManager],
|
||||
names: rawptr[list[rawptr[AST]]]):
|
||||
def __init__(self, pool: memhub.MemManager*,
|
||||
names: list[AST*]*):
|
||||
_init_ast(self, pool, 0, 0)
|
||||
self.names = names
|
||||
_set_parent_list(names, self)
|
||||
@@ -1047,20 +1047,20 @@ class Import(Stmt):
|
||||
class ImportFrom(Stmt):
|
||||
"""ImportFrom(module: str, names: list[rawptr[AST]], level: CInt)"""
|
||||
module: str
|
||||
names: rawptr[list[rawptr[AST]]]
|
||||
names: list[AST*]*
|
||||
level: int
|
||||
|
||||
def __new__(self, pool: rawptr[memhub.MemManager],
|
||||
def __new__(self, pool: memhub.MemManager*,
|
||||
module: str,
|
||||
names: rawptr[list[rawptr[AST]]],
|
||||
names: list[AST*]*,
|
||||
level: int):
|
||||
ptr: rawptr[ImportFrom] = pool.alloc(ImportFrom.__sizeof__())
|
||||
ptr: ImportFrom* = pool.alloc(ImportFrom.__sizeof__())
|
||||
if ptr: string.memset(ptr, 0, ImportFrom.__sizeof__())
|
||||
return ptr
|
||||
|
||||
def __init__(self, pool: rawptr[memhub.MemManager],
|
||||
def __init__(self, pool: memhub.MemManager*,
|
||||
module: str,
|
||||
names: rawptr[list[rawptr[AST]]],
|
||||
names: list[AST*]*,
|
||||
level: int):
|
||||
_init_ast(self, pool, 0, 0)
|
||||
self.module = _copy_str(pool, module)
|
||||
@@ -1095,21 +1095,21 @@ class Match(Stmt):
|
||||
is_switch=1: from `switch <expr>:` sugar (see _parse_switch), C semantics (no fall-through without
|
||||
`fallthrough`). is_switch=0: real `match`, fallthrough is completely forbidden (fail-fast).
|
||||
"""
|
||||
subject: rawptr[AST]
|
||||
cases: rawptr[list[rawptr[AST]]]
|
||||
subject: AST*
|
||||
cases: list[AST*]*
|
||||
is_switch: int
|
||||
|
||||
def __new__(self, pool: rawptr[memhub.MemManager],
|
||||
subject: rawptr[AST],
|
||||
cases: rawptr[list[rawptr[AST]]],
|
||||
def __new__(self, pool: memhub.MemManager*,
|
||||
subject: AST*,
|
||||
cases: list[AST*]*,
|
||||
is_switch: int):
|
||||
ptr: rawptr[Match] = pool.alloc(Match.__sizeof__())
|
||||
ptr: Match* = pool.alloc(Match.__sizeof__())
|
||||
if ptr: string.memset(ptr, 0, Match.__sizeof__())
|
||||
return ptr
|
||||
|
||||
def __init__(self, pool: rawptr[memhub.MemManager],
|
||||
subject: rawptr[AST],
|
||||
cases: rawptr[list[rawptr[AST]]],
|
||||
def __init__(self, pool: memhub.MemManager*,
|
||||
subject: AST*,
|
||||
cases: list[AST*]*,
|
||||
is_switch: int):
|
||||
_init_ast(self, pool, 0, 0)
|
||||
self.subject = subject
|
||||
|
||||
+26
-26
@@ -200,11 +200,11 @@ class Token:
|
||||
col_offset: int # Starting column offset
|
||||
end_lineno: int # Ending line number
|
||||
end_col_offset: int # Ending column offset
|
||||
next: rawptr[Token] # Next token in linked list
|
||||
next: Token* # Next token in linked list
|
||||
|
||||
def __new__(self, pool: rawptr[memhub.MemManager]):
|
||||
def __new__(self, pool: memhub.MemManager*):
|
||||
"""Allocate zero‑initialized Token struct memory from mpool"""
|
||||
ptr: rawptr[Token] = pool.alloc(Token.__sizeof__())
|
||||
ptr: Token* = pool.alloc(Token.__sizeof__())
|
||||
if ptr == None:
|
||||
_ast_pool_fatal("Token", sizet(Token.__sizeof__()))
|
||||
string.memset(ptr, 0, Token.__sizeof__())
|
||||
@@ -218,10 +218,10 @@ class Token:
|
||||
class KwEntry:
|
||||
name: str
|
||||
kw_id: int
|
||||
next: rawptr[KwEntry]
|
||||
next: KwEntry*
|
||||
|
||||
def __new__(self, pool: rawptr[memhub.MemManager]):
|
||||
ptr: rawptr[KwEntry] = pool.alloc(KwEntry.__sizeof__())
|
||||
def __new__(self, pool: memhub.MemManager*):
|
||||
ptr: KwEntry* = pool.alloc(KwEntry.__sizeof__())
|
||||
if ptr == None:
|
||||
_ast_pool_fatal("KwEntry", sizet(KwEntry.__sizeof__()))
|
||||
string.memset(ptr, 0, KwEntry.__sizeof__())
|
||||
@@ -229,8 +229,8 @@ class KwEntry:
|
||||
|
||||
|
||||
# Global keyword linked list head (lazy initialization)
|
||||
_kw_head: rawptr[KwEntry] = None
|
||||
_kw_pool: rawptr[memhub.MemManager] = None
|
||||
_kw_head: KwEntry* = None
|
||||
_kw_pool: memhub.MemManager* = None
|
||||
|
||||
# Keyword hash index (open addressing, linear probing): slot u64, 0 = empty else KwEntry address;
|
||||
# expected O(1) lookups, falling back to the list only when not built (alloc failure). Miss returns 0.
|
||||
@@ -253,7 +253,7 @@ def _kw_hash_str(key: str) -> uint64:
|
||||
return uint64(h)
|
||||
|
||||
|
||||
def _kw_index_put(entry: rawptr[KwEntry]):
|
||||
def _kw_index_put(entry: KwEntry*):
|
||||
"""Write a keyword entry into the hash index (silently skipped if not built); a duplicate key keeps
|
||||
the first registrant, and collisions are separated by strcmp (hash alone could return a wrong kw_id)."""
|
||||
if _kw_index == None: return
|
||||
@@ -272,10 +272,10 @@ def _kw_index_put(entry: rawptr[KwEntry]):
|
||||
idx = (idx + 1) & mask
|
||||
|
||||
|
||||
def _kw_intern(pool: rawptr[memhub.MemManager], name: str, kw_id: int):
|
||||
def _kw_intern(pool: memhub.MemManager*, name: str, kw_id: int):
|
||||
"""Register keyword name in the linked list"""
|
||||
global _kw_head
|
||||
entry: rawptr[KwEntry] = KwEntry(pool)
|
||||
entry: KwEntry* = KwEntry(pool)
|
||||
if entry == None: return
|
||||
slen: sizet = string.strlen(name)
|
||||
buf: str = pool.alloc(slen + 1)
|
||||
@@ -313,7 +313,7 @@ def _kw_lookup(name: str) -> int:
|
||||
return cur.kw_id
|
||||
idx = (idx + 1) & mask
|
||||
return 0
|
||||
cur2: rawptr[KwEntry] = _kw_head
|
||||
cur2: KwEntry* = _kw_head
|
||||
while cur2 != None:
|
||||
if string.strcmp(cur2.name, name) == 0:
|
||||
return cur2.kw_id
|
||||
@@ -321,7 +321,7 @@ def _kw_lookup(name: str) -> int:
|
||||
return 0
|
||||
|
||||
|
||||
def _init_keywords(pool: rawptr[memhub.MemManager]):
|
||||
def _init_keywords(pool: memhub.MemManager*):
|
||||
"""Initialize keyword linked list (only once)"""
|
||||
global _kw_head, _kw_pool, _kw_index
|
||||
if _kw_head != None: return
|
||||
@@ -406,21 +406,21 @@ class OpEntry:
|
||||
name: str # Operator text (e.g. "==", "+=")
|
||||
op_id: int
|
||||
length: int
|
||||
next: rawptr[OpEntry]
|
||||
next: OpEntry*
|
||||
|
||||
def __new__(self, pool: rawptr[memhub.MemManager]):
|
||||
ptr: rawptr[OpEntry] = pool.alloc(OpEntry.__sizeof__())
|
||||
def __new__(self, pool: memhub.MemManager*):
|
||||
ptr: OpEntry* = pool.alloc(OpEntry.__sizeof__())
|
||||
if ptr: string.memset(ptr, 0, OpEntry.__sizeof__())
|
||||
return ptr
|
||||
|
||||
|
||||
_op_head: rawptr[OpEntry] = None
|
||||
_op_head: OpEntry* = None
|
||||
|
||||
|
||||
def _op_intern(pool: rawptr[memhub.MemManager], name: str, op_id: int):
|
||||
def _op_intern(pool: memhub.MemManager*, name: str, op_id: int):
|
||||
global _op_head
|
||||
slen: sizet = string.strlen(name)
|
||||
entry: rawptr[OpEntry] = OpEntry(pool)
|
||||
entry: OpEntry* = OpEntry(pool)
|
||||
if entry == None: return
|
||||
buf: str = pool.alloc(slen + 1)
|
||||
if buf == None: return
|
||||
@@ -432,7 +432,7 @@ def _op_intern(pool: rawptr[memhub.MemManager], name: str, op_id: int):
|
||||
_op_head = entry
|
||||
|
||||
|
||||
def _init_operators(pool: rawptr[memhub.MemManager]):
|
||||
def _init_operators(pool: memhub.MemManager*):
|
||||
"""Initialize the operator table (register in descending length order for easy greedy matching)"""
|
||||
global _op_head
|
||||
if _op_head != None: return
|
||||
@@ -488,7 +488,7 @@ def _init_operators(pool: rawptr[memhub.MemManager]):
|
||||
_op_intern(pool, "~", TokOp.Tilde)
|
||||
|
||||
|
||||
def _init_tables(pool: rawptr[memhub.MemManager]):
|
||||
def _init_tables(pool: memhub.MemManager*):
|
||||
"""Initialize all lookup tables (idempotent)"""
|
||||
_init_keywords(pool)
|
||||
_init_operators(pool)
|
||||
@@ -498,10 +498,10 @@ def _init_tables(pool: rawptr[memhub.MemManager]):
|
||||
# Token creation helper functions
|
||||
# ============================================================
|
||||
|
||||
def new_token(pool: rawptr[memhub.MemManager], ttype: int, lineno: int,
|
||||
col_offset: int) -> rawptr[Token]:
|
||||
def new_token(pool: memhub.MemManager*, ttype: int, lineno: int,
|
||||
col_offset: int) -> Token*:
|
||||
"""Create a new empty Token and fill in fields later"""
|
||||
tok: rawptr[Token] = Token(pool)
|
||||
tok: Token* = Token(pool)
|
||||
if tok == None: return None
|
||||
tok.type = ttype
|
||||
tok.lineno = lineno
|
||||
@@ -511,7 +511,7 @@ def new_token(pool: rawptr[memhub.MemManager], ttype: int, lineno: int,
|
||||
return tok
|
||||
|
||||
|
||||
def token_set_str(pool: rawptr[memhub.MemManager], tok: rawptr[Token],
|
||||
def token_set_str(pool: memhub.MemManager*, tok: Token*,
|
||||
src: str, start: sizet, length: sizet):
|
||||
"""Copy text from src[start:start + length] to token.str_val
|
||||
|
||||
@@ -527,7 +527,7 @@ def token_set_str(pool: rawptr[memhub.MemManager], tok: rawptr[Token],
|
||||
tok.str_val = buf
|
||||
|
||||
|
||||
def token_set_str_literal(pool: rawptr[memhub.MemManager], tok: rawptr[Token],
|
||||
def token_set_str_literal(pool: memhub.MemManager*, tok: Token*,
|
||||
text: str):
|
||||
"""Copy a C string to token.str_val"""
|
||||
if tok == None or text == None: return
|
||||
|
||||
+1
-1
@@ -48,7 +48,7 @@ class md5:
|
||||
def __init__(self):
|
||||
string.memset(self.buf, 0, MD5_BLOCK_LEN)
|
||||
# MD5 single-group compression transform
|
||||
def transform(self, block: rawptr[uint8]):
|
||||
def transform(self, block: uint8*):
|
||||
a: uint32 = self.state[0]
|
||||
b: uint32 = self.state[1]
|
||||
c: uint32 = self.state[2]
|
||||
|
||||
+2
-2
@@ -27,9 +27,9 @@ class sha1:
|
||||
def __init__(self):
|
||||
string.memset(self.buf, 0, SHA1_BLOCK_LEN)
|
||||
# Single-group compression transform
|
||||
def transform(self, block: rawptr[uint8]):
|
||||
def transform(self, block: uint8*):
|
||||
w: [80]uint32
|
||||
data: rawptr[uint8] = block
|
||||
data: uint8* = block
|
||||
# First 16 words
|
||||
for i in range(16):
|
||||
w[i] = (((uint32(data[i * 4 + 0])) << 24) |
|
||||
|
||||
+1
-1
@@ -42,7 +42,7 @@ class sha256:
|
||||
string.memset(self, 0, sha256.__sizeof__())
|
||||
# string.memset(self.buf, 0, SHA256_BLOCK_LEN)
|
||||
# SHA256 single-group compression transform
|
||||
def transform(self, block: rawptr[uint8]):
|
||||
def transform(self, block: uint8*):
|
||||
w: [64]uint32
|
||||
for i in range(16):
|
||||
w[i] = ((uint32(block[i * 4 + 0]) << 24) |
|
||||
|
||||
+10
-10
@@ -31,7 +31,7 @@ class JsonValue:
|
||||
child: 'JsonValue' | t.CPtr
|
||||
child_count: sizet
|
||||
|
||||
def __new__(self, pool: rawptr[memhub.MemManager]):
|
||||
def __new__(self, pool: memhub.MemManager*):
|
||||
"""Allocate and zero-initialize a JsonValue struct from mpool."""
|
||||
ptr: JsonValue* = pool.alloc(JsonValue.__sizeof__())
|
||||
if ptr:
|
||||
@@ -148,34 +148,34 @@ class JsonValue:
|
||||
# Constructors: create each kind of JsonValue (allocated from mpool)
|
||||
# ============================================================
|
||||
|
||||
def null(pool: rawptr[memhub.MemManager]) -> JsonValue*:
|
||||
def null(pool: memhub.MemManager*) -> JsonValue*:
|
||||
v: JsonValue* = JsonValue(pool)
|
||||
if v == None: return None
|
||||
v.vtype = JSON_NULL
|
||||
return v
|
||||
|
||||
def bool_val(pool: rawptr[memhub.MemManager], val: bool) -> JsonValue*:
|
||||
def bool_val(pool: memhub.MemManager*, val: bool) -> JsonValue*:
|
||||
v: JsonValue* = JsonValue(pool)
|
||||
if v == None: return None
|
||||
v.vtype = JSON_BOOL
|
||||
v.bool_val = 1 if val else 0
|
||||
return v
|
||||
|
||||
def int_val(pool: rawptr[memhub.MemManager], val: int64) -> JsonValue*:
|
||||
def int_val(pool: memhub.MemManager*, val: int64) -> JsonValue*:
|
||||
v: JsonValue* = JsonValue(pool)
|
||||
if v == None: return None
|
||||
v.vtype = JSON_INT
|
||||
v.int_val = val
|
||||
return v
|
||||
|
||||
def float_val(pool: rawptr[memhub.MemManager], val: double) -> JsonValue*:
|
||||
def float_val(pool: memhub.MemManager*, val: double) -> JsonValue*:
|
||||
v: JsonValue* = JsonValue(pool)
|
||||
if v == None: return None
|
||||
v.vtype = JSON_FLOAT
|
||||
v.float_val = val
|
||||
return v
|
||||
|
||||
def string_val(pool: rawptr[memhub.MemManager], val: str) -> JsonValue*:
|
||||
def string_val(pool: memhub.MemManager*, val: str) -> JsonValue*:
|
||||
v: JsonValue* = JsonValue(pool)
|
||||
if v == None: return None
|
||||
v.vtype = JSON_STRING
|
||||
@@ -187,26 +187,26 @@ def string_val(pool: rawptr[memhub.MemManager], val: str) -> JsonValue*:
|
||||
v.str_val = buf
|
||||
return v
|
||||
|
||||
def array(pool: rawptr[memhub.MemManager]) -> JsonValue*:
|
||||
def array(pool: memhub.MemManager*) -> JsonValue*:
|
||||
v: JsonValue* = JsonValue(pool)
|
||||
if v == None: return None
|
||||
v.vtype = JSON_ARRAY
|
||||
return v
|
||||
|
||||
def object(pool: rawptr[memhub.MemManager]) -> JsonValue*:
|
||||
def object(pool: memhub.MemManager*) -> JsonValue*:
|
||||
v: JsonValue* = JsonValue(pool)
|
||||
if v == None: return None
|
||||
v.vtype = JSON_OBJECT
|
||||
return v
|
||||
|
||||
# Append an element to an array
|
||||
def array_append(pool: rawptr[memhub.MemManager], arr: JsonValue*, item: JsonValue*):
|
||||
def array_append(pool: memhub.MemManager*, arr: JsonValue*, item: JsonValue*):
|
||||
if arr == None or item == None: return
|
||||
if arr.vtype != JSON_ARRAY: return
|
||||
arr._append_child(item)
|
||||
|
||||
# Set a key/value pair on an object
|
||||
def object_set(pool: rawptr[memhub.MemManager], obj: JsonValue*, key: str, val: JsonValue*):
|
||||
def object_set(pool: memhub.MemManager*, obj: JsonValue*, key: str, val: JsonValue*):
|
||||
if obj == None or key == None or val == None: return
|
||||
if obj.vtype != JSON_OBJECT: return
|
||||
cur: JsonValue* = obj.child
|
||||
|
||||
+17
-17
@@ -13,25 +13,25 @@ class ParseState:
|
||||
src: str
|
||||
pos: sizet = 0
|
||||
len: sizet = 0
|
||||
pool: rawptr[memhub.MemManager]
|
||||
pool: memhub.MemManager*
|
||||
|
||||
def __init__(self, src: str, pool: rawptr[memhub.MemManager]):
|
||||
def __init__(self, src: str, pool: memhub.MemManager*):
|
||||
self.src = src
|
||||
self.len = string.strlen(src) if src != None else 0
|
||||
self.pool = pool
|
||||
|
||||
|
||||
def _peek(s: rawptr[ParseState]) -> char:
|
||||
def _peek(s: ParseState*) -> char:
|
||||
if s.pos >= s.len: return '\0'
|
||||
return s.src[s.pos]
|
||||
|
||||
def _advance(s: rawptr[ParseState]) -> char:
|
||||
def _advance(s: ParseState*) -> char:
|
||||
if s.pos >= s.len: return '\0'
|
||||
ch: char = s.src[s.pos]
|
||||
s.pos += 1
|
||||
return ch
|
||||
|
||||
def _skip_whitespace(s: rawptr[ParseState]):
|
||||
def _skip_whitespace(s: ParseState*):
|
||||
while s.pos < s.len:
|
||||
ch: char = s.src[s.pos]
|
||||
if ch == ' ' or ch == '\t' or ch == '\n' or ch == '\r':
|
||||
@@ -39,7 +39,7 @@ def _skip_whitespace(s: rawptr[ParseState]):
|
||||
else:
|
||||
break
|
||||
|
||||
def _expect(s: rawptr[ParseState], ch: char) -> bool:
|
||||
def _expect(s: ParseState*, ch: char) -> bool:
|
||||
_skip_whitespace(s)
|
||||
if s.pos >= s.len: return False
|
||||
if s.src[s.pos] != ch: return False
|
||||
@@ -47,7 +47,7 @@ def _expect(s: rawptr[ParseState], ch: char) -> bool:
|
||||
return True
|
||||
|
||||
|
||||
def _parse_string(s: rawptr[ParseState]) -> str:
|
||||
def _parse_string(s: ParseState*) -> str:
|
||||
if _peek(s) != '"': return None
|
||||
_advance(s)
|
||||
|
||||
@@ -103,7 +103,7 @@ def _parse_string(s: rawptr[ParseState]) -> str:
|
||||
return buf
|
||||
|
||||
|
||||
def _parse_number(s: rawptr[ParseState]) -> rawptr[JsonValue]:
|
||||
def _parse_number(s: ParseState*) -> JsonValue*:
|
||||
_skip_whitespace(s)
|
||||
is_float: bool = False
|
||||
start: sizet = s.pos
|
||||
@@ -157,7 +157,7 @@ def _parse_number(s: rawptr[ParseState]) -> rawptr[JsonValue]:
|
||||
return int_val(s.pool, ival)
|
||||
|
||||
|
||||
def _parse_value(s: rawptr[ParseState]) -> rawptr[JsonValue]:
|
||||
def _parse_value(s: ParseState*) -> JsonValue*:
|
||||
_skip_whitespace(s)
|
||||
if s.pos >= s.len:
|
||||
return null(s.pool)
|
||||
@@ -201,11 +201,11 @@ def _parse_value(s: rawptr[ParseState]) -> rawptr[JsonValue]:
|
||||
return null(s.pool)
|
||||
|
||||
|
||||
def _parse_array(s: rawptr[ParseState]) -> rawptr[JsonValue]:
|
||||
def _parse_array(s: ParseState*) -> JsonValue*:
|
||||
if not _expect(s, '['):
|
||||
return null(s.pool)
|
||||
|
||||
arr: rawptr[JsonValue] = array(s.pool)
|
||||
arr: JsonValue* = array(s.pool)
|
||||
# Pool exhausted => array() returns None; continuing to arr._append_child(...) would deref
|
||||
# a null pointer, so return None here (json.parse may return None; callers must check).
|
||||
if arr == None:
|
||||
@@ -216,7 +216,7 @@ def _parse_array(s: rawptr[ParseState]) -> rawptr[JsonValue]:
|
||||
_advance(s)
|
||||
return arr
|
||||
|
||||
item: rawptr[JsonValue] = _parse_value(s)
|
||||
item: JsonValue* = _parse_value(s)
|
||||
# item == None iff allocation failed somewhere inside _parse_value (syntax errors yield
|
||||
# a valid JSON_NULL node; only pool exhaustion yields None) => return None, append nothing.
|
||||
if item == None:
|
||||
@@ -239,11 +239,11 @@ def _parse_array(s: rawptr[ParseState]) -> rawptr[JsonValue]:
|
||||
return arr
|
||||
|
||||
|
||||
def _parse_object(s: rawptr[ParseState]) -> rawptr[JsonValue]:
|
||||
def _parse_object(s: ParseState*) -> JsonValue*:
|
||||
if not _expect(s, '{'):
|
||||
return null(s.pool)
|
||||
|
||||
obj: rawptr[JsonValue] = object(s.pool)
|
||||
obj: JsonValue* = object(s.pool)
|
||||
# Same as _parse_array: obj is None on pool exhaustion; do not call _append_child on None.
|
||||
if obj == None:
|
||||
return null(s.pool)
|
||||
@@ -256,7 +256,7 @@ def _parse_object(s: rawptr[ParseState]) -> rawptr[JsonValue]:
|
||||
_skip_whitespace(s)
|
||||
key: str = _parse_string(s)
|
||||
_expect(s, ':')
|
||||
val: rawptr[JsonValue] = _parse_value(s)
|
||||
val: JsonValue* = _parse_value(s)
|
||||
if key != None and val != None:
|
||||
klen: sizet = string.strlen(key)
|
||||
kbuf: str = s.pool.alloc(klen + 1)
|
||||
@@ -288,9 +288,9 @@ def _parse_object(s: rawptr[ParseState]) -> rawptr[JsonValue]:
|
||||
return obj
|
||||
|
||||
|
||||
def parse(pool: rawptr[memhub.MemManager], src: str) -> rawptr[JsonValue]:
|
||||
def parse(pool: memhub.MemManager*, src: str) -> JsonValue*:
|
||||
"""Parse a JSON string, returning a JsonValue tree."""
|
||||
if src == None:
|
||||
return null(pool)
|
||||
s: rawptr[ParseState] = ParseState(src, pool)
|
||||
s: ParseState* = ParseState(src, pool)
|
||||
return _parse_value(s)
|
||||
+5
-5
@@ -71,8 +71,8 @@ def _write_string_escaped(buf: str, pos: sizet, cap: sizet, s: str) -> sizet:
|
||||
return pos
|
||||
|
||||
|
||||
def _write_value(buf: str, pos: sizet, cap: sizet, val: rawptr[JsonValue],
|
||||
pool: rawptr[memhub.MemManager]) -> sizet:
|
||||
def _write_value(buf: str, pos: sizet, cap: sizet, val: JsonValue*,
|
||||
pool: memhub.MemManager*) -> sizet:
|
||||
if pos >= cap:
|
||||
return pos # already overflowed: stop writing (recursion converges here)
|
||||
if val == None:
|
||||
@@ -108,7 +108,7 @@ def _write_value(buf: str, pos: sizet, cap: sizet, val: rawptr[JsonValue],
|
||||
pos = _write_str(buf, pos, cap, "[]")
|
||||
return pos
|
||||
pos = _write_char(buf, pos, cap, '[')
|
||||
cur: rawptr[JsonValue] = val.child
|
||||
cur: JsonValue* = val.child
|
||||
first: bool = True
|
||||
while cur != None:
|
||||
if pos >= cap:
|
||||
@@ -125,7 +125,7 @@ def _write_value(buf: str, pos: sizet, cap: sizet, val: rawptr[JsonValue],
|
||||
pos = _write_str(buf, pos, cap, "{}")
|
||||
return pos
|
||||
pos = _write_char(buf, pos, cap, '{')
|
||||
cur2: rawptr[JsonValue] = val.child
|
||||
cur2: JsonValue* = val.child
|
||||
first2: bool = True
|
||||
while cur2 != None:
|
||||
if pos >= cap:
|
||||
@@ -144,7 +144,7 @@ def _write_value(buf: str, pos: sizet, cap: sizet, val: rawptr[JsonValue],
|
||||
|
||||
# Serialize to a JSON string. cap = output buffer size (bytes, incl trailing NUL), default 4096.
|
||||
# Returns None when content does not fit (never writes past the buffer).
|
||||
def write(pool: rawptr[memhub.MemManager], val: rawptr[JsonValue], pretty: bool,
|
||||
def write(pool: memhub.MemManager*, val: JsonValue*, pretty: bool,
|
||||
cap: sizet = 4096) -> str:
|
||||
"""Serialize a JsonValue into a JSON string."""
|
||||
if cap < 2:
|
||||
|
||||
@@ -453,7 +453,7 @@ def NewMemPool(base: rawptr, size: sizet) -> MemPool*:
|
||||
# detection) and then calls the existing virtual alloc => no new virtual function, no vtable change,
|
||||
# no contract change; for a MemBuddy pool its alloc_tagged is also available (that one additionally
|
||||
# records a record-table tag for [FREEFRAME] reports).
|
||||
def MemAllocTagged(pool: rawptr[MemManager], size: sizet, tag: sizet) -> rawptr:
|
||||
def MemAllocTagged(pool: MemManager*, size: sizet, tag: sizet) -> rawptr:
|
||||
if pool is None:
|
||||
return None
|
||||
prev: uint64 = _alloc_site_enter(uint64(tag))
|
||||
|
||||
+270
-270
File diff suppressed because it is too large.
Load diff
+109
-109
@@ -50,7 +50,7 @@ novirtual class Line(GSListNode[Line]):
|
||||
# ============================================================
|
||||
novirtual class BasicBlock(GSListNode[BasicBlock]):
|
||||
Name: str # block name (e.g. "entry"/"if.then")
|
||||
Lines: rawptr[GSList[Line]] # instruction-line list container (Head/Tail/Count)
|
||||
Lines: GSList[Line]* # instruction-line list container (Head/Tail/Count)
|
||||
IsTerminated: int # 1=terminator present (br/ret)
|
||||
|
||||
|
||||
@@ -63,7 +63,7 @@ novirtual class BasicBlock(GSListNode[BasicBlock]):
|
||||
# NOTE: must carry @t.NoVTable (same reason as Line).
|
||||
# ============================================================
|
||||
novirtual class Param(GSListNode[Param]):
|
||||
Ty: rawptr[LLVMType] # parameter type
|
||||
Ty: LLVMType* # parameter type
|
||||
Name: str # parameter name (e.g. "%0"/"%a")
|
||||
Attrs: str # parameter attribute text (None=none)
|
||||
|
||||
@@ -80,9 +80,9 @@ novirtual class Param(GSListNode[Param]):
|
||||
# ============================================================
|
||||
novirtual class Function(GSListNode[Function]):
|
||||
Name: str # function name
|
||||
RetTy: rawptr[LLVMType] # return type
|
||||
Params: rawptr[GSList[Param]] # parameter list container
|
||||
Blocks: rawptr[GSList[BasicBlock]] # basic-block list container
|
||||
RetTy: LLVMType* # return type
|
||||
Params: GSList[Param]* # parameter list container
|
||||
Blocks: GSList[BasicBlock]* # basic-block list container
|
||||
IsDeclared: int # 1=declaration only (declare), 0=definition (define)
|
||||
IsVarArg: int # 1=variadic function (...)
|
||||
Attrs: str # function attribute text (None=none)
|
||||
@@ -98,9 +98,9 @@ novirtual class Function(GSListNode[Function]):
|
||||
# Line hardcoded size: Next(8) + Buf(8) + Len(8) = 24 bytes
|
||||
define LINE_SIZE = 24
|
||||
|
||||
def new_line(pool: memhub.MemBuddy*, text: str) -> rawptr[Line]:
|
||||
def new_line(pool: memhub.MemBuddy*, text: str) -> Line*:
|
||||
"""Create an instruction line, copying text into a newly allocated buffer"""
|
||||
ptr: rawptr[Line] = pool.alloc(LINE_SIZE)
|
||||
ptr: Line* = pool.alloc(LINE_SIZE)
|
||||
if ptr is None: return None
|
||||
string.memset(ptr, 0, LINE_SIZE)
|
||||
if text is not None:
|
||||
@@ -124,9 +124,9 @@ def _new_gslist(pool: memhub.MemBuddy*, list_size: sizet) -> t.CPtr:
|
||||
# BasicBlock hardcoded size: Next(8) + Name(8) + Lines(8) + IsTerminated(4) = 32 bytes
|
||||
define BLOCK_SIZE = 32
|
||||
|
||||
def new_basic_block(pool: memhub.MemBuddy*, name: str) -> rawptr[BasicBlock]:
|
||||
def new_basic_block(pool: memhub.MemBuddy*, name: str) -> BasicBlock*:
|
||||
"""Create a basic block"""
|
||||
ptr: rawptr[BasicBlock] = pool.alloc(BLOCK_SIZE)
|
||||
ptr: BasicBlock* = pool.alloc(BLOCK_SIZE)
|
||||
if ptr is None: return None
|
||||
string.memset(ptr, 0, BLOCK_SIZE)
|
||||
ptr.Name = name
|
||||
@@ -138,10 +138,10 @@ def new_basic_block(pool: memhub.MemBuddy*, name: str) -> rawptr[BasicBlock]:
|
||||
# Param hardcoded size: Next(8) + Ty(8) + Name(8) + Attrs(8) = 32 bytes
|
||||
define PARAM_SIZE = 32
|
||||
|
||||
def new_param(pool: memhub.MemBuddy*, ty: rawptr[LLVMType],
|
||||
name: str) -> rawptr[Param]:
|
||||
def new_param(pool: memhub.MemBuddy*, ty: LLVMType*,
|
||||
name: str) -> Param*:
|
||||
"""Create a function parameter"""
|
||||
ptr: rawptr[Param] = pool.alloc(PARAM_SIZE)
|
||||
ptr: Param* = pool.alloc(PARAM_SIZE)
|
||||
if ptr is None: return None
|
||||
string.memset(ptr, 0, PARAM_SIZE)
|
||||
ptr.Ty = ty
|
||||
@@ -154,9 +154,9 @@ def new_param(pool: memhub.MemBuddy*, ty: rawptr[LLVMType],
|
||||
define FUNC_SIZE = 88
|
||||
|
||||
def new_function(pool: memhub.MemBuddy*, name: str,
|
||||
ret_ty: rawptr[LLVMType]) -> rawptr[Function]:
|
||||
ret_ty: LLVMType*) -> Function*:
|
||||
"""Create a function"""
|
||||
ptr: rawptr[Function] = pool.alloc(FUNC_SIZE)
|
||||
ptr: Function* = pool.alloc(FUNC_SIZE)
|
||||
if ptr is None: return None
|
||||
string.memset(ptr, 0, FUNC_SIZE)
|
||||
ptr.Name = name
|
||||
@@ -179,25 +179,25 @@ def new_function(pool: memhub.MemBuddy*, name: str,
|
||||
# ============================================================
|
||||
# List operations (delegating to GSList.append)
|
||||
# ============================================================
|
||||
def function_add_param(func: rawptr[Function], param: rawptr[Param]):
|
||||
def function_add_param(func: Function*, param: Param*):
|
||||
"""Append a parameter to the function's parameter list"""
|
||||
if func is None or param is None: return
|
||||
# NOTE: use a local variable + type parameter (see function_move_block_to_end): chaining
|
||||
# func.Params.append() mis-resolves to LinkedNode.append and corrupts memory 48 bytes before the container.
|
||||
params: rawptr[GSList[Param]] = func.Params
|
||||
params: GSList[Param]* = func.Params
|
||||
if params is None: return
|
||||
params.append(param)
|
||||
|
||||
|
||||
def function_add_block(func: rawptr[Function], block: rawptr[BasicBlock]):
|
||||
def function_add_block(func: Function*, block: BasicBlock*):
|
||||
"""Append a basic block to the function's block list"""
|
||||
if func is None or block is None: return
|
||||
blocks: rawptr[GSList[BasicBlock]] = func.Blocks
|
||||
blocks: GSList[BasicBlock]* = func.Blocks
|
||||
if blocks is None: return
|
||||
blocks.append(block)
|
||||
|
||||
|
||||
def function_move_block_to_end(func: rawptr[Function], block: rawptr[BasicBlock]):
|
||||
def function_move_block_to_end(func: Function*, block: BasicBlock*):
|
||||
"""Move block to the end of the function's block list (BB text order == control-flow order).
|
||||
|
||||
Fixes non-monotonic SSA numbering (BBs are created in order but instructions are emitted in
|
||||
@@ -206,7 +206,7 @@ def function_move_block_to_end(func: rawptr[Function], block: rawptr[BasicBlock]
|
||||
type and blocks.Head/Tail/Count field reads return garbage.
|
||||
"""
|
||||
if func is None or block is None: return
|
||||
blocks: rawptr[GSList[BasicBlock]] = func.Blocks
|
||||
blocks: GSList[BasicBlock]* = func.Blocks
|
||||
if blocks is None: return
|
||||
|
||||
# Already Tail; nothing to move
|
||||
@@ -219,7 +219,7 @@ def function_move_block_to_end(func: rawptr[Function], block: rawptr[BasicBlock]
|
||||
blocks.Head = block.Next
|
||||
else:
|
||||
# Walk to find the predecessor
|
||||
prev: rawptr[BasicBlock] = blocks.Head
|
||||
prev: BasicBlock* = blocks.Head
|
||||
while prev is not None and prev.Next is not block:
|
||||
prev = prev.Next
|
||||
if prev is None:
|
||||
@@ -237,38 +237,38 @@ def function_move_block_to_end(func: rawptr[Function], block: rawptr[BasicBlock]
|
||||
blocks.Tail = block
|
||||
|
||||
|
||||
def block_append_line(block: rawptr[BasicBlock], line: rawptr[Line]):
|
||||
def block_append_line(block: BasicBlock*, line: Line*):
|
||||
"""Append an instruction line to the basic block"""
|
||||
if block is None or line is None: return
|
||||
lines: rawptr[GSList[Line]] = block.Lines
|
||||
lines: GSList[Line]* = block.Lines
|
||||
if lines is None: return
|
||||
lines.append(line)
|
||||
|
||||
|
||||
def block_set_terminated(block: rawptr[BasicBlock], val: int):
|
||||
def block_set_terminated(block: BasicBlock*, val: int):
|
||||
"""Set the block terminator flag (cross-module call to avoid opaque chained field access)"""
|
||||
if block is None: return
|
||||
block.IsTerminated = val
|
||||
|
||||
|
||||
def block_get_terminated(block: rawptr[BasicBlock]) -> int:
|
||||
def block_get_terminated(block: BasicBlock*) -> int:
|
||||
"""Get the block terminator flag (cross-module call to avoid opaque chained field access)"""
|
||||
if block is None:
|
||||
return 1
|
||||
return block.IsTerminated
|
||||
|
||||
|
||||
def block_append_text(pool: memhub.MemBuddy*, block: rawptr[BasicBlock],
|
||||
def block_append_text(pool: memhub.MemBuddy*, block: BasicBlock*,
|
||||
text: str):
|
||||
"""Create an instruction line and append it to the basic block"""
|
||||
if block is None or text is None: return
|
||||
line: rawptr[Line] = new_line(pool, text)
|
||||
line: Line* = new_line(pool, text)
|
||||
if line is not None:
|
||||
block_append_line(block, line)
|
||||
|
||||
|
||||
def block_insert_text_before_terminator(pool: memhub.MemBuddy*,
|
||||
block: rawptr[BasicBlock],
|
||||
block: BasicBlock*,
|
||||
text: str):
|
||||
"""Create an instruction line and insert it before the block terminator.
|
||||
|
||||
@@ -277,14 +277,14 @@ def block_insert_text_before_terminator(pool: memhub.MemBuddy*,
|
||||
"""
|
||||
if block is None or text is None: return
|
||||
if block.Lines is None: return
|
||||
line: rawptr[Line] = new_line(pool, text)
|
||||
line: Line* = new_line(pool, text)
|
||||
if line is None: return
|
||||
# Block not terminated: append directly
|
||||
if block.IsTerminated == 0:
|
||||
block_append_line(block, line)
|
||||
return
|
||||
# Block terminated: insert before Tail (the terminator)
|
||||
lines: rawptr[GSList[Line]] = block.Lines
|
||||
lines: GSList[Line]* = block.Lines
|
||||
if lines.Head is None:
|
||||
block_append_line(block, line)
|
||||
return
|
||||
@@ -295,7 +295,7 @@ def block_insert_text_before_terminator(pool: memhub.MemBuddy*,
|
||||
lines.Count += 1
|
||||
return
|
||||
# Find the predecessor of Tail
|
||||
prev: rawptr[Line] = lines.Head
|
||||
prev: Line* = lines.Head
|
||||
while prev is not None and prev.Next is not lines.Tail:
|
||||
prev = prev.Next
|
||||
if prev is None:
|
||||
@@ -311,7 +311,7 @@ def block_insert_text_before_terminator(pool: memhub.MemBuddy*,
|
||||
# ============================================================
|
||||
# Attribute setters
|
||||
# ============================================================
|
||||
def function_set_attrs(func: rawptr[Function], attrs: str):
|
||||
def function_set_attrs(func: Function*, attrs: str):
|
||||
"""Set function-level attribute text (e.g. "nounwind"/"noinline")"""
|
||||
if func is None: return
|
||||
func.Attrs = attrs
|
||||
@@ -319,7 +319,7 @@ def function_set_attrs(func: rawptr[Function], attrs: str):
|
||||
|
||||
_g_attr_group_counter: int = 0
|
||||
|
||||
def function_set_attr_group(func: rawptr[Function], group: str):
|
||||
def function_set_attr_group(func: Function*, group: str):
|
||||
"""Set function string attribute group (e.g. '"section"=".text.startup"') and assign #N.
|
||||
|
||||
LLVM string attributes (with a value, e.g. section) cannot be inlined on the signature
|
||||
@@ -333,13 +333,13 @@ def function_set_attr_group(func: rawptr[Function], group: str):
|
||||
func.AttrGroupId = _g_attr_group_counter
|
||||
|
||||
|
||||
def param_set_attrs(param: rawptr[Param], attrs: str):
|
||||
def param_set_attrs(param: Param*, attrs: str):
|
||||
"""Set parameter attribute text (e.g. "noundef"/"nocapture"/"readonly")"""
|
||||
if param is None: return
|
||||
param.Attrs = attrs
|
||||
|
||||
|
||||
def function_set_dbg(func: rawptr[Function], ref: str):
|
||||
def function_set_dbg(func: Function*, ref: str):
|
||||
"""Set the function-level debug ref (DISubprogram node ref, e.g. "!3").
|
||||
|
||||
Kept as-is: MLIR printing ignores it (FunctionPrint emits no !dbg), so this only
|
||||
@@ -451,26 +451,26 @@ def _is_digit_ch(ch: char) -> int:
|
||||
def _map_get_i32(map_arr: str, idx: int) -> int:
|
||||
"""Read i32 array map_arr[idx] (explicit byte offset idx*4).
|
||||
|
||||
Casts the byte offset to i32* via (rawptr[int])(uint64), then dereferences with c.Deref.
|
||||
Casts the byte offset to i32* via (int*)(uint64), then dereferences with c.Deref.
|
||||
TPC has fixed type-union casts (_HandleTypeUnionCastLlvm fallback), so this form works.
|
||||
"""
|
||||
if map_arr is None:
|
||||
return -1
|
||||
byte_off: uint64 = uint64(map_arr) + idx * 4
|
||||
elem_ptr: rawptr[int] = (rawptr[int])(byte_off)
|
||||
elem_ptr: int* = (int*)(byte_off)
|
||||
return *elem_ptr
|
||||
|
||||
|
||||
def _map_set_i32(map_arr: str, idx: int, val: int):
|
||||
"""Write map_arr[idx] = val (i32 array, explicit byte offset idx*4).
|
||||
|
||||
Casts via (rawptr[int])(uint64) and assigns through c.DerefAs.
|
||||
Casts via (int*)(uint64) and assigns through c.DerefAs.
|
||||
TPC has fixed type-union casts, so this form works.
|
||||
"""
|
||||
if map_arr is None:
|
||||
return
|
||||
byte_off: uint64 = uint64(map_arr) + idx * 4
|
||||
elem_ptr: rawptr[int] = (rawptr[int])(byte_off)
|
||||
elem_ptr: int* = (int*)(byte_off)
|
||||
c.DerefAs(elem_ptr, val)
|
||||
|
||||
|
||||
@@ -492,13 +492,13 @@ def _scan_max_ssa_in_text(text: str, cur_max: int) -> int:
|
||||
return result
|
||||
|
||||
|
||||
def _find_max_ssa_number(func: rawptr[Function]) -> int:
|
||||
def _find_max_ssa_number(func: Function*) -> int:
|
||||
"""Walk all BB instruction lines for the largest %N; returns -1 if no numeric SSA names"""
|
||||
max_n: int = -1
|
||||
if func is None or func.Blocks is None:
|
||||
return max_n
|
||||
blocks: rawptr[GSList[BasicBlock]] = func.Blocks
|
||||
blk: rawptr[BasicBlock] = blocks.Head
|
||||
blocks: GSList[BasicBlock]* = func.Blocks
|
||||
blk: BasicBlock* = blocks.Head
|
||||
blk_steps: sizet = 0
|
||||
while blk is not None:
|
||||
blk_steps += 1
|
||||
@@ -506,8 +506,8 @@ def _find_max_ssa_number(func: rawptr[Function]) -> int:
|
||||
stdio.printf("[IR-DUMP] 链表成环: func blocks(函数名=%s,ssa 扫描终止)\n", func.Name)
|
||||
stdlib.exit(1)
|
||||
if blk.Lines is not None:
|
||||
lines: rawptr[GSList[Line]] = blk.Lines
|
||||
line: rawptr[Line] = lines.Head
|
||||
lines: GSList[Line]* = blk.Lines
|
||||
line: Line* = lines.Head
|
||||
line_steps: sizet = 0
|
||||
while line is not None:
|
||||
line_steps += 1
|
||||
@@ -605,7 +605,7 @@ def _replace_ssa_numbers(text: str,
|
||||
return new_buf
|
||||
|
||||
|
||||
def RenumberSSA(func: rawptr[Function], pool: memhub.MemBuddy*):
|
||||
def RenumberSSA(func: Function*, pool: memhub.MemBuddy*):
|
||||
"""Renumber all numeric SSA names in the function so text-output order is monotonic.
|
||||
|
||||
Called before FunctionPrint serializes the body; only applies to define (IsDeclared==0)
|
||||
@@ -633,8 +633,8 @@ def RenumberSSA(func: rawptr[Function], pool: memhub.MemBuddy*):
|
||||
|
||||
# 3. Second pass: assign new numbers in text order
|
||||
next_new: int = 0
|
||||
blocks: rawptr[GSList[BasicBlock]] = func.Blocks
|
||||
blk: rawptr[BasicBlock] = blocks.Head
|
||||
blocks: GSList[BasicBlock]* = func.Blocks
|
||||
blk: BasicBlock* = blocks.Head
|
||||
blk_steps: sizet = 0
|
||||
while blk is not None:
|
||||
blk_steps += 1
|
||||
@@ -642,8 +642,8 @@ def RenumberSSA(func: rawptr[Function], pool: memhub.MemBuddy*):
|
||||
stdio.printf("[IR-DUMP] 链表成环: func blocks(函数名=%s,ssa 重编号终止)\n", func.Name)
|
||||
stdlib.exit(1)
|
||||
if blk.Lines is not None:
|
||||
lines: rawptr[GSList[Line]] = blk.Lines
|
||||
line: rawptr[Line] = lines.Head
|
||||
lines: GSList[Line]* = blk.Lines
|
||||
line: Line* = lines.Head
|
||||
line_steps: sizet = 0
|
||||
while line is not None:
|
||||
line_steps += 1
|
||||
@@ -677,8 +677,8 @@ def RenumberSSA(func: rawptr[Function], pool: memhub.MemBuddy*):
|
||||
stdio.printf("[IR-DUMP] 链表成环: func blocks(函数名=%s,ssa 替换终止)\n", func.Name)
|
||||
stdlib.exit(1)
|
||||
if blk.Lines is not None:
|
||||
lines: rawptr[GSList[Line]] = blk.Lines
|
||||
line: rawptr[Line] = lines.Head
|
||||
lines: GSList[Line]* = blk.Lines
|
||||
line: Line* = lines.Head
|
||||
line_steps = 0
|
||||
while line is not None:
|
||||
line_steps += 1
|
||||
@@ -846,24 +846,24 @@ def _peep_is_alloc_of(eb: str, a_name: str, nl: sizet) -> int:
|
||||
return 0
|
||||
|
||||
|
||||
def _peephole_opt(func: rawptr[Function], pool: memhub.MemBuddy*):
|
||||
def _peephole_opt(func: Function*, pool: memhub.MemBuddy*):
|
||||
"""Text-layer local peephole: T1 ret zeroinitializer; T2 entry-slot store->load forwarding"""
|
||||
if func is None or func.Blocks is None or pool is None:
|
||||
return
|
||||
# NOTE: TPC silently drops assignments for a two-level "var = ptr.field.member" auto-deref
|
||||
# chain (the IR reads an uninitialized stack var -> random stack errors). Split into one level:
|
||||
# fetch the field into a local rawptr, then null-check before .Head (same pattern as FunctionPrint).
|
||||
func_blocks: rawptr[GSList[BasicBlock]] = func.Blocks
|
||||
blk: rawptr[BasicBlock] = None
|
||||
func_blocks: GSList[BasicBlock]* = func.Blocks
|
||||
blk: BasicBlock* = None
|
||||
if func_blocks is not None:
|
||||
blk = func_blocks.Head
|
||||
|
||||
# ---------- T1: ret <ty> zeroinitializer ----------
|
||||
blk_t1 = blk
|
||||
while blk_t1 is not None:
|
||||
line1: rawptr[Line] = None
|
||||
line1: Line* = None
|
||||
if blk_t1.Lines is not None:
|
||||
t1_lines: rawptr[GSList[Line]] = blk_t1.Lines
|
||||
t1_lines: GSList[Line]* = blk_t1.Lines
|
||||
line1 = t1_lines.Head
|
||||
while line1 is not None:
|
||||
if line1.Buf is not None:
|
||||
@@ -893,13 +893,13 @@ def _peephole_opt(func: rawptr[Function], pool: memhub.MemBuddy*):
|
||||
blk_t1 = blk_t1.Next
|
||||
|
||||
# ---------- T2: entry alloca slot forwarding ----------
|
||||
entry_blk: rawptr[BasicBlock] = blk
|
||||
entry_blk: BasicBlock* = blk
|
||||
if entry_blk is None:
|
||||
return
|
||||
entry_lines: rawptr[GSList[Line]] = entry_blk.Lines
|
||||
entry_lines: GSList[Line]* = entry_blk.Lines
|
||||
if entry_lines is None:
|
||||
return
|
||||
e_line: rawptr[Line] = entry_lines.Head
|
||||
e_line: Line* = entry_lines.Head
|
||||
while e_line is not None:
|
||||
eb: str = e_line.Buf
|
||||
if eb is not None:
|
||||
@@ -920,9 +920,9 @@ def _peephole_opt(func: rawptr[Function], pool: memhub.MemBuddy*):
|
||||
# First pass: count this alloca's store/load/other refs and line order
|
||||
blk_s = blk
|
||||
while blk_s is not None:
|
||||
l_s: rawptr[Line] = None
|
||||
l_s: Line* = None
|
||||
if blk_s.Lines is not None:
|
||||
scan_lines: rawptr[GSList[Line]] = blk_s.Lines
|
||||
scan_lines: GSList[Line]* = blk_s.Lines
|
||||
l_s = scan_lines.Head
|
||||
while l_s is not None:
|
||||
sb: str = l_s.Buf
|
||||
@@ -1008,9 +1008,9 @@ def _peephole_opt(func: rawptr[Function], pool: memhub.MemBuddy*):
|
||||
ltok_len: sizet = string.strlen(ltok)
|
||||
blk_r = blk
|
||||
while blk_r is not None:
|
||||
lr: rawptr[Line] = None
|
||||
lr: Line* = None
|
||||
if blk_r.Lines is not None:
|
||||
repl_lines: rawptr[GSList[Line]] = blk_r.Lines
|
||||
repl_lines: GSList[Line]* = blk_r.Lines
|
||||
lr = repl_lines.Head
|
||||
while lr is not None:
|
||||
if lr.Buf is not None:
|
||||
@@ -1023,9 +1023,9 @@ def _peephole_opt(func: rawptr[Function], pool: memhub.MemBuddy*):
|
||||
# Delete: alloca def / the single store / all load lines
|
||||
blk_d = blk
|
||||
while blk_d is not None:
|
||||
ld: rawptr[Line] = None
|
||||
ld: Line* = None
|
||||
if blk_d.Lines is not None:
|
||||
kill_lines: rawptr[GSList[Line]] = blk_d.Lines
|
||||
kill_lines: GSList[Line]* = blk_d.Lines
|
||||
ld = kill_lines.Head
|
||||
while ld is not None:
|
||||
db: str = ld.Buf
|
||||
@@ -1048,7 +1048,7 @@ def _peephole_opt(func: rawptr[Function], pool: memhub.MemBuddy*):
|
||||
_peep_noop_bitcast(func, pool)
|
||||
|
||||
|
||||
def _peep_noop_bitcast(func: rawptr[Function], pool: memhub.MemBuddy*):
|
||||
def _peep_noop_bitcast(func: Function*, pool: memhub.MemBuddy*):
|
||||
"""T3: remove no-op bitcast (bitcast <T> %x to <T>, same type on both sides).
|
||||
|
||||
The emitter (virtual calls / union width casts) produces same-type identity bitcasts
|
||||
@@ -1062,13 +1062,13 @@ def _peep_noop_bitcast(func: rawptr[Function], pool: memhub.MemBuddy*):
|
||||
# resuming from the next line; stop at the first non-matching bitcast. Equivalent deletion
|
||||
# result to the old rescan-from-block-head approach (replacement only touches operand tokens),
|
||||
# but removes the O(K*C) quadratic rescan.
|
||||
blk: rawptr[BasicBlock] = func.Blocks.Head
|
||||
blk: BasicBlock* = func.Blocks.Head
|
||||
while blk is not None:
|
||||
ln: rawptr[Line] = None
|
||||
ln: Line* = None
|
||||
if blk.Lines is not None:
|
||||
ln = blk.Lines.Head
|
||||
while ln is not None:
|
||||
nxt: rawptr[Line] = ln.Next
|
||||
nxt: Line* = ln.Next
|
||||
if ln.Buf is not None:
|
||||
eqpos: str = string.strstr(ln.Buf, " = bitcast ")
|
||||
if eqpos is not None:
|
||||
@@ -1105,10 +1105,10 @@ def _peep_noop_bitcast(func: rawptr[Function], pool: memhub.MemBuddy*):
|
||||
# nm_buf/src_buf are constant across the scan; strlen computed once (not per line)
|
||||
nm_buf_len: sizet = string.strlen(nm_buf)
|
||||
src_buf_len: sizet = string.strlen(src_buf)
|
||||
blk_r: rawptr[BasicBlock] = func.Blocks.Head
|
||||
blk_r: BasicBlock* = func.Blocks.Head
|
||||
while blk_r is not None:
|
||||
if blk_r.Lines is not None:
|
||||
ln2: rawptr[Line] = blk_r.Lines.Head
|
||||
ln2: Line* = blk_r.Lines.Head
|
||||
while ln2 is not None:
|
||||
if ln2.Buf is not None:
|
||||
rb: str = _peep_replace_token(pool, ln2.Buf, nm_buf, src_buf,
|
||||
@@ -1147,8 +1147,8 @@ define MLIR_ALIAS_CAP = 512
|
||||
# Render pass: 1=scan(register) 2=emit(write text)
|
||||
_MLIR_Pass: int = 0
|
||||
_MLIR_Pool: memhub.MemBuddy* = None
|
||||
_MLIR_Func: rawptr[Function] = None
|
||||
_MLIR_SrcBlk: rawptr[BasicBlock] = None
|
||||
_MLIR_Func: Function* = None
|
||||
_MLIR_SrcBlk: BasicBlock* = None
|
||||
|
||||
# Constant table: (MLIR type text, constant text) -> materialized SSA name
|
||||
_MLIR_ConstTy: t.CPtr = None
|
||||
@@ -1609,12 +1609,12 @@ def _MlirBlkRef(t: str) -> str:
|
||||
return t
|
||||
|
||||
|
||||
def _MlirFindBlock(func: rawptr[Function], name: str) -> rawptr[BasicBlock]:
|
||||
def _MlirFindBlock(func: Function*, name: str) -> BasicBlock*:
|
||||
"""Find a basic block by name (without %) within the function"""
|
||||
if func is None or func.Blocks is None or name is None:
|
||||
return None
|
||||
blocks: rawptr[GSList[BasicBlock]] = func.Blocks
|
||||
blk: rawptr[BasicBlock] = blocks.Head
|
||||
blocks: GSList[BasicBlock]* = func.Blocks
|
||||
blk: BasicBlock* = blocks.Head
|
||||
steps: int = 0
|
||||
while blk is not None:
|
||||
steps += 1
|
||||
@@ -1719,7 +1719,7 @@ def _MlirPhiParam(text: str) -> int:
|
||||
return 1
|
||||
|
||||
|
||||
def _MlirPhiFindIncoming(text: str, src: rawptr[BasicBlock]) -> int:
|
||||
def _MlirPhiFindIncoming(text: str, src: BasicBlock*) -> int:
|
||||
"""Find the phi incoming edge matching the source block; on success writes _SC_B1(value)/_SC_B2(type) and returns 1"""
|
||||
p: str = _mlir_ws(text)
|
||||
tb: str = _SC_Buf
|
||||
@@ -1772,12 +1772,12 @@ def _MlirPhiFindIncoming(text: str, src: rawptr[BasicBlock]) -> int:
|
||||
# ============================================================
|
||||
# Block parameters / block arguments
|
||||
# ============================================================
|
||||
def _MlirBlockHasPhi(blk: rawptr[BasicBlock]) -> int:
|
||||
def _MlirBlockHasPhi(blk: BasicBlock*) -> int:
|
||||
"""Whether the block head has a phi (i.e. the block carries block params)"""
|
||||
if blk is None or blk.Lines is None:
|
||||
return 0
|
||||
lines: rawptr[GSList[Line]] = blk.Lines
|
||||
ln: rawptr[Line] = lines.Head
|
||||
lines: GSList[Line]* = blk.Lines
|
||||
ln: Line* = lines.Head
|
||||
while ln is not None:
|
||||
if ln.Buf is not None:
|
||||
if _MlirIsPhiLine(ln.Buf) != 0:
|
||||
@@ -1788,7 +1788,7 @@ def _MlirBlockHasPhi(blk: rawptr[BasicBlock]) -> int:
|
||||
|
||||
|
||||
def _MlirBlockOperands(out: str, outsz: sizet,
|
||||
target: rawptr[BasicBlock], src: rawptr[BasicBlock]):
|
||||
target: BasicBlock*, src: BasicBlock*):
|
||||
"""Emit target's block arguments when branching to it: (%v : ty, ...).
|
||||
|
||||
Incoming edges are matched to phis by source block; no match -> loud error (never silently drop args).
|
||||
@@ -1799,8 +1799,8 @@ def _MlirBlockOperands(out: str, outsz: sizet,
|
||||
return
|
||||
tmp: str = _SC_Tmp
|
||||
tmp[0] = '\0'
|
||||
lines: rawptr[GSList[Line]] = target.Lines
|
||||
ln: rawptr[Line] = lines.Head
|
||||
lines: GSList[Line]* = target.Lines
|
||||
ln: Line* = lines.Head
|
||||
cnt: int = 0
|
||||
while ln is not None:
|
||||
if ln.Buf is None:
|
||||
@@ -1827,7 +1827,7 @@ def _MlirBlockOperands(out: str, outsz: sizet,
|
||||
_append_cstr(out, outsz, ")")
|
||||
|
||||
|
||||
def _MlirEmitBlockHeader(out: str, outsz: sizet, blk: rawptr[BasicBlock]):
|
||||
def _MlirEmitBlockHeader(out: str, outsz: sizet, blk: BasicBlock*):
|
||||
"""Emit a non-entry block header: ^name(%p: ty, ...):"""
|
||||
_append_cstr(out, outsz, "^")
|
||||
if blk.Name is not None:
|
||||
@@ -1835,8 +1835,8 @@ def _MlirEmitBlockHeader(out: str, outsz: sizet, blk: rawptr[BasicBlock]):
|
||||
if _MlirBlockHasPhi(blk) != 0:
|
||||
tmp: str = _SC_Tmp
|
||||
tmp[0] = '\0'
|
||||
lines: rawptr[GSList[Line]] = blk.Lines
|
||||
ln: rawptr[Line] = lines.Head
|
||||
lines: GSList[Line]* = blk.Lines
|
||||
ln: Line* = lines.Head
|
||||
cnt: int = 0
|
||||
while ln is not None:
|
||||
if ln.Buf is None:
|
||||
@@ -1863,12 +1863,12 @@ def _MlirEmitBlockHeader(out: str, outsz: sizet, blk: rawptr[BasicBlock]):
|
||||
_append_cstr(out, outsz, ":\n")
|
||||
|
||||
|
||||
def _MlirEmitBlockLines(out: str, outsz: sizet, blk: rawptr[BasicBlock]):
|
||||
def _MlirEmitBlockLines(out: str, outsz: sizet, blk: BasicBlock*):
|
||||
"""Emit in-block instructions (skip leading phis, which became block params)"""
|
||||
if blk is None or blk.Lines is None:
|
||||
return
|
||||
lines: rawptr[GSList[Line]] = blk.Lines
|
||||
ln: rawptr[Line] = lines.Head
|
||||
lines: GSList[Line]* = blk.Lines
|
||||
ln: Line* = lines.Head
|
||||
skipping: int = 1
|
||||
steps: int = 0
|
||||
while ln is not None:
|
||||
@@ -1884,7 +1884,7 @@ def _MlirEmitBlockLines(out: str, outsz: sizet, blk: rawptr[BasicBlock]):
|
||||
ln = ln.Next
|
||||
|
||||
|
||||
def _MlirCheckEntryNoPhi(blk: rawptr[BasicBlock]):
|
||||
def _MlirCheckEntryNoPhi(blk: BasicBlock*):
|
||||
"""entry block must not have phis (no predecessor, cannot become block params)"""
|
||||
if _MlirBlockHasPhi(blk) != 0:
|
||||
MlirFail("MLIR 渲染: entry 块不允许 phi(MLIR entry 块不接受块参数)")
|
||||
@@ -3136,7 +3136,7 @@ def _MlirRenderLine(text: str, out: str, outsz: sizet):
|
||||
# Function signature and body
|
||||
# ============================================================
|
||||
def _MlirFuncSig(buf: str, size: sizet,
|
||||
func: rawptr[Function], pool: memhub.MemBuddy*):
|
||||
func: Function*, pool: memhub.MemBuddy*):
|
||||
"""llvm.func @name(%a: i32, %b: i32) -> i32 (void return omits -> ty)"""
|
||||
_append_cstr(buf, size, "llvm.func @")
|
||||
if func.Name is not None:
|
||||
@@ -3147,8 +3147,8 @@ def _MlirFuncSig(buf: str, size: sizet,
|
||||
else:
|
||||
_append_cstr(buf, size, func.Name)
|
||||
_append_cstr(buf, size, "(")
|
||||
params: rawptr[GSList[Param]] = func.Params
|
||||
cur: rawptr[Param] = None
|
||||
params: GSList[Param]* = func.Params
|
||||
cur: Param* = None
|
||||
if params is not None:
|
||||
cur = params.Head
|
||||
first: int = 1
|
||||
@@ -3194,7 +3194,7 @@ def _MlirFuncSig(buf: str, size: sizet,
|
||||
|
||||
|
||||
def FunctionPrint(buf: str, size: sizet,
|
||||
func: rawptr[Function], pool: memhub.MemBuddy*):
|
||||
func: Function*, pool: memhub.MemBuddy*):
|
||||
"""Serialize function func as MLIR (llvm dialect) text APPENDED to buf.
|
||||
|
||||
NOTE: like the llvmlite version, this appends (so the module printer can concatenate
|
||||
@@ -3235,7 +3235,7 @@ def FunctionPrint(buf: str, size: sizet,
|
||||
_MlirOutTruncFail()
|
||||
return
|
||||
|
||||
blocks: rawptr[GSList[BasicBlock]] = func.Blocks
|
||||
blocks: GSList[BasicBlock]* = func.Blocks
|
||||
if blocks is None:
|
||||
_MlirFuncSig(buf, size, func, pool)
|
||||
_append_cstr(buf, size, "\n")
|
||||
@@ -3244,7 +3244,7 @@ def FunctionPrint(buf: str, size: sizet,
|
||||
|
||||
# ---- pass1: scan (register constants/aliases + shape checks) ----
|
||||
_MLIR_Pass = 1
|
||||
blk: rawptr[BasicBlock] = blocks.Head
|
||||
blk: BasicBlock* = blocks.Head
|
||||
blk_steps: int = 0
|
||||
while blk is not None:
|
||||
blk_steps += 1
|
||||
@@ -3252,8 +3252,8 @@ def FunctionPrint(buf: str, size: sizet,
|
||||
MlirFail("MLIR 渲染: 函数块链疑似成环")
|
||||
_MLIR_SrcBlk = blk
|
||||
if blk.Lines is not None:
|
||||
lines: rawptr[GSList[Line]] = blk.Lines
|
||||
ln: rawptr[Line] = lines.Head
|
||||
lines: GSList[Line]* = blk.Lines
|
||||
ln: Line* = lines.Head
|
||||
ln_steps: int = 0
|
||||
while ln is not None:
|
||||
ln_steps += 1
|
||||
@@ -3570,14 +3570,14 @@ def DebugTakeText() -> str:
|
||||
# These accessors run inside this module where the full type definitions exist, so they can access
|
||||
# all fields correctly; other modules get field values via function calls, bypassing the stub limits.
|
||||
# ============================================================
|
||||
def function_get_name(func: rawptr[Function]) -> str:
|
||||
def function_get_name(func: Function*) -> str:
|
||||
"""Get the function name"""
|
||||
if func is None:
|
||||
return None
|
||||
return func.Name
|
||||
|
||||
|
||||
def function_get_name_len(func: rawptr[Function]) -> sizet:
|
||||
def function_get_name_len(func: Function*) -> sizet:
|
||||
"""Get the function name length (computed once at creation, always == strlen(Name)).
|
||||
|
||||
Mirrors function_get_name's cross-module stub-bypass pattern: the user module only has a stub
|
||||
@@ -3590,59 +3590,59 @@ def function_get_name_len(func: rawptr[Function]) -> sizet:
|
||||
return func.NameLen
|
||||
|
||||
|
||||
def function_get_ret_ty(func: rawptr[Function]) -> rawptr[LLVMType]:
|
||||
def function_get_ret_ty(func: Function*) -> LLVMType*:
|
||||
"""Get the function return type"""
|
||||
if func is None:
|
||||
return None
|
||||
return func.RetTy
|
||||
|
||||
|
||||
def function_get_params(func: rawptr[Function]) -> rawptr[GSList[Param]]:
|
||||
def function_get_params(func: Function*) -> GSList[Param]*:
|
||||
"""Get the function parameter list container"""
|
||||
if func is None:
|
||||
return None
|
||||
return func.Params
|
||||
|
||||
|
||||
def function_get_param_head(func: rawptr[Function]) -> rawptr[Param]:
|
||||
def function_get_param_head(func: Function*) -> Param*:
|
||||
"""Get the function parameter list head (one step, avoiding GSList.Head access by callers)"""
|
||||
if func is None:
|
||||
return None
|
||||
params: rawptr[GSList[Param]] = func.Params
|
||||
params: GSList[Param]* = func.Params
|
||||
if params is None:
|
||||
return None
|
||||
return params.Head
|
||||
|
||||
|
||||
def function_get_next(func: rawptr[Function]) -> rawptr[Function]:
|
||||
def function_get_next(func: Function*) -> Function*:
|
||||
"""Get the next function in the list"""
|
||||
if func is None:
|
||||
return None
|
||||
return func.Next
|
||||
|
||||
|
||||
def function_is_declared(func: rawptr[Function]) -> int:
|
||||
def function_is_declared(func: Function*) -> int:
|
||||
"""Get whether the function is a declaration (1=declare, 0=define)"""
|
||||
if func is None:
|
||||
return 0
|
||||
return func.IsDeclared
|
||||
|
||||
|
||||
def param_get_name(param: rawptr[Param]) -> str:
|
||||
def param_get_name(param: Param*) -> str:
|
||||
"""Get the parameter name"""
|
||||
if param is None:
|
||||
return None
|
||||
return param.Name
|
||||
|
||||
|
||||
def param_get_ty(param: rawptr[Param]) -> rawptr[LLVMType]:
|
||||
def param_get_ty(param: Param*) -> LLVMType*:
|
||||
"""Get the parameter type"""
|
||||
if param is None:
|
||||
return None
|
||||
return param.Ty
|
||||
|
||||
|
||||
def param_get_next(param: rawptr[Param]) -> rawptr[Param]:
|
||||
def param_get_next(param: Param*) -> Param*:
|
||||
"""Get the next parameter in the list"""
|
||||
if param is None:
|
||||
return None
|
||||
|
||||
+63
-63
@@ -110,8 +110,8 @@ def _str_dup(pool: memhub.MemBuddy*, src: str) -> str:
|
||||
# ============================================================
|
||||
# Convenience factory: create a named basic block
|
||||
# ============================================================
|
||||
def create_block(pool: memhub.MemBuddy*, func: rawptr[Function],
|
||||
name: str) -> rawptr[BasicBlock]:
|
||||
def create_block(pool: memhub.MemBuddy*, func: Function*,
|
||||
name: str) -> BasicBlock*:
|
||||
"""Create a basic block and add it to the function."""
|
||||
# Block-name/param conflict guard: block label "entry:" is value %entry, so a param %entry
|
||||
# collides; on collision append .1/.2/... (strip a leading % from Param.Name before comparing).
|
||||
@@ -125,7 +125,7 @@ def create_block(pool: memhub.MemBuddy*, func: rawptr[Function],
|
||||
cb_collide: int = 1
|
||||
while cb_collide != 0:
|
||||
cb_collide = 0
|
||||
cb_p: rawptr[Param] = function_get_param_head(func)
|
||||
cb_p: Param* = function_get_param_head(func)
|
||||
while cb_p is not None:
|
||||
cb_pnm: str = param_get_name(cb_p)
|
||||
if cb_pnm is not None:
|
||||
@@ -141,7 +141,7 @@ def create_block(pool: memhub.MemBuddy*, func: rawptr[Function],
|
||||
use_name = cb_buf
|
||||
cb_k += 1
|
||||
name_dup: str = _str_dup(pool, use_name)
|
||||
blk: rawptr[BasicBlock] = new_basic_block(pool, name_dup)
|
||||
blk: BasicBlock* = new_basic_block(pool, name_dup)
|
||||
if blk is not None:
|
||||
function_add_block(func, blk)
|
||||
return blk
|
||||
@@ -151,12 +151,12 @@ def create_block(pool: memhub.MemBuddy*, func: rawptr[Function],
|
||||
# Convenience factory: create an integer constant value
|
||||
# ============================================================
|
||||
def const_int(pool: memhub.MemBuddy*, bits: int,
|
||||
val: int64) -> rawptr[Value]:
|
||||
val: int64) -> Value*:
|
||||
"""Create an integer constant value (auto-creates type + name text).
|
||||
bits: bit width (1/8/16/32/64); val: integer value.
|
||||
"""
|
||||
# create type
|
||||
ty: rawptr[LLVMType] = pool.alloc(LLVMType.__sizeof__())
|
||||
ty: LLVMType* = pool.alloc(LLVMType.__sizeof__())
|
||||
if ty is None: return None
|
||||
string.memset(ty, 0, LLVMType.__sizeof__())
|
||||
c.DerefAs(ty, LLVMType.Int(bits))
|
||||
@@ -174,12 +174,12 @@ def const_int(pool: memhub.MemBuddy*, bits: int,
|
||||
return ConstInt(pool, ty, val, name)
|
||||
|
||||
|
||||
def const_int32(pool: memhub.MemBuddy*, val: int64) -> rawptr[Value]:
|
||||
def const_int32(pool: memhub.MemBuddy*, val: int64) -> Value*:
|
||||
"""Convenience: create an i32 integer constant."""
|
||||
return const_int(pool, 32, val)
|
||||
|
||||
|
||||
def const_int64(pool: memhub.MemBuddy*, val: int64) -> rawptr[Value]:
|
||||
def const_int64(pool: memhub.MemBuddy*, val: int64) -> Value*:
|
||||
"""Convenience: create an i64 integer constant."""
|
||||
return const_int(pool, 64, val)
|
||||
|
||||
@@ -187,21 +187,21 @@ def const_int64(pool: memhub.MemBuddy*, val: int64) -> rawptr[Value]:
|
||||
# ============================================================
|
||||
# Convenience factory: create a function and add it to the module
|
||||
# ============================================================
|
||||
def create_function(pool: memhub.MemBuddy*, mod: rawptr[LLVMModule],
|
||||
name: str, ret_ty: rawptr[LLVMType]) -> rawptr[Function]:
|
||||
def create_function(pool: memhub.MemBuddy*, mod: LLVMModule*,
|
||||
name: str, ret_ty: LLVMType*) -> Function*:
|
||||
"""Create a function and add it to the module."""
|
||||
name_dup: str = _str_dup(pool, name)
|
||||
func: rawptr[Function] = new_function(pool, name_dup, ret_ty)
|
||||
func: Function* = new_function(pool, name_dup, ret_ty)
|
||||
if func is not None:
|
||||
module_add_function(mod, func)
|
||||
return func
|
||||
|
||||
|
||||
def add_param(pool: memhub.MemBuddy*, func: rawptr[Function],
|
||||
ty: rawptr[LLVMType], name: str) -> rawptr[Param]:
|
||||
def add_param(pool: memhub.MemBuddy*, func: Function*,
|
||||
ty: LLVMType*, name: str) -> Param*:
|
||||
"""Create a parameter and add it to the function."""
|
||||
name_dup: str = _str_dup(pool, name)
|
||||
param: rawptr[Param] = new_param(pool, ty, name_dup)
|
||||
param: Param* = new_param(pool, ty, name_dup)
|
||||
if param is not None:
|
||||
function_add_param(func, param)
|
||||
return param
|
||||
@@ -210,13 +210,13 @@ def add_param(pool: memhub.MemBuddy*, func: rawptr[Function],
|
||||
# ============================================================
|
||||
# Convenience factory: create a function declaration (declare)
|
||||
# ============================================================
|
||||
def create_declare(pool: memhub.MemBuddy*, mod: rawptr[LLVMModule],
|
||||
name: str, ret_ty: rawptr[LLVMType]) -> rawptr[Function]:
|
||||
def create_declare(pool: memhub.MemBuddy*, mod: LLVMModule*,
|
||||
name: str, ret_ty: LLVMType*) -> Function*:
|
||||
"""Create a function declaration (declare, no body) and add it to the module.
|
||||
Unlike create_function, it emits only: declare <ret_ty> @<name>(<params>)
|
||||
"""
|
||||
name_dup: str = _str_dup(pool, name)
|
||||
func: rawptr[Function] = new_function(pool, name_dup, ret_ty)
|
||||
func: Function* = new_function(pool, name_dup, ret_ty)
|
||||
if func is not None:
|
||||
func.IsDeclared = 1
|
||||
module_add_function(mod, func)
|
||||
@@ -229,8 +229,8 @@ def create_declare(pool: memhub.MemBuddy*, mod: rawptr[LLVMModule],
|
||||
# The initializer is stored in gv.Initializer as llvmlite-shaped LLVM syntax text (c"contents\00");
|
||||
# the MLIR render stage (__module.vp/_MlirGlobalInit) converts it to the attribute form "contents".
|
||||
# ============================================================
|
||||
def create_global_string(pool: memhub.MemBuddy*, mod: rawptr[LLVMModule],
|
||||
name: str, text: str) -> rawptr[GlobalVariable]:
|
||||
def create_global_string(pool: memhub.MemBuddy*, mod: LLVMModule*,
|
||||
name: str, text: str) -> GlobalVariable*:
|
||||
"""Create a string-constant global variable and add it to the module.
|
||||
name: global name (e.g. ".str"); text: C string without trailing NUL (added automatically).
|
||||
Returns: GlobalVariable pointer of type [len+1 x i8].
|
||||
@@ -240,20 +240,20 @@ def create_global_string(pool: memhub.MemBuddy*, mod: rawptr[LLVMModule],
|
||||
count: int = slen + 1 # includes the trailing NUL
|
||||
|
||||
# create i8 type
|
||||
i8_ty: rawptr[LLVMType] = pool.alloc(LLVMType.__sizeof__())
|
||||
i8_ty: LLVMType* = pool.alloc(LLVMType.__sizeof__())
|
||||
if i8_ty is None: return None
|
||||
string.memset(i8_ty, 0, LLVMType.__sizeof__())
|
||||
c.DerefAs(i8_ty, LLVMType.Int(8))
|
||||
|
||||
# create [count x i8] array type
|
||||
arr_ty: rawptr[LLVMType] = pool.alloc(LLVMType.__sizeof__())
|
||||
arr_ty: LLVMType* = pool.alloc(LLVMType.__sizeof__())
|
||||
if arr_ty is None: return None
|
||||
string.memset(arr_ty, 0, LLVMType.__sizeof__())
|
||||
c.DerefAs(arr_ty, LLVMType.Array(i8_ty, count))
|
||||
|
||||
# create global variable
|
||||
name_dup: str = _str_dup(pool, name)
|
||||
gv: rawptr[GlobalVariable] = new_global_variable(pool, name_dup, arr_ty)
|
||||
gv: GlobalVariable* = new_global_variable(pool, name_dup, arr_ty)
|
||||
if gv is None: return None
|
||||
|
||||
# set attributes: private + unnamed_addr + constant
|
||||
@@ -310,19 +310,19 @@ def create_global_string(pool: memhub.MemBuddy*, mod: rawptr[LLVMModule],
|
||||
# ============================================================
|
||||
# Convenience factory: create an integer global with an initializer
|
||||
# ============================================================
|
||||
def create_global_int(pool: memhub.MemBuddy*, mod: rawptr[LLVMModule],
|
||||
name: str, bits: int, val: int64) -> rawptr[GlobalVariable]:
|
||||
def create_global_int(pool: memhub.MemBuddy*, mod: LLVMModule*,
|
||||
name: str, bits: int, val: int64) -> GlobalVariable*:
|
||||
"""Create an integer global variable and add it to the module.
|
||||
MLIR output: llvm.mlir.global @<name>(<val> : i<bits>) : i<bits>
|
||||
"""
|
||||
# create integer type
|
||||
ty: rawptr[LLVMType] = pool.alloc(LLVMType.__sizeof__())
|
||||
ty: LLVMType* = pool.alloc(LLVMType.__sizeof__())
|
||||
if ty is None: return None
|
||||
string.memset(ty, 0, LLVMType.__sizeof__())
|
||||
c.DerefAs(ty, LLVMType.Int(bits))
|
||||
|
||||
name_dup: str = _str_dup(pool, name)
|
||||
gv: rawptr[GlobalVariable] = new_global_variable(pool, name_dup, ty)
|
||||
gv: GlobalVariable* = new_global_variable(pool, name_dup, ty)
|
||||
if gv is None: return None
|
||||
|
||||
# build initializer text "42" (the type is printed separately by the global render stage)
|
||||
@@ -353,109 +353,109 @@ class LLVMModuleCore:
|
||||
self.Pool = pool
|
||||
|
||||
# ---- module operations ----
|
||||
def NewModule(self, name: str) -> rawptr[LLVMModule]:
|
||||
def NewModule(self, name: str) -> LLVMModule*:
|
||||
return new_module(self.Pool, name)
|
||||
|
||||
def CreateFunction(self, mod: rawptr[LLVMModule], name: str,
|
||||
ret_ty: rawptr[LLVMType]) -> rawptr[Function]:
|
||||
def CreateFunction(self, mod: LLVMModule*, name: str,
|
||||
ret_ty: LLVMType*) -> Function*:
|
||||
return create_function(self.Pool, mod, name, ret_ty)
|
||||
|
||||
def CreateDeclare(self, mod: rawptr[LLVMModule], name: str,
|
||||
ret_ty: rawptr[LLVMType]) -> rawptr[Function]:
|
||||
def CreateDeclare(self, mod: LLVMModule*, name: str,
|
||||
ret_ty: LLVMType*) -> Function*:
|
||||
"""Create a function declaration (declare, no body)."""
|
||||
return create_declare(self.Pool, mod, name, ret_ty)
|
||||
|
||||
def AddParam(self, func: rawptr[Function], ty: rawptr[LLVMType],
|
||||
name: str) -> rawptr[Param]:
|
||||
def AddParam(self, func: Function*, ty: LLVMType*,
|
||||
name: str) -> Param*:
|
||||
return add_param(self.Pool, func, ty, name)
|
||||
|
||||
def FunctionSetAttrs(self, func: rawptr[Function], attrs: str):
|
||||
def FunctionSetAttrs(self, func: Function*, attrs: str):
|
||||
"""Set the function-level attribute text."""
|
||||
function_set_attrs(func, attrs)
|
||||
|
||||
def ParamSetAttrs(self, param: rawptr[Param], attrs: str):
|
||||
def ParamSetAttrs(self, param: Param*, attrs: str):
|
||||
"""Set the parameter attribute text."""
|
||||
param_set_attrs(param, attrs)
|
||||
|
||||
def CreateBlock(self, func: rawptr[Function],
|
||||
name: str) -> rawptr[BasicBlock]:
|
||||
def CreateBlock(self, func: Function*,
|
||||
name: str) -> BasicBlock*:
|
||||
return create_block(self.Pool, func, name)
|
||||
|
||||
def NewBuilder(self, func: rawptr[Function]) -> rawptr[IRBuilder]:
|
||||
def NewBuilder(self, func: Function*) -> IRBuilder*:
|
||||
return new_builder(self.Pool, func)
|
||||
|
||||
# ---- globals ----
|
||||
def NewGlobal(self, mod: rawptr[LLVMModule], name: str,
|
||||
ty: rawptr[LLVMType]) -> rawptr[GlobalVariable]:
|
||||
def NewGlobal(self, mod: LLVMModule*, name: str,
|
||||
ty: LLVMType*) -> GlobalVariable*:
|
||||
"""Create a global variable and add it to the module."""
|
||||
name_dup: str = _str_dup(self.Pool, name)
|
||||
gv: rawptr[GlobalVariable] = new_global_variable(self.Pool, name_dup, ty)
|
||||
gv: GlobalVariable* = new_global_variable(self.Pool, name_dup, ty)
|
||||
if gv is not None:
|
||||
module_add_global(mod, gv)
|
||||
return gv
|
||||
|
||||
def CreateGlobalString(self, mod: rawptr[LLVMModule], name: str,
|
||||
text: str) -> rawptr[GlobalVariable]:
|
||||
def CreateGlobalString(self, mod: LLVMModule*, name: str,
|
||||
text: str) -> GlobalVariable*:
|
||||
"""Create a string-constant global variable."""
|
||||
return create_global_string(self.Pool, mod, name, text)
|
||||
|
||||
def CreateGlobalInt(self, mod: rawptr[LLVMModule], name: str,
|
||||
bits: int, val: int64) -> rawptr[GlobalVariable]:
|
||||
def CreateGlobalInt(self, mod: LLVMModule*, name: str,
|
||||
bits: int, val: int64) -> GlobalVariable*:
|
||||
"""Create an integer global with an initializer."""
|
||||
return create_global_int(self.Pool, mod, name, bits, val)
|
||||
|
||||
def GlobalSetConstant(self, gv: rawptr[GlobalVariable], is_const: int):
|
||||
def GlobalSetConstant(self, gv: GlobalVariable*, is_const: int):
|
||||
global_set_constant(gv, is_const)
|
||||
|
||||
def GlobalSetLinkage(self, gv: rawptr[GlobalVariable], linkage: str):
|
||||
def GlobalSetLinkage(self, gv: GlobalVariable*, linkage: str):
|
||||
global_set_linkage(gv, linkage)
|
||||
|
||||
def GlobalSetUnnamedAddr(self, gv: rawptr[GlobalVariable], level: int):
|
||||
def GlobalSetUnnamedAddr(self, gv: GlobalVariable*, level: int):
|
||||
global_set_unnamed_addr(gv, level)
|
||||
|
||||
def GlobalSetSection(self, gv: rawptr[GlobalVariable], section: str):
|
||||
def GlobalSetSection(self, gv: GlobalVariable*, section: str):
|
||||
global_set_section(gv, section)
|
||||
|
||||
# ---- value creation ----
|
||||
def ConstInt(self, bits: int, val: int64) -> rawptr[Value]:
|
||||
def ConstInt(self, bits: int, val: int64) -> Value*:
|
||||
return const_int(self.Pool, bits, val)
|
||||
|
||||
def ConstInt32(self, val: int64) -> rawptr[Value]:
|
||||
def ConstInt32(self, val: int64) -> Value*:
|
||||
return const_int32(self.Pool, val)
|
||||
|
||||
def ConstInt64(self, val: int64) -> rawptr[Value]:
|
||||
def ConstInt64(self, val: int64) -> Value*:
|
||||
return const_int64(self.Pool, val)
|
||||
|
||||
def ConstFloat(self, ty: rawptr[LLVMType], val: double) -> rawptr[Value]:
|
||||
def ConstFloat(self, ty: LLVMType*, val: double) -> Value*:
|
||||
return ConstFloat(self.Pool, ty, val)
|
||||
|
||||
def SSAValue(self, ty: rawptr[LLVMType], name: str) -> rawptr[Value]:
|
||||
def SSAValue(self, ty: LLVMType*, name: str) -> Value*:
|
||||
return SSAValue(self.Pool, ty, name)
|
||||
|
||||
def ConstNull(self, ty: rawptr[LLVMType], name: str) -> rawptr[Value]:
|
||||
def ConstNull(self, ty: LLVMType*, name: str) -> Value*:
|
||||
return ConstNull(self.Pool, ty, name)
|
||||
|
||||
# ---- printing ----
|
||||
def PrintValue(self, buf: str, size: sizet, val: rawptr[Value]):
|
||||
def PrintValue(self, buf: str, size: sizet, val: Value*):
|
||||
ValuePrint(buf, size, val, self.Pool)
|
||||
|
||||
def PrintFunction(self, buf: str, size: sizet, func: rawptr[Function]):
|
||||
def PrintFunction(self, buf: str, size: sizet, func: Function*):
|
||||
FunctionPrint(buf, size, func, self.Pool)
|
||||
|
||||
def PrintModule(self, buf: str, size: sizet, mod: rawptr[LLVMModule]):
|
||||
def PrintModule(self, buf: str, size: sizet, mod: LLVMModule*):
|
||||
LLVMModulePrint(buf, size, mod, self.Pool, OUTPUT_FULL)
|
||||
|
||||
# ---- SSA verification ----
|
||||
def NewVerifyResult(self, buf_size: sizet) -> rawptr[VerifyResult]:
|
||||
def NewVerifyResult(self, buf_size: sizet) -> VerifyResult*:
|
||||
"""Create a verify-result object (buf_size = error message buffer size)."""
|
||||
return _new_verify_result(self.Pool, buf_size)
|
||||
|
||||
def VerifyFunction(self, func: rawptr[Function],
|
||||
result: rawptr[VerifyResult]) -> int:
|
||||
def VerifyFunction(self, func: Function*,
|
||||
result: VerifyResult*) -> int:
|
||||
"""Verify SSA correctness of one function; returns error count (0 = pass)."""
|
||||
return verify_function(self.Pool, func, result)
|
||||
|
||||
def VerifyModule(self, mod: rawptr[LLVMModule],
|
||||
result: rawptr[VerifyResult]) -> int:
|
||||
def VerifyModule(self, mod: LLVMModule*,
|
||||
result: VerifyResult*) -> int:
|
||||
"""Verify SSA correctness of all functions in the module; returns error count (0 = pass)."""
|
||||
return verify_module(self.Pool, mod, result)
|
||||
+69
-69
@@ -23,7 +23,7 @@ from .__function import (
|
||||
# and linkage; strong-typed Next via GSListNode[GlobalVariable].
|
||||
novirtual class GlobalVariable(GSListNode[GlobalVariable]):
|
||||
Name: str # Global name (e.g. ".str" / "my_global")
|
||||
Ty: rawptr[LLVMType] # Variable type
|
||||
Ty: LLVMType* # Variable type
|
||||
Initializer: rawptr # Initializer Value* (None = no initializer)
|
||||
IsConstant: int # 1=constant, 0=variable
|
||||
Linkage: str # Linkage ("private"/"internal"/"external"/...)
|
||||
@@ -36,7 +36,7 @@ novirtual class GlobalVariable(GSListNode[GlobalVariable]):
|
||||
# strong-typed Next via GSListNode[NamedTypeNode].
|
||||
@t.NoVTable
|
||||
class NamedTypeNode(GSListNode[NamedTypeNode]):
|
||||
Ty: rawptr[LLVMType] # Named-struct type pointer
|
||||
Ty: LLVMType* # Named-struct type pointer
|
||||
IsPacked: int # 1 = packed struct (MLIR !llvm.struct<"name", packed (…)>; no field padding)
|
||||
|
||||
|
||||
@@ -61,22 +61,22 @@ class DINamedMeta(GSListNode[DINamedMeta]):
|
||||
@t.NoVTable
|
||||
class LLVMModule:
|
||||
Name: str # Module name
|
||||
FuncHead: rawptr[Function] # Function list head
|
||||
FuncTail: rawptr[Function] # Function list tail
|
||||
FuncHead: Function* # Function list head
|
||||
FuncTail: Function* # Function list tail
|
||||
FuncCount: sizet # Function count
|
||||
GlobalHead: rawptr[GlobalVariable] # Global list head
|
||||
GlobalTail: rawptr[GlobalVariable] # Global list tail
|
||||
GlobalHead: GlobalVariable* # Global list head
|
||||
GlobalTail: GlobalVariable* # Global list tail
|
||||
GlobalCount: sizet # Global count
|
||||
TargetTriple: str # Target triple (e.g. "x86_64-pc-linux-gnu")
|
||||
DataLayout: str # Data layout (e.g. "e-m:e-p270:32:32-...")
|
||||
NamedTypeHead: rawptr[NamedTypeNode] # Named-struct type list head
|
||||
NamedTypeTail: rawptr[NamedTypeNode] # Named-struct type list tail
|
||||
NamedTypeHead: NamedTypeNode* # Named-struct type list head
|
||||
NamedTypeTail: NamedTypeNode* # Named-struct type list tail
|
||||
NamedTypeCount: sizet # Named-struct type count
|
||||
DIMetaHead: rawptr[DINode] # DI metadata node list head (kept in sync; not printed by MLIR)
|
||||
DIMetaTail: rawptr[DINode] # DI metadata node list tail
|
||||
DIMetaHead: DINode* # DI metadata node list head (kept in sync; not printed by MLIR)
|
||||
DIMetaTail: DINode* # DI metadata node list tail
|
||||
DIMetaCount: sizet # DI node count (= next !N id)
|
||||
DINamedHead: rawptr[DINamedMeta] # named metadata list head
|
||||
DINamedTail: rawptr[DINamedMeta] # named metadata list tail
|
||||
DINamedHead: DINamedMeta* # named metadata list head
|
||||
DINamedTail: DINamedMeta* # named metadata list tail
|
||||
DINamedCount: sizet # named metadata count
|
||||
# Total: 18 fields * 8 = 144 bytes (no vtable; same layout as includes/llvmlite)
|
||||
|
||||
@@ -84,7 +84,7 @@ class LLVMModule:
|
||||
# kept as one-line delegates).
|
||||
|
||||
# ---- List operations ----
|
||||
def add_function(self, func: rawptr[Function]):
|
||||
def add_function(self, func: Function*):
|
||||
"""Append a function to the module's function list (O(1))."""
|
||||
if self is None or func is None: return
|
||||
func.Next = None
|
||||
@@ -95,7 +95,7 @@ class LLVMModule:
|
||||
self.FuncTail = func
|
||||
self.FuncCount += 1
|
||||
|
||||
def add_global(self, gv: rawptr[GlobalVariable]):
|
||||
def add_global(self, gv: GlobalVariable*):
|
||||
"""Append a global to the module's global list (O(1))."""
|
||||
if self is None or gv is None: return
|
||||
gv.Next = None
|
||||
@@ -127,7 +127,7 @@ class LLVMModule:
|
||||
"""
|
||||
if self is None or pool is None or text is None:
|
||||
return -1
|
||||
node: rawptr[DINode] = pool.alloc(DI_NODE_SIZE)
|
||||
node: DINode* = pool.alloc(DI_NODE_SIZE)
|
||||
if node is None:
|
||||
return -1
|
||||
string.memset(node, 0, DI_NODE_SIZE)
|
||||
@@ -155,7 +155,7 @@ class LLVMModule:
|
||||
"""
|
||||
if self is None or pool is None or name is None:
|
||||
return
|
||||
cur: rawptr[DINamedMeta] = self.DINamedHead
|
||||
cur: DINamedMeta* = self.DINamedHead
|
||||
cur_steps: sizet = 0
|
||||
while cur is not None:
|
||||
cur_steps += 1
|
||||
@@ -178,7 +178,7 @@ class LLVMModule:
|
||||
cur.Refs = merged
|
||||
return
|
||||
cur = cur.Next
|
||||
entry: rawptr[DINamedMeta] = pool.alloc(DI_NAMED_SIZE)
|
||||
entry: DINamedMeta* = pool.alloc(DI_NAMED_SIZE)
|
||||
if entry is None:
|
||||
return
|
||||
string.memset(entry, 0, DI_NAMED_SIZE)
|
||||
@@ -201,7 +201,7 @@ class LLVMModule:
|
||||
self.DINamedCount += 1
|
||||
|
||||
# ---- Named-struct type management ----
|
||||
def add_named_type(self, pool: memhub.MemBuddy*, ty: rawptr[LLVMType]):
|
||||
def add_named_type(self, pool: memhub.MemBuddy*, ty: LLVMType*):
|
||||
"""Register a named struct type in the module (MLIR keeps the model only, no output).
|
||||
|
||||
Non-named structs (None Name or non-Struct) are ignored. Dedup by Name; a full definition
|
||||
@@ -215,7 +215,7 @@ class LLVMModule:
|
||||
if name is None:
|
||||
return
|
||||
# Dedup check (a full definition may replace an opaque declaration)
|
||||
cur: rawptr[NamedTypeNode] = self.NamedTypeHead
|
||||
cur: NamedTypeNode* = self.NamedTypeHead
|
||||
cnt_dedup: int = 0
|
||||
while cur is not None:
|
||||
# Step guard: a cyclic NamedTypeHead list (corruption/insert bug) would hang the
|
||||
@@ -241,7 +241,7 @@ class LLVMModule:
|
||||
return
|
||||
cur = cur.Next
|
||||
# Create a new node
|
||||
node: rawptr[NamedTypeNode] = pool.alloc(NAMED_TYPE_NODE_SIZE)
|
||||
node: NamedTypeNode* = pool.alloc(NAMED_TYPE_NODE_SIZE)
|
||||
if node is None:
|
||||
return
|
||||
string.memset(node, 0, NAMED_TYPE_NODE_SIZE)
|
||||
@@ -268,7 +268,7 @@ class LLVMModule:
|
||||
"""Return 1 if the module already defines a struct with this name, else 0."""
|
||||
if self is None or name is None:
|
||||
return 0
|
||||
cur: rawptr[NamedTypeNode] = self.NamedTypeHead
|
||||
cur: NamedTypeNode* = self.NamedTypeHead
|
||||
cnt_tdm: int = 0
|
||||
while cur is not None:
|
||||
# Step guard: as above, prevent infinite traversal of a cyclic NamedTypeHead
|
||||
@@ -287,7 +287,7 @@ class LLVMModule:
|
||||
return 0
|
||||
|
||||
def ensure_opaque_for_type(self, pool: memhub.MemBuddy*,
|
||||
ty: rawptr[LLVMType]):
|
||||
ty: LLVMType*):
|
||||
"""Add opaque declarations for cross-module struct references in a type.
|
||||
|
||||
When the type references Ptr(Struct(name)) with a '.' in name (SHA1-qualified) and the
|
||||
@@ -343,7 +343,7 @@ class LLVMModule:
|
||||
|
||||
# Globals (MLIR has no standalone type-definition line: named structs are inlined at the
|
||||
# use site, so NamedTypeHead definitions are not emitted here, only registered for lookup).
|
||||
gv: rawptr[GlobalVariable] = self.GlobalHead
|
||||
gv: GlobalVariable* = self.GlobalHead
|
||||
gv_steps: sizet = 0
|
||||
while gv is not None:
|
||||
gv_steps += 1
|
||||
@@ -365,7 +365,7 @@ class LLVMModule:
|
||||
gv = gv.Next
|
||||
|
||||
# Walk functions (filter declare/define by mode)
|
||||
func: rawptr[Function] = self.FuncHead
|
||||
func: Function* = self.FuncHead
|
||||
func_steps: sizet = 0
|
||||
while func is not None:
|
||||
func_steps += 1
|
||||
@@ -397,7 +397,7 @@ class LLVMModule:
|
||||
# Name-only type text (%"sha1.Cls") must expand to the inline named body, so this publishes a
|
||||
# name → full-definition lookup (opaque entries too, so they report "still opaque", not
|
||||
# "unregistered") plus each node's packed flag (NamedTypeNode.IsPacked) for the render side.
|
||||
def _MlirPublishNamedTypes(mod: rawptr[LLVMModule], pool: memhub.MemBuddy*):
|
||||
def _MlirPublishNamedTypes(mod: LLVMModule*, pool: memhub.MemBuddy*):
|
||||
"""Rebuild the named-struct registry from NamedTypeHead (print-time lookup, incl. packed).
|
||||
|
||||
Count the real list length first (not trusting NamedTypeCount), then allocate exactly that
|
||||
@@ -407,7 +407,7 @@ def _MlirPublishNamedTypes(mod: rawptr[LLVMModule], pool: memhub.MemBuddy*):
|
||||
if mod is None or pool is None:
|
||||
return
|
||||
cnt: sizet = 0
|
||||
nt: rawptr[NamedTypeNode] = mod.NamedTypeHead
|
||||
nt: NamedTypeNode* = mod.NamedTypeHead
|
||||
nt_steps: sizet = 0
|
||||
while nt is not None:
|
||||
nt_steps += 1
|
||||
@@ -434,11 +434,11 @@ def _MlirPublishNamedTypes(mod: rawptr[LLVMModule], pool: memhub.MemBuddy*):
|
||||
|
||||
|
||||
# Factory functions
|
||||
def new_module(pool: memhub.MemBuddy*, name: str) -> rawptr[LLVMModule]:
|
||||
def new_module(pool: memhub.MemBuddy*, name: str) -> LLVMModule*:
|
||||
"""Create a module."""
|
||||
# Hardcoded 144 bytes: 18 fields * 8 bytes (no vtable, @t.NoVTable), incl. the DI fields
|
||||
# (DIMetaHead/Tail/Count, DINamedHead/Tail/Count), same layout as llvmlite.
|
||||
ptr: rawptr[LLVMModule] = pool.alloc(144)
|
||||
ptr: LLVMModule* = pool.alloc(144)
|
||||
if ptr is None: return None
|
||||
string.memset(ptr, 0, 144)
|
||||
ptr.Name = name
|
||||
@@ -475,9 +475,9 @@ define DI_NODE_SIZE = 16
|
||||
define DI_NAMED_SIZE = 24
|
||||
|
||||
def new_global_variable(pool: memhub.MemBuddy*,
|
||||
name: str, ty: rawptr[LLVMType]) -> rawptr[GlobalVariable]:
|
||||
name: str, ty: LLVMType*) -> GlobalVariable*:
|
||||
"""Create a global variable."""
|
||||
ptr: rawptr[GlobalVariable] = pool.alloc(GV_SIZE)
|
||||
ptr: GlobalVariable* = pool.alloc(GV_SIZE)
|
||||
if ptr is None: return None
|
||||
string.memset(ptr, 0, GV_SIZE)
|
||||
ptr.Name = name
|
||||
@@ -492,37 +492,37 @@ def new_global_variable(pool: memhub.MemBuddy*,
|
||||
|
||||
|
||||
# List operations (embedded Head/Tail/Count, O(1) append)
|
||||
def module_add_function(mod: rawptr[LLVMModule], func: rawptr[Function]):
|
||||
def module_add_function(mod: LLVMModule*, func: Function*):
|
||||
mod.add_function(func)
|
||||
|
||||
|
||||
def module_get_func_head(mod: rawptr[LLVMModule]) -> rawptr[Function]:
|
||||
def module_get_func_head(mod: LLVMModule*) -> Function*:
|
||||
"""Return the module's function list head (cross-module accessor bypassing the stub-field trap)."""
|
||||
if mod is None:
|
||||
return None
|
||||
return mod.FuncHead
|
||||
|
||||
|
||||
def module_add_global(mod: rawptr[LLVMModule], gv: rawptr[GlobalVariable]):
|
||||
def module_add_global(mod: LLVMModule*, gv: GlobalVariable*):
|
||||
mod.add_global(gv)
|
||||
|
||||
|
||||
def module_set_target(mod: rawptr[LLVMModule], triple: str):
|
||||
def module_set_target(mod: LLVMModule*, triple: str):
|
||||
mod.set_target(triple)
|
||||
|
||||
|
||||
def module_set_datalayout(mod: rawptr[LLVMModule], layout: str):
|
||||
def module_set_datalayout(mod: LLVMModule*, layout: str):
|
||||
mod.set_datalayout(layout)
|
||||
|
||||
|
||||
# DI debug metadata (kept in sync; ignored at MLIR print time, model only)
|
||||
def module_add_di_node(mod: rawptr[LLVMModule], pool: memhub.MemBuddy*,
|
||||
def module_add_di_node(mod: LLVMModule*, pool: memhub.MemBuddy*,
|
||||
text: str) -> int:
|
||||
"""Append a DI metadata node; return its !N id (-1 on failure)."""
|
||||
return mod.add_di_node(pool, text)
|
||||
|
||||
|
||||
def module_add_named_metadata(mod: rawptr[LLVMModule], pool: memhub.MemBuddy*,
|
||||
def module_add_named_metadata(mod: LLVMModule*, pool: memhub.MemBuddy*,
|
||||
name: str, refs: str):
|
||||
"""Register named metadata "!<name> = !{ <refs> }"."""
|
||||
mod.add_named_metadata(pool, name, refs)
|
||||
@@ -535,7 +535,7 @@ def module_add_named_metadata(mod: rawptr[LLVMModule], pool: memhub.MemBuddy*,
|
||||
# name only), created by Struct(pool, None, -1, name). Must be distinguished from an empty struct
|
||||
# (fcount==0, fields==None), which is a valid full definition ({} type, allocatable).
|
||||
# Returns: 1 = opaque / 0 = not.
|
||||
def _is_opaque_struct(ty: rawptr[LLVMType]) -> int:
|
||||
def _is_opaque_struct(ty: LLVMType*) -> int:
|
||||
"""Return 1 if the type is an opaque struct, else 0.
|
||||
|
||||
opaque is a cross-module forward declaration (name only) created by
|
||||
@@ -555,13 +555,13 @@ def _is_opaque_struct(ty: rawptr[LLVMType]) -> int:
|
||||
return 0
|
||||
|
||||
|
||||
def module_add_named_type(mod: rawptr[LLVMModule], pool: memhub.MemBuddy*,
|
||||
ty: rawptr[LLVMType]):
|
||||
def module_add_named_type(mod: LLVMModule*, pool: memhub.MemBuddy*,
|
||||
ty: LLVMType*):
|
||||
mod.add_named_type(pool, ty)
|
||||
|
||||
|
||||
def module_set_named_type_packed(mod: rawptr[LLVMModule], pool: memhub.MemBuddy*,
|
||||
ty: rawptr[LLVMType], is_packed: int):
|
||||
def module_set_named_type_packed(mod: LLVMModule*, pool: memhub.MemBuddy*,
|
||||
ty: LLVMType*, is_packed: int):
|
||||
"""Set a named struct's packed flag by name (MLIR emits !llvm.struct<"name", packed (…)>).
|
||||
|
||||
Called after parsing @c.Attribute(t.attr.packed) so llc computes field offsets/GEP with the
|
||||
@@ -575,7 +575,7 @@ def module_set_named_type_packed(mod: rawptr[LLVMModule], pool: memhub.MemBuddy*
|
||||
name: str = get_struct_name(ty)
|
||||
if name is None:
|
||||
return
|
||||
cur: rawptr[NamedTypeNode] = mod.NamedTypeHead
|
||||
cur: NamedTypeNode* = mod.NamedTypeHead
|
||||
cnt_p: int = 0
|
||||
while cur is not None:
|
||||
cnt_p += 1
|
||||
@@ -592,13 +592,13 @@ def module_set_named_type_packed(mod: rawptr[LLVMModule], pool: memhub.MemBuddy*
|
||||
# module_ensure_opaque_for_type - add opaque declarations for cross-module struct references.
|
||||
# Recursively scans the LLVMType tree; for a Ptr(Struct(name)) whose '.'-containing (SHA1-qualified)
|
||||
# name is undefined in the module, adds an opaque declaration, fixing llc "use of undefined type".
|
||||
def _is_type_defined_in_module(mod: rawptr[LLVMModule], name: str) -> int:
|
||||
def _is_type_defined_in_module(mod: LLVMModule*, name: str) -> int:
|
||||
return mod._is_type_defined_in_module(name)
|
||||
|
||||
|
||||
def _scan_type_for_cross_module_refs(pool: memhub.MemBuddy*,
|
||||
mod: rawptr[LLVMModule],
|
||||
ty: rawptr[LLVMType],
|
||||
mod: LLVMModule*,
|
||||
ty: LLVMType*,
|
||||
depth: int = 0):
|
||||
"""Recursively scan the type tree and add opaque declarations for cross-module struct refs."""
|
||||
if ty is None or mod is None or pool is None:
|
||||
@@ -620,13 +620,13 @@ def _scan_type_for_cross_module_refs(pool: memhub.MemBuddy*,
|
||||
# Create an opaque type and add it to the module; fcount=-1 marks
|
||||
# opaque (vs. empty {} struct, whose fcount==0 is a valid
|
||||
# full definition and can be alloc'd).
|
||||
opaque_ty: rawptr[LLVMType] = Struct(pool, None, -1, sname)
|
||||
opaque_ty: LLVMType* = Struct(pool, None, -1, sname)
|
||||
if opaque_ty is not None:
|
||||
module_add_named_type(mod, pool, opaque_ty)
|
||||
# Recurse into struct fields for cross-module refs
|
||||
# (e.g. HashTable in TypeRegistry{HashTable*, MemManager*}).
|
||||
if sfields is not None:
|
||||
fld: rawptr[ParamNode] = sfields
|
||||
fld: ParamNode* = sfields
|
||||
fld_steps: sizet = 0
|
||||
while fld is not None:
|
||||
fld_steps += 1
|
||||
@@ -642,7 +642,7 @@ def _scan_type_for_cross_module_refs(pool: memhub.MemBuddy*,
|
||||
case LLVMType.Struct(sfields2, sfcount2, sname2):
|
||||
# Top-level struct (non-pointer): recurse into fields
|
||||
if sfields2 is not None:
|
||||
fld2: rawptr[ParamNode] = sfields2
|
||||
fld2: ParamNode* = sfields2
|
||||
fld2_steps: sizet = 0
|
||||
while fld2 is not None:
|
||||
fld2_steps += 1
|
||||
@@ -660,32 +660,32 @@ def _scan_type_for_cross_module_refs(pool: memhub.MemBuddy*,
|
||||
pass
|
||||
|
||||
|
||||
def module_ensure_opaque_for_type(mod: rawptr[LLVMModule],
|
||||
def module_ensure_opaque_for_type(mod: LLVMModule*,
|
||||
pool: memhub.MemBuddy*,
|
||||
ty: rawptr[LLVMType]):
|
||||
ty: LLVMType*):
|
||||
mod.ensure_opaque_for_type(pool, ty)
|
||||
|
||||
|
||||
# Global variable attribute setters
|
||||
def global_set_constant(gv: rawptr[GlobalVariable], is_const: int):
|
||||
def global_set_constant(gv: GlobalVariable*, is_const: int):
|
||||
"""Set whether the global is a constant."""
|
||||
if gv is None: return
|
||||
gv.IsConstant = is_const
|
||||
|
||||
|
||||
def global_set_linkage(gv: rawptr[GlobalVariable], linkage: str):
|
||||
def global_set_linkage(gv: GlobalVariable*, linkage: str):
|
||||
"""Set the linkage (private/internal/external/...)."""
|
||||
if gv is None: return
|
||||
gv.Linkage = linkage
|
||||
|
||||
|
||||
def global_set_unnamed_addr(gv: rawptr[GlobalVariable], level: int):
|
||||
def global_set_unnamed_addr(gv: GlobalVariable*, level: int):
|
||||
"""Set the unnamed_addr attribute (0=none, 1=unnamed_addr, 2=local_unnamed_addr)."""
|
||||
if gv is None: return
|
||||
gv.UnnamedAddr = level
|
||||
|
||||
|
||||
def global_set_section(gv: rawptr[GlobalVariable], section: str):
|
||||
def global_set_section(gv: GlobalVariable*, section: str):
|
||||
"""Set the section name."""
|
||||
if gv is None: return
|
||||
gv.Section = section
|
||||
@@ -704,7 +704,7 @@ _MlirModOutTrunc: int = 0
|
||||
|
||||
# LLVMModulePrint: serialize the module to .ll text; mode: OUTPUT_FULL / OUTPUT_STUB / OUTPUT_TEXT.
|
||||
def LLVMModulePrint(buf: str, size: sizet,
|
||||
mod: rawptr[LLVMModule], pool: memhub.MemBuddy*,
|
||||
mod: LLVMModule*, pool: memhub.MemBuddy*,
|
||||
mode: int):
|
||||
global _MlirModOutTrunc
|
||||
_MlirModOutTrunc = 0
|
||||
@@ -720,7 +720,7 @@ def LLVMModulePrint(buf: str, size: sizet,
|
||||
# zeroinitializer, struct/vtable, symbol-referencing aggregates, pointer initializers → empty value
|
||||
# parens + initializer region). Any form neither path covers fails loud via MlirFail.
|
||||
def _MlirGlobalLine(buf: str, size: sizet,
|
||||
pool: memhub.MemBuddy*, gv: rawptr[GlobalVariable],
|
||||
pool: memhub.MemBuddy*, gv: GlobalVariable*,
|
||||
stub: int):
|
||||
"""Render one llvm.mlir.global (stub=1 emits the external declaration form)."""
|
||||
if gv is None:
|
||||
@@ -803,7 +803,7 @@ def _MlirGlobalLine(buf: str, size: sizet,
|
||||
|
||||
|
||||
def _MlirGlobalInit(buf: str, size: sizet,
|
||||
pool: memhub.MemBuddy*, gv: rawptr[GlobalVariable]):
|
||||
pool: memhub.MemBuddy*, gv: GlobalVariable*):
|
||||
"""Render a global initializer (MLIR attribute text)."""
|
||||
x: str = gv.Initializer
|
||||
if x is None:
|
||||
@@ -1057,7 +1057,7 @@ def _MlirGvArrayNeedsRegion(x: str) -> int:
|
||||
|
||||
|
||||
def _MlirGlobalInitRegion(buf: str, size: sizet,
|
||||
pool: memhub.MemBuddy*, gv: rawptr[GlobalVariable]):
|
||||
pool: memhub.MemBuddy*, gv: GlobalVariable*):
|
||||
"""Render the initializer region body (lines indented 2 spaces, without the outer braces).
|
||||
|
||||
Each line ends with '\\n'; the caller appends '}' and the module layer re-indents by 2.
|
||||
@@ -1116,7 +1116,7 @@ def _MlirGlobalInitRegion(buf: str, size: sizet,
|
||||
_append_cstr(buf, size, "\n")
|
||||
|
||||
|
||||
def _MlirGvWalk(p: str, ty: rawptr[LLVMType], path: str, depth: int) -> str:
|
||||
def _MlirGvWalk(p: str, ty: LLVMType*, path: str, depth: int) -> str:
|
||||
"""Walk one node of the initializer-tree × type-tree in parallel; returns the new cursor.
|
||||
|
||||
The result SSA name goes to _MlirGvLast (leaf = materialized name; aggregate = last
|
||||
@@ -1230,15 +1230,15 @@ def _MlirGvPathChild(path: str, idx: int, depth: int) -> str:
|
||||
return nb
|
||||
|
||||
|
||||
def _MlirGvWalkStruct(p: str, ty: rawptr[LLVMType], path: str, depth: int) -> str:
|
||||
def _MlirGvWalkStruct(p: str, ty: LLVMType*, path: str, depth: int) -> str:
|
||||
"""Struct initializer { elem, elem, … }: field types come from the type tree's Struct field chain."""
|
||||
fields: rawptr[ParamNode] = None
|
||||
fields: ParamNode* = None
|
||||
match ty:
|
||||
case LLVMType.Struct(sf, sfc, sn):
|
||||
fields = sf
|
||||
case _:
|
||||
MlirFail("MLIR 渲染: 初值为结构体,但全局类型不是结构体")
|
||||
cur: rawptr[ParamNode] = fields
|
||||
cur: ParamNode* = fields
|
||||
p = p + 1
|
||||
idx: int = 0
|
||||
done: int = 0
|
||||
@@ -1256,7 +1256,7 @@ def _MlirGvWalkStruct(p: str, ty: rawptr[LLVMType], path: str, depth: int) -> st
|
||||
elif p[0] == ',':
|
||||
p = p + 1
|
||||
else:
|
||||
fty: rawptr[LLVMType] = None
|
||||
fty: LLVMType* = None
|
||||
if cur is not None:
|
||||
fty = paramnode_get_ty(cur)
|
||||
p = _MlirGvWalk(p, fty, _MlirGvPathChild(path, idx, depth), depth + 1)
|
||||
@@ -1268,9 +1268,9 @@ def _MlirGvWalkStruct(p: str, ty: rawptr[LLVMType], path: str, depth: int) -> st
|
||||
return p
|
||||
|
||||
|
||||
def _MlirGvWalkArray(p: str, ty: rawptr[LLVMType], path: str, depth: int) -> str:
|
||||
def _MlirGvWalkArray(p: str, ty: LLVMType*, path: str, depth: int) -> str:
|
||||
"""Array initializer [ elem, elem, … ]: element type comes from the type tree's Array element type."""
|
||||
elem_ty: rawptr[LLVMType] = None
|
||||
elem_ty: LLVMType* = None
|
||||
match ty:
|
||||
case LLVMType.Array(ae, ac):
|
||||
elem_ty = ae
|
||||
@@ -1326,7 +1326,7 @@ def _MlirGvIsBareValue(p: str) -> int:
|
||||
return 0
|
||||
|
||||
|
||||
def _MlirGvWalkLeaf(p: str, ty: rawptr[LLVMType], path: str, depth: int) -> str:
|
||||
def _MlirGvWalkLeaf(p: str, ty: LLVMType*, path: str, depth: int) -> str:
|
||||
"""Leaf element `<LLVM type> <value>`: the value parses to a symbol ref / null / scalar literal.
|
||||
|
||||
The element MLIR type comes from the type tree (ty), not the text's type token. A top-level
|
||||
@@ -1465,7 +1465,7 @@ def _MlirGvEmitAddressOf(name: str):
|
||||
string.strcpy(_MlirGvLast, ln)
|
||||
|
||||
|
||||
def _MlirGvEmitZero(ty: rawptr[LLVMType]):
|
||||
def _MlirGvEmitZero(ty: LLVMType*):
|
||||
"""Emit a leaf op: %vN = llvm.mlir.zero : <element MLIR type>."""
|
||||
mt: str = _MlirGvTyBuf
|
||||
mt[0] = '\0'
|
||||
@@ -1479,7 +1479,7 @@ def _MlirGvEmitZero(ty: rawptr[LLVMType]):
|
||||
string.strcpy(_MlirGvLast, ln)
|
||||
|
||||
|
||||
def _MlirGvEmitConst(val: str, ty: rawptr[LLVMType]):
|
||||
def _MlirGvEmitConst(val: str, ty: LLVMType*):
|
||||
"""Emit a leaf op: %vN = llvm.mlir.constant(<lit> : <element MLIR type>) : <same type>."""
|
||||
mt: str = _MlirGvTyBuf
|
||||
mt[0] = '\0'
|
||||
|
||||
+95
-95
@@ -24,23 +24,23 @@ class LLVMType(t.REnum):
|
||||
|
||||
# Pointer type: pointee*
|
||||
class Ptr:
|
||||
Pointee: rawptr[LLVMType]
|
||||
Pointee: LLVMType*
|
||||
|
||||
# Function type: ret (params)
|
||||
class Func:
|
||||
Ret: rawptr[LLVMType]
|
||||
Params: rawptr[ParamNode]
|
||||
Ret: LLVMType*
|
||||
Params: ParamNode*
|
||||
PCount: int
|
||||
|
||||
# Array type: [N x elem_ty]
|
||||
class Array:
|
||||
ElemTy: rawptr[LLVMType]
|
||||
ElemTy: LLVMType*
|
||||
Count: int
|
||||
|
||||
# Struct type {ty1, ty2, ...} or %"name" = type {...}; Fields reuse the ParamNode list
|
||||
# (ParamNode.Ty is the field type); a non-None Name makes it named (%"name" output).
|
||||
class Struct:
|
||||
Fields: rawptr[ParamNode]
|
||||
Fields: ParamNode*
|
||||
FCount: int
|
||||
Name: str
|
||||
|
||||
@@ -73,52 +73,52 @@ def _TypeSizeGuard() -> sizet:
|
||||
return sz
|
||||
|
||||
|
||||
def _new_type(pool: memhub.MemBuddy*) -> rawptr[LLVMType]:
|
||||
def _new_type(pool: memhub.MemBuddy*) -> LLVMType*:
|
||||
"""Allocate a zero-initialized LLVMType from the pool."""
|
||||
sz_nt: sizet = _TypeSizeGuard()
|
||||
ptr: rawptr[LLVMType] = pool.alloc(sz_nt)
|
||||
ptr: LLVMType* = pool.alloc(sz_nt)
|
||||
if ptr:
|
||||
string.memset(ptr, 0, sz_nt)
|
||||
return ptr
|
||||
|
||||
|
||||
# Type factory functions
|
||||
def Int1(pool: memhub.MemBuddy*) -> rawptr[LLVMType]:
|
||||
ptr: rawptr[LLVMType] = _new_type(pool)
|
||||
def Int1(pool: memhub.MemBuddy*) -> LLVMType*:
|
||||
ptr: LLVMType* = _new_type(pool)
|
||||
if ptr is None: return None
|
||||
c.DerefAs(ptr, LLVMType.Int(1))
|
||||
return ptr
|
||||
|
||||
|
||||
def Int8(pool: memhub.MemBuddy*) -> rawptr[LLVMType]:
|
||||
ptr: rawptr[LLVMType] = _new_type(pool)
|
||||
def Int8(pool: memhub.MemBuddy*) -> LLVMType*:
|
||||
ptr: LLVMType* = _new_type(pool)
|
||||
if ptr is None: return None
|
||||
c.DerefAs(ptr, LLVMType.Int(8))
|
||||
return ptr
|
||||
|
||||
|
||||
def Int16(pool: memhub.MemBuddy*) -> rawptr[LLVMType]:
|
||||
ptr: rawptr[LLVMType] = _new_type(pool)
|
||||
def Int16(pool: memhub.MemBuddy*) -> LLVMType*:
|
||||
ptr: LLVMType* = _new_type(pool)
|
||||
if ptr is None: return None
|
||||
c.DerefAs(ptr, LLVMType.Int(16))
|
||||
return ptr
|
||||
|
||||
|
||||
def Int32(pool: memhub.MemBuddy*) -> rawptr[LLVMType]:
|
||||
ptr: rawptr[LLVMType] = _new_type(pool)
|
||||
def Int32(pool: memhub.MemBuddy*) -> LLVMType*:
|
||||
ptr: LLVMType* = _new_type(pool)
|
||||
if ptr is None: return None
|
||||
c.DerefAs(ptr, LLVMType.Int(32))
|
||||
return ptr
|
||||
|
||||
|
||||
def Int64(pool: memhub.MemBuddy*) -> rawptr[LLVMType]:
|
||||
ptr: rawptr[LLVMType] = _new_type(pool)
|
||||
def Int64(pool: memhub.MemBuddy*) -> LLVMType*:
|
||||
ptr: LLVMType* = _new_type(pool)
|
||||
if ptr is None: return None
|
||||
c.DerefAs(ptr, LLVMType.Int(64))
|
||||
return ptr
|
||||
|
||||
|
||||
def Ptr(pool: memhub.MemBuddy*, pointee: rawptr[LLVMType]) -> rawptr[LLVMType]:
|
||||
def Ptr(pool: memhub.MemBuddy*, pointee: LLVMType*) -> LLVMType*:
|
||||
"""Create pointer type Ptr(pointee).
|
||||
|
||||
LLVM IR forbids void* pointers ("pointers to void are invalid"): None or
|
||||
@@ -126,7 +126,7 @@ def Ptr(pool: memhub.MemBuddy*, pointee: rawptr[LLVMType]) -> rawptr[LLVMType]:
|
||||
all other types build Ptr(pointee) normally.
|
||||
"""
|
||||
# Pre-check: reject Void / None pointee (void* is illegal).
|
||||
safe_pointee: rawptr[LLVMType] = pointee
|
||||
safe_pointee: LLVMType* = pointee
|
||||
if safe_pointee is None:
|
||||
safe_pointee = Int8(pool)
|
||||
else:
|
||||
@@ -135,84 +135,84 @@ def Ptr(pool: memhub.MemBuddy*, pointee: rawptr[LLVMType]) -> rawptr[LLVMType]:
|
||||
safe_pointee = Int8(pool)
|
||||
case _:
|
||||
pass
|
||||
ptr: rawptr[LLVMType] = _new_type(pool)
|
||||
ptr: LLVMType* = _new_type(pool)
|
||||
if ptr is None: return None
|
||||
c.DerefAs(ptr, LLVMType.Ptr(safe_pointee))
|
||||
return ptr
|
||||
|
||||
|
||||
def Func(pool: memhub.MemBuddy*, ret: rawptr[LLVMType],
|
||||
params: rawptr[ParamNode], count: int) -> rawptr[LLVMType]:
|
||||
ptr: rawptr[LLVMType] = _new_type(pool)
|
||||
def Func(pool: memhub.MemBuddy*, ret: LLVMType*,
|
||||
params: ParamNode*, count: int) -> LLVMType*:
|
||||
ptr: LLVMType* = _new_type(pool)
|
||||
if ptr is None: return None
|
||||
c.DerefAs(ptr, LLVMType.Func(ret, params, count))
|
||||
return ptr
|
||||
|
||||
|
||||
def Void(pool: memhub.MemBuddy*) -> rawptr[LLVMType]:
|
||||
ptr: rawptr[LLVMType] = _new_type(pool)
|
||||
def Void(pool: memhub.MemBuddy*) -> LLVMType*:
|
||||
ptr: LLVMType* = _new_type(pool)
|
||||
if ptr is None: return None
|
||||
c.DerefAs(ptr, LLVMType.Void())
|
||||
return ptr
|
||||
|
||||
|
||||
def Array(pool: memhub.MemBuddy*, elem_ty: rawptr[LLVMType],
|
||||
count: int) -> rawptr[LLVMType]:
|
||||
def Array(pool: memhub.MemBuddy*, elem_ty: LLVMType*,
|
||||
count: int) -> LLVMType*:
|
||||
"""Create array type [count x elem_ty]."""
|
||||
ptr: rawptr[LLVMType] = _new_type(pool)
|
||||
ptr: LLVMType* = _new_type(pool)
|
||||
if ptr is None: return None
|
||||
c.DerefAs(ptr, LLVMType.Array(elem_ty, count))
|
||||
return ptr
|
||||
|
||||
|
||||
def Struct(pool: memhub.MemBuddy*, fields: rawptr[ParamNode],
|
||||
fcount: int, name: str) -> rawptr[LLVMType]:
|
||||
def Struct(pool: memhub.MemBuddy*, fields: ParamNode*,
|
||||
fcount: int, name: str) -> LLVMType*:
|
||||
"""Create struct type {ty1, ty2, ...}.
|
||||
|
||||
fields is the ParamNode list head and fcount the field count; a non-None name
|
||||
(e.g. "sha1.ClassName") yields a named struct printed as %"name", else anonymous.
|
||||
"""
|
||||
ptr: rawptr[LLVMType] = _new_type(pool)
|
||||
ptr: LLVMType* = _new_type(pool)
|
||||
if ptr is None: return None
|
||||
c.DerefAs(ptr, LLVMType.Struct(fields, fcount, name))
|
||||
return ptr
|
||||
|
||||
|
||||
def Half(pool: memhub.MemBuddy*) -> rawptr[LLVMType]:
|
||||
def Half(pool: memhub.MemBuddy*) -> LLVMType*:
|
||||
"""Create half-precision float type half (16-bit)."""
|
||||
ptr: rawptr[LLVMType] = _new_type(pool)
|
||||
ptr: LLVMType* = _new_type(pool)
|
||||
if ptr is None: return None
|
||||
c.DerefAs(ptr, LLVMType.Float(16))
|
||||
return ptr
|
||||
|
||||
|
||||
def Float(pool: memhub.MemBuddy*) -> rawptr[LLVMType]:
|
||||
def Float(pool: memhub.MemBuddy*) -> LLVMType*:
|
||||
"""Create single-precision float type float (32-bit)."""
|
||||
ptr: rawptr[LLVMType] = _new_type(pool)
|
||||
ptr: LLVMType* = _new_type(pool)
|
||||
if ptr is None: return None
|
||||
c.DerefAs(ptr, LLVMType.Float(32))
|
||||
return ptr
|
||||
|
||||
|
||||
def Double(pool: memhub.MemBuddy*) -> rawptr[LLVMType]:
|
||||
def Double(pool: memhub.MemBuddy*) -> LLVMType*:
|
||||
"""Create double-precision float type double (64-bit)."""
|
||||
ptr: rawptr[LLVMType] = _new_type(pool)
|
||||
ptr: LLVMType* = _new_type(pool)
|
||||
if ptr is None: return None
|
||||
c.DerefAs(ptr, LLVMType.Float(64))
|
||||
return ptr
|
||||
|
||||
|
||||
def FP128(pool: memhub.MemBuddy*) -> rawptr[LLVMType]:
|
||||
def FP128(pool: memhub.MemBuddy*) -> LLVMType*:
|
||||
"""Create quad-precision float type fp128 (128-bit)."""
|
||||
ptr: rawptr[LLVMType] = _new_type(pool)
|
||||
ptr: LLVMType* = _new_type(pool)
|
||||
if ptr is None: return None
|
||||
c.DerefAs(ptr, LLVMType.Float(128))
|
||||
return ptr
|
||||
|
||||
|
||||
def Label(pool: memhub.MemBuddy*) -> rawptr[LLVMType]:
|
||||
def Label(pool: memhub.MemBuddy*) -> LLVMType*:
|
||||
"""Create label type label."""
|
||||
ptr: rawptr[LLVMType] = _new_type(pool)
|
||||
ptr: LLVMType* = _new_type(pool)
|
||||
if ptr is None: return None
|
||||
c.DerefAs(ptr, LLVMType.Label())
|
||||
return ptr
|
||||
@@ -222,9 +222,9 @@ def Label(pool: memhub.MemBuddy*) -> rawptr[LLVMType]:
|
||||
# ParamNode hardcoded size: Next(8) + Ty(8) = 16 bytes
|
||||
define PNODE_SIZE = 16
|
||||
|
||||
def new_param_node(pool: memhub.MemBuddy*, ty: rawptr[LLVMType]) -> rawptr[ParamNode]:
|
||||
def new_param_node(pool: memhub.MemBuddy*, ty: LLVMType*) -> ParamNode*:
|
||||
"""Create a parameter node with Ty set to the given type pointer."""
|
||||
ptr: rawptr[ParamNode] = pool.alloc(PNODE_SIZE)
|
||||
ptr: ParamNode* = pool.alloc(PNODE_SIZE)
|
||||
if ptr is None: return None
|
||||
string.memset(ptr, 0, PNODE_SIZE)
|
||||
ptr.Ty = ty
|
||||
@@ -232,8 +232,8 @@ def new_param_node(pool: memhub.MemBuddy*, ty: rawptr[LLVMType]) -> rawptr[Param
|
||||
return ptr
|
||||
|
||||
|
||||
def param_list_append(head: rawptr[ParamNode], tail: rawptr[ParamNode],
|
||||
node: rawptr[ParamNode]) -> rawptr[ParamNode]:
|
||||
def param_list_append(head: ParamNode*, tail: ParamNode*,
|
||||
node: ParamNode*) -> ParamNode*:
|
||||
"""Append node to the parameter list tail, returning head and updated tail."""
|
||||
if node is None: return head
|
||||
node.Next = None
|
||||
@@ -246,28 +246,28 @@ def param_list_append(head: rawptr[ParamNode], tail: rawptr[ParamNode],
|
||||
|
||||
# ParamNode field accessors (bypass the stub-type limitation): cross-module consumers
|
||||
# only have the stub type, so field access is skipped; these run where the type is full.
|
||||
def paramnode_get_ty(node: rawptr[ParamNode]) -> rawptr[LLVMType]:
|
||||
def paramnode_get_ty(node: ParamNode*) -> LLVMType*:
|
||||
"""Return the parameter node's type."""
|
||||
if node is None:
|
||||
return None
|
||||
return (rawptr[LLVMType])(node.Ty)
|
||||
return (LLVMType*)(node.Ty)
|
||||
|
||||
|
||||
def paramnode_get_next(node: rawptr[ParamNode]) -> rawptr[ParamNode]:
|
||||
def paramnode_get_next(node: ParamNode*) -> ParamNode*:
|
||||
"""Return the next parameter node in the list."""
|
||||
if node is None:
|
||||
return None
|
||||
return node.Next
|
||||
|
||||
|
||||
def paramnode_set_ty(node: rawptr[ParamNode], ty: rawptr[LLVMType]):
|
||||
def paramnode_set_ty(node: ParamNode*, ty: LLVMType*):
|
||||
"""Set the parameter node's type."""
|
||||
if node is None:
|
||||
return
|
||||
node.Ty = ty
|
||||
|
||||
|
||||
def paramnode_set_next(node: rawptr[ParamNode], nxt: rawptr[ParamNode]):
|
||||
def paramnode_set_next(node: ParamNode*, nxt: ParamNode*):
|
||||
"""Set the next parameter node in the list."""
|
||||
if node is None:
|
||||
return
|
||||
@@ -284,64 +284,64 @@ class LLVMTypeCore:
|
||||
def __init__(self, pool: memhub.MemBuddy*):
|
||||
self.Pool = pool
|
||||
|
||||
def Int1(self) -> rawptr[LLVMType]:
|
||||
def Int1(self) -> LLVMType*:
|
||||
return Int1(self.Pool)
|
||||
|
||||
def Int8(self) -> rawptr[LLVMType]:
|
||||
def Int8(self) -> LLVMType*:
|
||||
return Int8(self.Pool)
|
||||
|
||||
def Int16(self) -> rawptr[LLVMType]:
|
||||
def Int16(self) -> LLVMType*:
|
||||
return Int16(self.Pool)
|
||||
|
||||
def Int32(self) -> rawptr[LLVMType]:
|
||||
def Int32(self) -> LLVMType*:
|
||||
return Int32(self.Pool)
|
||||
|
||||
def Int64(self) -> rawptr[LLVMType]:
|
||||
def Int64(self) -> LLVMType*:
|
||||
return Int64(self.Pool)
|
||||
|
||||
def Ptr(self, pointee: rawptr[LLVMType]) -> rawptr[LLVMType]:
|
||||
def Ptr(self, pointee: LLVMType*) -> LLVMType*:
|
||||
return Ptr(self.Pool, pointee)
|
||||
|
||||
def Func(self, ret: rawptr[LLVMType], params: rawptr[ParamNode],
|
||||
count: int) -> rawptr[LLVMType]:
|
||||
def Func(self, ret: LLVMType*, params: ParamNode*,
|
||||
count: int) -> LLVMType*:
|
||||
return Func(self.Pool, ret, params, count)
|
||||
|
||||
def Array(self, elem_ty: rawptr[LLVMType], count: int) -> rawptr[LLVMType]:
|
||||
def Array(self, elem_ty: LLVMType*, count: int) -> LLVMType*:
|
||||
return Array(self.Pool, elem_ty, count)
|
||||
|
||||
def Struct(self, fields: rawptr[ParamNode], fcount: int,
|
||||
name: str = None) -> rawptr[LLVMType]:
|
||||
def Struct(self, fields: ParamNode*, fcount: int,
|
||||
name: str = None) -> LLVMType*:
|
||||
return Struct(self.Pool, fields, fcount, name)
|
||||
|
||||
def Void(self) -> rawptr[LLVMType]:
|
||||
def Void(self) -> LLVMType*:
|
||||
return Void(self.Pool)
|
||||
|
||||
def Half(self) -> rawptr[LLVMType]:
|
||||
def Half(self) -> LLVMType*:
|
||||
return Half(self.Pool)
|
||||
|
||||
def Float(self) -> rawptr[LLVMType]:
|
||||
def Float(self) -> LLVMType*:
|
||||
return Float(self.Pool)
|
||||
|
||||
def Double(self) -> rawptr[LLVMType]:
|
||||
def Double(self) -> LLVMType*:
|
||||
return Double(self.Pool)
|
||||
|
||||
def FP128(self) -> rawptr[LLVMType]:
|
||||
def FP128(self) -> LLVMType*:
|
||||
return FP128(self.Pool)
|
||||
|
||||
def Label(self) -> rawptr[LLVMType]:
|
||||
def Label(self) -> LLVMType*:
|
||||
return Label(self.Pool)
|
||||
|
||||
def NewParamNode(self, ty: rawptr[LLVMType]) -> rawptr[ParamNode]:
|
||||
def NewParamNode(self, ty: LLVMType*) -> ParamNode*:
|
||||
return new_param_node(self.Pool, ty)
|
||||
|
||||
# ---- List helpers ----
|
||||
def ParamListAppend(self, head: rawptr[ParamNode], tail: rawptr[ParamNode],
|
||||
node: rawptr[ParamNode]) -> rawptr[ParamNode]:
|
||||
def ParamListAppend(self, head: ParamNode*, tail: ParamNode*,
|
||||
node: ParamNode*) -> ParamNode*:
|
||||
"""Append node to the parameter/field list, returning the new tail."""
|
||||
return param_list_append(head, tail, node)
|
||||
|
||||
# ---- Printing ----
|
||||
def PrintType(self, buf: str, size: sizet, ty: rawptr[LLVMType]):
|
||||
def PrintType(self, buf: str, size: sizet, ty: LLVMType*):
|
||||
TypePrint(buf, size, ty, self.Pool)
|
||||
|
||||
|
||||
@@ -418,7 +418,7 @@ def MlirNamedTypesClear():
|
||||
_MlirNamedCap = 0
|
||||
|
||||
|
||||
def MlirNamedTypeRegister(ty: rawptr[LLVMType], is_packed: int):
|
||||
def MlirNamedTypeRegister(ty: LLVMType*, is_packed: int):
|
||||
"""Register a named struct type and its packed flag (same name: full def replaces opaque).
|
||||
|
||||
Dedup matches module_add_named_type; non-named structs are ignored; overflow stops
|
||||
@@ -434,7 +434,7 @@ def MlirNamedTypeRegister(ty: rawptr[LLVMType], is_packed: int):
|
||||
fcount: int = get_struct_fcount(ty)
|
||||
for i in range(_MlirNamedCount):
|
||||
slot: sizet* = _MlirNamedSlot(i)
|
||||
ex: rawptr[LLVMType] = (rawptr[LLVMType])(slot[0])
|
||||
ex: LLVMType* = (LLVMType*)(slot[0])
|
||||
ex_name: str = get_struct_name(ex)
|
||||
if ex_name is not None and string.strcmp(ex_name, name) == 0:
|
||||
if fcount < 0 and get_struct_fcount(ex) >= 0:
|
||||
@@ -456,7 +456,7 @@ def _MlirNamedFindSlot(name: str) -> int:
|
||||
return -1
|
||||
for i in range(_MlirNamedCount):
|
||||
slot: sizet* = _MlirNamedSlot(i)
|
||||
ty: rawptr[LLVMType] = (rawptr[LLVMType])(slot[0])
|
||||
ty: LLVMType* = (LLVMType*)(slot[0])
|
||||
nm: str = get_struct_name(ty)
|
||||
if nm is not None and string.strcmp(nm, name) == 0:
|
||||
return i
|
||||
@@ -517,7 +517,7 @@ def _MlirNamedCheckName(pool: memhub.MemBuddy*, name: str):
|
||||
|
||||
|
||||
def _MlirNamedStructAppend(dst: str, dstsz: sizet, name: str,
|
||||
fields: rawptr[ParamNode], fcount: int, packed: int,
|
||||
fields: ParamNode*, fcount: int, packed: int,
|
||||
pool: memhub.MemBuddy*, depth: int):
|
||||
"""Append MLIR named-struct type text to dst.
|
||||
|
||||
@@ -542,7 +542,7 @@ def _MlirNamedStructAppend(dst: str, dstsz: sizet, name: str,
|
||||
if packed != 0:
|
||||
_strappend(dst, dstsz, "packed ")
|
||||
_strappend(dst, dstsz, "(")
|
||||
cur: rawptr[ParamNode] = fields
|
||||
cur: ParamNode* = fields
|
||||
first: int = 1
|
||||
fidx: int = 0
|
||||
tmp: str = pool.alloc(4096)
|
||||
@@ -578,7 +578,7 @@ def _MlirNamedBodyFromTable(dst: str, dstsz: sizet, name: str,
|
||||
if si < 0:
|
||||
return 0
|
||||
slot: sizet* = _MlirNamedSlot(si)
|
||||
sty: rawptr[LLVMType] = (rawptr[LLVMType])(slot[0])
|
||||
sty: LLVMType* = (LLVMType*)(slot[0])
|
||||
spk: int = int(slot[1])
|
||||
match sty:
|
||||
case LLVMType.Struct(sf, sc, _):
|
||||
@@ -593,7 +593,7 @@ def _MlirNamedBodyFromTable(dst: str, dstsz: sizet, name: str,
|
||||
# Func→!llvm.func<ret (p0, p1)>, Void→none (omitted at return position); Label/Metadata fail loud.
|
||||
# Embedded types already arrive as MLIR text; pool allocates temp buffers for subtypes.
|
||||
def TypePrint(buf: str, size: sizet,
|
||||
ty: rawptr[LLVMType], pool: memhub.MemBuddy*):
|
||||
ty: LLVMType*, pool: memhub.MemBuddy*):
|
||||
"""Serialize type ty as MLIR type text into buf (capacity size).
|
||||
|
||||
pool allocates temp buffers for subtypes; overflow (text exceeds size) fails loud, since
|
||||
@@ -919,7 +919,7 @@ def _MlirNamedStructText(dst: str, dstsz: sizet, p: str, lt: sizet,
|
||||
"MLIR 渲染: 命名结构体类型文本未在模块中登记完整定义(MLIR 不允许无体前向声明,须以 !llvm.struct<\"name\", (…)> 内联形态使用)",
|
||||
nm)
|
||||
slot: sizet* = _MlirNamedSlot(si)
|
||||
ty: rawptr[LLVMType] = (rawptr[LLVMType])(slot[0])
|
||||
ty: LLVMType* = (LLVMType*)(slot[0])
|
||||
packed: int = int(slot[1])
|
||||
match ty:
|
||||
case LLVMType.Struct(fields, fcount, _):
|
||||
@@ -1008,7 +1008,7 @@ def _MlirFuncText(dst: str, dstsz: sizet, p: str, lt: sizet, fp: sizet,
|
||||
define TYPEPRINT_MAX_DEPTH = 100
|
||||
|
||||
def _MlirTypePrintDepth(buf: str, size: sizet,
|
||||
ty: rawptr[LLVMType], pool: memhub.MemBuddy*,
|
||||
ty: LLVMType*, pool: memhub.MemBuddy*,
|
||||
depth: int):
|
||||
"""Internal MLIR type printer with a recursion depth cap (overwrite-writes buf)."""
|
||||
if ty is None or buf is None or size == 0:
|
||||
@@ -1070,7 +1070,7 @@ def _MlirTypePrintDepth(buf: str, size: sizet,
|
||||
_MlirTypePrintDepth(rfb, 4096, ret, pool, depth + 1)
|
||||
_strappend(buf, size, rfb)
|
||||
_strappend(buf, size, " (")
|
||||
cur2: rawptr[ParamNode] = params
|
||||
cur2: ParamNode* = params
|
||||
first2: int = 1
|
||||
_pc2: int = 0
|
||||
tmp3: str = pool.alloc(4096)
|
||||
@@ -1100,12 +1100,12 @@ def _MlirTypePrintDepth(buf: str, size: sizet,
|
||||
|
||||
|
||||
def _MlirStructFields(buf: str, size: sizet,
|
||||
fields: rawptr[ParamNode], pool: memhub.MemBuddy*,
|
||||
fields: ParamNode*, pool: memhub.MemBuddy*,
|
||||
depth: int):
|
||||
"""Render !llvm.struct<(f0, f1, …)> (overwrite-writes buf)."""
|
||||
buf[0] = '\0'
|
||||
_strappend(buf, size, "!llvm.struct<(")
|
||||
cur: rawptr[ParamNode] = fields
|
||||
cur: ParamNode* = fields
|
||||
first: int = 1
|
||||
fidx: int = 0
|
||||
tmp: str = pool.alloc(4096)
|
||||
@@ -1154,7 +1154,7 @@ def _strappend(dst: str, dst_size: sizet, src: str):
|
||||
# MLIR has no standalone type definition; struct types are inlined at the use site, so this
|
||||
# writes an empty string. The same-name/same-signature API is kept to match llvmlite.
|
||||
def PrintStructDefinition(buf: str, size: sizet,
|
||||
ty: rawptr[LLVMType], pool: memhub.MemBuddy*,
|
||||
ty: LLVMType*, pool: memhub.MemBuddy*,
|
||||
packed: int = 0):
|
||||
"""No type definition line on the MLIR side: write an empty string (API kept in sync)."""
|
||||
if buf is None or size == 0:
|
||||
@@ -1164,7 +1164,7 @@ def PrintStructDefinition(buf: str, size: sizet,
|
||||
|
||||
# get_struct_name - returns the named struct's Name (e.g. "sha1.ClassName"), or None for a
|
||||
# non-Struct / anonymous Struct; used by module_add_named_type to detect named structs and dedup.
|
||||
def get_struct_name(ty: rawptr[LLVMType]) -> str:
|
||||
def get_struct_name(ty: LLVMType*) -> str:
|
||||
"""Return the named struct's name, or None if not a named struct."""
|
||||
if ty is None:
|
||||
return None
|
||||
@@ -1175,7 +1175,7 @@ def get_struct_name(ty: rawptr[LLVMType]) -> str:
|
||||
return None
|
||||
|
||||
|
||||
def get_struct_fields(ty: rawptr[LLVMType]) -> rawptr[ParamNode]:
|
||||
def get_struct_fields(ty: LLVMType*) -> ParamNode*:
|
||||
"""Return the struct's field list (used to rebuild Struct types across modules)."""
|
||||
if ty is None:
|
||||
return None
|
||||
@@ -1186,7 +1186,7 @@ def get_struct_fields(ty: rawptr[LLVMType]) -> rawptr[ParamNode]:
|
||||
return None
|
||||
|
||||
|
||||
def get_struct_fcount(ty: rawptr[LLVMType]) -> int:
|
||||
def get_struct_fcount(ty: LLVMType*) -> int:
|
||||
"""Return the struct's field count (used to rebuild Struct types across modules)."""
|
||||
if ty is None:
|
||||
return 0
|
||||
@@ -1204,13 +1204,13 @@ def get_struct_fcount(ty: rawptr[LLVMType]) -> int:
|
||||
define DEEPCOPY_MAX_DEPTH = 64
|
||||
|
||||
def DeepCopyType(pool: memhub.MemBuddy*,
|
||||
ty: rawptr[LLVMType]) -> rawptr[LLVMType]:
|
||||
ty: LLVMType*) -> LLVMType*:
|
||||
"""Deep-copy LLVMType to the permanent pool (depth-limited against self-recursion); None on failure."""
|
||||
return _DeepCopyDepth(pool, ty, 0)
|
||||
|
||||
|
||||
def _DeepCopyDepth(pool: memhub.MemBuddy*,
|
||||
ty: rawptr[LLVMType], depth: int) -> rawptr[LLVMType]:
|
||||
ty: LLVMType*, depth: int) -> LLVMType*:
|
||||
"""Deep-copy implementation with a depth cap.
|
||||
|
||||
The passed pool decides the lifetime: the main pool gives a transient copy (reclaimed by
|
||||
@@ -1219,7 +1219,7 @@ def _DeepCopyDepth(pool: memhub.MemBuddy*,
|
||||
if ty is None:
|
||||
return None
|
||||
sz_dc: sizet = _TypeSizeGuard()
|
||||
new_ty: rawptr[LLVMType] = (rawptr[LLVMType])(pool.alloc(sz_dc))
|
||||
new_ty: LLVMType* = (LLVMType*)(pool.alloc(sz_dc))
|
||||
if new_ty is None:
|
||||
return None
|
||||
string.memset(new_ty, 0, sz_dc)
|
||||
@@ -1271,19 +1271,19 @@ def _DeepCopyDepth(pool: memhub.MemBuddy*,
|
||||
|
||||
|
||||
def _DeepCopyParamChain(pool: memhub.MemBuddy*,
|
||||
head: rawptr[ParamNode], depth: int) -> rawptr[ParamNode]:
|
||||
head: ParamNode*, depth: int) -> ParamNode*:
|
||||
"""Deep-copy the ParamNode chain to the permanent pool."""
|
||||
if head is None:
|
||||
return None
|
||||
first: rawptr[ParamNode] = None
|
||||
prev: rawptr[ParamNode] = None
|
||||
cur: rawptr[ParamNode] = head
|
||||
first: ParamNode* = None
|
||||
prev: ParamNode* = None
|
||||
cur: ParamNode* = head
|
||||
guard: int = 0
|
||||
while cur is not None:
|
||||
guard += 1
|
||||
if guard > 512:
|
||||
break
|
||||
node: rawptr[ParamNode] = (rawptr[ParamNode])(pool.alloc(PNODE_SIZE))
|
||||
node: ParamNode* = (ParamNode*)(pool.alloc(PNODE_SIZE))
|
||||
if node is None:
|
||||
break
|
||||
string.memset(node, 0, PNODE_SIZE)
|
||||
|
||||
+27
-27
@@ -19,7 +19,7 @@ from .__types import LLVMType, TypePrint
|
||||
# ============================================================
|
||||
@t.NoVTable
|
||||
class Value(GSListNode[Value]):
|
||||
Ty: rawptr[LLVMType] # value type
|
||||
Ty: LLVMType* # value type
|
||||
Name: str # SSA name ("%0"/"%result") or constant text ("42"/"1.5e+00")
|
||||
IsConst: int # 1 = constant literal, 0 = SSA temporary
|
||||
IntVal: int64 # integer constant value (used when IsConst=1)
|
||||
@@ -32,20 +32,20 @@ class Value(GSListNode[Value]):
|
||||
# Value hardcoded size: Next(8) + Ty(8) + Name(8) + IsConst(4) + IntVal(8) + FloatVal(8) = 48 bytes
|
||||
define VALUE_SIZE = 48
|
||||
|
||||
def new_value(pool: memhub.MemBuddy*) -> rawptr[Value]:
|
||||
def new_value(pool: memhub.MemBuddy*) -> Value*:
|
||||
"""Allocate a zero-initialized Value from mpool."""
|
||||
ptr: rawptr[Value] = pool.alloc(VALUE_SIZE)
|
||||
ptr: Value* = pool.alloc(VALUE_SIZE)
|
||||
if ptr:
|
||||
string.memset(ptr, 0, VALUE_SIZE)
|
||||
return ptr
|
||||
|
||||
|
||||
def ConstInt(pool: memhub.MemBuddy*, ty: rawptr[LLVMType],
|
||||
val: int64, name: str) -> rawptr[Value]:
|
||||
def ConstInt(pool: memhub.MemBuddy*, ty: LLVMType*,
|
||||
val: int64, name: str) -> Value*:
|
||||
"""Create an integer constant value.
|
||||
ty: integer type (Int1/Int8/Int32/Int64); val: integer value; name: caller-provided constant text (e.g. "42").
|
||||
"""
|
||||
v: rawptr[Value] = new_value(pool)
|
||||
v: Value* = new_value(pool)
|
||||
if v is None: return None
|
||||
v.Ty = ty
|
||||
v.Name = name
|
||||
@@ -54,10 +54,10 @@ def ConstInt(pool: memhub.MemBuddy*, ty: rawptr[LLVMType],
|
||||
return v
|
||||
|
||||
|
||||
def ConstNull(pool: memhub.MemBuddy*, ty: rawptr[LLVMType],
|
||||
name: str) -> rawptr[Value]:
|
||||
def ConstNull(pool: memhub.MemBuddy*, ty: LLVMType*,
|
||||
name: str) -> Value*:
|
||||
"""Create a null pointer constant."""
|
||||
v: rawptr[Value] = new_value(pool)
|
||||
v: Value* = new_value(pool)
|
||||
if v is None: return None
|
||||
v.Ty = ty
|
||||
v.Name = name
|
||||
@@ -66,9 +66,9 @@ def ConstNull(pool: memhub.MemBuddy*, ty: rawptr[LLVMType],
|
||||
return v
|
||||
|
||||
|
||||
def ConstZero(pool: memhub.MemBuddy*, ty: rawptr[LLVMType]) -> rawptr[Value]:
|
||||
def ConstZero(pool: memhub.MemBuddy*, ty: LLVMType*) -> Value*:
|
||||
"""Create a zeroinitializer constant (zero-initialized aggregate: struct/array)."""
|
||||
v: rawptr[Value] = new_value(pool)
|
||||
v: Value* = new_value(pool)
|
||||
if v is None: return None
|
||||
v.Ty = ty
|
||||
v.Name = "zeroinitializer"
|
||||
@@ -77,14 +77,14 @@ def ConstZero(pool: memhub.MemBuddy*, ty: rawptr[LLVMType]) -> rawptr[Value]:
|
||||
return v
|
||||
|
||||
|
||||
def ConstFloat(pool: memhub.MemBuddy*, ty: rawptr[LLVMType],
|
||||
val: double) -> rawptr[Value]:
|
||||
def ConstFloat(pool: memhub.MemBuddy*, ty: LLVMType*,
|
||||
val: double) -> Value*:
|
||||
"""Create a float constant value.
|
||||
|
||||
ty: float type; val: float value. Name is the raw bit pattern (f16 0x%04x, f32 0x%08x,
|
||||
f64 0x%016llx, f128 0x%032x hi+lo) so MLIR FloatAttr is lossless; use CRT stdio.snprintf (%g in viperlib is buggy).
|
||||
"""
|
||||
v: rawptr[Value] = new_value(pool)
|
||||
v: Value* = new_value(pool)
|
||||
if v is None: return None
|
||||
v.Ty = ty
|
||||
v.IsConst = 1
|
||||
@@ -113,11 +113,11 @@ def ConstFloat(pool: memhub.MemBuddy*, ty: rawptr[LLVMType],
|
||||
# quad: double -> fp128 is lossless (fpext); little-endian low 64 first, print big-endian
|
||||
# (hi first). c.Load width follows the source pointee, so cast the source to u64* to avoid overflow.
|
||||
q128: t.CFloat128T = t.CFloat128T(val)
|
||||
q8: rawptr[uint8] = (rawptr[uint8])(&q128)
|
||||
q8: uint8* = (uint8*)(&q128)
|
||||
q_lo: uint64 = 0
|
||||
q_hi: uint64 = 0
|
||||
*&q_lo = *(rawptr[uint64])(q8)
|
||||
*&q_hi = *(rawptr[uint64])(q8 + 8)
|
||||
*&q_lo = *(uint64*)(q8)
|
||||
*&q_hi = *(uint64*)(q8 + 8)
|
||||
stdio.snprintf(name_buf, 64, "0x%016llx%016llx", q_hi, q_lo)
|
||||
else:
|
||||
fv_bits: uint64 = 0
|
||||
@@ -127,12 +127,12 @@ def ConstFloat(pool: memhub.MemBuddy*, ty: rawptr[LLVMType],
|
||||
return v
|
||||
|
||||
|
||||
def SSAValue(pool: memhub.MemBuddy*, ty: rawptr[LLVMType],
|
||||
name: str) -> rawptr[Value]:
|
||||
def SSAValue(pool: memhub.MemBuddy*, ty: LLVMType*,
|
||||
name: str) -> Value*:
|
||||
"""Create an SSA temporary value.
|
||||
ty: value type; name: caller-provided SSA name (e.g. "%0"/"%result").
|
||||
"""
|
||||
v: rawptr[Value] = new_value(pool)
|
||||
v: Value* = new_value(pool)
|
||||
if v is None: return None
|
||||
v.Ty = ty
|
||||
v.Name = name
|
||||
@@ -149,7 +149,7 @@ def SSAValue(pool: memhub.MemBuddy*, ty: rawptr[LLVMType],
|
||||
# must first be materialized as llvm.mlir.constant/zero/addressof ops).
|
||||
# ============================================================
|
||||
def ValuePrint(buf: str, size: sizet,
|
||||
val: rawptr[Value], pool: memhub.MemBuddy*):
|
||||
val: Value*, pool: memhub.MemBuddy*):
|
||||
"""Serialize val into buf as MLIR text; pool is used to allocate scratch buffers for
|
||||
recursive complex types (Array/Struct/Func).
|
||||
"""
|
||||
@@ -177,42 +177,42 @@ def ValuePrint(buf: str, size: sizet,
|
||||
# Cross-module callers only see a stub Value (missing/wrong fields), so TransPyC silently skips
|
||||
# field access; these accessors run inside this module with the full type definition.
|
||||
# ============================================================
|
||||
def value_get_ty(val: rawptr[Value]) -> rawptr[LLVMType]:
|
||||
def value_get_ty(val: Value*) -> LLVMType*:
|
||||
"""Get the value's type."""
|
||||
if val is None:
|
||||
return None
|
||||
return val.Ty
|
||||
|
||||
|
||||
def value_get_next(val: rawptr[Value]) -> rawptr[Value]:
|
||||
def value_get_next(val: Value*) -> Value*:
|
||||
"""Get the next value in the list."""
|
||||
if val is None:
|
||||
return None
|
||||
return val.Next
|
||||
|
||||
|
||||
def value_set_ty(val: rawptr[Value], ty: rawptr[LLVMType]):
|
||||
def value_set_ty(val: Value*, ty: LLVMType*):
|
||||
"""Set the value's type."""
|
||||
if val is None:
|
||||
return
|
||||
val.Ty = ty
|
||||
|
||||
|
||||
def value_set_next(val: rawptr[Value], nxt: rawptr[Value]):
|
||||
def value_set_next(val: Value*, nxt: Value*):
|
||||
"""Set the next value in the list."""
|
||||
if val is None:
|
||||
return
|
||||
val.Next = nxt
|
||||
|
||||
|
||||
def value_set_name(val: rawptr[Value], name: str):
|
||||
def value_set_name(val: Value*, name: str):
|
||||
"""Set the value's name."""
|
||||
if val is None:
|
||||
return
|
||||
val.Name = name
|
||||
|
||||
|
||||
def value_set_isconst(val: rawptr[Value], is_const: int):
|
||||
def value_set_isconst(val: Value*, is_const: int):
|
||||
"""Set whether the value is a constant."""
|
||||
if val is None:
|
||||
return
|
||||
|
||||
+27
-27
@@ -55,9 +55,9 @@ class VerifyResult:
|
||||
# Helper functions
|
||||
# ============================================================
|
||||
def _new_verify_result(pool: memhub.MemBuddy*,
|
||||
buf_size: sizet) -> rawptr[VerifyResult]:
|
||||
buf_size: sizet) -> VerifyResult*:
|
||||
"""Create a VerifyResult object"""
|
||||
ptr: rawptr[VerifyResult] = pool.alloc(VerifyResult.__sizeof__())
|
||||
ptr: VerifyResult* = pool.alloc(VerifyResult.__sizeof__())
|
||||
if ptr is None: return None
|
||||
string.memset(ptr, 0, VerifyResult.__sizeof__())
|
||||
ptr.ErrorCount = 0
|
||||
@@ -71,7 +71,7 @@ def _new_verify_result(pool: memhub.MemBuddy*,
|
||||
return ptr
|
||||
|
||||
|
||||
def _report_error(result: rawptr[VerifyResult], code: int, msg: str):
|
||||
def _report_error(result: VerifyResult*, code: int, msg: str):
|
||||
"""Record one error"""
|
||||
if result is None: return
|
||||
result.ErrorCount += 1
|
||||
@@ -125,9 +125,9 @@ def _append_cstr(dst: str, dst_size: sizet, src: str):
|
||||
# ============================================================
|
||||
# SSA name-table operations
|
||||
# ============================================================
|
||||
def _new_name_table(pool: memhub.MemBuddy*) -> rawptr[GSList[NameEntry]]:
|
||||
def _new_name_table(pool: memhub.MemBuddy*) -> GSList[NameEntry]*:
|
||||
"""Create an empty name table"""
|
||||
gsl: rawptr[GSList[NameEntry]] = pool.alloc(24) # GSList: Head+Tail+Count
|
||||
gsl: GSList[NameEntry]* = pool.alloc(24) # GSList: Head+Tail+Count
|
||||
if gsl is None: return None
|
||||
string.memset(gsl, 0, 24)
|
||||
return gsl
|
||||
@@ -136,19 +136,19 @@ def _new_name_table(pool: memhub.MemBuddy*) -> rawptr[GSList[NameEntry]]:
|
||||
# NameEntry hardcoded size: Next(8) + Name(8) = 16 bytes
|
||||
define NENTRY_SIZE = 16
|
||||
|
||||
def _name_table_add(table: rawptr[GSList[NameEntry]],
|
||||
def _name_table_add(table: GSList[NameEntry]*,
|
||||
pool: memhub.MemBuddy*,
|
||||
name: str) -> int:
|
||||
"""Add a name to the table. Returns 1=duplicate, 0=added"""
|
||||
if table is None or name is None: return 0
|
||||
# Check for duplicates
|
||||
cur: rawptr[NameEntry] = table.Head
|
||||
cur: NameEntry* = table.Head
|
||||
while cur is not None:
|
||||
if string.strcmp(cur.Name, name) == 0:
|
||||
return 1
|
||||
cur = cur.Next
|
||||
# Add new entry
|
||||
entry: rawptr[NameEntry] = pool.alloc(NENTRY_SIZE)
|
||||
entry: NameEntry* = pool.alloc(NENTRY_SIZE)
|
||||
if entry is None: return 0
|
||||
string.memset(entry, 0, NENTRY_SIZE)
|
||||
entry.Name = name
|
||||
@@ -156,11 +156,11 @@ def _name_table_add(table: rawptr[GSList[NameEntry]],
|
||||
return 0
|
||||
|
||||
|
||||
def _name_table_contains(table: rawptr[GSList[NameEntry]],
|
||||
def _name_table_contains(table: GSList[NameEntry]*,
|
||||
name: str) -> int:
|
||||
"""Return 1 if name is in the table, else 0"""
|
||||
if table is None or name is None: return 0
|
||||
cur: rawptr[NameEntry] = table.Head
|
||||
cur: NameEntry* = table.Head
|
||||
while cur is not None:
|
||||
if string.strcmp(cur.Name, name) == 0:
|
||||
return 1
|
||||
@@ -222,7 +222,7 @@ def _is_phi(text: str) -> int:
|
||||
return 0
|
||||
|
||||
|
||||
def _check_uses_in_line(table: rawptr[GSList[NameEntry]],
|
||||
def _check_uses_in_line(table: GSList[NameEntry]*,
|
||||
text: str,
|
||||
def_name: str) -> int:
|
||||
"""Check that all SSA name uses in the line are defined.
|
||||
@@ -254,10 +254,10 @@ def _check_uses_in_line(table: rawptr[GSList[NameEntry]],
|
||||
|
||||
|
||||
def _name_matches_at(text: str, start: int, length: int,
|
||||
table: rawptr[GSList[NameEntry]]) -> int:
|
||||
table: GSList[NameEntry]*) -> int:
|
||||
"""Return 1 if text[start:start+length] matches an entry in the name table, else 0."""
|
||||
if table is None: return 0
|
||||
cur: rawptr[NameEntry] = table.Head
|
||||
cur: NameEntry* = table.Head
|
||||
while cur is not None:
|
||||
if cur.Name is not None:
|
||||
if _str_matches_at(text, start, length, cur.Name) == 1:
|
||||
@@ -282,20 +282,20 @@ def _str_matches_at(text: str, start: int, length: int,
|
||||
# Main verification functions
|
||||
# ============================================================
|
||||
def verify_function(pool: memhub.MemBuddy*,
|
||||
func: rawptr[Function],
|
||||
result: rawptr[VerifyResult]) -> int:
|
||||
func: Function*,
|
||||
result: VerifyResult*) -> int:
|
||||
"""Verify a function's SSA correctness; result must be created via
|
||||
_new_verify_result. Returns the error count (0 = pass).
|
||||
"""
|
||||
if func is None or result is None: return 1
|
||||
|
||||
# Create name table
|
||||
name_table: rawptr[GSList[NameEntry]] = _new_name_table(pool)
|
||||
name_table: GSList[NameEntry]* = _new_name_table(pool)
|
||||
if name_table is None: return 1
|
||||
|
||||
# 1. Add function params to the name table (params are defined)
|
||||
params: rawptr[GSList[Param]] = func.Params
|
||||
param: rawptr[Param] = None
|
||||
params: GSList[Param]* = func.Params
|
||||
param: Param* = None
|
||||
if params is not None:
|
||||
param = params.Head
|
||||
while param is not None:
|
||||
@@ -304,8 +304,8 @@ def verify_function(pool: memhub.MemBuddy*,
|
||||
param = param.Next
|
||||
|
||||
# 1b. Add block names to the table (block labels like %then are valid br/phi targets)
|
||||
blocks: rawptr[GSList[BasicBlock]] = func.Blocks
|
||||
blk_iter: rawptr[BasicBlock] = None
|
||||
blocks: GSList[BasicBlock]* = func.Blocks
|
||||
blk_iter: BasicBlock* = None
|
||||
if blocks is not None:
|
||||
blk_iter = blocks.Head
|
||||
while blk_iter is not None:
|
||||
@@ -322,7 +322,7 @@ def verify_function(pool: memhub.MemBuddy*,
|
||||
blk_iter = blk_iter.Next
|
||||
|
||||
# 2. Walk all blocks
|
||||
blk: rawptr[BasicBlock] = None
|
||||
blk: BasicBlock* = None
|
||||
if blocks is not None:
|
||||
blk = blocks.Head
|
||||
while blk is not None:
|
||||
@@ -330,9 +330,9 @@ def verify_function(pool: memhub.MemBuddy*,
|
||||
if blk.IsTerminated == 0:
|
||||
# Also check whether the last line is a terminator
|
||||
has_term: int = 0
|
||||
line_check: rawptr[Line] = None
|
||||
line_check: Line* = None
|
||||
if blk.Lines is not None:
|
||||
lines_check: rawptr[GSList[Line]] = blk.Lines
|
||||
lines_check: GSList[Line]* = blk.Lines
|
||||
line_check = lines_check.Head
|
||||
while line_check is not None:
|
||||
if line_check.Buf is not None:
|
||||
@@ -350,9 +350,9 @@ def verify_function(pool: memhub.MemBuddy*,
|
||||
|
||||
# Walk instruction lines in the block
|
||||
seen_non_phi: int = 0
|
||||
line: rawptr[Line] = None
|
||||
line: Line* = None
|
||||
if blk.Lines is not None:
|
||||
lines: rawptr[GSList[Line]] = blk.Lines
|
||||
lines: GSList[Line]* = blk.Lines
|
||||
line = lines.Head
|
||||
while line is not None:
|
||||
if line.Buf is not None:
|
||||
@@ -396,12 +396,12 @@ def verify_function(pool: memhub.MemBuddy*,
|
||||
return result.ErrorCount
|
||||
|
||||
|
||||
def verify_module(pool: memhub.MemBuddy*, mod: rawptr[LLVMModule], result: rawptr[VerifyResult]) -> int:
|
||||
def verify_module(pool: memhub.MemBuddy*, mod: LLVMModule*, result: VerifyResult*) -> int:
|
||||
"""Verify SSA correctness of all functions in the module.
|
||||
Returns the total error count.
|
||||
"""
|
||||
if mod is None or result is None: return 1
|
||||
func: rawptr[Function] = mod.FuncHead
|
||||
func: Function* = mod.FuncHead
|
||||
while func is not None:
|
||||
if func.IsDeclared == 0:
|
||||
# Verify only definitions with a body; skip declarations
|
||||
|
||||
+18
-18
@@ -34,9 +34,9 @@ class ndarray[T]:
|
||||
ndim: int
|
||||
size: sizet
|
||||
owns_data: int
|
||||
pool: rawptr[memhub.MemManager]
|
||||
pool: memhub.MemManager*
|
||||
|
||||
def __new__(self, pool: rawptr[memhub.MemManager], n: sizet):
|
||||
def __new__(self, pool: memhub.MemManager*, n: sizet):
|
||||
self.pool = pool
|
||||
self.data = pool.alloc(n * T.__sizeof__())
|
||||
if self.data:
|
||||
@@ -261,7 +261,7 @@ Uint8Array: t.CTypedef = ndarray[uchar]
|
||||
# Internal helpers (specialized for float64 by default)
|
||||
# Use _alloc_ndarray_t[T] / _empty_like_t[T] for other types
|
||||
# ============================================================
|
||||
def _alloc_ndarray(pool: rawptr[memhub.MemManager]) -> ndarray[double]*:
|
||||
def _alloc_ndarray(pool: memhub.MemManager*) -> ndarray[double]*:
|
||||
a: ndarray[double]* = pool.alloc(ndarray[double].__sizeof__())
|
||||
if a:
|
||||
string.memset(a, 0, ndarray[double].__sizeof__())
|
||||
@@ -296,7 +296,7 @@ def _empty_like(a: ndarray[double]*) -> ndarray[double]*:
|
||||
# ============================================================
|
||||
# Array creation functions (float64 default)
|
||||
# ============================================================
|
||||
def array(pool: rawptr[memhub.MemManager], data: double*, n: sizet) -> ndarray[double]*:
|
||||
def array(pool: memhub.MemManager*, data: double*, n: sizet) -> ndarray[double]*:
|
||||
a: ndarray[double]* = _alloc_ndarray(pool)
|
||||
if not a: return None
|
||||
a.data = pool.alloc(n * double.__sizeof__())
|
||||
@@ -312,7 +312,7 @@ def array(pool: rawptr[memhub.MemManager], data: double*, n: sizet) -> ndarray[d
|
||||
a.owns_data = 1
|
||||
return a
|
||||
|
||||
def zeros(pool: rawptr[memhub.MemManager], n: sizet) -> ndarray[double]*:
|
||||
def zeros(pool: memhub.MemManager*, n: sizet) -> ndarray[double]*:
|
||||
a: ndarray[double]* = _alloc_ndarray(pool)
|
||||
if not a: return None
|
||||
a.data = pool.alloc(n * double.__sizeof__())
|
||||
@@ -328,19 +328,19 @@ def zeros(pool: rawptr[memhub.MemManager], n: sizet) -> ndarray[double]*:
|
||||
a.owns_data = 1
|
||||
return a
|
||||
|
||||
def ones(pool: rawptr[memhub.MemManager], n: sizet) -> ndarray[double]*:
|
||||
def ones(pool: memhub.MemManager*, n: sizet) -> ndarray[double]*:
|
||||
a: ndarray[double]* = zeros(pool, n)
|
||||
if not a: return None
|
||||
a.fill(double(1.0))
|
||||
return a
|
||||
|
||||
def full(pool: rawptr[memhub.MemManager], n: sizet, val: double) -> ndarray[double]*:
|
||||
def full(pool: memhub.MemManager*, n: sizet, val: double) -> ndarray[double]*:
|
||||
a: ndarray[double]* = zeros(pool, n)
|
||||
if not a: return None
|
||||
a.fill(val)
|
||||
return a
|
||||
|
||||
def arange(pool: rawptr[memhub.MemManager], start: double, stop: double, step: double) -> ndarray[double]*:
|
||||
def arange(pool: memhub.MemManager*, start: double, stop: double, step: double) -> ndarray[double]*:
|
||||
if step == double(0.0): return None
|
||||
n: sizet = 0
|
||||
if step > double(0.0):
|
||||
@@ -362,7 +362,7 @@ def arange(pool: rawptr[memhub.MemManager], start: double, stop: double, step: d
|
||||
v += step
|
||||
return a
|
||||
|
||||
def linspace(pool: rawptr[memhub.MemManager], start: double, stop: double, num: sizet) -> ndarray[double]*:
|
||||
def linspace(pool: memhub.MemManager*, start: double, stop: double, num: sizet) -> ndarray[double]*:
|
||||
if num == 0: return None
|
||||
a: ndarray[double]* = zeros(pool, num)
|
||||
if not a: return None
|
||||
@@ -374,7 +374,7 @@ def linspace(pool: rawptr[memhub.MemManager], start: double, stop: double, num:
|
||||
a.data[i] = start + double(i) * step
|
||||
return a
|
||||
|
||||
def empty2d(pool: rawptr[memhub.MemManager], rows: sizet, cols: sizet) -> ndarray[double]*:
|
||||
def empty2d(pool: memhub.MemManager*, rows: sizet, cols: sizet) -> ndarray[double]*:
|
||||
a: ndarray[double]* = _alloc_ndarray(pool)
|
||||
if not a: return None
|
||||
total: sizet = rows * cols
|
||||
@@ -392,23 +392,23 @@ def empty2d(pool: rawptr[memhub.MemManager], rows: sizet, cols: sizet) -> ndarra
|
||||
_compute_strides(a)
|
||||
return a
|
||||
|
||||
def zeros2d(pool: rawptr[memhub.MemManager], rows: sizet, cols: sizet) -> ndarray[double]*:
|
||||
def zeros2d(pool: memhub.MemManager*, rows: sizet, cols: sizet) -> ndarray[double]*:
|
||||
return empty2d(pool, rows, cols)
|
||||
|
||||
def ones2d(pool: rawptr[memhub.MemManager], rows: sizet, cols: sizet) -> ndarray[double]*:
|
||||
def ones2d(pool: memhub.MemManager*, rows: sizet, cols: sizet) -> ndarray[double]*:
|
||||
a: ndarray[double]* = empty2d(pool, rows, cols)
|
||||
if not a: return None
|
||||
a.fill(double(1.0))
|
||||
return a
|
||||
|
||||
def eye(pool: rawptr[memhub.MemManager], n: sizet) -> ndarray[double]*:
|
||||
def eye(pool: memhub.MemManager*, n: sizet) -> ndarray[double]*:
|
||||
a: ndarray[double]* = empty2d(pool, n, n)
|
||||
if not a: return None
|
||||
for i in range(n):
|
||||
a.data[i * n + i] = double(1.0)
|
||||
return a
|
||||
|
||||
def diag(pool: rawptr[memhub.MemManager], vals: ndarray[double]*) -> ndarray[double]*:
|
||||
def diag(pool: memhub.MemManager*, vals: ndarray[double]*) -> ndarray[double]*:
|
||||
n: sizet = vals.size
|
||||
a: ndarray[double]* = empty2d(pool, n, n)
|
||||
if not a: return None
|
||||
@@ -887,10 +887,10 @@ def np_greater_equal(a: ndarray[double]*, b: ndarray[double]*) -> ndarray[double
|
||||
# ============================================================
|
||||
# Additional creation functions (float64 default)
|
||||
# ============================================================
|
||||
def empty(pool: rawptr[memhub.MemManager], n: sizet) -> ndarray[double]*:
|
||||
def empty(pool: memhub.MemManager*, n: sizet) -> ndarray[double]*:
|
||||
return zeros(pool, n)
|
||||
|
||||
def full2d(pool: rawptr[memhub.MemManager], rows: sizet, cols: sizet, val: double) -> ndarray[double]*:
|
||||
def full2d(pool: memhub.MemManager*, rows: sizet, cols: sizet, val: double) -> ndarray[double]*:
|
||||
a: ndarray[double]* = empty2d(pool, rows, cols)
|
||||
if not a: return None
|
||||
a.fill(val)
|
||||
@@ -920,10 +920,10 @@ def ones_like(a: ndarray[double]*) -> ndarray[double]*:
|
||||
result.fill(double(1.0))
|
||||
return result
|
||||
|
||||
def arange1(pool: rawptr[memhub.MemManager], stop: double) -> ndarray[double]*:
|
||||
def arange1(pool: memhub.MemManager*, stop: double) -> ndarray[double]*:
|
||||
return arange(pool, double(0.0), stop, double(1.0))
|
||||
|
||||
def linspace2(pool: rawptr[memhub.MemManager], start: double, stop: double) -> ndarray[double]*:
|
||||
def linspace2(pool: memhub.MemManager*, start: double, stop: double) -> ndarray[double]*:
|
||||
return linspace(pool, start, stop, 50)
|
||||
|
||||
def meshgrid(x: ndarray[double]*, y: ndarray[double]*) -> ndarray[double]*:
|
||||
|
||||
+2
-2
@@ -16,7 +16,7 @@ _mbuddy: memhub.MemBuddy*
|
||||
# File/Directory Attribute Query
|
||||
# =============================================================================
|
||||
|
||||
def _stat(path: str) -> rawptr[posix.Stat]:
|
||||
def _stat(path: str) -> posix.Stat*:
|
||||
"""Call stat and return a Stat struct pointer. Return None on failure.
|
||||
Note: the Stat struct is allocated via _mbuddy; the caller must free it."""
|
||||
st: posix.Stat = posix.Stat()
|
||||
@@ -146,7 +146,7 @@ def listdir(path: str, out_names: str*, max_count: ULONG) -> ULONG:
|
||||
|
||||
count: ULONG = 0
|
||||
while count < max_count:
|
||||
entry: rawptr[posix.Dirent] = posix.readdir(dirp)
|
||||
entry: posix.Dirent* = posix.readdir(dirp)
|
||||
if entry == None:
|
||||
break
|
||||
|
||||
|
||||
@@ -162,42 +162,42 @@ class Dirent():
|
||||
# =============================================================================
|
||||
# File operations (10)
|
||||
# =============================================================================
|
||||
extern def open(path: t.CConst | str, oflag: INT, *args) -> INT
|
||||
extern def open(path: const str, oflag: INT, *args) -> INT
|
||||
extern def close(fd: INT) -> INT
|
||||
extern def read(fd: INT, buf: bytes, count: sizet) -> ssize_t
|
||||
extern def write(fd: INT, buf: t.CConst | bytes, count: sizet) -> ssize_t
|
||||
extern def write(fd: INT, buf: const bytes, count: sizet) -> ssize_t
|
||||
extern def lseek(fd: INT, offset: off_t, whence: INT) -> off_t
|
||||
extern def unlink(path: t.CConst | str) -> INT
|
||||
extern def access(path: t.CConst | str, amode: INT) -> INT
|
||||
extern def realpath(path: t.CConst | str, resolved: CHARPTR) -> CHARPTR
|
||||
extern def rename(oldpath: t.CConst | str, newpath: t.CConst | str) -> INT
|
||||
extern def chmod(path: t.CConst | str, mode: mode_t) -> INT
|
||||
extern def unlink(path: const str) -> INT
|
||||
extern def access(path: const str, amode: INT) -> INT
|
||||
extern def realpath(path: const str, resolved: CHARPTR) -> CHARPTR
|
||||
extern def rename(oldpath: const str, newpath: const str) -> INT
|
||||
extern def chmod(path: const str, mode: mode_t) -> INT
|
||||
|
||||
# =============================================================================
|
||||
# stat series (2)
|
||||
# =============================================================================
|
||||
extern def stat(path: t.CConst | str, buf: Stat*) -> INT
|
||||
extern def stat(path: const str, buf: Stat*) -> INT
|
||||
extern def fstat(fd: INT, buf: Stat*) -> INT
|
||||
|
||||
|
||||
# =============================================================================
|
||||
# Directory operations (6)
|
||||
# =============================================================================
|
||||
extern def opendir(name: t.CConst | str) -> DIR
|
||||
extern def opendir(name: const str) -> DIR
|
||||
extern def readdir(dirp: DIR) -> Dirent*
|
||||
extern def closedir(dirp: DIR) -> INT
|
||||
extern def mkdir(path: t.CConst | str, mode: mode_t) -> INT
|
||||
extern def rmdir(path: t.CConst | str) -> INT
|
||||
extern def mkdir(path: const str, mode: mode_t) -> INT
|
||||
extern def rmdir(path: const str) -> INT
|
||||
extern def getcwd(buf: CHARPTR, size: sizet) -> CHARPTR
|
||||
extern def chdir(path: t.CConst | str) -> INT
|
||||
extern def chdir(path: const str) -> INT
|
||||
|
||||
|
||||
# =============================================================================
|
||||
# Process operations (8)
|
||||
# =============================================================================
|
||||
extern def fork() -> pid_t
|
||||
extern def execvp(file: t.CConst | str, argv: CHARPTR*) -> INT
|
||||
extern def execv(path: t.CConst | str, argv: CHARPTR*) -> INT
|
||||
extern def execvp(file: const str, argv: CHARPTR*) -> INT
|
||||
extern def execv(path: const str, argv: CHARPTR*) -> INT
|
||||
extern def waitpid(pid: pid_t, status: INT*, options: INT) -> pid_t
|
||||
extern def pipe(fds: INT*) -> INT
|
||||
extern def dup2(oldfd: INT, newfd: INT) -> INT
|
||||
@@ -208,8 +208,8 @@ extern def getpid() -> pid_t
|
||||
# =============================================================================
|
||||
# Environment operations (4)
|
||||
# =============================================================================
|
||||
extern def getenv(name: t.CConst | str) -> CHARPTR
|
||||
extern def setenv(name: t.CConst | str, value: t.CConst | str, overwrite: INT) -> INT
|
||||
extern def getenv(name: const str) -> CHARPTR
|
||||
extern def setenv(name: const str, value: const str, overwrite: INT) -> INT
|
||||
extern def sysconf(name: INT) -> LONG
|
||||
extern def isatty(fd: INT) -> INT
|
||||
|
||||
|
||||
@@ -63,7 +63,7 @@ def rdseed64() -> uint64:
|
||||
# Step version (with success flag, matching GCC builtin interface)
|
||||
# Returns success flag: 1 on success, 0 on failure; random value written to *p
|
||||
# ============================================================
|
||||
def rdrand16_step(p: rawptr[uint16]) -> int:
|
||||
def rdrand16_step(p: uint16*) -> int:
|
||||
val: uint32 = 0
|
||||
ok: uint32 = 0
|
||||
c.Asm(f"""rdrand {c.AsmOut(val, t.ASM_DESCR.OUTPUT_REG)}
|
||||
@@ -74,7 +74,7 @@ def rdrand16_step(p: rawptr[uint16]) -> int:
|
||||
p[0] = uint16(val)
|
||||
return int(ok)
|
||||
|
||||
def rdrand32_step(p: rawptr[uint32]) -> int:
|
||||
def rdrand32_step(p: uint32*) -> int:
|
||||
val: uint32 = 0
|
||||
ok: uint32 = 0
|
||||
c.Asm(f"""rdrand {c.AsmOut(val, t.ASM_DESCR.OUTPUT_REG)}
|
||||
@@ -85,7 +85,7 @@ def rdrand32_step(p: rawptr[uint32]) -> int:
|
||||
p[0] = val
|
||||
return int(ok)
|
||||
|
||||
def rdrand64_step(p: rawptr[uint64]) -> int:
|
||||
def rdrand64_step(p: uint64*) -> int:
|
||||
val: uint64 = 0
|
||||
ok: uint32 = 0
|
||||
c.Asm(f"""rdrand {c.AsmOut(val, t.ASM_DESCR.OUTPUT_REG)}
|
||||
@@ -96,7 +96,7 @@ def rdrand64_step(p: rawptr[uint64]) -> int:
|
||||
p[0] = val
|
||||
return int(ok)
|
||||
|
||||
def rdseed16_step(p: rawptr[uint16]) -> int:
|
||||
def rdseed16_step(p: uint16*) -> int:
|
||||
val: uint32 = 0
|
||||
ok: uint32 = 0
|
||||
c.Asm(f"""rdseed {c.AsmOut(val, t.ASM_DESCR.OUTPUT_REG)}
|
||||
@@ -107,7 +107,7 @@ def rdseed16_step(p: rawptr[uint16]) -> int:
|
||||
p[0] = uint16(val)
|
||||
return int(ok)
|
||||
|
||||
def rdseed32_step(p: rawptr[uint32]) -> int:
|
||||
def rdseed32_step(p: uint32*) -> int:
|
||||
val: uint32 = 0
|
||||
ok: uint32 = 0
|
||||
c.Asm(f"""rdseed {c.AsmOut(val, t.ASM_DESCR.OUTPUT_REG)}
|
||||
@@ -118,7 +118,7 @@ def rdseed32_step(p: rawptr[uint32]) -> int:
|
||||
p[0] = val
|
||||
return int(ok)
|
||||
|
||||
def rdseed64_step(p: rawptr[uint64]) -> int:
|
||||
def rdseed64_step(p: uint64*) -> int:
|
||||
val: uint64 = 0
|
||||
ok: uint32 = 0
|
||||
c.Asm(f"""rdseed {c.AsmOut(val, t.ASM_DESCR.OUTPUT_REG)}
|
||||
|
||||
@@ -374,7 +374,7 @@ def download(url: str, path: str, threads: INT = 1,
|
||||
job.status = 0
|
||||
ctxs[i] = t.CPtr(uint64(job))
|
||||
|
||||
th: rawptr[vt.Thread] = vt.Thread(_dl_worker, ctxs[i])
|
||||
th: vt.Thread* = vt.Thread(_dl_worker, ctxs[i])
|
||||
if th is None:
|
||||
stdlib.free(job.buf)
|
||||
stdlib.free(job.path)
|
||||
|
||||
+14
-14
@@ -219,7 +219,7 @@ def _TlsErrText():
|
||||
# Core request
|
||||
# ============================================================
|
||||
|
||||
def _HttpsRequest(method: str, url: str, verify: bool, ca_file: str, data: str, content_type: str, auth: str = None) -> rawptr[requests.Response]:
|
||||
def _HttpsRequest(method: str, url: str, verify: bool, ca_file: str, data: str, content_type: str, auth: str = None) -> requests.Response*:
|
||||
"""HTTPS GET/POST core. verify=False skips cert chain/hostname checks (not recommended);
|
||||
verify=True uses ca_file PEM bundle (else system default); auth adds Authorization header on POST only.
|
||||
"""
|
||||
@@ -228,7 +228,7 @@ def _HttpsRequest(method: str, url: str, verify: bool, ca_file: str, data: str,
|
||||
|
||||
_last_verify_flag = 1 if verify else 0
|
||||
|
||||
resp: rawptr[requests.Response] = requests.create_response()
|
||||
resp: requests.Response* = requests.create_response()
|
||||
if resp is None: return None
|
||||
|
||||
if _EnsureReady() != 0:
|
||||
@@ -478,7 +478,7 @@ def _HttpsRequest(method: str, url: str, verify: bool, ca_file: str, data: str,
|
||||
# Public API
|
||||
# ============================================================
|
||||
|
||||
def _HttpsRedirectLoop(method: str, url: str, verify: bool, ca_file: str, data: str, content_type: str, auth: str = None) -> rawptr[requests.Response]:
|
||||
def _HttpsRedirectLoop(method: str, url: str, verify: bool, ca_file: str, data: str, content_type: str, auth: str = None) -> requests.Response*:
|
||||
"""HTTPS GET/POST with redirect following (cross http/https, max 5 hops).
|
||||
auth is passed through to _HttpsRequest; note Authorization also follows cross-host redirects.
|
||||
"""
|
||||
@@ -493,7 +493,7 @@ def _HttpsRedirectLoop(method: str, url: str, verify: bool, ca_file: str, data:
|
||||
string.strcpy(cur, url)
|
||||
|
||||
for hop in range(5):
|
||||
resp: rawptr[requests.Response] = _HttpsRequest(method, cur, verify, ca_file, data, content_type, auth)
|
||||
resp: requests.Response* = _HttpsRequest(method, cur, verify, ca_file, data, content_type, auth)
|
||||
if resp is None:
|
||||
requests._mbuddy.free(cur)
|
||||
return None
|
||||
@@ -530,7 +530,7 @@ def _HttpsRedirectLoop(method: str, url: str, verify: bool, ca_file: str, data:
|
||||
if string.strncmp(nxt, "https://", 8) != 0:
|
||||
requests._mbuddy.free(loc)
|
||||
requests._mbuddy.free(cur)
|
||||
http_resp: rawptr[requests.Response] = requests.get(nxt)
|
||||
http_resp: requests.Response* = requests.get(nxt)
|
||||
requests._mbuddy.free(nxt)
|
||||
return http_resp
|
||||
|
||||
@@ -543,7 +543,7 @@ def _HttpsRedirectLoop(method: str, url: str, verify: bool, ca_file: str, data:
|
||||
return None
|
||||
|
||||
|
||||
def get(url: str, verify: bool = True, ca_file: str = None) -> rawptr[requests.Response]:
|
||||
def get(url: str, verify: bool = True, ca_file: str = None) -> requests.Response*:
|
||||
"""HTTPS GET (follows 3xx redirects, max 5 hops). verify checks cert chain + hostname;
|
||||
ca_file is a PEM CA bundle path, None uses system default. Returns Response* or None.
|
||||
"""
|
||||
@@ -551,7 +551,7 @@ def get(url: str, verify: bool = True, ca_file: str = None) -> rawptr[requests.R
|
||||
|
||||
|
||||
def post(url: str, data: str = None, content_type: str = "application/x-www-form-urlencoded",
|
||||
verify: bool = True, ca_file: str = None, auth: str = None) -> rawptr[requests.Response]:
|
||||
verify: bool = True, ca_file: str = None, auth: str = None) -> requests.Response*:
|
||||
"""HTTPS POST (follows 3xx redirects, max 5 hops). verify checks cert chain + hostname;
|
||||
ca_file PEM CA bundle (None = system default); auth optional "Bearer <key>", sent when non-empty.
|
||||
"""
|
||||
@@ -563,20 +563,20 @@ def post(url: str, data: str = None, content_type: str = "application/x-www-form
|
||||
# choices[0].delta.content from data:{json} lines into _st_buf; blocking, returns HTTP status or -1/-2.
|
||||
# ============================================================
|
||||
|
||||
def _SseDeltaContent(root: rawptr[json.JsonValue]) -> str:
|
||||
def _SseDeltaContent(root: json.JsonValue*) -> str:
|
||||
"""Extract choices[0].delta.content from a stream data event; None if absent."""
|
||||
if root is None or not root.is_object():
|
||||
return None
|
||||
cv: rawptr[json.JsonValue] = root["choices"]
|
||||
cv: json.JsonValue* = root["choices"]
|
||||
if cv is None or not cv.is_array():
|
||||
return None
|
||||
m0: rawptr[json.JsonValue] = cv.get_item(0)
|
||||
m0: json.JsonValue* = cv.get_item(0)
|
||||
if m0 is None or not m0.is_object():
|
||||
return None
|
||||
dv: rawptr[json.JsonValue] = m0["delta"]
|
||||
dv: json.JsonValue* = m0["delta"]
|
||||
if dv is None or not dv.is_object():
|
||||
return None
|
||||
content_v: rawptr[json.JsonValue] = dv["content"]
|
||||
content_v: json.JsonValue* = dv["content"]
|
||||
if content_v is None or not content_v.is_string():
|
||||
return None
|
||||
return content_v.as_string()
|
||||
@@ -782,7 +782,7 @@ def post_stream(url: str, data: str, content_type: str = "application/json",
|
||||
sock.close()
|
||||
requests._mbuddy.free(errmsg)
|
||||
return -1
|
||||
jpool: rawptr[memhub.MemPool] = memhub.MemPool(pmem, 524288)
|
||||
jpool: memhub.MemPool* = memhub.MemPool(pmem, 524288)
|
||||
|
||||
leftover: t.CArray[char, 16384]
|
||||
llen: INT = 0
|
||||
@@ -840,7 +840,7 @@ def post_stream(url: str, data: str, content_type: str = "application/json",
|
||||
if pl[0] != 0:
|
||||
if string.strncmp(pl, "[DONE]", 6) != 0 or pl[6] != 0:
|
||||
jpool.reset()
|
||||
ev: rawptr[json.JsonValue] = json.parse(jpool, pl)
|
||||
ev: json.JsonValue* = json.parse(jpool, pl)
|
||||
dtx: str = _SseDeltaContent(ev)
|
||||
if dtx is not None:
|
||||
_StreamAppendContent(dtx)
|
||||
|
||||
@@ -193,7 +193,7 @@ def _rmtree_posix(path: str) -> int:
|
||||
|
||||
path_len: sizet = len(path)
|
||||
result: int = 0
|
||||
entry: rawptr[posix.Dirent] = posix.readdir(dirp)
|
||||
entry: posix.Dirent* = posix.readdir(dirp)
|
||||
while entry != None:
|
||||
name: str = entry.d_name
|
||||
# Skip . and ..
|
||||
|
||||
@@ -90,7 +90,7 @@ extern def bind(fd: u64, addr: SocketAddr*, addrlen: INT) -> INT
|
||||
extern def listen(fd: u64, backlog: INT) -> INT
|
||||
extern def accept(fd: u64, addr: SocketAddr*, addrlen: INT*) -> u64
|
||||
extern def setsockopt(fd: u64, level: INT, optname: INT, optval: t.CPtr, optlen: INT) -> INT
|
||||
extern def gethostbyname(name: t.CConst | str) -> HostEnt*
|
||||
extern def gethostbyname(name: const str) -> HostEnt*
|
||||
extern def ntohs(netshort: u16) -> u16
|
||||
extern def htons(hostshort: u16) -> u16
|
||||
extern def close(fd: u64) -> INT
|
||||
@@ -123,7 +123,7 @@ def _MakeAddr(host: str, port: INT) -> SocketAddr:
|
||||
# DNS resolution — gethostbyname returns struct hostent*
|
||||
# h_addr_list is char** → h_addr_list[0] is char* → *(uint32_t*)h_addr_list[0] is IP
|
||||
if platmacro.IS_WINDOWS:
|
||||
he_raw: rawptr[w32.winsock2.WSAHostEnt] = w32.winsock2.gethostbyname(host)
|
||||
he_raw: w32.winsock2.WSAHostEnt* = w32.winsock2.gethostbyname(host)
|
||||
if he_raw is not None:
|
||||
# he_raw.h_addr_list → he_raw->h_addr_list (char**)
|
||||
# c.Deref(uint64(he_raw.h_addr_list, t.CPtr)) → *(uint64_t*)(he_raw->h_addr_list) → h_addr_list[0]
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import t, c
|
||||
|
||||
|
||||
extern def printf(fmt: t.CConst | str, *args) -> int
|
||||
extern def fprintf(stream: bytes, fmt: t.CConst | str, *args) -> int
|
||||
extern def sprintf(buf: bytes, fmt: t.CConst | str, *args) -> int
|
||||
extern def snprintf(buf: bytes, size: sizet, fmt: t.CConst | str, *args) -> int
|
||||
extern def puts(s: t.CConst | str) -> int
|
||||
extern def fputs(s: t.CConst | str, stream: bytes) -> int
|
||||
extern def printf(fmt: const str, *args) -> int
|
||||
extern def fprintf(stream: bytes, fmt: const str, *args) -> int
|
||||
extern def sprintf(buf: bytes, fmt: const str, *args) -> int
|
||||
extern def snprintf(buf: bytes, size: sizet, fmt: const str, *args) -> int
|
||||
extern def puts(s: const str) -> int
|
||||
extern def fputs(s: const str, stream: bytes) -> int
|
||||
extern def fgets(buf: bytes, size: int, stream: bytes) -> bytes
|
||||
extern def fflush(stream: bytes) -> int
|
||||
@@ -6,5 +6,5 @@ extern def malloc(size: sizet) -> t.CPtr
|
||||
extern def calloc(nmemb: sizet, size: sizet) -> t.CPtr
|
||||
extern def realloc(p: t.CPtr, size: sizet) -> t.CPtr
|
||||
extern def free(p: t.CPtr)
|
||||
extern def system(cmd: t.CConst | str) -> int
|
||||
extern def system(cmd: const str) -> int
|
||||
extern def exit(status: int)
|
||||
+2
-2
@@ -52,7 +52,7 @@ def zeros(pool: memhub.MemBuddy*, rows: sizet,
|
||||
"""torch.zeros: create a rows x cols all-zero Tensor, optionally allocating a Grad buffer"""
|
||||
if pool is None:
|
||||
return None
|
||||
t0: rawptr[Tensor] = pool.alloc(TENSOR_SIZE)
|
||||
t0: Tensor* = pool.alloc(TENSOR_SIZE)
|
||||
if t0 is None:
|
||||
return None
|
||||
string.memset(t0, 0, TENSOR_SIZE)
|
||||
@@ -73,7 +73,7 @@ def from_raw(pool: memhub.MemBuddy*, data: t.CPtr,
|
||||
"""torch.from_raw: wrap existing memory as a Tensor (no copy, not owned)"""
|
||||
if pool is None:
|
||||
return None
|
||||
t0: rawptr[Tensor] = pool.alloc(TENSOR_SIZE)
|
||||
t0: Tensor* = pool.alloc(TENSOR_SIZE)
|
||||
if t0 is None:
|
||||
return None
|
||||
string.memset(t0, 0, TENSOR_SIZE)
|
||||
|
||||
+10
-10
@@ -533,7 +533,7 @@ class TracebackState():
|
||||
# Sole global state: None = not installed (zero side effects while the sidecar is absent).
|
||||
# Pointer + lazy allocation instead of a module-level object constant, which would emit a
|
||||
# constructor that may run after Install and wipe the state it wrote.
|
||||
_State: rawptr[TracebackState] = None
|
||||
_State: TracebackState* = None
|
||||
|
||||
|
||||
# ---- Dump atomic lock / locked output handle ----
|
||||
@@ -827,7 +827,7 @@ def EntryRva(Index: int) -> uint64:
|
||||
"""RVA of record Index (record area starts at MapBase + 20).
|
||||
|
||||
The bare `_State` null-check below is REQUIRED: the attribute layer registers `_State` per
|
||||
function before it can resolve this module-level `rawptr[TracebackState]`; without it
|
||||
function before it can resolve this module-level `TracebackState*`; without it
|
||||
`_State.MapBase` is silently folded to null (see header section 11 A). It also guards
|
||||
against an uninstalled state (returns 0).
|
||||
"""
|
||||
@@ -1131,7 +1131,7 @@ def ReadMemCb(hProcess: HANDLE, Addr: ULONGLONG, Buf: VOIDPTR, Size: DWORD,
|
||||
Read: sizet = 0
|
||||
R: BOOL = wm.ReadProcessMemory(hProcess, t.CPtr(Addr), Buf, sizet(Size), &Read)
|
||||
if pRead != None:
|
||||
Rd: rawptr[uint32] = (rawptr[uint32])(pRead)
|
||||
Rd: uint32* = (uint32*)(pRead)
|
||||
Rd[0] = uint32(Read)
|
||||
if R == 0 and _State != None and _State.ReadMemFailed == 0:
|
||||
# Record only the first failure (address/size/error); WalkViaDbgHelp prints it next to the
|
||||
@@ -1153,7 +1153,7 @@ def WalkViaDbgHelp(hProcess: HANDLE, hThread: HANDLE, CtxPtr: VOIDPTR,
|
||||
never enters. It is the only path that can cross a frameless system frame (RBP=0 in the Ctrl+C
|
||||
context) via the PE unwind tables (.pdata) and reach the real .vp stack.
|
||||
|
||||
STACKFRAME64 fields are accessed through explicit sub-struct pointers (rawptr[dbg.ADDRESS64]):
|
||||
STACKFRAME64 fields are accessed through explicit sub-struct pointers (dbg.ADDRESS64*):
|
||||
the ADDRESS64 structures sit at offsets 0 / 16 / 32 / 48 (= AddrPC / AddrReturn / AddrFrame /
|
||||
AddrStack, see includes/w32/win32dbghelp.vp). After zeroing, AddrPC/AddrFrame/AddrStack are
|
||||
pre-filled with the context's Rip/Rbp/Rsp and Mode = AddrModeFlat(3); MachineType is passed on
|
||||
@@ -1200,10 +1200,10 @@ def WalkViaDbgHelp(hProcess: HANDLE, hThread: HANDLE, CtxPtr: VOIDPTR,
|
||||
Reason: str = "frame_limit"
|
||||
if TRACEBACK_USE_DBGHELP != 0:
|
||||
string.memset(FBuf, 0, dbg.STACKFRAME64.__sizeof__())
|
||||
ctx: rawptr[wp.CONTEXT] = (rawptr[wp.CONTEXT])(CtxPtr)
|
||||
Pc: rawptr[dbg.ADDRESS64] = (rawptr[dbg.ADDRESS64])(FBuf)
|
||||
Fm: rawptr[dbg.ADDRESS64] = (rawptr[dbg.ADDRESS64])(FBuf + 32)
|
||||
St: rawptr[dbg.ADDRESS64] = (rawptr[dbg.ADDRESS64])(FBuf + 48)
|
||||
ctx: wp.CONTEXT* = (wp.CONTEXT*)(CtxPtr)
|
||||
Pc: dbg.ADDRESS64* = (dbg.ADDRESS64*)(FBuf)
|
||||
Fm: dbg.ADDRESS64* = (dbg.ADDRESS64*)(FBuf + 32)
|
||||
St: dbg.ADDRESS64* = (dbg.ADDRESS64*)(FBuf + 48)
|
||||
Pc.Offset = ctx.Rip
|
||||
Pc.Mode = uint32(dbg.ADDR_MODE_FLAT)
|
||||
Fm.Offset = ctx.Rbp
|
||||
@@ -1628,7 +1628,7 @@ def DumpMainThread(IsBreak: int) -> int:
|
||||
return 0
|
||||
# CONTEXT: zero it first, then set ContextFlags (x64 needs the CONTEXT_AMD64 bit).
|
||||
string.memset(_State.ContextBuf, 0, wp.CONTEXT.__sizeof__())
|
||||
ctx: rawptr[wp.CONTEXT] = (rawptr[wp.CONTEXT])(_State.ContextBuf)
|
||||
ctx: wp.CONTEXT* = (wp.CONTEXT*)(_State.ContextBuf)
|
||||
ctx.ContextFlags = uint32(wp.CONTEXT_FULL)
|
||||
if wp.GetThreadContext(hThread, t.CPtr(_State.ContextBuf)) == 0:
|
||||
N = stdio.snprintf(_State.LineBuf, sizet(TRACEBACK_LINE_CAP),
|
||||
@@ -1878,7 +1878,7 @@ def DumpCrashThread(Info: VOIDPTR) -> int:
|
||||
AtomicLeaveDump()
|
||||
return 0
|
||||
Base: uint64 = uint64(GetModuleHandleA(None))
|
||||
ctx: rawptr[wp.CONTEXT] = (rawptr[wp.CONTEXT])(_State.ContextBuf)
|
||||
ctx: wp.CONTEXT* = (wp.CONTEXT*)(_State.ContextBuf)
|
||||
Rip: uint64 = uint64(ctx.Rip)
|
||||
Rsp: uint64 = uint64(ctx.Rsp)
|
||||
Rbp: uint64 = uint64(ctx.Rbp)
|
||||
|
||||
+14
-14
@@ -67,7 +67,7 @@ pyzlib_error_code_val: int = 0
|
||||
# Structures
|
||||
# ============================================================
|
||||
class Compress:
|
||||
pool: rawptr[memhub.MemManager]
|
||||
pool: memhub.MemManager*
|
||||
stream: VOIDPTR
|
||||
is_initialized: int
|
||||
is_finished: int
|
||||
@@ -140,7 +140,7 @@ class Compress:
|
||||
if not out_len:
|
||||
set_error(Z_STREAM_ERROR, "out_len is None")
|
||||
return None
|
||||
s: rawptr[zdeflate.zdeflate_stream] = self.stream # implicit type conversion
|
||||
s: zdeflate.zdeflate_stream* = self.stream # implicit type conversion
|
||||
if mode == Z_FINISH:
|
||||
if not self.header_written:
|
||||
self.header_written = 1
|
||||
@@ -231,7 +231,7 @@ class Compress:
|
||||
set_error(Z_MEM_ERROR, "out of memory")
|
||||
return None
|
||||
copy_obj.pool = self.pool
|
||||
s: rawptr[zdeflate.zdeflate_stream] = self.stream # implicit type conversion
|
||||
s: zdeflate.zdeflate_stream* = self.stream # implicit type conversion
|
||||
copy_obj.stream = s.copy()
|
||||
if not copy_obj.stream:
|
||||
if self.pool == None:
|
||||
@@ -274,7 +274,7 @@ class Compress:
|
||||
|
||||
def delete(self):
|
||||
if self.is_initialized and self.stream:
|
||||
s: rawptr[zdeflate.zdeflate_stream] = self.stream # implicit type conversion
|
||||
s: zdeflate.zdeflate_stream* = self.stream # implicit type conversion
|
||||
s.destroy()
|
||||
if self.pool == None:
|
||||
stdlib.free(self.zdict)
|
||||
@@ -290,7 +290,7 @@ class Compress:
|
||||
|
||||
|
||||
class Decompress:
|
||||
pool: rawptr[memhub.MemManager]
|
||||
pool: memhub.MemManager*
|
||||
stream: VOIDPTR
|
||||
is_initialized: int
|
||||
eof: int
|
||||
@@ -338,7 +338,7 @@ class Decompress:
|
||||
p7: BYTEPTR = BYTEPTR(self.pool.alloc(1))
|
||||
string.memset(p7, 0, 1)
|
||||
return p7
|
||||
s: rawptr[zinflate.zinflate_stream] = zinflate.zinflate_create(self.pool, self.wbits)
|
||||
s: zinflate.zinflate_stream* = zinflate.zinflate_create(self.pool, self.wbits)
|
||||
if not s:
|
||||
set_error(Z_MEM_ERROR, "out of memory")
|
||||
return None
|
||||
@@ -473,7 +473,7 @@ def set_error(code: int, msg: str):
|
||||
else:
|
||||
pyzlib_error_msg[0] = '\0'
|
||||
|
||||
def clone_bytes(pool: rawptr[memhub.MemManager], src: BYTEPTR, length: sizet) -> BYTEPTR:
|
||||
def clone_bytes(pool: memhub.MemManager*, src: BYTEPTR, length: sizet) -> BYTEPTR:
|
||||
if not src or length == 0: return None
|
||||
if pool == None:
|
||||
dst: BYTEPTR = BYTEPTR(stdlib.malloc(length))
|
||||
@@ -483,7 +483,7 @@ def clone_bytes(pool: rawptr[memhub.MemManager], src: BYTEPTR, length: sizet) ->
|
||||
return dst
|
||||
|
||||
# buf is a "pointer to pointer" (i8**). Do NOT write `BYTE | t.CPtr[t.CPtr]`: with an embedded `t.CPtr[...]` subscript the declare side (StubGen/VpiReader) does not recognize it as a CPtr marker and collapses it to BYTE = i8, mismatching the definition side's i8** (cross-module ABI mismatch; see includes/zlib/zinflate.vp decompress). Use "pointer alias | t.CPtr" instead.
|
||||
def append_bytes(pool: rawptr[memhub.MemManager], buf: BYTEPTR*, length: sizet*, cap: sizet*,
|
||||
def append_bytes(pool: memhub.MemManager*, buf: BYTEPTR*, length: sizet*, cap: sizet*,
|
||||
data: BYTEPTR, data_len: sizet) -> int:
|
||||
if not data or data_len == 0: return 0
|
||||
needed: sizet = *length + data_len
|
||||
@@ -505,7 +505,7 @@ def append_bytes(pool: rawptr[memhub.MemManager], buf: BYTEPTR*, length: sizet*,
|
||||
return 0
|
||||
|
||||
|
||||
def shrink_to_fit(pool: rawptr[memhub.MemManager], buf: BYTEPTR, length: sizet) -> BYTEPTR:
|
||||
def shrink_to_fit(pool: memhub.MemManager*, buf: BYTEPTR, length: sizet) -> BYTEPTR:
|
||||
if length == 0:
|
||||
if pool == None:
|
||||
stdlib.free(buf)
|
||||
@@ -541,7 +541,7 @@ def clear_error():
|
||||
pyzlib_error_msg[0] = '\0'
|
||||
pyzlib_error_code_val = 0
|
||||
|
||||
def compress(pool: rawptr[memhub.MemManager], data: BYTEPTR, data_len: sizet,
|
||||
def compress(pool: memhub.MemManager*, data: BYTEPTR, data_len: sizet,
|
||||
level: int, wbits: int, out_len: sizet*) -> BYTEPTR:
|
||||
if not data and data_len > 0:
|
||||
set_error(Z_STREAM_ERROR, "data is None but data_len > 0")
|
||||
@@ -604,7 +604,7 @@ def compress(pool: rawptr[memhub.MemManager], data: BYTEPTR, data_len: sizet,
|
||||
return shrink_to_fit(pool, raw_result, *out_len)
|
||||
|
||||
|
||||
def decompress(pool: rawptr[memhub.MemManager], data: BYTEPTR, data_len: sizet,
|
||||
def decompress(pool: memhub.MemManager*, data: BYTEPTR, data_len: sizet,
|
||||
wbits: int, bufsize: sizet, out_len: sizet*) -> BYTEPTR:
|
||||
if not data and data_len > 0:
|
||||
set_error(Z_STREAM_ERROR, "data is None but data_len > 0")
|
||||
@@ -618,7 +618,7 @@ def decompress(pool: rawptr[memhub.MemManager], data: BYTEPTR, data_len: sizet,
|
||||
return None
|
||||
return shrink_to_fit(pool, result, *out_len)
|
||||
|
||||
def compressobj(pool: rawptr[memhub.MemManager], level: int, method: int, wbits: int,
|
||||
def compressobj(pool: memhub.MemManager*, level: int, method: int, wbits: int,
|
||||
memLevel: int, strategy: int,
|
||||
zdict: BYTEPTR, zdict_len: sizet) -> Compress*:
|
||||
if pool == None:
|
||||
@@ -632,7 +632,7 @@ def compressobj(pool: rawptr[memhub.MemManager], level: int, method: int, wbits:
|
||||
obj.pool = pool
|
||||
actual_wbits: int = wbits
|
||||
if wbits > MAX_WBITS: actual_wbits = wbits - 16
|
||||
s: rawptr[zdeflate.zdeflate_stream] = zdeflate.zdeflate_create(pool, level, actual_wbits, memLevel, strategy)
|
||||
s: zdeflate.zdeflate_stream* = zdeflate.zdeflate_create(pool, level, actual_wbits, memLevel, strategy)
|
||||
if not s:
|
||||
if pool == None:
|
||||
stdlib.free(obj)
|
||||
@@ -662,7 +662,7 @@ def compressobj(pool: rawptr[memhub.MemManager], level: int, method: int, wbits:
|
||||
return obj
|
||||
|
||||
|
||||
def decompressobj(pool: rawptr[memhub.MemManager], wbits: int, zdict: BYTEPTR, zdict_len: sizet) -> Decompress*:
|
||||
def decompressobj(pool: memhub.MemManager*, wbits: int, zdict: BYTEPTR, zdict_len: sizet) -> Decompress*:
|
||||
if pool == None:
|
||||
obj: Decompress* = stdlib.calloc(1, Decompress.__sizeof__())
|
||||
else:
|
||||
|
||||
+4
-4
@@ -95,13 +95,13 @@ zdeflate_codelen_order: t.CArray[int, 19] = [
|
||||
# Bit writer - writes bits LSB first into a byte buffer
|
||||
# ============================================================
|
||||
class zbit_writer:
|
||||
pool: rawptr[memhub.MemManager]
|
||||
pool: memhub.MemManager*
|
||||
buf: BYTE*
|
||||
cap: sizet
|
||||
byte_pos: sizet
|
||||
bit_pos: int
|
||||
|
||||
def __init__(self, pool: rawptr[memhub.MemManager]):
|
||||
def __init__(self, pool: memhub.MemManager*):
|
||||
self.pool = pool
|
||||
self.cap = 4096
|
||||
if pool == None:
|
||||
@@ -275,10 +275,10 @@ class zbit_reader:
|
||||
# Memory allocation helper for bare metal
|
||||
# Can be replaced with custom allocator
|
||||
# ============================================================
|
||||
def zdef_alloc(pool: rawptr[memhub.MemManager], n: sizet) -> VOIDPTR:
|
||||
def zdef_alloc(pool: memhub.MemManager*, n: sizet) -> VOIDPTR:
|
||||
if pool == None: return stdlib.malloc(n)
|
||||
return pool.alloc(n)
|
||||
def zdef_free(pool: rawptr[memhub.MemManager], p: VOIDPTR):
|
||||
def zdef_free(pool: memhub.MemManager*, p: VOIDPTR):
|
||||
if pool == None:
|
||||
stdlib.free(p)
|
||||
return
|
||||
|
||||
+5
-5
@@ -8,7 +8,7 @@ import t, c
|
||||
|
||||
|
||||
class zdeflate_stream:
|
||||
pool: rawptr[memhub.MemManager]
|
||||
pool: memhub.MemManager*
|
||||
writer: zdef.zbit_writer
|
||||
window: BYTE*
|
||||
window_pos: int
|
||||
@@ -92,7 +92,7 @@ class zdeflate_stream:
|
||||
lit_tree.encode_symbol(256, &self.writer)
|
||||
|
||||
def encode_block_data(self, data: UINT8PTR, length: sizet,
|
||||
lit_tree: rawptr[zhuff.zhuff_tree], dist_tree: rawptr[zhuff.zhuff_tree]):
|
||||
lit_tree: zhuff.zhuff_tree*, dist_tree: zhuff.zhuff_tree*):
|
||||
pos: sizet = 0
|
||||
while pos < length:
|
||||
best_dist: int = 0
|
||||
@@ -335,7 +335,7 @@ def zdeflate_count_cl_freqs(all_lengths: INTPTR, total: int, cl_freqs: INTPTR):
|
||||
# Remaining 1~2 equal-length values are not silently skipped; the outer loop counts them literally (symbol val), so the covered total is exactly total
|
||||
|
||||
def zdeflate_write_cl_encoded(all_lengths: INTPTR, total: int,
|
||||
w: rawptr[zdef.zbit_writer], cl_tree: rawptr[zhuff.zhuff_tree]):
|
||||
w: zdef.zbit_writer*, cl_tree: zhuff.zhuff_tree*):
|
||||
i: int = 0
|
||||
while i < total:
|
||||
if all_lengths[i] == 0:
|
||||
@@ -375,7 +375,7 @@ def zdeflate_write_cl_encoded(all_lengths: INTPTR, total: int,
|
||||
|
||||
|
||||
|
||||
def zdeflate_create(pool: rawptr[memhub.MemManager], level: int, wbits: int, mem_level: int, strategy: int) -> zdeflate_stream*:
|
||||
def zdeflate_create(pool: memhub.MemManager*, level: int, wbits: int, mem_level: int, strategy: int) -> zdeflate_stream*:
|
||||
n: sizet = zdeflate_stream.__sizeof__()
|
||||
s: zdeflate_stream* = zdef.zdef_alloc(pool, n)
|
||||
if not s: return None
|
||||
@@ -402,7 +402,7 @@ def zdeflate_create(pool: rawptr[memhub.MemManager], level: int, wbits: int, mem
|
||||
return s
|
||||
|
||||
|
||||
def zdeflate_one_shot(pool: rawptr[memhub.MemManager], data: UINT8PTR, length: sizet,
|
||||
def zdeflate_one_shot(pool: memhub.MemManager*, data: UINT8PTR, length: sizet,
|
||||
level: int, wbits: int, out_len: sizet*) -> uint8*:
|
||||
s: zdeflate_stream* = zdeflate_create(pool, level, wbits, 8, 0)
|
||||
if not s: return None
|
||||
|
||||
+4
-4
@@ -15,7 +15,7 @@ class zhuff_code:
|
||||
|
||||
@t.Object
|
||||
class zhuff_tree:
|
||||
pool: rawptr[memhub.MemManager]
|
||||
pool: memhub.MemManager*
|
||||
codes: t.CArray[zhuff_code, ZHUFF_MAX_CODES]
|
||||
count: int
|
||||
max_bits: int
|
||||
@@ -95,7 +95,7 @@ class zhuff_tree:
|
||||
else:
|
||||
self.codes[i].code = 0
|
||||
|
||||
def encode_symbol(self, symbol: int, writer: rawptr[zdef.zbit_writer]):
|
||||
def encode_symbol(self, symbol: int, writer: zdef.zbit_writer*):
|
||||
if symbol < 0 or symbol >= self.count:
|
||||
return
|
||||
if self.codes[symbol].bits == 0:
|
||||
@@ -304,7 +304,7 @@ class zhuff_decode_node:
|
||||
|
||||
|
||||
class zhuff_decode_tree:
|
||||
pool: rawptr[memhub.MemManager]
|
||||
pool: memhub.MemManager*
|
||||
nodes: t.CArray[zhuff_decode_node, 2 * ZHUFF_MAX_CODES]
|
||||
node_count: int
|
||||
root: int
|
||||
@@ -345,7 +345,7 @@ class zhuff_decode_tree:
|
||||
else:
|
||||
self.nodes[self.nodes[node].children[dir]].symbol = i
|
||||
|
||||
def decode_symbol(self, reader: rawptr[zdef.zbit_reader]) -> int:
|
||||
def decode_symbol(self, reader: zdef.zbit_reader*) -> int:
|
||||
node: int = self.root
|
||||
while self.nodes[node].symbol == -1:
|
||||
bit: uint
|
||||
|
||||
+6
-6
@@ -8,7 +8,7 @@ import t, c
|
||||
|
||||
|
||||
class zinflate_stream:
|
||||
pool: rawptr[memhub.MemManager]
|
||||
pool: memhub.MemManager*
|
||||
reader: zdef.zbit_reader
|
||||
|
||||
window: BYTEPTR
|
||||
@@ -108,7 +108,7 @@ class zinflate_stream:
|
||||
return 0
|
||||
|
||||
|
||||
def read_huffman(self, dt: rawptr[zhuff.zhuff_decode_tree]) -> int:
|
||||
def read_huffman(self, dt: zhuff.zhuff_decode_tree*) -> int:
|
||||
node: int = dt.root
|
||||
while dt.nodes[node].symbol == -1:
|
||||
bit: UINT
|
||||
@@ -141,8 +141,8 @@ class zinflate_stream:
|
||||
lit_tree.build_fixed_lit_tree()
|
||||
dist_tree.build_fixed_dist_tree()
|
||||
|
||||
lit_dt: rawptr[zhuff.zhuff_decode_tree] = zdef.zdef_alloc(self.pool, zhuff.zhuff_decode_tree.__sizeof__())
|
||||
dist_dt: rawptr[zhuff.zhuff_decode_tree] = zdef.zdef_alloc(self.pool, zhuff.zhuff_decode_tree.__sizeof__())
|
||||
lit_dt: zhuff.zhuff_decode_tree* = zdef.zdef_alloc(self.pool, zhuff.zhuff_decode_tree.__sizeof__())
|
||||
dist_dt: zhuff.zhuff_decode_tree* = zdef.zdef_alloc(self.pool, zhuff.zhuff_decode_tree.__sizeof__())
|
||||
if not lit_dt or not dist_dt:
|
||||
if lit_dt: zdef.zdef_free(self.pool, lit_dt)
|
||||
if dist_dt: zdef.zdef_free(self.pool, dist_dt)
|
||||
@@ -430,7 +430,7 @@ class zinflate_stream:
|
||||
zdef.zdef_free(self.pool, self)
|
||||
|
||||
|
||||
def zinflate_one_shot(pool: rawptr[memhub.MemManager], data: UINT8PTR, length: sizet,
|
||||
def zinflate_one_shot(pool: memhub.MemManager*, data: UINT8PTR, length: sizet,
|
||||
wbits: int, bufsize: sizet, out_len: sizet*) -> uint8*:
|
||||
s: zinflate_stream* = zinflate_create(pool, wbits)
|
||||
if not s: return None
|
||||
@@ -441,7 +441,7 @@ def zinflate_one_shot(pool: rawptr[memhub.MemManager], data: UINT8PTR, length: s
|
||||
return out
|
||||
|
||||
|
||||
def zinflate_create(pool: rawptr[memhub.MemManager], wbits: int) -> zinflate_stream*:
|
||||
def zinflate_create(pool: memhub.MemManager*, wbits: int) -> zinflate_stream*:
|
||||
s: zinflate_stream* = zdef.zdef_alloc(pool, zinflate_stream.__sizeof__())
|
||||
if not s: return None
|
||||
string.memset(s, 0, zinflate_stream.__sizeof__())
|
||||
|
||||
Reference in new issue
Block a user