语法侧(M2.4):ast/base.vp 枚举尾部追加 ASTKind.New;ast/exprs.vp 新增 NEW_SRC_*/NEW_LIFE_* 与 class New;ast/parser.vp 新增 _is_new_expr/_parse_new_expr(new 为软关键字,不进 Keyword 表,new=1/new.x/new(1) 仍是标识符);ast/__init__.vp 再导出 New 与常量。 其余为既有 WIP 改动一并快照,保持基线一致(39 文件,+312/-237)。 未纳入:ctraits.vpi(已删除)、ctraits.vpnci、tomllib/(均未跟踪)。
46 lines
1.9 KiB
Plaintext
46 lines
1.9 KiB
Plaintext
# Variant type tags (fixed enumeration + custom pointer type)
|
|
define VARIANT_NONE = 0 # Untyped / null value
|
|
define VARIANT_INT = 1 # int (i64)
|
|
define VARIANT_FLOAT = 2 # float (f32)
|
|
define VARIANT_DOUBLE = 3 # double (f64)
|
|
define VARIANT_STR = 4 # str (i8*)
|
|
define VARIANT_DICT = 5 # dict*
|
|
define VARIANT_LIST = 6 # list*
|
|
define VARIANT_BOOL = 7 # bool (i1/i32)
|
|
define VARIANT_PTR = 8 # Custom pointer type
|
|
|
|
|
|
class Variant:
|
|
"""Generic variant type storing a type tag and untyped pointer.
|
|
Used for universal object storage inside dict/list, supports nesting and JSON serialization.
|
|
|
|
Usage:
|
|
v: Variant = Variant(VARIANT_INT, 42)
|
|
v2: Variant = Variant(VARIANT_STR, "hello")
|
|
|
|
# Retrieve value
|
|
ptr: rawptr = v.ptr
|
|
i: int = *((int*)(ptr)) # int values are stored as i32, so read them back through an int* view
|
|
"""
|
|
vtype: int
|
|
ptr: rawptr
|
|
|
|
def __init__(self, vtype: int, val: &temp void):
|
|
"""Construct Variant instance.
|
|
`&temp void` takes the address of val: non-pointer values are materialized on the
|
|
caller's stack, values that are already pointers are stored as-is.
|
|
Note: The lifecycle of val is managed by the caller; Variant only stores a pointer reference.
|
|
"""
|
|
self.vtype = vtype
|
|
self.ptr = val
|
|
|
|
def is_none(self) -> int: return self.vtype == VARIANT_NONE
|
|
def is_int(self) -> int: return self.vtype == VARIANT_INT
|
|
def is_float(self) -> int: return self.vtype == VARIANT_FLOAT
|
|
def is_double(self) -> int: return self.vtype == VARIANT_DOUBLE
|
|
def is_str(self) -> int: return self.vtype == VARIANT_STR
|
|
def is_dict(self) -> int: return self.vtype == VARIANT_DICT
|
|
def is_list(self) -> int: return self.vtype == VARIANT_LIST
|
|
def is_bool(self) -> int: return self.vtype == VARIANT_BOOL
|
|
def is_ptr(self) -> int: return self.vtype == VARIANT_PTR
|