feat(ast): 整型字面量支持显式宽度后缀 _int<N>/_uint<N>/_i<N>/_u<N>

This commit is contained in:
TermiNexus committed 2026-10-12 18:24:54 +08:00
1 parent fb365a1707
commit 94ae0d32b7
4 files changed
+6158 -6085

No files matched your search

+10 -2
View File
@@ -82,11 +82,16 @@ class Constant(ExprNode):
float_val: double
str_val: str
const_kind: int
# 显式整型宽度后缀(_int<N>/_uint<N>):int_width>0 = 声明宽度,0 = 未指定;
# int_unsigned=1 表示 uint 形式。追加在末尾,保持既有字段偏移不变(经 __sizeof__ 分配并 memset)。
int_width: int
int_unsigned: int
def __new__(self, pool: memhub.MemManager*,
const_kind: int, int_val: int64,
float_val: double, str_val: str,
lineno: int, col: int):
lineno: int, col: int,
int_width: int = 0, int_unsigned: int = 0):
ptr: Constant* = pool.alloc(Constant.__sizeof__())
if ptr:
string.memset(ptr, 0, Constant.__sizeof__())
@@ -95,11 +100,14 @@ class Constant(ExprNode):
def __init__(self, pool: memhub.MemManager*,
const_kind: int, int_val: int64,
float_val: double, str_val: str,
lineno: int, col: int):
lineno: int, col: int,
int_width: int = 0, int_unsigned: int = 0):
_init_ast(self, pool, lineno, col)
self.const_kind = const_kind
self.int_val = int_val
self.float_val = float_val
self.int_width = int_width
self.int_unsigned = int_unsigned
if str_val is not None:
self.str_val = _copy_str(pool, str_val)
else:
+1191 -1131
View File
File diff suppressed because it is too large. Load diff
+4950 -4949
View File
File diff suppressed because it is too large. Load diff
+7 -3
View File
@@ -200,6 +200,10 @@ class Token:
end_lineno: int # Ending line number
end_col_offset: int # Ending column offset
next: Token* # Next token in linked list
# 显式整型宽度后缀(_int<N>/_uint<N>/_i<N>/_u<N>):N>0 = 声明宽度,0 = 未指定;
# int_unsigned=1 表示 uint<N> 形式。追加在末尾,保持既有字段偏移不变(Token 经 __sizeof__ 分配并 memset)。
int_width: int
int_unsigned: int
def __new__(self, pool: memhub.MemManager*):
"""Allocate zero‑initialized Token struct memory from mpool"""
@@ -259,7 +263,7 @@ def _kw_index_put(entry: KwEntry*):
h: uint64 = _kw_hash_str(entry.name)
mask: sizet = sizet(_KW_IDX_CAP - 1)
idx: sizet = sizet(h) & mask
for i in range(_KW_IDX_CAP):
for i in range(int(_KW_IDX_CAP)):
slot: sizet* = (sizet*)(t.CPtr(uint64(_kw_index) + uint64(idx * 8)))
cur_s: sizet = slot[0]
if cur_s == 0:
@@ -302,7 +306,7 @@ def _kw_lookup(name: str) -> int:
h: uint64 = _kw_hash_str(name)
mask: sizet = sizet(_KW_IDX_CAP - 1)
idx: sizet = sizet(h) & mask
for i in range(_KW_IDX_CAP):
for i in range(int(_KW_IDX_CAP)):
slot: sizet* = (sizet*)(t.CPtr(uint64(_kw_index) + uint64(idx * 8)))
cur_s: sizet = slot[0]
if cur_s == 0:
@@ -520,7 +524,7 @@ def token_set_str(pool: memhub.MemManager*, tok: Token*,
buf: str = pool.alloc(length + 1)
if buf == None:
_ast_pool_fatal("token.str_val", length + 1)
for i in range(length):
for i in range(int(length)):
buf[i] = src[start + i]
buf[length] = '\0'
tok.str_val = buf