Rewrote the comments in the libraries under 'includes' in English (excluding those inside folders)
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
# GCC/Clang 内建函数声明
|
||||
# 所有函数均为仅声明(t.State 等价于 CExtern | CExport),由编译器/运行时提供实现
|
||||
# GCC/Clang Built-in Function Declarations
|
||||
# All functions are declared only (t.State equivalent to CExtern | CExport); implementations are provided by compiler/runtime
|
||||
import t
|
||||
|
||||
|
||||
# ============================================================
|
||||
# 随机数生成 (RDRAND / RDSEED)
|
||||
# Random Number Generation (RDRAND / RDSEED)
|
||||
# ============================================================
|
||||
|
||||
def __builtin_ia32_rdrand16_step(p: t.CUInt16T | t.CPtr) -> t.CInt | t.State: pass
|
||||
@@ -16,7 +16,7 @@ def __builtin_ia32_rdseed64_step(p: t.CUInt64T | t.CPtr) -> t.CInt | t.State: pa
|
||||
|
||||
|
||||
# ============================================================
|
||||
# 时间戳计数器 (RDTSC / RDTSCP)
|
||||
# Time-Stamp Counter (RDTSC / RDTSCP)
|
||||
# ============================================================
|
||||
|
||||
def __builtin_ia32_rdtsc() -> t.CUInt64T | t.State: pass
|
||||
@@ -33,7 +33,7 @@ def __builtin_ia32_cpuid_count(level: t.CUInt32T, count: t.CUInt32T, a: t.CUInt3
|
||||
|
||||
|
||||
# ============================================================
|
||||
# 内存屏障 (Fence)
|
||||
# Memory Barriers (Fence)
|
||||
# ============================================================
|
||||
|
||||
def __builtin_ia32_lfence() -> t.State: pass
|
||||
@@ -43,7 +43,7 @@ def __builtin_ia32_pause() -> t.State: pass
|
||||
|
||||
|
||||
# ============================================================
|
||||
# 位操作 (POPCNT / BSF / BSR / TZCNT / LZCNT / BEXTR / PDEP / PEXT / ANDN)
|
||||
# Bit Manipulation (POPCNT / BSF / BSR / TZCNT / LZCNT / BEXTR / PDEP / PEXT / ANDN)
|
||||
# ============================================================
|
||||
|
||||
def __builtin_ia32_popcntsi(x: t.CUInt32T) -> t.CInt | t.State: pass
|
||||
@@ -73,7 +73,7 @@ def __builtin_ia32_andn_di(a: t.CUInt64T, b: t.CUInt64T) -> t.CUInt64T | t.State
|
||||
|
||||
|
||||
# ============================================================
|
||||
# 字节序交换 (BSWAP)
|
||||
# Byte Swap (BSWAP)
|
||||
# ============================================================
|
||||
|
||||
def __builtin_bswap16(x: t.CUInt16T) -> t.CUInt16T | t.State: pass
|
||||
@@ -82,7 +82,7 @@ def __builtin_bswap64(x: t.CUInt64T) -> t.CUInt64T | t.State: pass
|
||||
|
||||
|
||||
# ============================================================
|
||||
# 缓存操作 (Cache)
|
||||
# Cache Operations
|
||||
# ============================================================
|
||||
|
||||
def __builtin_ia32_clflush(p: t.CConst | t.CPtr) -> t.State: pass
|
||||
@@ -92,7 +92,7 @@ def __builtin_ia32_clzero() -> t.State: pass
|
||||
|
||||
|
||||
# ============================================================
|
||||
# 预取 (Prefetch)
|
||||
# Prefetch
|
||||
# ============================================================
|
||||
|
||||
def __builtin_prefetch(addr: t.CConst | t.CPtr, rw: t.CInt = 0, locality: t.CInt = 3) -> t.State: pass
|
||||
@@ -103,7 +103,7 @@ def __builtin_ia32_prefetchnta(p: t.CChar | t.CConst | t.CPtr) -> t.State: pass
|
||||
|
||||
|
||||
# ============================================================
|
||||
# 非临时存储 (Non-Temporal Store)
|
||||
# Non-Temporal Stores
|
||||
# ============================================================
|
||||
|
||||
def __builtin_ia32_movnti(p: t.CUInt32T | t.CPtr, val: t.CUInt32T) -> t.State: pass
|
||||
@@ -114,7 +114,7 @@ def __builtin_ia32_movntpd(p: t.CDouble | t.CPtr, val: t.CDouble) -> t.State: pa
|
||||
|
||||
|
||||
# ============================================================
|
||||
# I/O 端口操作 (Port I/O)
|
||||
# I/O Port Operations
|
||||
# ============================================================
|
||||
|
||||
def __builtin_ia32_inb(port: t.CUInt16T) -> t.CUInt8T | t.State: pass
|
||||
@@ -126,7 +126,7 @@ def __builtin_ia32_outl(val: t.CUInt32T, port: t.CUInt16T) -> t.State: pass
|
||||
|
||||
|
||||
# ============================================================
|
||||
# 模型特定寄存器 (MSR)
|
||||
# Model-Specific Registers (MSR)
|
||||
# ============================================================
|
||||
|
||||
def __builtin_ia32_rdmsr(msr: t.CUInt32T, val: t.CUInt64T | t.CPtr) -> t.State: pass
|
||||
@@ -134,7 +134,7 @@ def __builtin_ia32_wrmsr(msr: t.CUInt32T, val: t.CUInt64T) -> t.State: pass
|
||||
|
||||
|
||||
# ============================================================
|
||||
# 系统指令 (System)
|
||||
# System Instructions
|
||||
# ============================================================
|
||||
|
||||
def __builtin_ia32_hlt() -> t.State: pass
|
||||
@@ -150,7 +150,7 @@ def __builtin_ia32_ud2() -> t.State: pass
|
||||
|
||||
|
||||
# ============================================================
|
||||
# 描述符表 (GDT / IDT / LDT / TR)
|
||||
# Descriptor Tables (GDT / IDT / LDT / TR)
|
||||
# ============================================================
|
||||
|
||||
def __builtin_ia32_lgdt(p: t.CPtr) -> t.State: pass
|
||||
@@ -164,7 +164,7 @@ def __builtin_ia32_str(p: t.CPtr) -> t.State: pass
|
||||
|
||||
|
||||
# ============================================================
|
||||
# 控制寄存器 (CR / MSW)
|
||||
# Control Registers (CR / MSW)
|
||||
# ============================================================
|
||||
|
||||
def __builtin_ia32_lmsw(val: t.CUInt32T) -> t.State: pass
|
||||
@@ -172,7 +172,7 @@ def __builtin_ia32_smsw(p: t.CPtr) -> t.State: pass
|
||||
|
||||
|
||||
# ============================================================
|
||||
# 监控等待 (MONITOR / MWAIT)
|
||||
# Monitor / MWAIT
|
||||
# ============================================================
|
||||
|
||||
def __builtin_ia32_monitor(p: t.CPtr, extensions: t.CUInt32T, hints: t.CUInt32T) -> t.State: pass
|
||||
@@ -180,7 +180,7 @@ def __builtin_ia32_mwait(extensions: t.CUInt32T, hints: t.CUInt32T) -> t.State:
|
||||
|
||||
|
||||
# ============================================================
|
||||
# XSAVE 状态操作
|
||||
# XSAVE State Operations
|
||||
# ============================================================
|
||||
|
||||
def __builtin_ia32_xsave(p: t.CPtr, mask: t.CUInt64T) -> t.State: pass
|
||||
@@ -192,7 +192,7 @@ def __builtin_ia32_xsaves(p: t.CPtr, mask: t.CUInt64T) -> t.State: pass
|
||||
|
||||
|
||||
# ============================================================
|
||||
# 通用内建函数 (Generic Builtins)
|
||||
# Generic Built-in Functions
|
||||
# ============================================================
|
||||
|
||||
def __builtin_expect(exp: t.CLong, c: t.CLong) -> t.CLong | t.State: pass
|
||||
@@ -208,7 +208,7 @@ def __builtin_function_start(func: t.CPtr) -> t.CPtr | t.State: pass
|
||||
|
||||
|
||||
# ============================================================
|
||||
# 可变参数 (VaList)
|
||||
# Variable Arguments (VaList)
|
||||
# ============================================================
|
||||
|
||||
def __builtin_va_start(va: t.CPtr, *args) -> t.State: pass
|
||||
@@ -218,7 +218,7 @@ def __builtin_va_copy(dst: t.CPtr, src: t.CConst | t.CPtr) -> t.State: pass
|
||||
|
||||
|
||||
# ============================================================
|
||||
# 栈与调用信息 (Stack / Frame)
|
||||
# Stack & Call Information
|
||||
# ============================================================
|
||||
|
||||
def __builtin_return_address(level: t.CUInt32T) -> t.CPtr | t.State: pass
|
||||
@@ -228,7 +228,7 @@ def __builtin_alloca_with_align(size: t.CSizeT, alignment: t.CSizeT) -> t.CPtr |
|
||||
|
||||
|
||||
# ============================================================
|
||||
# 内存操作 (Memory)
|
||||
# Memory Operations
|
||||
# ============================================================
|
||||
|
||||
def __builtin_memcpy(dst: t.CPtr, src: t.CConst | t.CPtr, n: t.CSizeT) -> t.CPtr | t.State: pass
|
||||
@@ -240,7 +240,7 @@ def __builtin_memchr(s: t.CConst | t.CPtr, c: t.CInt, n: t.CSizeT) -> t.CPtr | t
|
||||
|
||||
|
||||
# ============================================================
|
||||
# 字符串操作 (String)
|
||||
# String Operations
|
||||
# ============================================================
|
||||
|
||||
def __builtin_strcpy(dst: t.CChar | t.CPtr, src: t.CChar | t.CConst | t.CPtr) -> t.CChar | t.CPtr | t.State: pass
|
||||
@@ -256,7 +256,7 @@ def __builtin_strstr(haystack: t.CChar | t.CConst | t.CPtr, needle: t.CChar | t.
|
||||
|
||||
|
||||
# ============================================================
|
||||
# 数学内建函数 (Math)
|
||||
# Math Built-in Functions
|
||||
# ============================================================
|
||||
|
||||
def __builtin_sqrt(x: t.CDouble) -> t.CDouble | t.State: pass
|
||||
@@ -292,7 +292,7 @@ def __builtin_rint(x: t.CDouble) -> t.CDouble | t.State: pass
|
||||
|
||||
|
||||
# ============================================================
|
||||
# 位计数内建函数 (Bit Counting)
|
||||
# Bit Counting Builtins
|
||||
# ============================================================
|
||||
|
||||
def __builtin_ffs(x: t.CUInt32T) -> t.CInt | t.State: pass
|
||||
@@ -315,7 +315,7 @@ def __builtin_parityll(x: t.CUInt64T) -> t.CInt | t.State: pass
|
||||
|
||||
|
||||
# ============================================================
|
||||
# 对象大小检查 (Object size check)
|
||||
# Object Size Checking
|
||||
# ============================================================
|
||||
|
||||
def __builtin_object_size(ptr: t.CConst | t.CPtr, typ: t.CInt) -> t.CSizeT | t.State: pass
|
||||
@@ -334,7 +334,7 @@ def __builtin___sprintf_chk(s: t.CChar | t.CPtr, flag: t.CInt, slen: t.CSizeT, f
|
||||
|
||||
|
||||
# ============================================================
|
||||
# 浮点分类 (FP Classification)
|
||||
# Floating-Point Classification
|
||||
# ============================================================
|
||||
|
||||
def __builtin_isnan(x: t.CDouble) -> t.CInt | t.State: pass
|
||||
@@ -352,7 +352,7 @@ def __builtin_isunordered(x: t.CDouble, y: t.CDouble) -> t.CInt | t.State: pass
|
||||
|
||||
|
||||
# ============================================================
|
||||
# 特殊值 (Special Values)
|
||||
# Special Floating-Point Values
|
||||
# ============================================================
|
||||
|
||||
def __builtin_nan(s: t.CChar | t.CConst | t.CPtr) -> t.CDouble | t.State: pass
|
||||
@@ -370,7 +370,7 @@ def __builtin_inf_sign() -> t.CInt | t.State: pass
|
||||
|
||||
|
||||
# ============================================================
|
||||
# 类型转换与溢出检查 (Overflow)
|
||||
# Type Conversion & Overflow Checking
|
||||
# ============================================================
|
||||
|
||||
def __builtin_add_overflow(a: t.CUInt64T, b: t.CUInt64T, res: t.CUInt64T | t.CPtr) -> t.CBool | t.State: pass
|
||||
@@ -385,7 +385,7 @@ def __builtin_umul_overflow(a: t.CUInt64T, b: t.CUInt64T, res: t.CUInt64T | t.CP
|
||||
|
||||
|
||||
# ============================================================
|
||||
# MMX / SSE 状态
|
||||
# MMX / SSE State Management
|
||||
# ============================================================
|
||||
|
||||
def __builtin_ia32_emms() -> t.State: pass
|
||||
@@ -393,7 +393,7 @@ def __builtin_ia32_femms() -> t.State: pass
|
||||
|
||||
|
||||
# ============================================================
|
||||
# 排队指令 (ENQCMD)
|
||||
# Enqueue Commands (ENQCMD)
|
||||
# ============================================================
|
||||
|
||||
def __builtin_ia32_enqcmd(dst: t.CPtr, src: t.CConst | t.CPtr) -> t.CBool | t.State: pass
|
||||
@@ -401,7 +401,7 @@ def __builtin_ia32_enqcmds(dst: t.CPtr, src: t.CConst | t.CPtr) -> t.CBool | t.S
|
||||
|
||||
|
||||
# ============================================================
|
||||
# 用户级等待 (UMWAIT / UMONITOR / TPAUSE)
|
||||
# User-Level Monitor & Wait (UMWAIT / UMONITOR / TPAUSE)
|
||||
# ============================================================
|
||||
|
||||
def __builtin_ia32_umonitor(p: t.CPtr) -> t.State: pass
|
||||
@@ -410,7 +410,7 @@ def __builtin_ia32_tpause(extensions: t.CUInt32T, counter: t.CUInt64T) -> t.CUIn
|
||||
|
||||
|
||||
# ============================================================
|
||||
# 访问控制 (CLAC / STAC)
|
||||
# Access Control (CLAC / STAC)
|
||||
# ============================================================
|
||||
|
||||
def __builtin_ia32_clac() -> t.State: pass
|
||||
@@ -418,8 +418,8 @@ def __builtin_ia32_stac() -> t.State: pass
|
||||
|
||||
|
||||
# ============================================================
|
||||
# TLB 无效化 (INVLPG 变体)
|
||||
# TLB Invalidation (INVLPG Variants)
|
||||
# ============================================================
|
||||
|
||||
def __builtin_ia32_invlpgb(aux: t.CUInt64T, pcid: t.CUInt64T) -> t.State: pass
|
||||
def __builtin_ia32_tlbsync() -> t.State: pass
|
||||
def __builtin_ia32_tlbsync() -> t.State: pass
|
||||
@@ -4,8 +4,8 @@ import string
|
||||
import json
|
||||
from stdint import *
|
||||
|
||||
# Variant 类型标签 (与 _variant.py 保持一致)
|
||||
VARIANT_NONE: t.CDefine = 0 # 无类型/空值
|
||||
# Variant type tags (consistent with _variant.py)
|
||||
VARIANT_NONE: t.CDefine = 0 # Untyped / null value
|
||||
VARIANT_INT: t.CDefine = 1 # int (i64)
|
||||
VARIANT_FLOAT: t.CDefine = 2 # float (f32)
|
||||
VARIANT_DOUBLE: t.CDefine = 3 # double (f64)
|
||||
@@ -13,25 +13,25 @@ VARIANT_STR: t.CDefine = 4 # str (i8*)
|
||||
VARIANT_DICT: t.CDefine = 5 # dict*
|
||||
VARIANT_LIST: t.CDefine = 6 # list*
|
||||
VARIANT_BOOL: t.CDefine = 7 # bool (i1/i32)
|
||||
VARIANT_PTR: t.CDefine = 8 # 自定义指针类型
|
||||
VARIANT_PTR: t.CDefine = 8 # Custom pointer type
|
||||
|
||||
# Variant 结构体大小: vtype(i32, 4 bytes) + padding(4 bytes) + ptr(i8*, 8 bytes) = 16 bytes
|
||||
# Variant structure size: vtype(i32, 4 bytes) + padding(4 bytes) + ptr(i8*, 8 bytes) = 16 bytes
|
||||
_VARIANT_SIZE: t.CDefine = 16
|
||||
|
||||
|
||||
class dict:
|
||||
"""堆上动态字典容器,基于 mbuddy 分配器。
|
||||
键类型固定为 str (i8*),值使用 Variant 存储 (类型标签 + 无类型指针)。
|
||||
支持嵌套 dict/list 和 JSON 序列化。
|
||||
"""Heap-allocated dynamic dictionary container based on mbuddy allocator.
|
||||
Key type is fixed to str (i8*), values are stored as Variant (type tag + untyped pointer).
|
||||
Supports nested dict/list structures and JSON serialization.
|
||||
|
||||
用法:
|
||||
Usage:
|
||||
mb: memhub.MemBuddy = memhub.MemBuddy(arena, arena_size)
|
||||
d: dict = dict(mb)
|
||||
d.set_int("x", 42)
|
||||
p: t.CPtr = d["x"]
|
||||
v: int = c.Deref(p)
|
||||
|
||||
# 嵌套 dict
|
||||
# Nested dict
|
||||
inner: dict = dict(mb)
|
||||
inner.set_int("a", 1)
|
||||
d.set_dict("sub", inner)
|
||||
@@ -46,7 +46,7 @@ class dict:
|
||||
__iter_index__: t.CSizeT = 0
|
||||
|
||||
def __new__(self, mb: memhub.MemBuddy | t.CPtr) -> t.CPtr:
|
||||
# 堆分配 dict 对象
|
||||
# Heap allocation for dict object
|
||||
return mb.alloc(dict.__sizeof__())
|
||||
|
||||
def __init__(self, mb: memhub.MemBuddy | t.CPtr):
|
||||
@@ -58,32 +58,32 @@ class dict:
|
||||
return self.__count__
|
||||
|
||||
def _find(self, key: str) -> t.CSizeT:
|
||||
"""查找 key 的索引,找不到返回 __count__"""
|
||||
"""Find index of target key; returns __count__ if not found"""
|
||||
for i in range(self.__count__):
|
||||
key_ptr: str | t.CPtr = t.CPtr(t.CUInt64T(self.__keys__) + i * 8)
|
||||
if key_ptr[0] == key: return i
|
||||
return self.__count__
|
||||
|
||||
def __getitem__(self, key: str) -> t.CPtr:
|
||||
"""返回值的无类型指针。用户用 c.Deref 解引用获取实际值。
|
||||
例: p: t.CPtr = d["x"]; v: int = c.Deref(p)"""
|
||||
"""Return untyped pointer to value. Use c.Deref to resolve the actual value.
|
||||
Example: p: t.CPtr = d["x"]; v: int = c.Deref(p)"""
|
||||
idx: t.CSizeT = self._find(key)
|
||||
if idx >= self.__count__: return None
|
||||
# Variant.ptr 在 Variant 结构体偏移 8 处
|
||||
# Variant.ptr is located at offset 8 within Variant structure
|
||||
val_ptr: str | t.CPtr = t.CPtr(t.CUInt64T(self.__values__) + idx * _VARIANT_SIZE + 8)
|
||||
return val_ptr[0]
|
||||
|
||||
def __setitem__(self, key: str, val: t.CNeedPtr):
|
||||
"""存储值为 VARIANT_PTR。val 自动取地址 (t.CNeedPtr)。
|
||||
注意: val 指向的值生命周期由调用者管理。
|
||||
如需持久存储,请使用 set_int / set_str 等类型化方法。"""
|
||||
"""Store value as VARIANT_PTR. Address is automatically resolved via t.CNeedPtr.
|
||||
Note: Lifecycle of the data pointed to by val is managed by caller.
|
||||
Use typed methods such as set_int / set_str for persistent storage."""
|
||||
self._set_variant_raw(key, VARIANT_PTR, val)
|
||||
|
||||
def _set_variant_raw(self, key: str, vtype: t.CInt, ptr: t.CPtr):
|
||||
"""内部方法: 存储 Variant (vtype + ptr)。不自动取地址。"""
|
||||
"""Internal method: store Variant entry (vtype + ptr). No automatic address resolution."""
|
||||
idx: t.CSizeT = self._find(key)
|
||||
if idx < self.__count__:
|
||||
# 更新已有键
|
||||
# Update existing key
|
||||
vtype_ptr: t.CInt | t.CPtr = t.CPtr(t.CUInt64T(self.__values__) + idx * _VARIANT_SIZE)
|
||||
vtype_ptr[0] = vtype
|
||||
val_ptr: str | t.CPtr = t.CPtr(t.CUInt64T(self.__values__) + idx * _VARIANT_SIZE + 8)
|
||||
@@ -108,55 +108,55 @@ class dict:
|
||||
self.__count__ += 1
|
||||
|
||||
# ============================================================
|
||||
# 类型化 setter — 在 __mbuddy__ 中分配持久存储
|
||||
# Typed setters — allocate persistent storage inside __mbuddy__
|
||||
# ============================================================
|
||||
|
||||
def set_int(self, key: str, val: int):
|
||||
"""存储 int 值 (VARIANT_INT)。值复制到 __mbuddy__ 持久存储。"""
|
||||
"""Store integer value (VARIANT_INT). Value is copied to persistent storage within __mbuddy__."""
|
||||
storage: t.CPtr = self.__mbuddy__.alloc(8)
|
||||
int_ptr: int | t.CPtr = t.CVoid(t.CUInt64T(storage), t.CPtr)
|
||||
int_ptr[0] = val
|
||||
self._set_variant_raw(key, VARIANT_INT, storage)
|
||||
|
||||
def set_str(self, key: str, val: str):
|
||||
"""存储 str 值 (VARIANT_STR)。直接存储字符串指针。"""
|
||||
"""Store string value (VARIANT_STR). Raw string pointer is stored directly."""
|
||||
self._set_variant_raw(key, VARIANT_STR, val)
|
||||
|
||||
def set_float(self, key: str, val: float):
|
||||
"""存储 float 值 (VARIANT_FLOAT)。值复制到 __mbuddy__ 持久存储。"""
|
||||
"""Store float value (VARIANT_FLOAT). Value is copied to persistent storage within __mbuddy__."""
|
||||
storage: t.CPtr = self.__mbuddy__.alloc(8)
|
||||
float_ptr: float | t.CPtr = t.CVoid(t.CUInt64T(storage), t.CPtr)
|
||||
float_ptr[0] = val
|
||||
self._set_variant_raw(key, VARIANT_FLOAT, storage)
|
||||
|
||||
def set_double(self, key: str, val: t.CDouble):
|
||||
"""存储 double 值 (VARIANT_DOUBLE)。值复制到 __mbuddy__ 持久存储。"""
|
||||
"""Store double value (VARIANT_DOUBLE). Value is copied to persistent storage within __mbuddy__."""
|
||||
storage: t.CPtr = self.__mbuddy__.alloc(8)
|
||||
dbl_ptr: t.CDouble | t.CPtr = t.CVoid(t.CUInt64T(storage), t.CPtr)
|
||||
dbl_ptr[0] = val
|
||||
self._set_variant_raw(key, VARIANT_DOUBLE, storage)
|
||||
|
||||
def set_dict(self, key: str, val: dict | t.CPtr):
|
||||
"""存储嵌套 dict 指针 (VARIANT_DICT)。"""
|
||||
"""Store nested dictionary pointer (VARIANT_DICT)."""
|
||||
self._set_variant_raw(key, VARIANT_DICT, val)
|
||||
|
||||
def set_list(self, key: str, val: t.CPtr):
|
||||
"""存储嵌套 list 指针 (VARIANT_LIST)。"""
|
||||
"""Store nested list pointer (VARIANT_LIST)."""
|
||||
self._set_variant_raw(key, VARIANT_LIST, val)
|
||||
|
||||
def set_bool(self, key: str, val: t.CInt):
|
||||
"""存储 bool 值 (VARIANT_BOOL)。值复制到 __mbuddy__ 持久存储。"""
|
||||
"""Store boolean value (VARIANT_BOOL). Value is copied to persistent storage within __mbuddy__."""
|
||||
storage: t.CPtr = self.__mbuddy__.alloc(8)
|
||||
bool_ptr: t.CInt | t.CPtr = t.CVoid(t.CUInt64T(storage), t.CPtr)
|
||||
bool_ptr[0] = val
|
||||
self._set_variant_raw(key, VARIANT_BOOL, storage)
|
||||
|
||||
# ============================================================
|
||||
# 查询方法
|
||||
# Query methods
|
||||
# ============================================================
|
||||
|
||||
def get_vtype(self, key: str) -> t.CInt:
|
||||
"""返回 key 对应值的 Variant 类型标签。"""
|
||||
"""Return Variant type tag associated with specified key."""
|
||||
idx: t.CSizeT = self._find(key)
|
||||
if idx >= self.__count__:
|
||||
return VARIANT_NONE
|
||||
@@ -164,7 +164,7 @@ class dict:
|
||||
return vtype_ptr[0]
|
||||
|
||||
def get(self, key: str, default: t.CPtr) -> t.CPtr:
|
||||
"""返回值指针,不存在则返回 default。"""
|
||||
"""Return value pointer; return default pointer if key does not exist."""
|
||||
idx: t.CSizeT = self._find(key)
|
||||
if idx >= self.__count__:
|
||||
return default
|
||||
@@ -172,7 +172,7 @@ class dict:
|
||||
return val_ptr[0]
|
||||
|
||||
def contains(self, key: str) -> t.CInt:
|
||||
"""检查 key 是否存在。"""
|
||||
"""Check whether target key exists."""
|
||||
idx: t.CSizeT = self._find(key)
|
||||
if idx < self.__count__:
|
||||
return 1
|
||||
@@ -191,12 +191,12 @@ class dict:
|
||||
return key_ptr[0]
|
||||
|
||||
# ============================================================
|
||||
# JSON 处理:利用 includes/json 库实现序列化/反序列化
|
||||
# JSON utilities: serialization / deserialization via includes/json library
|
||||
# ============================================================
|
||||
|
||||
def to_json(self, pool: memhub.MemManager | t.CPtr) -> json.JsonValue | t.CPtr:
|
||||
"""将 dict 转换为 JsonValue 对象 (JSON_OBJECT)。
|
||||
根据 Variant 类型标签自动选择合适的 JSON 值类型。"""
|
||||
"""Convert dict instance to JsonValue object (JSON_OBJECT).
|
||||
Automatically select corresponding JSON value type according to Variant tag."""
|
||||
obj: json.JsonValue | t.CPtr = json.object(pool)
|
||||
i: t.CSizeT = 0
|
||||
while i < self.__count__:
|
||||
@@ -223,7 +223,7 @@ class dict:
|
||||
fp: float | t.CPtr = t.CVoid(t.CUInt64T(vp), t.CPtr)
|
||||
jv.float_val = fp[0]
|
||||
elif vt == VARIANT_PTR:
|
||||
# 默认: 将 PTR 作为整数处理
|
||||
# Fallback: treat raw pointer as integer
|
||||
jv.vtype = 2 # JSON_INT
|
||||
ip: int | t.CPtr = t.CVoid(t.CUInt64T(vp), t.CPtr)
|
||||
jv.int_val = ip[0]
|
||||
@@ -232,8 +232,8 @@ class dict:
|
||||
return obj
|
||||
|
||||
def from_json(self, pool: memhub.MemManager | t.CPtr, root: json.JsonValue | t.CPtr):
|
||||
"""从 JsonValue 对象填充 dict。
|
||||
根据 JSON 值类型自动提取并存储为对应 Variant 类型。"""
|
||||
"""Populate dict from JsonValue object.
|
||||
Extract values and store them as matching Variant types based on JSON type tag."""
|
||||
if root == None:
|
||||
return
|
||||
if root.vtype != 6: # JSON_OBJECT
|
||||
@@ -261,11 +261,11 @@ class dict:
|
||||
cur = cur.next
|
||||
|
||||
def dumps(self, pool: memhub.MemManager | t.CPtr) -> str:
|
||||
"""将 dict 序列化为 JSON 字符串。"""
|
||||
"""Serialize dict to JSON string."""
|
||||
obj: json.JsonValue | t.CPtr = self.to_json(pool)
|
||||
return json.write(pool, obj, False)
|
||||
|
||||
def loads(self, pool: memhub.MemManager | t.CPtr, json_str: str):
|
||||
"""从 JSON 字符串解析并填充 dict。"""
|
||||
"""Parse JSON string and populate dict instance."""
|
||||
root: json.JsonValue | t.CPtr = json.parse(pool, json_str)
|
||||
self.from_json(pool, root)
|
||||
|
||||
@@ -9,7 +9,8 @@ class _Type:
|
||||
|
||||
|
||||
class _str:
|
||||
# 编译期元数据:声明此类希望从 with 上下文获取 __mbuddy__ 字段(非必要,找不到不报错)
|
||||
# Compile-time metadata: declares that this class attempts to retrieve the __mbuddy__ field from the with context
|
||||
# (optional; no error will be raised if the field cannot be located)
|
||||
__requires__: list[str] = ['__mbuddy__']
|
||||
__data__: str
|
||||
__mbuddy__: memhub.MemBuddy | t.CPtr
|
||||
|
||||
@@ -5,15 +5,15 @@ from stdint import *
|
||||
|
||||
|
||||
class list[T]:
|
||||
"""堆上动态列表容器,基于 memhub.MemManager 多态分配器。
|
||||
"""Heap-allocated dynamic list container backed by memhub.MemManager polymorphic allocator.
|
||||
|
||||
用法:
|
||||
Usage:
|
||||
pool: memhub.MemManager = memhub.MemBuddy(arena, arena_size)
|
||||
nums: list[int] = list[int](pool)
|
||||
nums.append(42)
|
||||
x: int = nums.get(0)
|
||||
|
||||
对于指针类型(如 AST | t.CPtr),传 elem_size=8 避免对象切片:
|
||||
For pointer types (e.g. AST | t.CPtr), pass elem_size=8 to avoid object slicing:
|
||||
lst: list[AST | t.CPtr] = list[AST | t.CPtr](pool, 8)
|
||||
"""
|
||||
__data__: t.CVoid | t.CPtr
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import t, c
|
||||
from stdint import *
|
||||
|
||||
# Variant 类型标签 (固定枚举 + 自定义 PTR)
|
||||
VARIANT_NONE: t.CDefine = 0 # 无类型/空值
|
||||
# Variant type tags (fixed enumeration + custom pointer type)
|
||||
VARIANT_NONE: t.CDefine = 0 # Untyped / null value
|
||||
VARIANT_INT: t.CDefine = 1 # int (i64)
|
||||
VARIANT_FLOAT: t.CDefine = 2 # float (f32)
|
||||
VARIANT_DOUBLE: t.CDefine = 3 # double (f64)
|
||||
@@ -10,55 +10,55 @@ VARIANT_STR: t.CDefine = 4 # str (i8*)
|
||||
VARIANT_DICT: t.CDefine = 5 # dict*
|
||||
VARIANT_LIST: t.CDefine = 6 # list*
|
||||
VARIANT_BOOL: t.CDefine = 7 # bool (i1/i32)
|
||||
VARIANT_PTR: t.CDefine = 8 # 自定义指针类型
|
||||
VARIANT_PTR: t.CDefine = 8 # Custom pointer type
|
||||
|
||||
|
||||
class Variant:
|
||||
"""通用变体类型,存储类型标签 + 无类型指针。
|
||||
用于 dict/list 的万能对象存储,支持嵌套和 JSON 序列化。
|
||||
"""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, t.CNeedPtr(42))
|
||||
v2: Variant = Variant(VARIANT_STR, t.CNeedPtr("hello"))
|
||||
|
||||
# 获取值
|
||||
# Retrieve value
|
||||
ptr: t.CPtr = v.ptr
|
||||
i: int = c.Deref(ptr)
|
||||
"""
|
||||
vtype: t.CInt
|
||||
vtype: int
|
||||
ptr: t.CPtr
|
||||
|
||||
def __init__(self, vtype: t.CInt, val: t.CNeedPtr):
|
||||
"""构造 Variant。
|
||||
val 使用 t.CNeedPtr 自动取地址(非指针值自动 alloca+store)。
|
||||
注意: val 的生命周期由调用者管理,Variant 仅存储指针。
|
||||
def __init__(self, vtype: int, val: t.CNeedPtr):
|
||||
"""Construct Variant instance.
|
||||
t.CNeedPtr automatically obtains address of val (non-pointer values will be allocated on stack and stored).
|
||||
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) -> t.CInt:
|
||||
def is_none(self) -> int:
|
||||
return self.vtype == VARIANT_NONE
|
||||
|
||||
def is_int(self) -> t.CInt:
|
||||
def is_int(self) -> int:
|
||||
return self.vtype == VARIANT_INT
|
||||
|
||||
def is_float(self) -> t.CInt:
|
||||
def is_float(self) -> int:
|
||||
return self.vtype == VARIANT_FLOAT
|
||||
|
||||
def is_double(self) -> t.CInt:
|
||||
def is_double(self) -> int:
|
||||
return self.vtype == VARIANT_DOUBLE
|
||||
|
||||
def is_str(self) -> t.CInt:
|
||||
def is_str(self) -> int:
|
||||
return self.vtype == VARIANT_STR
|
||||
|
||||
def is_dict(self) -> t.CInt:
|
||||
def is_dict(self) -> int:
|
||||
return self.vtype == VARIANT_DICT
|
||||
|
||||
def is_list(self) -> t.CInt:
|
||||
def is_list(self) -> int:
|
||||
return self.vtype == VARIANT_LIST
|
||||
|
||||
def is_bool(self) -> t.CInt:
|
||||
def is_bool(self) -> int:
|
||||
return self.vtype == VARIANT_BOOL
|
||||
|
||||
def is_ptr(self) -> t.CInt:
|
||||
def is_ptr(self) -> int:
|
||||
return self.vtype == VARIANT_PTR
|
||||
|
||||
@@ -6,31 +6,31 @@ import stdio
|
||||
import string
|
||||
|
||||
|
||||
# 最大提供者栈深度(编译器会检查是否够用,不够再往上提)
|
||||
# Maximum provider stack depth (compiler verifies sufficiency; increase if needed)
|
||||
_MAX_PROVIDER_DEPTH: t.CDefine = 32
|
||||
|
||||
|
||||
@t.Object
|
||||
class _ProviderStack:
|
||||
"""提供者栈,存储字段名和指针对。"""
|
||||
"""Provider stack, stores pairs of field names and pointers."""
|
||||
names: t.CArray[VOIDPTR, 32]
|
||||
ptrs: t.CArray[VOIDPTR, 32]
|
||||
top: UINT64
|
||||
|
||||
|
||||
# TLS 索引(全局,所有线程共享同一个索引)
|
||||
# TLS index (global; all threads share the same index)
|
||||
_tls_index: ULONG = 0
|
||||
|
||||
|
||||
@t.TLS
|
||||
def _init_tls():
|
||||
"""初始化 TLS 索引(一次性执行,后续调用跳过)。"""
|
||||
"""Initialize TLS index (executes once; subsequent calls are skipped)."""
|
||||
global _tls_index
|
||||
_tls_index = TlsAlloc()
|
||||
|
||||
|
||||
def _get_stack() -> _ProviderStack | t.CPtr:
|
||||
"""获取当前线程的提供者栈,不存在则分配。"""
|
||||
"""Obtain current thread's provider stack. Allocate one if none exists."""
|
||||
_init_tls()
|
||||
stack: _ProviderStack | t.CPtr = TlsGetValue(_tls_index)
|
||||
if stack == None:
|
||||
@@ -41,7 +41,7 @@ def _get_stack() -> _ProviderStack | t.CPtr:
|
||||
|
||||
|
||||
def _push_provider(field_name: str, ptr: t.CPtr):
|
||||
"""压入提供者 (field_name, ptr) 到栈中。"""
|
||||
"""Push a provider (field_name, ptr) onto the stack."""
|
||||
stack: _ProviderStack | t.CPtr = _get_stack()
|
||||
if stack.top >= _MAX_PROVIDER_DEPTH:
|
||||
stdio.printf("[with] ERROR: provider stack overflow (depth=%lu, max=%d), field '%s' not injected\n", stack.top, _MAX_PROVIDER_DEPTH, field_name)
|
||||
@@ -52,16 +52,17 @@ def _push_provider(field_name: str, ptr: t.CPtr):
|
||||
|
||||
|
||||
def _pop_provider():
|
||||
"""弹出栈顶提供者。"""
|
||||
"""Pop the top provider entry from the stack."""
|
||||
stack: _ProviderStack | t.CPtr = _get_stack()
|
||||
if stack.top > 0:
|
||||
stack.top = stack.top - 1
|
||||
|
||||
|
||||
def _find_provider(field_name: str) -> t.CPtr:
|
||||
"""从栈顶向下查找匹配 field_name 的提供者,返回对应的指针。找不到返回 NULL。"""
|
||||
"""Search for matching field_name starting from stack top.
|
||||
Return associated pointer, or NULL if no match found."""
|
||||
stack: _ProviderStack | t.CPtr = _get_stack()
|
||||
for i in range(stack.top - 1, -1, -1):
|
||||
if stack.names[i] == field_name:
|
||||
return stack.ptrs[i]
|
||||
return None
|
||||
return None
|
||||
@@ -1,5 +1,4 @@
|
||||
import t, c
|
||||
from stdint import *
|
||||
import string
|
||||
import memhub
|
||||
import stdio
|
||||
@@ -7,9 +6,9 @@ import hashtable
|
||||
|
||||
|
||||
# ============================================================
|
||||
# argparse.py — 命令行参数解析库(Python argparse 风格)
|
||||
# argparse.vp — Command line argument parsing library, inspired by Python argparse
|
||||
#
|
||||
# 用法:
|
||||
# Usage:
|
||||
# argparse._mbuddy = mb
|
||||
# parser = argparse.ArgumentParser("myprog", "A test", pool=mb)
|
||||
# parser.add_argument("--input", "-i", arg_type=argparse.STRING,
|
||||
@@ -23,49 +22,49 @@ import hashtable
|
||||
# args = parser.parse_args(argc, argv)
|
||||
# if args is not None:
|
||||
# inp: str = args.get_str("input")
|
||||
# cnt: INT = args.get_int("count")
|
||||
# cnt: int = args.get_int("count")
|
||||
# verb: bool = args.get_bool("verbose")
|
||||
# out: str = args.get_str("output")
|
||||
# argparse.release(args)
|
||||
# ============================================================
|
||||
|
||||
# 类型常量
|
||||
# Type constants
|
||||
STRING: t.CDefine = 0
|
||||
INT: t.CDefine = 1
|
||||
BOOL: t.CDefine = 2
|
||||
|
||||
# 动作常量
|
||||
# Action constants
|
||||
STORE: t.CDefine = 0
|
||||
STORE_TRUE: t.CDefine = 1
|
||||
STORE_FALSE: t.CDefine = 2
|
||||
COUNT: t.CDefine = 3
|
||||
|
||||
# 限制
|
||||
# Limits
|
||||
MAX_ARGS: t.CDefine = 32
|
||||
|
||||
# 模块级 mbuddy 指针(由用户在 main 中赋值)
|
||||
# Module-level membuddy pointer (assigned inside main by user)
|
||||
_mbuddy: memhub.MemBuddy | t.CPtr
|
||||
|
||||
|
||||
# ============================================================
|
||||
# Argument — 参数定义结构体
|
||||
# Argument — Argument definition structure
|
||||
# ============================================================
|
||||
|
||||
class Argument:
|
||||
name: str # "--input" 或 "output"(位置参数)
|
||||
short_name: str # "-i" 或 None
|
||||
help_text: str # 帮助文本
|
||||
arg_type: INT # STRING, INT, BOOL
|
||||
action: INT # STORE, STORE_TRUE, STORE_FALSE, COUNT
|
||||
default_int: INT # INT 类型默认值
|
||||
default_str: str # STRING 类型默认值
|
||||
required: bool # 是否必须
|
||||
is_positional: bool # 是否位置参数
|
||||
dest: str # 查找键名("--input" → "input")
|
||||
name: str # "--input" or positional "output"
|
||||
short_name: str # "-i" or null
|
||||
help_text: str # Help description text
|
||||
arg_type: int # STRING, INT, BOOL
|
||||
action: int # STORE, STORE_TRUE, STORE_FALSE, COUNT
|
||||
default_int: int # Default value for integer types
|
||||
default_str: str # Default value for string types
|
||||
required: bool # Whether this argument is mandatory
|
||||
is_positional: bool # True for positional parameters
|
||||
dest: str # Lookup key ("--input" → "input")
|
||||
|
||||
|
||||
# ============================================================
|
||||
# ParsedArgs — 解析结果
|
||||
# ParsedArgs — Parsing result container
|
||||
# ============================================================
|
||||
|
||||
class ParsedArgs:
|
||||
@@ -80,30 +79,33 @@ class ParsedArgs:
|
||||
self._ht = hashtable.HashTable(mb)
|
||||
|
||||
def get_str(self, name: str) -> str:
|
||||
"""获取字符串值。键不存在返回 None。"""
|
||||
if self._ht.__contains__(name) == 0: return None
|
||||
"""Fetch string value. Returns None if key not found."""
|
||||
if self._ht.__contains__(name) == 0:
|
||||
return None
|
||||
return self._ht[name]
|
||||
|
||||
def get_int(self, name: str) -> INT:
|
||||
"""获取整数值。键不存在返回 0。"""
|
||||
if self._ht.__contains__(name) == 0: return 0
|
||||
def get_int(self, name: str) -> int:
|
||||
"""Fetch integer value. Returns 0 if key not found."""
|
||||
if self._ht.__contains__(name) == 0:
|
||||
return 0
|
||||
ptr: t.CPtr = self._ht[name]
|
||||
return c.Deref(t.CInt(t.CUInt64T(ptr), t.CPtr))
|
||||
|
||||
def get_bool(self, name: str) -> INT:
|
||||
"""获取布尔值(返回 1 或 0)。键不存在返回 0。"""
|
||||
if self._ht.__contains__(name) == 0: return 0
|
||||
def get_bool(self, name: str) -> bool:
|
||||
"""Fetch boolean value. Returns false if key not found."""
|
||||
if self._ht.__contains__(name) == 0:
|
||||
return False
|
||||
ptr: t.CPtr = self._ht[name]
|
||||
return 1 if c.Deref(t.CInt(t.CUInt64T(ptr), t.CPtr)) != 0 else 0
|
||||
return c.Deref(t.CInt(t.CUInt64T(ptr), t.CPtr)) != 0
|
||||
|
||||
def has(self, name: str) -> bool:
|
||||
"""检查键是否存在。"""
|
||||
"""Check whether specified key exists."""
|
||||
return self._ht.__contains__(name) != 0
|
||||
|
||||
def _set_str(self, name: str, val: str):
|
||||
self._ht.set_str(name, val)
|
||||
|
||||
def _set_int(self, name: str, val: INT):
|
||||
def _set_int(self, name: str, val: int):
|
||||
self._ht.set_int(name, val)
|
||||
|
||||
def _set_bool(self, name: str, val: bool):
|
||||
@@ -114,21 +116,22 @@ class ParsedArgs:
|
||||
|
||||
|
||||
# ============================================================
|
||||
# ArgumentParser — 命令行参数解析器
|
||||
# ArgumentParser — Command line argument parser
|
||||
# ============================================================
|
||||
|
||||
class ArgumentParser:
|
||||
_prog: str
|
||||
_description: str
|
||||
_args: Argument | t.CPtr
|
||||
_arg_count: INT
|
||||
_arg_count: int
|
||||
__mbuddy__: memhub.MemBuddy | t.CPtr
|
||||
|
||||
def __new__(self, prog: str = "", description: str = "",
|
||||
pool: memhub.MemBuddy | t.CPtr = None) -> t.CPtr:
|
||||
stdio.printf("[DBG-argparse] __new__ enter pool=%p\n", pool)
|
||||
mb: memhub.MemBuddy | t.CPtr = pool
|
||||
if mb is None: mb = _mbuddy
|
||||
if mb is None:
|
||||
mb = _mbuddy
|
||||
stdio.printf("[DBG-argparse] __new__ mb=%p\n", mb)
|
||||
ret: t.CPtr = mb.alloc(40)
|
||||
stdio.printf("[DBG-argparse] __new__ ret=%p\n", ret)
|
||||
@@ -138,7 +141,8 @@ class ArgumentParser:
|
||||
pool: memhub.MemBuddy | t.CPtr = None):
|
||||
stdio.printf("[DBG-argparse] __init__ enter self=%p pool=%p\n", self, pool)
|
||||
mb: memhub.MemBuddy | t.CPtr = pool
|
||||
if mb is None: mb = _mbuddy
|
||||
if mb is None:
|
||||
mb = _mbuddy
|
||||
stdio.printf("[DBG-argparse] __init__ mb=%p\n", mb)
|
||||
self.__mbuddy__ = mb
|
||||
self._prog = prog
|
||||
@@ -149,24 +153,25 @@ class ArgumentParser:
|
||||
stdio.printf("[DBG-argparse] __init__ after alloc _args=%p\n", self._args)
|
||||
|
||||
def add_argument(self, name: str = "", short: str = None,
|
||||
arg_type: INT = 0, default: INT = 0,
|
||||
arg_type: int = 0, default: int = 0,
|
||||
default_str: str = None, required: bool = False,
|
||||
action: INT = 0, help: str = None):
|
||||
"""注册一个命令行参数。
|
||||
action: int = 0, help: str = None):
|
||||
"""Register a command line argument.
|
||||
|
||||
Args:
|
||||
name: 参数名("--input" 或 "output")
|
||||
short: 短选项("-i"),可选
|
||||
arg_type: 类型(STRING/INT/BOOL)
|
||||
default: INT 默认值
|
||||
default_str: STRING 默认值
|
||||
required: 是否必须
|
||||
action: 动作(STORE/STORE_TRUE/STORE_FALSE/COUNT)
|
||||
help: 帮助文本
|
||||
name: Argument name ("--input" or positional "output")
|
||||
short: Short option ("-i"), optional
|
||||
arg_type: Data type (STRING/INT/BOOL)
|
||||
default: Default integer value
|
||||
default_str: Default string value
|
||||
required: Mandatory flag
|
||||
action: Action mode (STORE/STORE_TRUE/STORE_FALSE/COUNT)
|
||||
help: Help description text
|
||||
"""
|
||||
stdio.printf("[DBG-argparse] enter add_argument name=%s args_ptr=%p\n", name, self._args)
|
||||
if self._arg_count >= MAX_ARGS: return
|
||||
idx: INT = self._arg_count
|
||||
if self._arg_count >= MAX_ARGS:
|
||||
return
|
||||
idx: int = self._arg_count
|
||||
stdio.printf("[DBG-argparse] idx=%d sizeof(Argument)=%d\n", idx, Argument.__sizeof__())
|
||||
arg: Argument | t.CPtr = t.CPtr(t.CUInt64T(self._args) + idx * Argument.__sizeof__())
|
||||
stdio.printf("[DBG-argparse] arg ptr=%p\n", arg)
|
||||
@@ -180,7 +185,7 @@ class ArgumentParser:
|
||||
arg.default_str = default_str
|
||||
arg.required = required
|
||||
stdio.printf("[DBG-argparse] before dest logic\n")
|
||||
# 判断是否位置参数
|
||||
# Determine positional flag
|
||||
if name is not None and name[0] != '-':
|
||||
arg.is_positional = True
|
||||
arg.dest = name
|
||||
@@ -194,12 +199,12 @@ class ArgumentParser:
|
||||
self._arg_count = idx + 1
|
||||
stdio.printf("[DBG-argparse] exit add_argument\n")
|
||||
|
||||
def _get_arg(self, idx: INT) -> Argument | t.CPtr:
|
||||
def _get_arg(self, idx: int) -> Argument | t.CPtr:
|
||||
return t.CPtr(t.CUInt64T(self._args) + idx * Argument.__sizeof__())
|
||||
|
||||
def _find_long(self, token: str) -> INT:
|
||||
"""精确匹配长选项名"""
|
||||
i: INT = 0
|
||||
def _find_long(self, token: str) -> int:
|
||||
"""Exact match for long option name"""
|
||||
i: int = 0
|
||||
while i < self._arg_count:
|
||||
arg: Argument | t.CPtr = self._get_arg(i)
|
||||
if string.strcmp(arg.name, token) == 0:
|
||||
@@ -207,20 +212,20 @@ class ArgumentParser:
|
||||
i += 1
|
||||
return -1
|
||||
|
||||
def _find_long_prefix(self, token: str) -> INT:
|
||||
"""匹配 --name=value 中的 name 前缀"""
|
||||
i: INT = 0
|
||||
def _find_long_prefix(self, token: str) -> int:
|
||||
"""Match prefix for --name=value syntax"""
|
||||
i: int = 0
|
||||
while i < self._arg_count:
|
||||
arg: Argument | t.CPtr = self._get_arg(i)
|
||||
name_len: INT = string.strlen(arg.name)
|
||||
name_len: int = string.strlen(arg.name)
|
||||
if string.strncmp(token, arg.name, name_len) == 0:
|
||||
if token[name_len] == '=':
|
||||
return i
|
||||
i += 1
|
||||
return -1
|
||||
|
||||
def _find_short(self, token: str) -> INT:
|
||||
i: INT = 0
|
||||
def _find_short(self, token: str) -> int:
|
||||
i: int = 0
|
||||
while i < self._arg_count:
|
||||
arg: Argument | t.CPtr = self._get_arg(i)
|
||||
if arg.short_name is not None:
|
||||
@@ -229,9 +234,9 @@ class ArgumentParser:
|
||||
i += 1
|
||||
return -1
|
||||
|
||||
def _find_positional(self, pos_idx: INT) -> INT:
|
||||
count: INT = 0
|
||||
i: INT = 0
|
||||
def _find_positional(self, pos_idx: int) -> int:
|
||||
count: int = 0
|
||||
i: int = 0
|
||||
while i < self._arg_count:
|
||||
arg: Argument | t.CPtr = self._get_arg(i)
|
||||
if arg.is_positional:
|
||||
@@ -248,11 +253,8 @@ class ArgumentParser:
|
||||
elif arg.arg_type == STRING:
|
||||
args._set_str(arg.dest, value)
|
||||
elif arg.arg_type == BOOL:
|
||||
v: INT = string.atoi(value)
|
||||
if v != 0:
|
||||
args._set_bool(arg.dest, True)
|
||||
else:
|
||||
args._set_bool(arg.dest, False)
|
||||
v: int = string.atoi(value)
|
||||
args._set_bool(arg.dest, v != 0)
|
||||
|
||||
def _apply_action(self, args: ParsedArgs | t.CPtr, arg: Argument | t.CPtr):
|
||||
if arg.action == STORE_TRUE:
|
||||
@@ -260,25 +262,27 @@ class ArgumentParser:
|
||||
elif arg.action == STORE_FALSE:
|
||||
args._set_bool(arg.dest, False)
|
||||
elif arg.action == COUNT:
|
||||
cur: INT = args.get_int(arg.dest)
|
||||
cur: int = args.get_int(arg.dest)
|
||||
args._set_int(arg.dest, cur + 1)
|
||||
|
||||
def parse_args(self, argc: INT, argv: str | t.CPtr) -> ParsedArgs | t.CPtr:
|
||||
"""解析命令行参数。
|
||||
def parse_args(self, argc: int, argv: str | t.CPtr) -> ParsedArgs | t.CPtr:
|
||||
"""Parse command line arguments.
|
||||
|
||||
Args:
|
||||
argc: 参数个数
|
||||
argv: 参数数组(char**,argv[0] 为程序名)
|
||||
argc: Argument count
|
||||
argv: Argument array (char**, argv[0] = program name)
|
||||
Returns:
|
||||
ParsedArgs 指针,失败返回 None
|
||||
Pointer to ParsedArgs; returns None on failure
|
||||
"""
|
||||
if self.__mbuddy__ is None: return None
|
||||
if self.__mbuddy__ is None:
|
||||
return None
|
||||
|
||||
args: ParsedArgs | t.CPtr = ParsedArgs(self.__mbuddy__)
|
||||
if args is None: return None
|
||||
if args is None:
|
||||
return None
|
||||
|
||||
# 初始化默认值
|
||||
i: INT = 0
|
||||
# Initialize default values
|
||||
i: int = 0
|
||||
while i < self._arg_count:
|
||||
arg: Argument | t.CPtr = self._get_arg(i)
|
||||
if arg.action == STORE:
|
||||
@@ -294,22 +298,22 @@ class ArgumentParser:
|
||||
args._set_int(arg.dest, 0)
|
||||
i += 1
|
||||
|
||||
# 解析 argv
|
||||
idx: INT = 1
|
||||
pos_idx: INT = 0
|
||||
# Traverse argv
|
||||
idx: int = 1
|
||||
pos_idx: int = 0
|
||||
token: str = None
|
||||
found: INT = 0
|
||||
found: int = 0
|
||||
arg: Argument | t.CPtr = None
|
||||
value: str = None
|
||||
entry: str | t.CPtr = None
|
||||
name_len: INT = 0
|
||||
|
||||
while idx < argc:
|
||||
entry = t.CPtr(t.CUInt64T(argv) + idx * 8)
|
||||
token = entry[0]
|
||||
if token is None: break
|
||||
if token is None:
|
||||
break
|
||||
|
||||
# "--" 结束符:后续全部为位置参数
|
||||
# "--" terminator: all subsequent tokens become positional arguments
|
||||
if token[0] == '-' and token[1] == '-' and token[2] == 0:
|
||||
idx += 1
|
||||
while idx < argc:
|
||||
@@ -326,9 +330,8 @@ class ArgumentParser:
|
||||
idx += 1
|
||||
break
|
||||
|
||||
# 长选项 --name 或 --name=value
|
||||
# Long option --name or --name=value
|
||||
if token[0] == '-' and token[1] == '-':
|
||||
# 检查是否含 =
|
||||
has_eq: bool = False
|
||||
p: str = token
|
||||
while p[0] != 0:
|
||||
@@ -338,32 +341,28 @@ class ArgumentParser:
|
||||
p += 1
|
||||
|
||||
if has_eq:
|
||||
# --name=value
|
||||
# --name=value syntax
|
||||
found = self._find_long_prefix(token)
|
||||
if found < 0:
|
||||
stdio.printf(
|
||||
"error: unrecognized argument '%s'\n", token)
|
||||
stdio.printf("error: unrecognized argument '%s'\n", token)
|
||||
release(args)
|
||||
return None
|
||||
arg = self._get_arg(found)
|
||||
# 提取 = 后的值
|
||||
arg_name_len: INT = string.strlen(arg.name)
|
||||
arg_name_len: int = string.strlen(arg.name)
|
||||
value = token + arg_name_len + 1
|
||||
self._store_value(args, arg, value)
|
||||
idx += 1
|
||||
else:
|
||||
# --name(值在下一个 argv 或标志)
|
||||
# --name with value in next token or flag action
|
||||
found = self._find_long(token)
|
||||
if found < 0:
|
||||
stdio.printf(
|
||||
"error: unrecognized argument '%s'\n", token)
|
||||
stdio.printf("error: unrecognized argument '%s'\n", token)
|
||||
release(args)
|
||||
return None
|
||||
arg = self._get_arg(found)
|
||||
if arg.action == STORE:
|
||||
if idx + 1 >= argc:
|
||||
stdio.printf(
|
||||
"error: %s requires a value\n", arg.name)
|
||||
stdio.printf("error: %s requires a value\n", arg.name)
|
||||
release(args)
|
||||
return None
|
||||
entry = t.CPtr(t.CUInt64T(argv) + (idx + 1) * 8)
|
||||
@@ -374,19 +373,17 @@ class ArgumentParser:
|
||||
self._apply_action(args, arg)
|
||||
idx += 1
|
||||
|
||||
# 短选项 -x
|
||||
# Short option -x
|
||||
elif token[0] == '-':
|
||||
found = self._find_short(token)
|
||||
if found < 0:
|
||||
stdio.printf(
|
||||
"error: unrecognized argument '%s'\n", token)
|
||||
stdio.printf("error: unrecognized argument '%s'\n", token)
|
||||
release(args)
|
||||
return None
|
||||
arg = self._get_arg(found)
|
||||
if arg.action == STORE:
|
||||
if idx + 1 >= argc:
|
||||
stdio.printf(
|
||||
"error: %s requires a value\n", arg.name)
|
||||
stdio.printf("error: %s requires a value\n", arg.name)
|
||||
release(args)
|
||||
return None
|
||||
entry = t.CPtr(t.CUInt64T(argv) + (idx + 1) * 8)
|
||||
@@ -397,12 +394,11 @@ class ArgumentParser:
|
||||
self._apply_action(args, arg)
|
||||
idx += 1
|
||||
|
||||
# 位置参数
|
||||
# Positional argument
|
||||
else:
|
||||
found = self._find_positional(pos_idx)
|
||||
if found < 0:
|
||||
stdio.printf(
|
||||
"error: unexpected argument '%s'\n", token)
|
||||
stdio.printf("error: unexpected argument '%s'\n", token)
|
||||
release(args)
|
||||
return None
|
||||
arg = self._get_arg(found)
|
||||
@@ -410,15 +406,13 @@ class ArgumentParser:
|
||||
pos_idx += 1
|
||||
idx += 1
|
||||
|
||||
# 检查必须参数
|
||||
# Validate required arguments
|
||||
i = 0
|
||||
while i < self._arg_count:
|
||||
arg = self._get_arg(i)
|
||||
if arg.required:
|
||||
if not args.has(arg.dest):
|
||||
stdio.printf(
|
||||
"error: missing required argument '%s'\n",
|
||||
arg.name)
|
||||
stdio.printf("error: missing required argument '%s'\n", arg.name)
|
||||
release(args)
|
||||
return None
|
||||
i += 1
|
||||
@@ -426,17 +420,18 @@ class ArgumentParser:
|
||||
return args
|
||||
|
||||
def print_help(self):
|
||||
"""打印帮助信息"""
|
||||
"""Print complete help message"""
|
||||
stdio.printf("usage: %s [options]\n", self._prog)
|
||||
if self._description is not None and self._description[0] != 0:
|
||||
stdio.printf("\n%s\n", self._description)
|
||||
stdio.printf("\npositional arguments:\n")
|
||||
i: INT = 0
|
||||
i: int = 0
|
||||
while i < self._arg_count:
|
||||
arg: Argument | t.CPtr = self._get_arg(i)
|
||||
if arg.is_positional:
|
||||
ht: str = arg.help_text
|
||||
if ht is None: ht = ""
|
||||
if ht is None:
|
||||
ht = ""
|
||||
stdio.printf(" %-20s %s\n", arg.name, ht)
|
||||
i += 1
|
||||
stdio.printf("\noptional arguments:\n")
|
||||
@@ -445,27 +440,29 @@ class ArgumentParser:
|
||||
arg = self._get_arg(i)
|
||||
if not arg.is_positional:
|
||||
ht: str = arg.help_text
|
||||
if ht is None: ht = ""
|
||||
if ht is None:
|
||||
ht = ""
|
||||
if arg.short_name is not None:
|
||||
stdio.printf(" %s, %-18s %s\n",
|
||||
arg.short_name, arg.name, ht)
|
||||
stdio.printf(" %s, %-18s %s\n", arg.short_name, arg.name, ht)
|
||||
else:
|
||||
stdio.printf(" %-22s %s\n", arg.name, ht)
|
||||
i += 1
|
||||
|
||||
def print_usage(self):
|
||||
"""打印用法简述"""
|
||||
"""Print brief usage summary"""
|
||||
stdio.printf("usage: %s [options]\n", self._prog)
|
||||
|
||||
|
||||
# ============================================================
|
||||
# release — 释放 ParsedArgs 及其内部资源
|
||||
# release — Release ParsedArgs and all internal resources
|
||||
# ============================================================
|
||||
|
||||
def release(args: ParsedArgs | t.CPtr):
|
||||
"""释放 ParsedArgs 对象及其内部 HashTable。"""
|
||||
if args is None: return
|
||||
if args.__mbuddy__ is None: return
|
||||
"""Free ParsedArgs object and its inner HashTable resources."""
|
||||
if args is None:
|
||||
return
|
||||
if args.__mbuddy__ is None:
|
||||
return
|
||||
if args._ht is not None:
|
||||
if args._ht.__slots__ is not None:
|
||||
args.__mbuddy__.free(args._ht.__slots__)
|
||||
|
||||
@@ -802,6 +802,7 @@ def _parse_paren(ps: Parser | t.CPtr) -> AST | t.CPtr:
|
||||
lineno: t.CInt = _cur_lineno(ps)
|
||||
col: t.CInt = _cur_col(ps)
|
||||
_advance(ps) # (
|
||||
_skip_nl(ps) # 跳过 ( 后的换行(多行元组)
|
||||
if _match_op(ps, TokOp.RPar):
|
||||
_advance(ps)
|
||||
# 空元组
|
||||
@@ -820,6 +821,7 @@ def _parse_paren(ps: Parser | t.CPtr) -> AST | t.CPtr:
|
||||
elts: list[AST | t.CPtr] | t.CPtr = list[AST | t.CPtr](ps.pool, 8)
|
||||
elts.append(first)
|
||||
while _accept_op(ps, TokOp.Comma):
|
||||
_skip_nl(ps)
|
||||
if _match_op(ps, TokOp.RPar):
|
||||
break
|
||||
e: AST | t.CPtr = _parse_expr(ps)
|
||||
@@ -840,6 +842,7 @@ def _parse_list(ps: Parser | t.CPtr) -> AST | t.CPtr:
|
||||
lineno: t.CInt = _cur_lineno(ps)
|
||||
col: t.CInt = _cur_col(ps)
|
||||
_advance(ps) # [
|
||||
_skip_nl(ps) # 跳过 [ 后的换行(多行列表)
|
||||
if _match_op(ps, TokOp.Rsqb):
|
||||
_advance(ps)
|
||||
empty: list[AST | t.CPtr] | t.CPtr = list[AST | t.CPtr](ps.pool, 8)
|
||||
|
||||
@@ -2,9 +2,9 @@ import t, c
|
||||
|
||||
|
||||
# ==============================================
|
||||
# Base64 编解码 纯裸实现
|
||||
# Base64 Encoder & Decoder, pure bare-metal implementation
|
||||
# ==============================================
|
||||
# Base64 编码对照表
|
||||
# Base64 encoding lookup table
|
||||
b64_tab: t.CArray[t.CChar, None] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
|
||||
|
||||
# Base64 反向解码表,映射字符到索引值
|
||||
@@ -16,63 +16,65 @@ b64_dec_tab: t.CArray[t.CInt8T, 80] = [
|
||||
36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51
|
||||
]
|
||||
|
||||
# * @brief Base64 编码
|
||||
# * @param in: 输入二进制数据
|
||||
# * @param in_len: 输入长度
|
||||
# * @param out: 输出Base64字符串缓冲区
|
||||
# * @retval 编码后字符串长度
|
||||
# * @brief Base64 encoding
|
||||
# * @param s: Input binary data
|
||||
# * @param out: Output buffer for Base64 string
|
||||
# * @retval Length of encoded string
|
||||
def b64encode(s: str, out: str) -> t.CSizeT:
|
||||
_s = t.CUInt8T(s, t.CPtr)
|
||||
length: t.CSizeT = len(s)
|
||||
i: t.CSizeT = 0
|
||||
j: t.CSizeT = 0
|
||||
val: t.CUInt32T = 0
|
||||
# 每3字节一组转4字节Base64
|
||||
# Process input in groups of 3 bytes, produce 4 Base64 characters
|
||||
for i in range(0, length, 3):
|
||||
# 拼接24bit分组
|
||||
# Assemble 24-bit chunk
|
||||
val = ((t.CUInt32T(_s[i + 0]) << 16 ) |
|
||||
(t.CUInt32T(_s[i + 1]) << 8 if (i + 1 < length) else 0) |
|
||||
(t.CUInt32T(_s[i + 2]) << 0 if (i + 2 < length) else 0))
|
||||
# 拆分4个6bit 查表
|
||||
# Split into four 6-bit values for table lookup
|
||||
out[j + 0] = b64_tab[(val >> 18) & 0x3F]
|
||||
out[j + 1] = b64_tab[(val >> 12) & 0x3F]
|
||||
out[j + 2] = b64_tab[(val >> 6) & 0x3F] if (i + 1 < length) else '='
|
||||
out[j + 3] = b64_tab[(val >> 0) & 0x3F] if (i + 2 < length) else '='
|
||||
j += 4
|
||||
out[j] = '\0' # 字符串结尾
|
||||
out[j] = '\0' # Null terminator for C-style string
|
||||
return j
|
||||
|
||||
|
||||
# * @brief Base64 解码
|
||||
# * @param in: Base64字符串
|
||||
# * @param out: 输出二进制缓冲区
|
||||
# * @retval 解码后二进制长度
|
||||
# * @brief Base64 decoding
|
||||
# * @param s: Base64 encoded string
|
||||
# * @param out: Output binary buffer
|
||||
# * @retval Length of decoded binary data
|
||||
def b64decode(s: str, out: t.CUInt8T | t.CPtr) -> t.CSizeT:
|
||||
length: t.CSizeT = len(s)
|
||||
i: t.CSizeT = 0
|
||||
j: t.CSizeT = 0
|
||||
val: t.CUInt32T = 0
|
||||
c: t.CInt
|
||||
# 每4个Base64字符还原3字节
|
||||
# Restore 3 bytes from every 4 Base64 characters
|
||||
for i in range(0, length, 4):
|
||||
if s[i] == '=': break
|
||||
if s[i] == '=':
|
||||
break
|
||||
val = 0
|
||||
# 逐个解析6bit
|
||||
# Parse 6-bit values sequentially
|
||||
c = s[i] - 43
|
||||
val |= (b64_dec_tab[c] & 0x3F) << 18
|
||||
c = s[i+1] - 43
|
||||
val |= (b64_dec_tab[c] & 0x3F) << 12
|
||||
c = s[i+2] - 43
|
||||
if s[i+2] != '=': val |= (b64_dec_tab[c] & 0x3F) << 6
|
||||
if s[i+2] != '=':
|
||||
val |= (b64_dec_tab[c] & 0x3F) << 6
|
||||
c = s[i+3] - 43
|
||||
if s[i+3] != '=': val |= (b64_dec_tab[c] & 0x3F)
|
||||
# 还原3字节
|
||||
if s[i+3] != '=':
|
||||
val |= (b64_dec_tab[c] & 0x3F)
|
||||
# Write recovered bytes
|
||||
out[j] = (val >> 16) & 0xFF
|
||||
j += 1
|
||||
if s[i+2] != '=':
|
||||
if s[i+2] != '=':
|
||||
out[j] = (val >> 8) & 0xFF
|
||||
j += 1
|
||||
if s[i+3] != '=':
|
||||
if s[i+3] != '=':
|
||||
out[j] = val & 0xFF
|
||||
j += 1
|
||||
return j
|
||||
|
||||
@@ -1,11 +1,2 @@
|
||||
import t
|
||||
|
||||
|
||||
def print(*args, sep: str = " ", end: str = "\n") -> t.State:
|
||||
...
|
||||
def input(prompt: str = "") -> str | t.State:
|
||||
...
|
||||
|
||||
class type:
|
||||
def __init__(self): ...
|
||||
def __str__(self): ...
|
||||
@@ -9,11 +9,10 @@ from w32.win32sync import (
|
||||
)
|
||||
|
||||
|
||||
@t.Object
|
||||
class Condition:
|
||||
"""基于 Windows 条件变量的条件变量,内部包含 CRITICAL_SECTION。
|
||||
"""Windows condition variable backed primitive, internally bundled with CRITICAL_SECTION.
|
||||
|
||||
用法:
|
||||
Usage:
|
||||
cond: Condition = Condition()
|
||||
with cond:
|
||||
while not ready:
|
||||
|
||||
@@ -1,20 +1,19 @@
|
||||
"""ctraits — 编译时类型特征库
|
||||
"""ctraits — Compile-time type trait library
|
||||
|
||||
提供编译时类型判断函数,不纳入运行时编译。
|
||||
所有函数仅在编译时求值,可与 c.CIf 等编译时条件配合使用。
|
||||
Provides compile-time type predicates with no runtime code generated.
|
||||
All functions are evaluated exclusively at compile time and can be combined with conditional compilation constructs such as c.CIf.
|
||||
"""
|
||||
import t
|
||||
|
||||
|
||||
def isptr(x: t.CType) -> bool:
|
||||
"""编译时判断 x 的类型是否为指针类型。
|
||||
"""Compile-time predicate to determine whether the type of x is a pointer.
|
||||
|
||||
返回 True 如果 x 是指针(ptr_count > 0),否则返回 False。
|
||||
可与 c.CIf 配合使用实现条件编译。
|
||||
Returns True if x is a pointer type (ptr_count > 0); otherwise returns False.
|
||||
Can be used alongside c.CIf to implement conditional compilation.
|
||||
|
||||
示例:
|
||||
Example:
|
||||
if c.CIf(ctraits.isptr(my_var)):
|
||||
# 仅当 my_var 是指针类型时编译此分支
|
||||
# This branch compiles only when my_var is a pointer type
|
||||
...
|
||||
"""
|
||||
pass
|
||||
pass
|
||||
@@ -6,12 +6,12 @@ from w32.win32sync import CreateEventA, SetEvent, ResetEvent, WaitForSingleObjec
|
||||
|
||||
@t.Object
|
||||
class Event:
|
||||
"""基于 Windows Event 的事件对象,支持手动/自动重置。
|
||||
"""Windows Event-based event object, supports manual-reset and auto-reset modes.
|
||||
|
||||
用法:
|
||||
evt: Event = Event(FALSE, FALSE)
|
||||
evt.set()
|
||||
evt.wait()
|
||||
Usage:
|
||||
evt: Event = Event(FALSE, FALSE)
|
||||
evt.set()
|
||||
evt.wait()
|
||||
"""
|
||||
handle: HANDLE
|
||||
manual_reset: BOOL
|
||||
|
||||
@@ -1,60 +1,60 @@
|
||||
# hashtable - 开放寻址哈希表库
|
||||
# 使用线性探测处理冲突,支持自动扩容和墓碑删除
|
||||
# 键类型固定为 str (i8*),值类型为 void* (通用指针)
|
||||
# hashtable - Open-addressing hash table library
|
||||
# Linear probing for collision resolution, supports auto-resizing and tombstone deletion
|
||||
# Key type fixed as str (i8*), value type is void* (generic pointer)
|
||||
import t, c
|
||||
import string
|
||||
import memhub
|
||||
from stdint import *
|
||||
|
||||
# 空槽标记 (hash == 0)
|
||||
# Empty slot marker (hash == 0)
|
||||
_HT_EMPTY: t.CDefine = 0
|
||||
# 墓碑标记 (hash == 1)
|
||||
# Tombstone slot marker (hash == 1)
|
||||
_HT_TOMBSTONE: t.CDefine = 1
|
||||
# 默认初始容量 (必须是 2 的幂)
|
||||
# Default initial capacity (must be power of two)
|
||||
_HT_INIT_CAP: t.CDefine = 16
|
||||
# 槽大小: hash(8) + key(8) + value(8) = 24 字节
|
||||
# Slot memory layout: hash(8) + key pointer(8) + value pointer(8) = 24 bytes
|
||||
_HT_SLOT_SIZE: t.CDefine = 24
|
||||
# FNV-1a 64-bit 常量
|
||||
# FNV-1a 64-bit constants
|
||||
_FNV_OFFSET: t.CUInt64T = 0xcbf29ce484222325
|
||||
_FNV_PRIME: t.CUInt64T = 0x100000001b3
|
||||
|
||||
|
||||
def _fnv1a_hash(key: str) -> t.CUInt64T:
|
||||
"""FNV-1a 64-bit 哈希函数"""
|
||||
"""FNV-1a 64-bit hash function."""
|
||||
h: t.CUInt64T = _FNV_OFFSET
|
||||
k: str = key
|
||||
while k[0] != 0:
|
||||
h = h ^ t.CUInt64T(k[0])
|
||||
h = h * _FNV_PRIME
|
||||
k += 1
|
||||
# 保证 h >= 2 (避开空槽 0 和墓碑 1)
|
||||
# Ensure h >= 2 (avoids empty slot marker 0 and tombstone marker 1)
|
||||
if h < 2:
|
||||
h = 2
|
||||
return h
|
||||
|
||||
|
||||
class HashTable:
|
||||
"""开放寻址哈希表,使用线性探测处理冲突。
|
||||
"""Open-addressing hash table using linear probing for collision resolution.
|
||||
|
||||
键类型固定为 str (i8*),值类型为 void* (通用指针)。
|
||||
使用 mbuddy 分配器管理内存。负载因子超过 0.75 时自动扩容。
|
||||
Key type fixed as str (i8*), value type is void* (generic pointer).
|
||||
Memory is managed via the mbuddy allocator. Automatically resizes when load factor exceeds 0.75.
|
||||
|
||||
用法:
|
||||
Usage:
|
||||
mb: memhub.MemBuddy = memhub.MemBuddy(arena, arena_size)
|
||||
ht: HashTable = HashTable(mb)
|
||||
ht.set_int("x", 42)
|
||||
p: t.CPtr = ht["x"]
|
||||
v: int = c.Deref(p)
|
||||
"""
|
||||
__slots__: t.CVoid | t.CPtr # 槽位数组基址
|
||||
__count__: t.CSizeT = 0 # 已用条目数
|
||||
__capacity__: t.CSizeT = 16 # 槽位总数 (2 的幂)
|
||||
__tombstones__: t.CSizeT = 0 # 墓碑数
|
||||
__slots__: t.CVoid | t.CPtr # Base address of slot array
|
||||
__count__: t.CSizeT = 0 # Number of occupied entries
|
||||
__capacity__: t.CSizeT = 16 # Total slot count (power of two)
|
||||
__tombstones__: t.CSizeT = 0 # Tombstone entry count
|
||||
__mbuddy__: memhub.MemBuddy | t.CPtr
|
||||
__iter_index__: t.CSizeT = 0
|
||||
|
||||
def __new__(self, mb: memhub.MemBuddy | t.CPtr) -> t.CPtr:
|
||||
# 堆分配 HashTable 对象 (6 字段 x 8 字节 = 48 字节)
|
||||
# Heap-allocate HashTable object (6 fields × 8 bytes = 48 bytes)
|
||||
return mb.alloc(48)
|
||||
|
||||
def __init__(self, mb: memhub.MemBuddy | t.CPtr):
|
||||
@@ -63,26 +63,26 @@ class HashTable:
|
||||
self.__count__ = 0
|
||||
self.__tombstones__ = 0
|
||||
self.__slots__ = mb.alloc(self.__capacity__ * _HT_SLOT_SIZE)
|
||||
# 初始化所有槽为空 (hash = 0)
|
||||
# Initialize all slots to empty (hash = 0)
|
||||
string.memset(self.__slots__, 0, self.__capacity__ * _HT_SLOT_SIZE)
|
||||
|
||||
def _slot_hash(self, idx: t.CSizeT) -> t.CUInt64T:
|
||||
"""读取槽位的 hash 值"""
|
||||
"""Read hash value from target slot."""
|
||||
ptr: t.CUInt64T | t.CPtr = (t.CVoid | t.CPtr)(t.CUInt64T(self.__slots__) + idx * _HT_SLOT_SIZE)
|
||||
return ptr[0]
|
||||
|
||||
def _slot_key(self, idx: t.CSizeT) -> str:
|
||||
"""读取槽位的 key 指针"""
|
||||
"""Read key pointer from target slot."""
|
||||
ptr: str | t.CPtr = (t.CVoid | t.CPtr)(t.CUInt64T(self.__slots__) + idx * _HT_SLOT_SIZE + 8)
|
||||
return ptr[0]
|
||||
|
||||
def _slot_value(self, idx: t.CSizeT) -> t.CPtr:
|
||||
"""读取槽位的 value 指针"""
|
||||
"""Read value pointer from target slot."""
|
||||
ptr: t.CUInt64T | t.CPtr = (t.CVoid | t.CPtr)(t.CUInt64T(self.__slots__) + idx * _HT_SLOT_SIZE + 16)
|
||||
return ptr[0]
|
||||
|
||||
def _set_slot(self, idx: t.CSizeT, h: t.CUInt64T, key: str, val: t.CPtr):
|
||||
"""设置槽位的三个字段"""
|
||||
"""Assign three fields of the target slot."""
|
||||
h_ptr: t.CUInt64T | t.CPtr = (t.CVoid | t.CPtr)(t.CUInt64T(self.__slots__) + idx * _HT_SLOT_SIZE)
|
||||
h_ptr[0] = h
|
||||
k_ptr: str | t.CPtr = (t.CVoid | t.CPtr)(t.CUInt64T(self.__slots__) + idx * _HT_SLOT_SIZE + 8)
|
||||
@@ -91,9 +91,9 @@ class HashTable:
|
||||
v_ptr[0] = val
|
||||
|
||||
def _find_slot(self, key: str, h: t.CUInt64T) -> t.CSizeT:
|
||||
"""查找 key 应该插入或已存在的槽位索引。
|
||||
"""Locate slot index for key insertion or lookup.
|
||||
|
||||
返回: 如果找到 key,返回其索引;否则返回第一个可插入的空槽/墓碑索引。
|
||||
Returns: Index of matching key if found; otherwise returns index of first usable empty/tombstone slot.
|
||||
"""
|
||||
mask: t.CSizeT = self.__capacity__ - 1
|
||||
idx: t.CSizeT = t.CSizeT(h) & mask
|
||||
@@ -120,7 +120,7 @@ class HashTable:
|
||||
return self.__capacity__
|
||||
|
||||
def _resize(self, new_cap: t.CSizeT):
|
||||
"""扩容并重新哈希所有条目"""
|
||||
"""Resize table and rehash all entries."""
|
||||
old_slots: t.CVoid | t.CPtr = self.__slots__
|
||||
old_cap: t.CSizeT = self.__capacity__
|
||||
new_slots: t.CVoid | t.CPtr = self.__mbuddy__.alloc(new_cap * _HT_SLOT_SIZE)
|
||||
@@ -146,7 +146,7 @@ class HashTable:
|
||||
i += 1
|
||||
|
||||
def __setitem__(self, key: str, val: t.CNeedPtr):
|
||||
"""插入或更新键值对。val 自动取地址 (t.CNeedPtr: 已是指针则不取)。"""
|
||||
"""Insert or update key-value pair. val automatically decays to pointer (t.CNeedPtr: no conversion if already pointer)."""
|
||||
h: t.CUInt64T = _fnv1a_hash(key)
|
||||
idx: t.CSizeT = self._find_slot(key, h)
|
||||
if idx >= self.__capacity__:
|
||||
@@ -157,7 +157,7 @@ class HashTable:
|
||||
self.__tombstones__ -= 1
|
||||
self._set_slot(idx, h, key, val)
|
||||
self.__count__ += 1
|
||||
# 负载因子 > 0.75 时扩容
|
||||
# Resize when load factor > 0.75
|
||||
load: t.CSizeT = self.__count__ + self.__tombstones__
|
||||
if load * 4 >= self.__capacity__ * 3:
|
||||
self._resize(self.__capacity__ * 2)
|
||||
@@ -165,7 +165,7 @@ class HashTable:
|
||||
self._set_slot(idx, h, key, val)
|
||||
|
||||
def __getitem__(self, key: str) -> t.CPtr:
|
||||
"""查找 key,返回值指针。不存在返回 None。"""
|
||||
"""Lookup key and return value pointer. Returns None if key not found."""
|
||||
h: t.CUInt64T = _fnv1a_hash(key)
|
||||
idx: t.CSizeT = self._find_slot(key, h)
|
||||
if idx >= self.__capacity__:
|
||||
@@ -176,7 +176,7 @@ class HashTable:
|
||||
return self._slot_value(idx)
|
||||
|
||||
def __contains__(self, key: str) -> t.CInt:
|
||||
"""检查 key 是否存在。"""
|
||||
"""Check whether key exists in table."""
|
||||
h: t.CUInt64T = _fnv1a_hash(key)
|
||||
idx: t.CSizeT = self._find_slot(key, h)
|
||||
if idx >= self.__capacity__:
|
||||
@@ -187,7 +187,7 @@ class HashTable:
|
||||
return 1
|
||||
|
||||
def __delitem__(self, key: str) -> t.CInt:
|
||||
"""删除 key。成功返回 1,key 不存在返回 0。"""
|
||||
"""Delete entry by key. Return 1 on success, 0 if key not present."""
|
||||
h: t.CUInt64T = _fnv1a_hash(key)
|
||||
idx: t.CSizeT = self._find_slot(key, h)
|
||||
if idx >= self.__capacity__:
|
||||
@@ -218,7 +218,7 @@ class HashTable:
|
||||
raise StopIteration
|
||||
|
||||
def get(self, key: str, default: t.CPtr) -> t.CPtr:
|
||||
"""返回值指针,不存在则返回 default。"""
|
||||
"""Return value pointer; return default pointer if key not found."""
|
||||
h: t.CUInt64T = _fnv1a_hash(key)
|
||||
idx: t.CSizeT = self._find_slot(key, h)
|
||||
if idx >= self.__capacity__:
|
||||
@@ -229,12 +229,12 @@ class HashTable:
|
||||
return self._slot_value(idx)
|
||||
|
||||
def set_int(self, key: str, val: int):
|
||||
"""存储 int 值。值复制到 mbuddy 持久存储。"""
|
||||
"""Store integer value. Value is copied into mbuddy-managed storage."""
|
||||
storage: t.CVoid | t.CPtr = self.__mbuddy__.alloc(8)
|
||||
int_ptr: int | t.CPtr = t.CVoid(t.CUInt64T(storage), t.CPtr)
|
||||
int_ptr[0] = val
|
||||
self[key] = storage
|
||||
|
||||
def set_str(self, key: str, val: str):
|
||||
"""存储 str 值。直接存储字符串指针。"""
|
||||
"""Store string value. Directly store the string pointer."""
|
||||
self[key] = val
|
||||
|
||||
@@ -2,4 +2,4 @@ import stdio
|
||||
|
||||
|
||||
def helloworld():
|
||||
stdio.printf("Hello, world!\n")
|
||||
stdio.printf("Hello, world!\n")
|
||||
|
||||
@@ -3,38 +3,39 @@ from stdint import *
|
||||
|
||||
|
||||
# ============================================================
|
||||
# LinkedNode: 非多态继承基类(@t.NoVTable)
|
||||
# LinkedNode: Non-polymorphic base class (@t.NoVTable)
|
||||
#
|
||||
# 子类继承此类即"启用"标准链表/树形结构能力:
|
||||
# - 双向兄弟链表(next/prev)→ O(1) 删除
|
||||
# - 父子树结构(child/last_child/parent)→ O(1) 追加子节点
|
||||
# - 子节点计数(child_count)
|
||||
# Subclasses inheriting from this class gain standard linked list and tree capabilities:
|
||||
# - Bidirectional sibling links (next/prev) → O(1) removal
|
||||
# - Parent-child tree structure (child/last_child/parent) → O(1) child appending
|
||||
# - Child counter (child_count)
|
||||
#
|
||||
# 字段展平嵌入子类,无 vtable 开销(对应 C++ 非多态继承)。
|
||||
# OOP 方法通过 _generate_inherited_method_wrappers 自动生成子类包装
|
||||
# (self bitcast 为父类指针后调用),子类可直接调用继承的方法。
|
||||
# Fields are flattened and embedded into subclasses with no vtable overhead
|
||||
# (equivalent to non-polymorphic inheritance in C++).
|
||||
# OOP methods are automatically wrapped for subclasses via _generate_inherited_method_wrappers
|
||||
# (self pointer cast to base type before invocation). Inherited methods can be called directly by subclasses.
|
||||
#
|
||||
# 用法:
|
||||
# Usage:
|
||||
# class MyNode(LinkedNode):
|
||||
# value: t.CInt
|
||||
# root: MyNode = MyNode()
|
||||
# child: MyNode = MyNode()
|
||||
# root.append(child) # OOP 调用,self = root
|
||||
# child.detach() # 从兄弟链摘除(分离自己)
|
||||
# root.append(child) # OOP invocation, self = root
|
||||
# child.detach() # Remove self from sibling chain
|
||||
# ============================================================
|
||||
@t.NoVTable
|
||||
class LinkedNode:
|
||||
next: "LinkedNode" | t.CPtr # 下一个兄弟节点
|
||||
prev: "LinkedNode" | t.CPtr # 上一个兄弟节点(双向链表,O(1) 删除)
|
||||
child: "LinkedNode" | t.CPtr # 第一个子节点
|
||||
last_child: "LinkedNode" | t.CPtr # 最后一个子节点(O(1) 追加)
|
||||
parent: "LinkedNode" | t.CPtr # 父节点
|
||||
child_count: t.CSizeT # 子节点数
|
||||
next: "LinkedNode" | t.CPtr # Next sibling node
|
||||
prev: "LinkedNode" | t.CPtr # Previous sibling node (doubly linked list, O(1) removal)
|
||||
child: "LinkedNode" | t.CPtr # First child node
|
||||
last_child: "LinkedNode" | t.CPtr # Last child node (O(1) append)
|
||||
parent: "LinkedNode" | t.CPtr # Parent node
|
||||
child_count: t.CSizeT # Number of child nodes
|
||||
|
||||
def append(self, node: "LinkedNode" | t.CPtr):
|
||||
"""将 node 追加为 self 的最后一个子节点(O(1))。
|
||||
"""Append node as the last child of self (O(1)).
|
||||
|
||||
若 node 已在某链表中,调用方应先 node.detach() 再 append。
|
||||
If node is already attached to any list, the caller shall invoke node.detach() prior to append.
|
||||
"""
|
||||
if self is None or node is None: return
|
||||
node.parent = self
|
||||
@@ -48,7 +49,7 @@ class LinkedNode:
|
||||
self.child_count += 1
|
||||
|
||||
def prepend(self, node: "LinkedNode" | t.CPtr):
|
||||
"""将 node 插入为 self 的第一个子节点(O(1))"""
|
||||
"""Insert node as the first child of self (O(1))."""
|
||||
if self is None or node is None: return
|
||||
node.parent = self
|
||||
node.prev = None
|
||||
@@ -62,7 +63,7 @@ class LinkedNode:
|
||||
|
||||
def insert_before(self, node: "LinkedNode" | t.CPtr,
|
||||
new_node: "LinkedNode" | t.CPtr):
|
||||
"""在 node 之前插入 new_node(node 必须是 self 的子节点,O(1))"""
|
||||
"""Insert new_node before node (O(1)). node must be a direct child of self."""
|
||||
if self is None or node is None or new_node is None: return
|
||||
new_node.parent = self
|
||||
new_node.prev = node.prev
|
||||
@@ -76,7 +77,7 @@ class LinkedNode:
|
||||
|
||||
def insert_after(self, node: "LinkedNode" | t.CPtr,
|
||||
new_node: "LinkedNode" | t.CPtr):
|
||||
"""在 node 之后插入 new_node(node 必须是 self 的子节点,O(1))"""
|
||||
"""Insert new_node after node (O(1)). node must be a direct child of self."""
|
||||
if self is None or node is None or new_node is None: return
|
||||
new_node.parent = self
|
||||
new_node.prev = node
|
||||
@@ -89,19 +90,20 @@ class LinkedNode:
|
||||
self.child_count += 1
|
||||
|
||||
def remove_child(self, node: "LinkedNode" | t.CPtr):
|
||||
"""从 self 的子链表中摘除 node(O(1))。node 必须是 self 的直接子节点。"""
|
||||
if self is None or node is None: return
|
||||
# 修复 prev.next
|
||||
"""Remove node from self's child linked list (O(1)). The node must be a direct child of self."""
|
||||
if self is None or node is None:
|
||||
return
|
||||
# Patch prev.next
|
||||
if node.prev is not None:
|
||||
node.prev.next = node.next
|
||||
else:
|
||||
self.child = node.next
|
||||
# 修复 next.prev
|
||||
# Patch next.prev
|
||||
if node.next is not None:
|
||||
node.next.prev = node.prev
|
||||
else:
|
||||
self.last_child = node.prev
|
||||
# 清除 node 的兄弟/父链接
|
||||
# Clear sibling and parent links of node
|
||||
node.next = None
|
||||
node.prev = None
|
||||
node.parent = None
|
||||
@@ -109,64 +111,70 @@ class LinkedNode:
|
||||
self.child_count -= 1
|
||||
|
||||
def detach(self):
|
||||
"""将 self 从其所在兄弟链表中摘除(O(1))。
|
||||
"""Detach self from its sibling linked list (O(1)).
|
||||
|
||||
调用后 self 的 next/prev/parent 被清空,child 链不受影响。
|
||||
After invocation, self.next/self.prev/self.parent are cleared. The child chain remains untouched.
|
||||
"""
|
||||
if self is None: return
|
||||
# 修复 prev.next
|
||||
if self is None:
|
||||
return
|
||||
# Patch prev.next
|
||||
if self.prev is not None:
|
||||
self.prev.next = self.next
|
||||
elif self.parent is not None:
|
||||
self.parent.child = self.next
|
||||
# 修复 next.prev
|
||||
# Patch next.prev
|
||||
if self.next is not None:
|
||||
self.next.prev = self.prev
|
||||
elif self.parent is not None:
|
||||
self.parent.last_child = self.prev
|
||||
# 递减父节点计数
|
||||
# Decrement parent child counter
|
||||
if self.parent is not None:
|
||||
if self.parent.child_count > 0:
|
||||
self.parent.child_count -= 1
|
||||
# 清除 self 链接
|
||||
# Clear links of self
|
||||
self.next = None
|
||||
self.prev = None
|
||||
self.parent = None
|
||||
|
||||
def unlink(self):
|
||||
"""断开 self 的所有连接(兄弟 + 父子),不递归处理子节点。
|
||||
"""Sever all links of self (siblings and parent). Child nodes are not processed recursively.
|
||||
|
||||
调用后 self 成为孤立节点,但其 child 链仍指向原子节点
|
||||
(子节点的 parent 仍指向 self)。若需完全隔离,调用方应
|
||||
先逐个 self.remove_child 子节点。
|
||||
After invocation, self becomes an isolated node, while its child chain still references original children
|
||||
(the parent field of child nodes still points to self). For full isolation, the caller shall
|
||||
invoke self.remove_child on each child beforehand.
|
||||
"""
|
||||
if self is None: return
|
||||
# 先从兄弟链摘除
|
||||
if self is None:
|
||||
return
|
||||
# First detach from sibling list
|
||||
self.detach()
|
||||
# 再断开父子链接
|
||||
# Then break parent-child links
|
||||
self.child = None
|
||||
self.last_child = None
|
||||
self.child_count = 0
|
||||
|
||||
def has_children(self) -> t.CInt:
|
||||
"""返回 1 若有子节点,否则 0"""
|
||||
if self is None: return 0
|
||||
if self.child is not None: return 1
|
||||
"""Return 1 if child nodes exist, otherwise return 0."""
|
||||
if self is None:
|
||||
return 0
|
||||
if self.child is not None:
|
||||
return 1
|
||||
return 0
|
||||
|
||||
def child_at(self, index: t.CSizeT) -> "LinkedNode" | t.CPtr:
|
||||
"""返回第 index 个子节点(O(n),从 0 开始),越界返回 None"""
|
||||
if self is None: return None
|
||||
"""Return the child node at specified zero-based index (O(n)). Return None if index out of bounds."""
|
||||
if self is None:
|
||||
return None
|
||||
cur: "LinkedNode" | t.CPtr = self.child
|
||||
i: t.CSizeT = 0
|
||||
while cur is not None:
|
||||
if i == index: return cur
|
||||
if i == index:
|
||||
return cur
|
||||
i += 1
|
||||
cur = cur.next
|
||||
return None
|
||||
|
||||
def count_children(self) -> t.CSizeT:
|
||||
"""遍历计算子节点数(O(n)),用于校验 child_count"""
|
||||
"""Count children by traversal (O(n)), used to validate child_count."""
|
||||
if self is None: return 0
|
||||
n: t.CSizeT = 0
|
||||
cur: "LinkedNode" | t.CPtr = self.child
|
||||
@@ -176,7 +184,7 @@ class LinkedNode:
|
||||
return n
|
||||
|
||||
def first_sibling(self) -> "LinkedNode" | t.CPtr:
|
||||
"""返回兄弟链表的头节点(沿 prev 回溯)"""
|
||||
"""Return the head node of sibling linked list (traverse backward via prev pointers)."""
|
||||
if self is None: return None
|
||||
cur: "LinkedNode" | t.CPtr = self
|
||||
while cur.prev is not None:
|
||||
@@ -184,7 +192,7 @@ class LinkedNode:
|
||||
return cur
|
||||
|
||||
def last_sibling(self) -> "LinkedNode" | t.CPtr:
|
||||
"""返回兄弟链表的尾节点(沿 next 前进)"""
|
||||
"""Return the tail node of sibling linked list (traverse forward via next pointers)."""
|
||||
if self is None: return None
|
||||
cur: "LinkedNode" | t.CPtr = self
|
||||
while cur.next is not None:
|
||||
@@ -193,24 +201,27 @@ class LinkedNode:
|
||||
|
||||
|
||||
# ============================================================
|
||||
# SListNode: 单向链表节点(@t.NoVTable)
|
||||
# SListNode: Singly linked list node (@t.NoVTable)
|
||||
#
|
||||
# 轻量级单向链表,仅 Next 指针,无 prev/parent/child。
|
||||
# 适用于队列/栈/简单链场景(如 llvmlite 的 Param/BasicBlock/Function/Line/Value)。
|
||||
# O(1) 追加需调用方维护 tail 指针(append_after);
|
||||
# O(n) 追加仅需 head(append)。
|
||||
# Lightweight singly linked list with only Next pointer. No prev/parent/child.
|
||||
# Suitable for queues, stacks and simple linked structures
|
||||
# (such as Param/BasicBlock/Function/Line/Value in llvmlite).
|
||||
# O(1) append requires caller to maintain tail pointer (append_after).
|
||||
# O(n) append works with head pointer only (append).
|
||||
# ============================================================
|
||||
@t.NoVTable
|
||||
class SListNode:
|
||||
Next: "SListNode" | t.CPtr # 下一个节点
|
||||
Next: "SListNode" | t.CPtr # Next node
|
||||
|
||||
def append(self, node: "SListNode" | t.CPtr) -> "SListNode" | t.CPtr:
|
||||
"""将 node 追加到链表末尾(O(n)),返回 self(head)。
|
||||
"""Append node to the end of the linked list (O(n)). Return self (head).
|
||||
|
||||
若 self 为 None,应直接使用 node 作为 head(调用方需自行处理)。
|
||||
If self is None, the caller shall adopt node directly as the new head.
|
||||
"""
|
||||
if self is None: return node
|
||||
if node is None: return self
|
||||
if self is None:
|
||||
return node
|
||||
if node is None:
|
||||
return self
|
||||
node.Next = None
|
||||
cur: "SListNode" | t.CPtr = self
|
||||
while cur.Next is not None:
|
||||
@@ -219,19 +230,21 @@ class SListNode:
|
||||
return self
|
||||
|
||||
def append_after(self, node: "SListNode" | t.CPtr) -> "SListNode" | t.CPtr:
|
||||
"""将 node 追加到 self 之后(O(1)),返回新的 tail(即 node)。
|
||||
"""Insert node immediately after self (O(1)). Return new tail (node).
|
||||
|
||||
调用方需自行维护 head 指针。若 self 为 None,返回 node 作为首节点。
|
||||
Caller must maintain the head pointer manually. Return node as head if self is None.
|
||||
"""
|
||||
if node is None: return self
|
||||
if node is None:
|
||||
return self
|
||||
node.Next = None
|
||||
if self is not None:
|
||||
self.Next = node
|
||||
return node
|
||||
|
||||
def count(self) -> t.CSizeT:
|
||||
"""遍历计算链表长度(O(n))"""
|
||||
if self is None: return 0
|
||||
"""Calculate list length via full traversal (O(n))."""
|
||||
if self is None:
|
||||
return 0
|
||||
n: t.CSizeT = 0
|
||||
cur: "SListNode" | t.CPtr = self
|
||||
while cur is not None:
|
||||
@@ -240,22 +253,25 @@ class SListNode:
|
||||
return n
|
||||
|
||||
def at(self, index: t.CSizeT) -> "SListNode" | t.CPtr:
|
||||
"""返回第 index 个节点(O(n),从 0 开始),越界返回 None"""
|
||||
if self is None: return None
|
||||
"""Return node at zero-based index (O(n)). Return None if index out of bounds."""
|
||||
if self is None:
|
||||
return None
|
||||
cur: "SListNode" | t.CPtr = self
|
||||
i: t.CSizeT = 0
|
||||
while cur is not None:
|
||||
if i == index: return cur
|
||||
if i == index:
|
||||
return cur
|
||||
i += 1
|
||||
cur = cur.Next
|
||||
return None
|
||||
|
||||
def remove(self, node: "SListNode" | t.CPtr) -> "SListNode" | t.CPtr:
|
||||
"""从链表中移除 node(O(n)),返回新的 head(self)。
|
||||
"""Remove node from list (O(n)). Return updated head.
|
||||
|
||||
node 的 Next 被清空。若 node 是 head,返回 head.Next。
|
||||
The Next pointer of node will be cleared. If node is the original head, return head.Next.
|
||||
"""
|
||||
if self is None or node is None: return self
|
||||
if self is None or node is None:
|
||||
return self
|
||||
if self is node:
|
||||
new_head: "SListNode" | t.CPtr = self.Next
|
||||
self.Next = None
|
||||
@@ -271,21 +287,22 @@ class SListNode:
|
||||
|
||||
|
||||
# ============================================================
|
||||
# GSListNode[T]: 泛型单向链表节点(@t.NoVTable + PEP 695 泛型)
|
||||
# GSListNode[T]: Generic singly linked list node (@t.NoVTable + PEP 695 generics)
|
||||
#
|
||||
# 相比 SListNode(非泛型,Next: SListNode|CPtr),GSListNode[T] 的 Next
|
||||
# 字段类型为 T|CPtr,特化后直接是具体节点类型,无需向下转型。
|
||||
# Unlike SListNode (non-generic, Next: SListNode|t.CPtr), the Next field of GSListNode[T]
|
||||
# is typed as T|t.CPtr. After specialization it becomes a concrete node type directly,
|
||||
# eliminating downcasts.
|
||||
#
|
||||
# 递归泛型用法(子类继承自身特化版本):
|
||||
# Recursive generic usage pattern (subclass inherits from self-specialized variant):
|
||||
# class GNode(GSListNode[GNode]):
|
||||
# value: t.CInt
|
||||
# # 此时 GNode.Next: GNode|CPtr(强类型,无转型)
|
||||
# # At this point GNode.Next: GNode|t.CPtr (strongly typed, no casting required)
|
||||
#
|
||||
# 技术验证点:
|
||||
# 1. 递归泛型 class GNode(GSListNode[GNode])
|
||||
# 2. @t.NoVTable + 泛型组合
|
||||
# 3. 泛型类作字段类型 list: GSList[GNode]
|
||||
# 4. 泛型方法继承(GSList[T].append 在特化后可用)
|
||||
# Technical validation targets:
|
||||
# 1. Recursive generics: class GNode(GSListNode[GNode])
|
||||
# 2. Combination of @t.NoVTable attribute with generics
|
||||
# 3. Generic class used as field type: list: GSList[GNode]
|
||||
# 4. Inheritance of generic methods (GSList[T].append available after specialization)
|
||||
# ============================================================
|
||||
@t.NoVTable
|
||||
class GSListNode[T]:
|
||||
@@ -293,14 +310,14 @@ class GSListNode[T]:
|
||||
|
||||
|
||||
# ============================================================
|
||||
# GSList[T]: 泛型单向链表容器(@t.NoVTable + PEP 695 泛型)
|
||||
# GSList[T]: Generic singly linked list container (@t.NoVTable + PEP 695 generics)
|
||||
#
|
||||
# 持有 Head/Tail/Count,提供 O(1) append 和 O(n) at。
|
||||
# 节点类型 T 必须继承 GSListNode[T](以获得 Next 字段)。
|
||||
# Holds Head, Tail and Count. Provides O(1) append and O(n) indexed access.
|
||||
# Node type T must inherit from GSListNode[T] (to acquire the Next field).
|
||||
#
|
||||
# 用法:
|
||||
# Usage:
|
||||
# list: GSList[GNode] | t.CPtr = GSList[GNode]()
|
||||
# list.append(node) # 方法调用,非全局函数
|
||||
# list.append(node) # Method invocation, not free function
|
||||
# ============================================================
|
||||
@t.NoVTable
|
||||
class GSList[T]:
|
||||
@@ -314,8 +331,9 @@ class GSList[T]:
|
||||
self.Count = 0
|
||||
|
||||
def append(self, node: T):
|
||||
"""将 node 追加到链表末尾(O(1))"""
|
||||
if node is None: return
|
||||
"""Append node to the end of the list (O(1))."""
|
||||
if node is None:
|
||||
return
|
||||
node.Next = None
|
||||
if self.Head is None:
|
||||
self.Head = node
|
||||
@@ -325,59 +343,63 @@ class GSList[T]:
|
||||
self.Count += 1
|
||||
|
||||
def count(self) -> t.CSizeT:
|
||||
"""返回节点数(O(1))"""
|
||||
"""Return node count (O(1))."""
|
||||
return self.Count
|
||||
|
||||
def at(self, index: t.CSizeT) -> T | t.CPtr:
|
||||
"""返回第 index 个节点(O(n),从 0 开始),越界返回 None"""
|
||||
if self.Head is None: return None
|
||||
"""Return node at zero-based index (O(n)). Return None if index out of bounds."""
|
||||
if self.Head is None:
|
||||
return None
|
||||
cur: T | t.CPtr = self.Head
|
||||
i: t.CSizeT = 0
|
||||
while cur is not None:
|
||||
if i == index: return cur
|
||||
if i == index:
|
||||
return cur
|
||||
i += 1
|
||||
cur = cur.Next
|
||||
return None
|
||||
|
||||
|
||||
# ============================================================
|
||||
# GTreeNode[T]: 泛型树节点(@t.NoVTable + PEP 695 泛型)
|
||||
# GTreeNode[T]: Generic tree node (@t.NoVTable + PEP 695 generics)
|
||||
#
|
||||
# 强类型版本的 LinkedNode,所有指针字段类型为 T|t.CPtr。
|
||||
# 提供:
|
||||
# - 双向兄弟链表(Next/Prev)→ O(1) 删除
|
||||
# - 父子树结构(Child/LastChild/Parent)→ O(1) 追加子节点
|
||||
# - 子节点计数(Count)
|
||||
# Type-safe variant of LinkedNode. All pointer fields are typed T|t.CPtr.
|
||||
# Capabilities provided:
|
||||
# - Bidirectional sibling linked list (Next/Prev) → O(1) removal
|
||||
# - Parent-child tree structure (Child/LastChild/Parent) → O(1) child appending
|
||||
# - Child counter (Count)
|
||||
#
|
||||
# 递归泛型用法(子类继承自身特化版本):
|
||||
# Recursive generic usage pattern (subclass inherits self-specialized variant):
|
||||
# @t.CVTable
|
||||
# class AST(GTreeNode[AST]):
|
||||
# def kind(self) -> t.CInt:
|
||||
# return 0
|
||||
# # 此时 AST.Next/Prev/Child/LastChild/Parent 均为 AST|t.CPtr(强类型)
|
||||
# # At this point AST.Next/Prev/Child/LastChild/Parent are all AST|t.CPtr (strongly typed)
|
||||
#
|
||||
# 字段展平嵌入子类,无 vtable 开销(对应 C++ 非多态继承)。
|
||||
# 子类若为 @t.CVTable,则获得自己的 vtable(offset 0),
|
||||
# GTreeNode 字段展平在 vtable 之后。
|
||||
# Fields are flattened and embedded into subclasses with no vtable overhead
|
||||
# (equivalent to non-polymorphic inheritance in C++).
|
||||
# If a subclass is marked @t.CVTable, it receives its own vtable (at offset 0),
|
||||
# and GTreeNode fields are laid out after the vtable.
|
||||
#
|
||||
# OOP 方法通过 _generate_inherited_method_wrappers 自动生成子类包装
|
||||
# (self bitcast 为父类指针后调用),子类可直接调用继承的方法。
|
||||
# OOP methods are automatically wrapped for subclasses via _generate_inherited_method_wrappers
|
||||
# (self pointer cast to base type before invocation). Inherited methods can be called directly by subclasses.
|
||||
# ============================================================
|
||||
@t.NoVTable
|
||||
class GTreeNode[T]:
|
||||
Next: T | t.CPtr # 下一个兄弟节点
|
||||
Prev: T | t.CPtr # 上一个兄弟节点(双向链表,O(1) 删除)
|
||||
Child: T | t.CPtr # 第一个子节点
|
||||
LastChild: T | t.CPtr # 最后一个子节点(O(1) 追加)
|
||||
Parent: T | t.CPtr # 父节点
|
||||
Count: t.CSizeT # 子节点数
|
||||
Next: T | t.CPtr # Next sibling node
|
||||
Prev: T | t.CPtr # Previous sibling node (doubly linked list, O(1) removal)
|
||||
Child: T | t.CPtr # First child node
|
||||
LastChild: T | t.CPtr # Last child node (O(1) append)
|
||||
Parent: T | t.CPtr # Parent node
|
||||
Count: t.CSizeT # Number of child nodes
|
||||
|
||||
def append(self, node: T | t.CPtr):
|
||||
"""将 node 追加为 self 的最后一个子节点(O(1))。
|
||||
"""Append node as the last child of self (O(1)).
|
||||
|
||||
若 node 已在某链表中,调用方应先 node.detach() 再 append。
|
||||
If node is already attached to any list, the caller shall invoke node.detach() prior to append.
|
||||
"""
|
||||
if self is None or node is None: return
|
||||
if self is None or node is None:
|
||||
return
|
||||
node.Parent = self
|
||||
node.Next = None
|
||||
node.Prev = self.LastChild
|
||||
@@ -389,8 +411,9 @@ class GTreeNode[T]:
|
||||
self.Count += 1
|
||||
|
||||
def prepend(self, node: T | t.CPtr):
|
||||
"""将 node 插入为 self 的第一个子节点(O(1))"""
|
||||
if self is None or node is None: return
|
||||
"""Insert node as the first child of self (O(1))."""
|
||||
if self is None or node is None:
|
||||
return
|
||||
node.Parent = self
|
||||
node.Prev = None
|
||||
node.Next = self.Child
|
||||
@@ -402,11 +425,12 @@ class GTreeNode[T]:
|
||||
self.Count += 1
|
||||
|
||||
def detach(self):
|
||||
"""将 self 从其所在兄弟链表中摘除(O(1))。
|
||||
"""Detach self from its sibling linked list (O(1)).
|
||||
|
||||
调用后 self 的 Next/Prev/Parent 被清空,Child 链不受影响。
|
||||
After invocation, self.Next/self.Prev/self.Parent are cleared. The child chain remains untouched.
|
||||
"""
|
||||
if self is None: return
|
||||
if self is None:
|
||||
return
|
||||
if self.Prev is not None:
|
||||
self.Prev.Next = self.Next
|
||||
elif self.Parent is not None:
|
||||
@@ -423,25 +447,30 @@ class GTreeNode[T]:
|
||||
self.Parent = None
|
||||
|
||||
def has_children(self) -> t.CInt:
|
||||
"""返回 1 若有子节点,否则 0"""
|
||||
if self is None: return 0
|
||||
if self.Child is not None: return 1
|
||||
"""Return 1 if child nodes exist, otherwise return 0."""
|
||||
if self is None:
|
||||
return 0
|
||||
if self.Child is not None:
|
||||
return 1
|
||||
return 0
|
||||
|
||||
def child_at(self, index: t.CSizeT) -> T | t.CPtr:
|
||||
"""返回第 index 个子节点(O(n),从 0 开始),越界返回 None"""
|
||||
if self is None: return None
|
||||
"""Return the child node at specified zero-based index (O(n)). Return None if index out of bounds."""
|
||||
if self is None:
|
||||
return None
|
||||
cur: T | t.CPtr = self.Child
|
||||
i: t.CSizeT = 0
|
||||
while cur is not None:
|
||||
if i == index: return cur
|
||||
if i == index:
|
||||
return cur
|
||||
i += 1
|
||||
cur = cur.Next
|
||||
return None
|
||||
|
||||
def count_children(self) -> t.CSizeT:
|
||||
"""遍历计算子节点数(O(n)),用于校验 Count"""
|
||||
if self is None: return 0
|
||||
"""Count children by traversal (O(n)), used to validate Count field."""
|
||||
if self is None:
|
||||
return 0
|
||||
n: t.CSizeT = 0
|
||||
cur: T | t.CPtr = self.Child
|
||||
while cur is not None:
|
||||
|
||||
@@ -218,9 +218,9 @@ def create_global_string(pool: memhub.MemBuddy | t.CPtr, mod: LLVMModule | t.CPt
|
||||
global_set_constant(gv, 1)
|
||||
|
||||
# 构造初始化值文本: c"contents\00"
|
||||
# LLVM IR 字符串字面量格式: c"<chars>" 其中非打印字符用 \xx 转义
|
||||
# 这里简单处理: 直接复制原始字节,末尾加 \00
|
||||
init_buf: t.CChar | t.CPtr = pool.alloc(slen + 8) # c"..." + \00 + "
|
||||
# LLVM IR 字符串字面量格式: c"<chars>" 其中 " 和 \ 及非打印字符用 \xx 转义
|
||||
# 缓冲区大小: 最坏情况每个字符4字节(\xx)+ c"..." + \00 + "
|
||||
init_buf: t.CChar | t.CPtr = pool.alloc(slen * 4 + 8)
|
||||
if init_buf is None: return None
|
||||
pos: t.CSizeT = 0
|
||||
init_buf[pos] = 'c'
|
||||
@@ -229,8 +229,26 @@ def create_global_string(pool: memhub.MemBuddy | t.CPtr, mod: LLVMModule | t.CPt
|
||||
pos += 1
|
||||
i: t.CSizeT = 0
|
||||
while i < slen:
|
||||
init_buf[pos] = text[i]
|
||||
pos += 1
|
||||
ch: t.CUInt8T = text[i]
|
||||
if ch == 0x22 or ch == 0x5C or ch < 0x20 or ch >= 0x7F:
|
||||
# 需要转义: " → \22, \ → \5c, 非打印字符 → \xx
|
||||
init_buf[pos] = '\\'
|
||||
pos += 1
|
||||
hi: t.CInt = (ch >> 4) & 0x0F
|
||||
lo: t.CInt = ch & 0x0F
|
||||
if hi < 10:
|
||||
init_buf[pos] = 0x30 + hi
|
||||
else:
|
||||
init_buf[pos] = 0x61 + hi - 10
|
||||
pos += 1
|
||||
if lo < 10:
|
||||
init_buf[pos] = 0x30 + lo
|
||||
else:
|
||||
init_buf[pos] = 0x61 + lo - 10
|
||||
pos += 1
|
||||
else:
|
||||
init_buf[pos] = ch
|
||||
pos += 1
|
||||
i += 1
|
||||
# 末尾 NUL 字节
|
||||
init_buf[pos] = '\\'
|
||||
|
||||
@@ -4,14 +4,13 @@ from w32.win32base import *
|
||||
from w32.win32sync import CRITICAL_SECTION, InitializeCriticalSection, EnterCriticalSection, LeaveCriticalSection, DeleteCriticalSection, TryEnterCriticalSection
|
||||
|
||||
|
||||
@t.Object
|
||||
class Lock:
|
||||
"""基于 CRITICAL_SECTION 的互斥锁,支持递归加锁。
|
||||
"""Mutex built on CRITICAL_SECTION, supports recursive locking.
|
||||
|
||||
用法:
|
||||
Usage:
|
||||
lock: Lock = Lock()
|
||||
with lock:
|
||||
# 临界区
|
||||
# Critical section
|
||||
pass
|
||||
"""
|
||||
cs: CRITICAL_SECTION
|
||||
|
||||
@@ -6,21 +6,21 @@ import viperio
|
||||
import stdio
|
||||
|
||||
# ============================================================
|
||||
# memhub - 统一内存管理库
|
||||
# MemManager (多态基类, vtable)
|
||||
# ├─ MemPool (arena bump 分配器, 不支持单个 free)
|
||||
# ├─ MemSlab (定长块池, 支持 alloc/free 位图跟踪)
|
||||
# └─ MemBuddy (伙伴系统, 支持 alloc/free/realloc 合并)
|
||||
# 所有子类通过 vtable 覆盖 alloc/free/reset, 可用 MemManager 指针多态调用
|
||||
# memhub - Unified memory management library
|
||||
# MemManager (polymorphic base class, vtable)
|
||||
# ├─ MemPool (arena bump allocator, no support for individual free)
|
||||
# ├─ MemSlab (fixed-size block pool, alloc/free tracked via bitmap)
|
||||
# └─ MemBuddy (buddy system, supports alloc/free/realloc with coalescing)
|
||||
# All subclasses override alloc/free/reset via vtable, invokable polymorphically through MemManager pointer
|
||||
# ============================================================
|
||||
|
||||
MEMHUB_ALIGN: t.CDefine = 8
|
||||
|
||||
# MemSlab 位图常量
|
||||
# MemSlab bitmap constants
|
||||
MEMSLAB_MIN_BLOCK: t.CDefine = 16
|
||||
MEMSLAB_BITMAP_BYTES: t.CDefine = 256
|
||||
|
||||
# MemBuddy 伙伴系统常量
|
||||
# MemBuddy buddy constants
|
||||
MEMBUDDY_MIN_BLOCK: t.CDefine = 32
|
||||
MEMBUDDY_MAX_ORDERS: t.CDefine = 32
|
||||
MEMBUDDY_HEADER_SIZE: t.CDefine = 8
|
||||
@@ -48,35 +48,35 @@ def _block_size_at_order(order: t.CInt) -> t.CSizeT:
|
||||
|
||||
|
||||
# ============================================================
|
||||
# MemManager - 多态基类
|
||||
# @t.CVTable 显式标记, 确保跨模块导入时也被识别为 vtable 类
|
||||
# (HandlesImports 只通过装饰器检测 IsCVTable, 不像同模块自动推断)
|
||||
# MemManager - Polymorphic base class
|
||||
# @t.CVTable explicit annotation to ensure recognition as vtable class during cross-module imports
|
||||
# (HandlesImports only detects IsCVTable via decorator; automatic inference is unavailable across modules)
|
||||
# ============================================================
|
||||
@t.CVTable
|
||||
class MemManager:
|
||||
__provides__: list[str] = ['__memmgr__']
|
||||
base: t.CVoid | t.CPtr # 内存区起始地址
|
||||
size: t.CSizeT # 内存区总大小
|
||||
base: t.CVoid | t.CPtr # Starting address of memory region
|
||||
size: t.CSizeT # Total size of memory region
|
||||
|
||||
def __init__(self, base: t.CVoid | t.CPtr, size: t.CSizeT):
|
||||
self.base = base
|
||||
self.size = size
|
||||
|
||||
# === 虚函数 (子类覆盖) ===
|
||||
# === Virtual functions (overridden by subclasses) ===
|
||||
|
||||
def alloc(self, size: t.CSizeT) -> t.CVoid | t.CPtr:
|
||||
# 默认: 不支持分配
|
||||
# Default: allocation not supported
|
||||
return None
|
||||
|
||||
def free(self, ptr: t.CVoid | t.CPtr) -> t.CInt:
|
||||
# 默认: 无操作
|
||||
# Default: no operation
|
||||
return 0
|
||||
|
||||
def reset(self) -> t.CInt:
|
||||
# 默认: 无操作
|
||||
# Default: no operation
|
||||
return 0
|
||||
|
||||
# === 具体方法 (调用虚函数, 自动多态分派) ===
|
||||
# === Concrete methods (invoke virtual functions for automatic polymorphic dispatch) ===
|
||||
|
||||
def calloc(self, count: t.CSizeT, size: t.CSizeT) -> t.CVoid | t.CPtr:
|
||||
total: t.CSizeT = count * size
|
||||
@@ -94,7 +94,7 @@ class MemManager:
|
||||
new_ptr: t.CVoid | t.CPtr = self.alloc(new_size)
|
||||
if new_ptr is None:
|
||||
return ptr
|
||||
# 基类无法追踪旧分配大小, 不复制数据; 子类可覆盖以保留数据
|
||||
# Base class cannot track original allocation size; data will not be copied. Subclasses may override to preserve data
|
||||
self.free(ptr)
|
||||
return new_ptr
|
||||
|
||||
@@ -117,12 +117,12 @@ class MemManager:
|
||||
|
||||
|
||||
# ============================================================
|
||||
# MemPool - arena bump 分配器
|
||||
# 不支持单个 free, reset 一次性回收全部
|
||||
# MemPool - Arena bump allocator
|
||||
# Individual free operations are unsupported; reset reclaims all memory at once
|
||||
# ============================================================
|
||||
class MemPool(MemManager):
|
||||
offset: t.CSizeT # bump 游标
|
||||
high_water: t.CSizeT # 峰值水位
|
||||
offset: t.CSizeT # Bump pointer offset
|
||||
high_water: t.CSizeT # High-water mark
|
||||
|
||||
def __init__(self, base: t.CVoid | t.CPtr, size: t.CSizeT):
|
||||
self.base = base
|
||||
@@ -141,7 +141,7 @@ class MemPool(MemManager):
|
||||
return ptr
|
||||
|
||||
def free(self, ptr: t.CVoid | t.CPtr) -> t.CInt:
|
||||
# bump 分配器不支持单个 free
|
||||
# Bump allocator does not support individual free operations
|
||||
return 1
|
||||
|
||||
def reset(self) -> t.CInt:
|
||||
@@ -151,18 +151,18 @@ class MemPool(MemManager):
|
||||
|
||||
|
||||
# ============================================================
|
||||
# MemSlab - 定长块池
|
||||
# arena 开头存位图, 后续区域按 block_size 切分, 空闲链管理
|
||||
# MemSlab - Fixed-size block pool
|
||||
# Bitmap stored at the start of arena; subsequent area split into block_size units managed by free list
|
||||
# ============================================================
|
||||
class MemSlab(MemManager):
|
||||
block_size: t.CSizeT # 每块大小 (对齐后)
|
||||
block_count: t.CSizeT # 总块数
|
||||
used_count: t.CSizeT # 已用块数
|
||||
free_list: t.CVoid | t.CPtr # 空闲链头
|
||||
alloc_map: t.CUInt8T | t.CPtr # 分配位图 (位于 arena 开头)
|
||||
alloc_map_size: t.CSizeT # 位图字节数
|
||||
usable: t.CVoid | t.CPtr # 可用块区起始 (跳过位图)
|
||||
usable_size: t.CSizeT # 可用块区大小
|
||||
block_size: t.CSizeT # Block size (aligned)
|
||||
block_count: t.CSizeT # Total block count
|
||||
used_count: t.CSizeT # Used block count
|
||||
free_list: t.CVoid | t.CPtr # Free list head
|
||||
alloc_map: t.CUInt8T | t.CPtr # Allocation bitmap (at start of arena)
|
||||
alloc_map_size: t.CSizeT # Bitmap byte count
|
||||
usable: t.CVoid | t.CPtr # Usable block area start (after bitmap)
|
||||
usable_size: t.CSizeT # Usable block area size
|
||||
|
||||
def __init__(self, base: t.CVoid | t.CPtr, size: t.CSizeT, block_size: t.CSizeT):
|
||||
self.base = base
|
||||
@@ -190,7 +190,7 @@ class MemSlab(MemManager):
|
||||
self.usable_size = size - map_bytes
|
||||
self.block_size = bs
|
||||
|
||||
# 清零位图
|
||||
# Clear bitmap
|
||||
idx: t.CSizeT = 0
|
||||
while idx < map_bytes:
|
||||
self.alloc_map[idx] = 0
|
||||
@@ -199,7 +199,7 @@ class MemSlab(MemManager):
|
||||
self.block_count = self.usable_size / bs
|
||||
if self.block_count == 0: return
|
||||
|
||||
# 构建空闲链: 每块首 8 字节存下一块指针
|
||||
# Construct free list: the first 8 bytes of each block store pointer to next block
|
||||
self.free_list = None
|
||||
i: t.CSizeT = 0
|
||||
while i < self.block_count:
|
||||
@@ -209,7 +209,7 @@ class MemSlab(MemManager):
|
||||
i += 1
|
||||
|
||||
def alloc(self, size: t.CSizeT) -> t.CVoid | t.CPtr:
|
||||
# slab 模式: 仅当请求 <= block_size 时分配一块
|
||||
# Slab mode: allocate one block only if requested size <= block_size
|
||||
if self.free_list is None: return None
|
||||
if size > self.block_size: return None
|
||||
block: t.CVoid | t.CPtr = self.free_list
|
||||
@@ -250,20 +250,20 @@ class MemSlab(MemManager):
|
||||
|
||||
|
||||
# ============================================================
|
||||
# MemBuddy - 伙伴系统分配器
|
||||
# arena 开头存空闲链头数组, 后续区域按 2 的幂管理
|
||||
# 线程安全 (自旋锁), 支持合并
|
||||
# MemBuddy - Buddy system allocator
|
||||
# Free list head array stored at arena start; subsequent memory managed in power-of-two sized blocks
|
||||
# Thread-safe (spinlock enabled), supports block coalescing
|
||||
# ============================================================
|
||||
class MemBuddy(MemManager):
|
||||
# 覆盖父类 __provides__:MemBuddy 同时提供 __mbuddy__ 和 __memmgr__,
|
||||
# 使 with MemBuddy(...) 上下文内的 __requires__=['__mbuddy__'] 类(如 _str)
|
||||
# 能通过 _find_provider 自动注入
|
||||
# Override parent __provides__: MemBuddy provides both __mbuddy__ and __memmgr__.
|
||||
# Within `with MemBuddy(...)` context, classes (e.g. _str) with __requires__=['__mbuddy__']
|
||||
# can be automatically injected via _find_provider
|
||||
__provides__: list[str] = ['__mbuddy__', '__memmgr__']
|
||||
max_order: t.CInt # 最大阶数
|
||||
free_lists: t.CUInt64T | t.CPtr # 空闲链头数组 (位于 arena 开头)
|
||||
lock_val: t.CVolatile | t.CInt # 自旋锁
|
||||
usable: t.CVoid | t.CPtr # 可用区起始 (跳过 free_lists)
|
||||
usable_size: t.CSizeT # 可用区大小 (2 的幂)
|
||||
max_order: t.CInt # Maximum order
|
||||
free_lists: t.CUInt64T | t.CPtr # Free list head array (located at arena start)
|
||||
lock_val: t.CVolatile | t.CInt # Spinlock
|
||||
usable: t.CVoid | t.CPtr # Start of usable memory region (skips free_lists)
|
||||
usable_size: t.CSizeT # Size of usable memory (power of two)
|
||||
|
||||
def __init__(self, base: t.CVoid | t.CPtr, size: t.CSizeT):
|
||||
self.base = base
|
||||
@@ -278,7 +278,7 @@ class MemBuddy(MemManager):
|
||||
fl_bytes: t.CSizeT = (MEMBUDDY_MAX_ORDERS + 1) * 8
|
||||
self.free_lists = base
|
||||
|
||||
# 初始化所有空闲链头为 0
|
||||
# Initialize all free list heads to be 0
|
||||
i: t.CInt
|
||||
for i in range(MEMBUDDY_MAX_ORDERS + 1):
|
||||
self.free_lists[i] = 0
|
||||
@@ -308,10 +308,10 @@ class MemBuddy(MemManager):
|
||||
bs = bs << 1
|
||||
self.max_order += 1
|
||||
|
||||
# 整个可用区作为 max_order 阶空闲块
|
||||
# Entire usable memory region as a max_order free block
|
||||
self._fl_push(self.max_order, self.usable)
|
||||
|
||||
# === 空闲链操作 ===
|
||||
# === Free list operations ===
|
||||
|
||||
def _fl_push(self, order: t.CInt, block: t.CVoid | t.CPtr):
|
||||
old_head: t.CUInt64T = self.free_lists[order]
|
||||
@@ -347,7 +347,7 @@ class MemBuddy(MemManager):
|
||||
cur = t.CVoid(c.Deref(t.CUInt64T(cur, t.CPtr)), t.CPtr)
|
||||
return 0
|
||||
|
||||
# === 伙伴系统核心 ===
|
||||
# === Buddy system core ===
|
||||
|
||||
def _buddy_of(self, block: t.CVoid | t.CPtr, order: t.CInt) -> t.CVoid | t.CPtr:
|
||||
offset: t.CSizeT = t.CUInt64T(block) - t.CUInt64T(self.usable)
|
||||
@@ -406,16 +406,16 @@ class MemBuddy(MemManager):
|
||||
if order > self.max_order: return 0
|
||||
return 1
|
||||
|
||||
# === 锁 ===
|
||||
# === Spinlock ===
|
||||
|
||||
def _lock(self):
|
||||
def _lock(self): # can use the spinlock library for decoupling
|
||||
while atom.__atomic_test_and_set(c.Addr(self.lock_val), atom.ATOMIC_ACQUIRE):
|
||||
pass
|
||||
|
||||
def _unlock(self):
|
||||
atom.__atomic_clear(c.Addr(self.lock_val), atom.ATOMIC_RELEASE)
|
||||
|
||||
# === 虚函数覆盖 ===
|
||||
# === Virtual function overrides ===
|
||||
|
||||
def alloc(self, size: t.CSizeT) -> t.CVoid | t.CPtr:
|
||||
self._lock()
|
||||
@@ -430,7 +430,7 @@ class MemBuddy(MemManager):
|
||||
c.DerefAs(block, t.CVoid(t.CUInt64T((order << 1) | 1), t.CPtr))
|
||||
result = t.CVoid(t.CUInt64T(block) + MEMBUDDY_HEADER_SIZE, t.CPtr)
|
||||
if result is None:
|
||||
# 分配失败: 打印内存使用情况
|
||||
# Allocation failure: print memory usage statistics
|
||||
fb: t.CSizeT = self.free_bytes()
|
||||
ub: t.CSizeT = self.usable_size - fb
|
||||
stdio.printf("[MEM-FAIL] alloc(%zu) failed: total=%zu used=%zu free=%zu free_blocks=%zu\n",
|
||||
@@ -460,7 +460,7 @@ class MemBuddy(MemManager):
|
||||
self._fl_push(self.max_order, self.usable)
|
||||
return 1
|
||||
|
||||
# realloc 覆盖: 伙伴系统从块头读取旧阶数, 无需 old_size
|
||||
# realloc override: buddy system reads original order from block header; old_size is not required
|
||||
def realloc(self, ptr: t.CVoid | t.CPtr, new_size: t.CSizeT) -> t.CVoid | t.CPtr:
|
||||
if ptr is None:
|
||||
return self.alloc(new_size)
|
||||
@@ -486,19 +486,19 @@ class MemBuddy(MemManager):
|
||||
self.free(ptr)
|
||||
return new_ptr
|
||||
|
||||
# === 状态查询 ===
|
||||
# === Status Queries ===
|
||||
|
||||
@property
|
||||
def mem_size(self) -> t.CSizeT:
|
||||
# 可用区总大小(2 的幂),分配上限为 mem_size - MEMBUDDY_HEADER_SIZE
|
||||
# Total usable region size (power of two). Maximum allocatable size = mem_size - MEMBUDDY_HEADER_SIZE
|
||||
return self.usable_size
|
||||
|
||||
def stats(self) -> t.CSizeT:
|
||||
# 返回可用区总大小,用于状态统计
|
||||
# Return total usable region size, for status statistics
|
||||
return self.usable_size
|
||||
|
||||
def free_count(self) -> t.CSizeT:
|
||||
# 统计所有阶数空闲链中的块总数
|
||||
# Count total blocks in all order lists for status statistics
|
||||
count: t.CSizeT = 0
|
||||
i: t.CInt
|
||||
for i in range(MEMBUDDY_MAX_ORDERS + 1):
|
||||
@@ -510,7 +510,7 @@ class MemBuddy(MemManager):
|
||||
return count
|
||||
|
||||
def free_bytes(self) -> t.CSizeT:
|
||||
# 统计所有空闲块的总字节数
|
||||
# Count total bytes in all free blocks for status statistics
|
||||
total: t.CSizeT = 0
|
||||
i: t.CInt
|
||||
for i in range(MEMBUDDY_MAX_ORDERS + 1):
|
||||
@@ -522,11 +522,11 @@ class MemBuddy(MemManager):
|
||||
return total
|
||||
|
||||
def used_bytes(self) -> t.CSizeT:
|
||||
# 已使用字节数 = 可用区总大小 - 空闲字节数
|
||||
# Used bytes = total usable region size - free bytes in all free blocks
|
||||
return self.usable_size - self.free_bytes()
|
||||
|
||||
def dump_stats(self, label: t.CChar | t.CPtr):
|
||||
# 打印内存使用统计
|
||||
# Print memory usage statistics
|
||||
fb: t.CSizeT = self.free_bytes()
|
||||
ub: t.CSizeT = self.usable_size - fb
|
||||
stdio.printf("[MEM] %s: total=%zu used=%zu (%zu%%) free=%zu free_blocks=%zu\n",
|
||||
@@ -535,7 +535,7 @@ class MemBuddy(MemManager):
|
||||
fb, self.free_count())
|
||||
|
||||
def self_check(self) -> t.CInt:
|
||||
# 验证伙伴分配器内部一致性,返回 0=OK,非 0=损坏
|
||||
# Validate buddy allocator internal consistency, return 0=OK, non-0=damage
|
||||
if self.usable is None:
|
||||
return 0
|
||||
i: t.CInt
|
||||
@@ -543,12 +543,12 @@ class MemBuddy(MemManager):
|
||||
head_val: t.CUInt64T = self.free_lists[i]
|
||||
cur: t.CVoid | t.CPtr = t.CVoid(head_val, t.CPtr)
|
||||
while t.CUInt64T(cur) != 0:
|
||||
# 检查指针在可用区内
|
||||
# Check pointer is in usable region range
|
||||
if t.CUInt64T(cur) < t.CUInt64T(self.usable):
|
||||
return 1
|
||||
if t.CUInt64T(cur) >= t.CUInt64T(self.usable) + self.usable_size:
|
||||
return 2
|
||||
# 检查对齐:order i 的块必须按 _block_size_at_order(i) 对齐
|
||||
# Check alignment: order i blocks must be aligned to size _block_size_at_order(i)
|
||||
offset: t.CSizeT = t.CUInt64T(cur) - t.CUInt64T(self.usable)
|
||||
bs: t.CSizeT = _block_size_at_order(i)
|
||||
if offset % bs != 0:
|
||||
|
||||
@@ -13,10 +13,10 @@ IS_ARM64: t.CDefine = 0
|
||||
IS_BIG_ENDIAN: t.CDefine = 0
|
||||
IS_ILP32: t.CDefine = 0
|
||||
|
||||
PTR_SIZE: t.CDefine = t.CSizeT().Size
|
||||
PTR_SIZE: t.CDefine = 8
|
||||
INT_SIZE: t.CDefine = 4
|
||||
LONG_SIZE: t.CDefine = t.CLong().Size
|
||||
WORD_SIZE: t.CDefine = t.CSizeT().Size
|
||||
LONG_SIZE: t.CDefine = 4
|
||||
WORD_SIZE: t.CDefine = 8
|
||||
|
||||
CACHE_LINE_SIZE: t.CDefine = 64
|
||||
PAGE_SIZE: t.CDefine = 4096
|
||||
@@ -37,21 +37,21 @@ HAS_FMA: t.CDefine = 1
|
||||
HAS_NEON: t.CDefine = 0
|
||||
|
||||
ALIGNOF_INT: t.CDefine = 4
|
||||
ALIGNOF_LONG: t.CDefine = t.CLong().Size // 8
|
||||
ALIGNOF_PTR: t.CDefine = t.CSizeT().Size // 8
|
||||
ALIGNOF_LONG: t.CDefine = 4
|
||||
ALIGNOF_PTR: t.CDefine = 8
|
||||
ALIGNOF_DOUBLE: t.CDefine = 8
|
||||
ALIGNOF_LONG_DOUBLE: t.CDefine = 16
|
||||
|
||||
SIZEOF_SHORT: t.CDefine = 2
|
||||
SIZEOF_INT: t.CDefine = 4
|
||||
SIZEOF_LONG: t.CDefine = t.CLong().Size // 8
|
||||
SIZEOF_LONG: t.CDefine = 4
|
||||
SIZEOF_LONG_LONG: t.CDefine = 8
|
||||
SIZEOF_FLOAT: t.CDefine = 4
|
||||
SIZEOF_DOUBLE: t.CDefine = 8
|
||||
SIZEOF_LONG_DOUBLE: t.CDefine = 16
|
||||
SIZEOF_POINTER: t.CDefine = t.CSizeT().Size // 8
|
||||
SIZEOF_SIZE_T: t.CDefine = t.CSizeT().Size // 8
|
||||
SIZEOF_PTRDIFF_T: t.CDefine = t.CPtrDiffT().Size // 8
|
||||
SIZEOF_POINTER: t.CDefine = 8
|
||||
SIZEOF_SIZE_T: t.CDefine = 8
|
||||
SIZEOF_PTRDIFF_T: t.CDefine = 8
|
||||
|
||||
BYTE_ORDER_LE: t.CDefine = 1
|
||||
BYTE_ORDER_BE: t.CDefine = 0
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
import t, c
|
||||
|
||||
|
||||
#class PList:
|
||||
# def
|
||||
@@ -3,25 +3,25 @@ from stdint import *
|
||||
|
||||
|
||||
# =============================================================================
|
||||
# POSIX 类型别名
|
||||
# 注意:ssize_t 已在 stdint.py 中定义为 t.CPtrDiffT,此处不再重复
|
||||
# POSIX Type Alias
|
||||
# Note: ssize_t has already been defined as t.CPtrDiffT in stdint.py, so we won’t repeat it here.
|
||||
# =============================================================================
|
||||
DIR: t.CTypedef = t.CVoid | t.CPtr # 不透明目录流句柄
|
||||
mode_t: t.CTypedef = t.CUInt32T # 文件模式/权限位
|
||||
pid_t: t.CTypedef = t.CInt32T # 进程 ID
|
||||
off_t: t.CTypedef = t.CInt64T # 文件偏移量(Linux x86_64)
|
||||
dev_t: t.CTypedef = t.CUInt64T # 设备号
|
||||
ino_t: t.CTypedef = t.CUInt64T # inode 号
|
||||
nlink_t: t.CTypedef = t.CUInt64T # 硬链接数
|
||||
uid_t: t.CTypedef = t.CUInt32T # 用户 ID
|
||||
gid_t: t.CTypedef = t.CUInt32T # 组 ID
|
||||
blksize_t: t.CTypedef = t.CInt64T # 文件系统 I/O 块大小
|
||||
blkcnt_t: t.CTypedef = t.CInt64T # 已分配块数
|
||||
time_t: t.CTypedef = t.CInt64T # 日历时间秒数
|
||||
DIR: t.CTypedef = t.CVoid | t.CPtr # Opaque directory stream handle
|
||||
mode_t: t.CTypedef = t.CUInt32T # File mode/permission bits
|
||||
pid_t: t.CTypedef = t.CInt32T # Process ID
|
||||
off_t: t.CTypedef = t.CInt64T # File offset (Linux x86_64)
|
||||
dev_t: t.CTypedef = t.CUInt64T # Device number
|
||||
ino_t: t.CTypedef = t.CUInt64T # inode number
|
||||
nlink_t: t.CTypedef = t.CUInt64T # Hard link count
|
||||
uid_t: t.CTypedef = t.CUInt32T # User ID
|
||||
gid_t: t.CTypedef = t.CUInt32T # Group ID
|
||||
blksize_t: t.CTypedef = t.CInt64T # File I/O block size
|
||||
blkcnt_t: t.CTypedef = t.CInt64T # Allocated block count
|
||||
time_t: t.CTypedef = t.CInt64T # Calendar time seconds
|
||||
|
||||
|
||||
# =============================================================================
|
||||
# open() 标志位
|
||||
# open() Flags
|
||||
# =============================================================================
|
||||
O_RDONLY: t.CDefine = 0
|
||||
O_WRONLY: t.CDefine = 1
|
||||
@@ -35,46 +35,46 @@ O_CLOEXEC: t.CDefine = 0o2000000
|
||||
|
||||
|
||||
# =============================================================================
|
||||
# access() 测试标志
|
||||
# access() Test Flags
|
||||
# =============================================================================
|
||||
F_OK: t.CDefine = 0 # 文件存在
|
||||
R_OK: t.CDefine = 4 # 可读
|
||||
W_OK: t.CDefine = 2 # 可写
|
||||
X_OK: t.CDefine = 1 # 可执行
|
||||
F_OK: t.CDefine = 0 # File exists
|
||||
R_OK: t.CDefine = 4 # Read permission
|
||||
W_OK: t.CDefine = 2 # Write permission
|
||||
X_OK: t.CDefine = 1 # Execute permission
|
||||
|
||||
|
||||
# =============================================================================
|
||||
# stat 结构体的 st_mode 掩码与类型位
|
||||
# stat struct st_mode Mask and Type Bits
|
||||
# =============================================================================
|
||||
S_IFMT: t.CDefine = 0o170000 # 类型掩码
|
||||
S_IFSOCK: t.CDefine = 0o140000 # 套接字
|
||||
S_IFLNK: t.CDefine = 0o120000 # 符号链接
|
||||
S_IFREG: t.CDefine = 0o100000 # 普通文件
|
||||
S_IFBLK: t.CDefine = 0o060000 # 块设备
|
||||
S_IFDIR: t.CDefine = 0o040000 # 目录
|
||||
S_IFCHR: t.CDefine = 0o020000 # 字符设备
|
||||
S_IFIFO: t.CDefine = 0o010000 # FIFO/管道
|
||||
S_IFMT: t.CDefine = 0o170000 # Type mask bits
|
||||
S_IFSOCK: t.CDefine = 0o140000 # Socket
|
||||
S_IFLNK: t.CDefine = 0o120000 # Symbolic link
|
||||
S_IFREG: t.CDefine = 0o100000 # Regular file
|
||||
S_IFBLK: t.CDefine = 0o060000 # Block device
|
||||
S_IFDIR: t.CDefine = 0o040000 # Directory
|
||||
S_IFCHR: t.CDefine = 0o020000 # Character device
|
||||
S_IFIFO: t.CDefine = 0o010000 # FIFO/pipe
|
||||
|
||||
# 权限位
|
||||
S_ISUID: t.CDefine = 0o4000 # set-user-ID
|
||||
S_ISGID: t.CDefine = 0o2000 # set-group-ID
|
||||
S_ISVTX: t.CDefine = 0o1000 # sticky 位
|
||||
S_IRWXU: t.CDefine = 0o700 # 用户读写执行
|
||||
S_IRUSR: t.CDefine = 0o400 # 用户读
|
||||
S_IWUSR: t.CDefine = 0o200 # 用户写
|
||||
S_IXUSR: t.CDefine = 0o100 # 用户执行
|
||||
S_IRWXG: t.CDefine = 0o070 # 组读写执行
|
||||
S_IRGRP: t.CDefine = 0o040 # 组读
|
||||
S_IWGRP: t.CDefine = 0o020 # 组写
|
||||
S_IXGRP: t.CDefine = 0o010 # 组执行
|
||||
S_IRWXO: t.CDefine = 0o007 # 其他读写执行
|
||||
S_IROTH: t.CDefine = 0o004 # 其他读
|
||||
S_IWOTH: t.CDefine = 0o002 # 其他写
|
||||
S_IXOTH: t.CDefine = 0o001 # 其他执行
|
||||
# Permission Bits
|
||||
S_ISUID: t.CDefine = 0o4000 # Set-user-ID
|
||||
S_ISGID: t.CDefine = 0o2000 # Set-group-ID
|
||||
S_ISVTX: t.CDefine = 0o1000 # Sticky bit
|
||||
S_IRWXU: t.CDefine = 0o700 # Read/write/execute permission
|
||||
S_IRUSR: t.CDefine = 0o400 # User read permission
|
||||
S_IWUSR: t.CDefine = 0o200 # User write permission
|
||||
S_IXUSR: t.CDefine = 0o100 # User execute permission
|
||||
S_IRWXG: t.CDefine = 0o070 # Read/write/execute permission
|
||||
S_IRGRP: t.CDefine = 0o040 # Read permission
|
||||
S_IWGRP: t.CDefine = 0o020 # Write
|
||||
S_IXGRP: t.CDefine = 0o010 # Execute
|
||||
S_IRWXO: t.CDefine = 0o007 # Read/write/execute permission
|
||||
S_IROTH: t.CDefine = 0o004 # Other read permission
|
||||
S_IWOTH: t.CDefine = 0o002 # Other write permission
|
||||
S_IXOTH: t.CDefine = 0o001 # Other execute permission
|
||||
|
||||
|
||||
# =============================================================================
|
||||
# lseek() whence 值
|
||||
# lseek() whence values
|
||||
# =============================================================================
|
||||
SEEK_SET: t.CDefine = 0
|
||||
SEEK_CUR: t.CDefine = 1
|
||||
@@ -82,14 +82,14 @@ SEEK_END: t.CDefine = 2
|
||||
|
||||
|
||||
# =============================================================================
|
||||
# 路径/名称长度限制
|
||||
# Path/name length limits
|
||||
# =============================================================================
|
||||
PATH_MAX: t.CDefine = 4096
|
||||
NAME_MAX: t.CDefine = 255
|
||||
|
||||
|
||||
# =============================================================================
|
||||
# sysconf() 参数
|
||||
# sysconf() parameters
|
||||
# =============================================================================
|
||||
_SC_NPROCESSORS_ONLN: t.CDefine = 84
|
||||
_SC_PAGESIZE: t.CDefine = 30
|
||||
@@ -97,7 +97,7 @@ _SC_CLK_TCK: t.CDefine = 2
|
||||
|
||||
|
||||
# =============================================================================
|
||||
# dirent 结构体的 d_type 值
|
||||
# dirent struct d_type values
|
||||
# =============================================================================
|
||||
DT_UNKNOWN: t.CDefine = 0
|
||||
DT_FIFO: t.CDefine = 1
|
||||
@@ -111,7 +111,7 @@ DT_WHT: t.CDefine = 14
|
||||
|
||||
|
||||
# =============================================================================
|
||||
# waitpid() 选项
|
||||
# waitpid() options
|
||||
# =============================================================================
|
||||
WNOHANG: t.CDefine = 1
|
||||
WUNTRACED: t.CDefine = 2
|
||||
@@ -119,12 +119,12 @@ WCONTINUED: t.CDefine = 8
|
||||
|
||||
|
||||
# =============================================================================
|
||||
# 结构体:Linux x86_64 布局
|
||||
# Struct: Linux x86_64 Layout
|
||||
# =============================================================================
|
||||
|
||||
# struct stat(144 字节,Linux x86_64 glibc 布局)
|
||||
# 注意:st_atim/st_mtim/st_ctim 在 C 中是 struct timespec { tv_sec; tv_nsec; }
|
||||
# 此处拆分为 _sec/_nsec 两个 LONGLONG 字段以保持二进制兼容
|
||||
# struct stat (144 bytes, Linux x86_64 glibc layout)
|
||||
# Note: st_atim/st_mtim/st_ctim in C are struct timespec { tv_sec; tv_nsec; }
|
||||
# Here split into _sec/_nsec two LONGLONG fields to maintain binary compatibility
|
||||
class Stat():
|
||||
st_dev: dev_t # @ 0
|
||||
st_ino: ino_t # @ 8
|
||||
@@ -148,19 +148,19 @@ class Stat():
|
||||
__unused2: LONGLONG # @ 136
|
||||
|
||||
|
||||
# struct dirent(Linux x86_64,d_name 为 char[256])
|
||||
# 注意:d_name 实际是定长 char[256],TransPyC 用 CHARPTR 占位(8 字节)。
|
||||
# 用户通常通过 readdir 返回的只读指针访问,不直接分配 Dirent 结构体。
|
||||
# struct dirent (Linux x86_64, d_name is char[256])
|
||||
# Note: d_name is actually a fixed-length char[256], TransPyC uses CHARPTR as a placeholder (8 bytes).
|
||||
# Users usually access it via the read-only pointer returned by readdir, not by directly allocating a Dirent structure.
|
||||
class Dirent():
|
||||
d_ino: ino_t # @ 0
|
||||
d_off: off_t # @ 8
|
||||
d_reclen: USHORT # @ 16
|
||||
d_type: BYTE # @ 18
|
||||
d_name: CHARPTR # @ 19(实际为 char[256],此处占位)
|
||||
d_name: CHARPTR # @ 19 (actually char[256], this is a placeholder)
|
||||
|
||||
|
||||
# =============================================================================
|
||||
# 文件操作函数(10 个)
|
||||
# File operations (10)
|
||||
# =============================================================================
|
||||
def open(path: t.CConst | str, oflag: INT, *args) -> INT | t.State: pass
|
||||
def close(fd: INT) -> INT | t.State: pass
|
||||
@@ -175,14 +175,14 @@ def chmod(path: t.CConst | str, mode: mode_t) -> INT | t.State: pass
|
||||
|
||||
|
||||
# =============================================================================
|
||||
# stat 系列(2 个)
|
||||
# stat series (2)
|
||||
# =============================================================================
|
||||
def stat(path: t.CConst | str, buf: Stat | t.CPtr) -> INT | t.State: pass
|
||||
def fstat(fd: INT, buf: Stat | t.CPtr) -> INT | t.State: pass
|
||||
|
||||
|
||||
# =============================================================================
|
||||
# 目录操作(6 个)
|
||||
# Directory operations (6)
|
||||
# =============================================================================
|
||||
def opendir(name: t.CConst | str) -> DIR | t.CPtr | t.State: pass
|
||||
def readdir(dirp: DIR | t.CPtr) -> Dirent | t.CPtr | t.State: pass
|
||||
@@ -194,7 +194,7 @@ def chdir(path: t.CConst | str) -> INT | t.State: pass
|
||||
|
||||
|
||||
# =============================================================================
|
||||
# 进程/管道(8 个)
|
||||
# Process operations (8)
|
||||
# =============================================================================
|
||||
def fork() -> pid_t | t.State: pass
|
||||
def execvp(file: t.CConst | str, argv: CHARPTR | t.CPtr) -> INT | t.State: pass
|
||||
@@ -207,7 +207,7 @@ def getpid() -> pid_t | t.State: pass
|
||||
|
||||
|
||||
# =============================================================================
|
||||
# 环境/系统(4 个)
|
||||
# Environment operations (4)
|
||||
# =============================================================================
|
||||
def getenv(name: t.CConst | str) -> CHARPTR | t.State: pass
|
||||
def setenv(name: t.CConst | str, value: t.CConst | str, overwrite: INT) -> INT | t.State: pass
|
||||
@@ -216,10 +216,10 @@ def isatty(fd: INT) -> INT | t.State: pass
|
||||
|
||||
|
||||
# =============================================================================
|
||||
# 内联宏(C 宏,用 TransPyC 普通函数实现,不标记 t.CExtern)
|
||||
# Inline macros (C macros, implemented as normal functions, not marked as t.CExtern)
|
||||
# =============================================================================
|
||||
|
||||
# st_mode 类型判定
|
||||
# st_mode type determination
|
||||
def S_ISREG(mode: mode_t) -> bool:
|
||||
return (mode & S_IFMT) == S_IFREG
|
||||
|
||||
@@ -248,7 +248,7 @@ def S_ISSOCK(mode: mode_t) -> bool:
|
||||
return (mode & S_IFMT) == S_IFSOCK
|
||||
|
||||
|
||||
# waitpid 状态解析
|
||||
# waitpid status parsing
|
||||
def WIFEXITED(status: INT) -> bool:
|
||||
return (status & 0x7F) == 0
|
||||
|
||||
|
||||
@@ -7,21 +7,21 @@ import stdio
|
||||
|
||||
|
||||
# ============================================================
|
||||
# requests.py — HTTP 客户端库(Python 原版风格)
|
||||
# requests.py — HTTP client library (Python original style)
|
||||
#
|
||||
# 用法:
|
||||
# requests._mbuddy = my_mbuddy
|
||||
# resp = requests.get("http://example.com/path")
|
||||
# if resp is not None:
|
||||
# print(resp.status_code)
|
||||
# print(resp.text)
|
||||
# requests.release(resp)
|
||||
# Usage:
|
||||
# requests._mbuddy = my_mbuddy
|
||||
# resp = requests.get("http://example.com/path")
|
||||
# if resp is not None:
|
||||
# print(resp.status_code)
|
||||
# print(resp.text)
|
||||
# requests.release(resp)
|
||||
# ============================================================
|
||||
|
||||
# 模块级全局 MBuddy 指针(由用户在 main 中赋值)
|
||||
# Module-level global MBuddy pointer (assigned by the user in main)
|
||||
_mbuddy: memhub.MemBuddy | t.CPtr
|
||||
|
||||
# Socket 初始化标记
|
||||
# Socket initialization flag
|
||||
_socket_ready: bool = False
|
||||
|
||||
HTTP_PORT: t.CDefine = 80
|
||||
@@ -29,26 +29,26 @@ HTTP_BUFSIZ: t.CDefine = 4096
|
||||
|
||||
|
||||
# ============================================================
|
||||
# Response — HTTP 响应对象
|
||||
# Response — HTTP response object
|
||||
# ============================================================
|
||||
|
||||
class Response:
|
||||
"""HTTP 响应对象,贴近 Python requests.Response 用法。
|
||||
"""HTTP response object, similar to how Python's requests.Response works.
|
||||
|
||||
从 _mbuddy 分配,使用完毕后调用 release(resp) 释放。
|
||||
Allocated from _mbuddy, call release(resp) to free it after use.
|
||||
"""
|
||||
status_code: INT # HTTP 状态码(如 200、404)
|
||||
text: str # 响应体文本(指向 _raw_buf 内部)
|
||||
body_len: INT # 响应体长度
|
||||
_raw_buf: str # 原始缓冲区指针
|
||||
status_code: INT # HTTP status code (e.g., 200, 404)
|
||||
text: str # Response body text (points into _raw_buf)
|
||||
body_len: INT # Response body length
|
||||
_raw_buf: str # Raw buffer pointer
|
||||
|
||||
|
||||
# ============================================================
|
||||
# 内部辅助函数
|
||||
# Internal auxiliary functions
|
||||
# ============================================================
|
||||
|
||||
def _EnsureSocketInit() -> INT:
|
||||
"""确保 Socket 库已初始化(幂等)。"""
|
||||
"""Ensure Socket library is initialized (idempotent)."""
|
||||
global _socket_ready
|
||||
if _socket_ready: return 0
|
||||
result: INT = socket.SocketInit()
|
||||
@@ -58,7 +58,7 @@ def _EnsureSocketInit() -> INT:
|
||||
|
||||
|
||||
def _AllocResponse() -> Response | t.CPtr:
|
||||
"""从 _mbuddy 分配 Response 结构体并就地初始化。"""
|
||||
"""Allocate Response struct from _mbuddy and initialize it in-place."""
|
||||
if _mbuddy is None: return None
|
||||
resp: Response | t.CPtr = _mbuddy.alloc(Response.__sizeof__())
|
||||
if resp is None: return None
|
||||
@@ -70,17 +70,17 @@ def _AllocResponse() -> Response | t.CPtr:
|
||||
|
||||
|
||||
def _ParseUrl(url: str, host_buf: str, host_size: INT, path_buf: str, path_size: INT, port: INT | t.CPtr) -> INT:
|
||||
"""解析 URL,提取 host、port、path。"""
|
||||
"""Parse URL and extract host, port, and path."""
|
||||
if url is None: return -1
|
||||
if host_buf is None or path_buf is None or port is None: return -1
|
||||
|
||||
p: str = url
|
||||
|
||||
# 跳过 "http://"
|
||||
# Skip "http://"
|
||||
if string.strncmp(p, "http://", 7) == 0:
|
||||
p += 7
|
||||
|
||||
# 解析 host
|
||||
# Parse host
|
||||
host_start: str = p
|
||||
host_len: INT = 0
|
||||
while p[0] != '\0' and p[0] != ':' and p[0] != '/':
|
||||
@@ -91,7 +91,7 @@ def _ParseUrl(url: str, host_buf: str, host_size: INT, path_buf: str, path_size:
|
||||
string.strncpy(host_buf, host_start, host_len)
|
||||
host_buf[host_len] = 0
|
||||
|
||||
# 解析 port
|
||||
# Parse port
|
||||
if p[0] == ':':
|
||||
p += 1
|
||||
port_val: INT = 0
|
||||
@@ -102,7 +102,7 @@ def _ParseUrl(url: str, host_buf: str, host_size: INT, path_buf: str, path_size:
|
||||
else:
|
||||
c.DerefAs(port, HTTP_PORT)
|
||||
|
||||
# 解析 path
|
||||
# Parse path
|
||||
if p[0] == '/':
|
||||
path_start: str = p
|
||||
path_len: INT = 0
|
||||
@@ -121,17 +121,17 @@ def _ParseUrl(url: str, host_buf: str, host_size: INT, path_buf: str, path_size:
|
||||
|
||||
|
||||
def _ParseStatusLine(resp_text: str, out_code: INT | t.CPtr) -> INT:
|
||||
"""解析 HTTP 状态行,提取状态码。返回状态行结束偏移。"""
|
||||
"""Parse HTTP status line and extract status code."""
|
||||
if resp_text is None or out_code is None: return -1
|
||||
|
||||
p: str = resp_text
|
||||
|
||||
# 跳过 "HTTP/x.x "
|
||||
# Skip "HTTP/x.x "
|
||||
while p[0] != '\0' and p[0] != ' ':
|
||||
p += 1
|
||||
if p[0] == ' ': p += 1
|
||||
|
||||
# 解析状态码
|
||||
# Parse status code
|
||||
code: INT = 0
|
||||
while p[0] >= '0' and p[0] <= '9':
|
||||
code = code * 10 + INT(p[0] - '0')
|
||||
@@ -139,7 +139,7 @@ def _ParseStatusLine(resp_text: str, out_code: INT | t.CPtr) -> INT:
|
||||
|
||||
c.DerefAs(out_code, code)
|
||||
|
||||
# 找到 \n
|
||||
# Find \n
|
||||
while p[0] != '\0' and p[0] != '\n':
|
||||
p += 1
|
||||
if p[0] == '\n': p += 1
|
||||
@@ -148,7 +148,7 @@ def _ParseStatusLine(resp_text: str, out_code: INT | t.CPtr) -> INT:
|
||||
|
||||
|
||||
def _FindBodyStart(resp_text: str, resp_len: INT) -> INT:
|
||||
"""找到 HTTP 响应体起始位置(\\r\\n\\r\\n 之后)。"""
|
||||
"""Find the start of the HTTP response body (after rnrn)."""
|
||||
if resp_text is None: return -1
|
||||
|
||||
end_of_headers: str = string.strstr(resp_text, "\r\n\r\n")
|
||||
@@ -166,13 +166,12 @@ def _FindBodyStart(resp_text: str, resp_len: INT) -> INT:
|
||||
# ============================================================
|
||||
|
||||
def get(url: str) -> Response | t.CPtr:
|
||||
"""HTTP GET 请求。
|
||||
"""HTTP GET request.
|
||||
|
||||
Args:
|
||||
url: 完整 URL (如 "http://example.com/path")
|
||||
url: Full URL (e.g., "http://example.com/path")
|
||||
Returns:
|
||||
Response 对象指针(从 _mbuddy 分配),失败返回 None。
|
||||
使用完毕后调用 release(resp) 释放。
|
||||
Pointer to a Response object (allocated from _mbuddy), returns None on failure.
|
||||
"""
|
||||
if _mbuddy is None: return None
|
||||
|
||||
@@ -183,7 +182,7 @@ def get(url: str) -> Response | t.CPtr:
|
||||
release(resp)
|
||||
return None
|
||||
|
||||
# 解析 URL
|
||||
# Parse URL
|
||||
host_buf: t.CArray[t.CChar, 256]
|
||||
path_buf: t.CArray[t.CChar, 1024]
|
||||
port: INT = 0
|
||||
@@ -192,7 +191,7 @@ def get(url: str) -> Response | t.CPtr:
|
||||
release(resp)
|
||||
return None
|
||||
|
||||
# 创建并连接 Socket
|
||||
# Create Socket
|
||||
sock = socket.Socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
if sock.fd == socket.INVALID_SOCKET:
|
||||
release(resp)
|
||||
@@ -203,7 +202,7 @@ def get(url: str) -> Response | t.CPtr:
|
||||
release(resp)
|
||||
return None
|
||||
|
||||
# 构建 HTTP 请求
|
||||
# Build HTTP request
|
||||
req_buf: str = _mbuddy.alloc(HTTP_BUFSIZ)
|
||||
if req_buf is None:
|
||||
sock.close()
|
||||
@@ -223,7 +222,7 @@ def get(url: str) -> Response | t.CPtr:
|
||||
release(resp)
|
||||
return None
|
||||
|
||||
# 接收响应
|
||||
# Receive response body
|
||||
resp_buf: str = _mbuddy.alloc(HTTP_BUFSIZ)
|
||||
if resp_buf is None:
|
||||
sock.close()
|
||||
@@ -241,10 +240,10 @@ def get(url: str) -> Response | t.CPtr:
|
||||
|
||||
resp._raw_buf = resp_buf
|
||||
|
||||
# 解析状态码
|
||||
# Parse status line
|
||||
_ParseStatusLine(resp_buf, c.Addr(resp.status_code))
|
||||
|
||||
# 找到 body
|
||||
# Find body start
|
||||
body_offset: INT = _FindBodyStart(resp_buf, total)
|
||||
if body_offset < 0 or body_offset >= total:
|
||||
resp.text = None
|
||||
@@ -257,14 +256,14 @@ def get(url: str) -> Response | t.CPtr:
|
||||
|
||||
|
||||
def post(url: str, data: str = None, content_type: str = "application/x-www-form-urlencoded") -> Response | t.CPtr:
|
||||
"""HTTP POST 请求。
|
||||
"""HTTP POST request.
|
||||
|
||||
Args:
|
||||
url: 完整 URL
|
||||
data: 请求体数据
|
||||
content_type: Content-Type 头(默认 "application/x-www-form-urlencoded")
|
||||
url: Full URL
|
||||
data: Request body data
|
||||
content_type: Content-Type header (default is "application/x-www-form-urlencoded")
|
||||
Returns:
|
||||
Response 对象指针(从 _mbuddy 分配),失败返回 None。
|
||||
Pointer to Response object (allocated from _mbuddy), returns None on failure.
|
||||
"""
|
||||
if _mbuddy is None: return None
|
||||
|
||||
@@ -275,7 +274,7 @@ def post(url: str, data: str = None, content_type: str = "application/x-www-form
|
||||
release(resp)
|
||||
return None
|
||||
|
||||
# 解析 URL
|
||||
# Parse URL
|
||||
host_buf: t.CArray[t.CChar, 256]
|
||||
path_buf: t.CArray[t.CChar, 1024]
|
||||
port: INT = 0
|
||||
@@ -287,7 +286,7 @@ def post(url: str, data: str = None, content_type: str = "application/x-www-form
|
||||
body_len: INT = INT(string.strlen(data)) if data is not None else 0
|
||||
ct: str = content_type if content_type is not None else "application/x-www-form-urlencoded"
|
||||
|
||||
# 创建并连接 Socket
|
||||
# Create Socket
|
||||
sock = socket.Socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
if sock.fd == socket.INVALID_SOCKET:
|
||||
release(resp)
|
||||
@@ -298,7 +297,7 @@ def post(url: str, data: str = None, content_type: str = "application/x-www-form
|
||||
release(resp)
|
||||
return None
|
||||
|
||||
# 构建 HTTP 请求
|
||||
# Build HTTP request
|
||||
req_buf: str = _mbuddy.alloc(HTTP_BUFSIZ)
|
||||
if req_buf is None:
|
||||
sock.close()
|
||||
@@ -311,14 +310,14 @@ def post(url: str, data: str = None, content_type: str = "application/x-www-form
|
||||
|
||||
hdr_len: INT = INT(string.strlen(req_buf))
|
||||
|
||||
# 发送头部 + body
|
||||
# Send headers + body
|
||||
sent: INT = sock.send(req_buf, hdr_len)
|
||||
if sent > 0 and body_len > 0 and data is not None:
|
||||
sock.send(data, body_len)
|
||||
|
||||
_mbuddy.free(req_buf)
|
||||
|
||||
# 接收响应
|
||||
# Receive response body
|
||||
resp_buf: str = _mbuddy.alloc(HTTP_BUFSIZ)
|
||||
if resp_buf is None:
|
||||
sock.close()
|
||||
@@ -349,13 +348,13 @@ def post(url: str, data: str = None, content_type: str = "application/x-www-form
|
||||
|
||||
|
||||
def release(resp: Response | t.CPtr):
|
||||
"""释放 Response 对象及其内部缓冲区。
|
||||
"""Release Response object and its internal buffers.
|
||||
|
||||
Args:
|
||||
resp: 要释放的 Response 对象
|
||||
resp: The Response object to release
|
||||
"""
|
||||
if resp is None: return
|
||||
if _mbuddy is None: return
|
||||
if resp._raw_buf is not None:
|
||||
_mbuddy.free(resp._raw_buf)
|
||||
_mbuddy.free(t.CVoid(t.CUInt64T(resp), t.CPtr))
|
||||
_mbuddy.free(t.CVoid(t.CUInt64T(resp), t.CPtr))
|
||||
|
||||
@@ -10,15 +10,15 @@ from w32.win32sync import (
|
||||
|
||||
@t.Object
|
||||
class RWLock:
|
||||
"""基于 SRWLock 的读写锁,支持多读单写,不支持递归。
|
||||
"""SRWLock-based read-write lock that supports multiple readers and single writer, but does not support recursion.
|
||||
|
||||
用法:
|
||||
Usage:
|
||||
rwlock: RWLock = RWLock()
|
||||
rwlock.acquire_read()
|
||||
# ... 读取共享数据
|
||||
# ... read shared data
|
||||
rwlock.release_read()
|
||||
rwlock.acquire_write()
|
||||
# ... 修改共享数据
|
||||
# ... modify shared data
|
||||
rwlock.release_write()
|
||||
"""
|
||||
lock: VOIDPTR
|
||||
|
||||
@@ -4,34 +4,34 @@ import platmacro
|
||||
import memhub
|
||||
import string
|
||||
|
||||
# Windows 后端依赖
|
||||
# Windows backend dependencies
|
||||
import w32.win32base
|
||||
import w32.win32file
|
||||
|
||||
# POSIX 后端依赖
|
||||
# POSIX backend dependencies
|
||||
import posix
|
||||
|
||||
|
||||
# 文件拷贝缓冲区大小
|
||||
COPY_BUF_SIZE: t.CDefine = 65536
|
||||
# File copy buffer size
|
||||
COPY_BUF_SIZE: t.CDefine = 65536 # 2^16
|
||||
|
||||
# 模块级全局 MBuddy 指针(由用户在 main 中赋值初始化)
|
||||
# Module-level global MBuddy pointer (initialized by the user in main)
|
||||
_mbuddy: memhub.MemBuddy | t.CPtr
|
||||
|
||||
|
||||
# =============================================================================
|
||||
# copyfile:拷贝文件内容(不保留权限/元数据)
|
||||
# copyfile: Copy file content (without preserving permissions/metadata)
|
||||
# =============================================================================
|
||||
|
||||
def copyfile(src: str, dst: str) -> int:
|
||||
"""拷贝文件内容。成功返回 0,失败返回 -1。"""
|
||||
"""Copy file content. Returns 0, otherwise -1."""
|
||||
if platmacro.IS_WINDOWS:
|
||||
return _copyfile_win32(src, dst)
|
||||
return _copyfile_posix(src, dst)
|
||||
|
||||
|
||||
def _copyfile_win32(src: str, dst: str) -> int:
|
||||
"""Windows:使用 CopyFileA 内核实现(高效)"""
|
||||
"""Windows: Use CopyFileA kernel implementation (efficient)."""
|
||||
result: BOOL = w32.win32file.CopyFileA(src, dst, 0)
|
||||
if result == 0:
|
||||
return -1
|
||||
@@ -39,7 +39,7 @@ def _copyfile_win32(src: str, dst: str) -> int:
|
||||
|
||||
|
||||
def _copyfile_posix(src: str, dst: str) -> int:
|
||||
"""POSIX:手动 read/write 循环拷贝"""
|
||||
"""POSIX: Manual file read/write loop copy"""
|
||||
fd_in: INT = posix.open(src, posix.O_RDONLY, 0)
|
||||
if fd_in < 0:
|
||||
return -1
|
||||
@@ -70,23 +70,23 @@ def _copyfile_posix(src: str, dst: str) -> int:
|
||||
|
||||
|
||||
# =============================================================================
|
||||
# copy:拷贝文件并保留权限
|
||||
# copy: Copy file and preserve permissions/metadata (POSIX only)
|
||||
# =============================================================================
|
||||
|
||||
def copy(src: str, dst: str) -> int:
|
||||
"""拷贝文件并保留权限(POSIX 上调用 stat+chmod)。成功返回 0,失败返回 -1。"""
|
||||
"""Copy file and preserve permissions/metadata (POSIX only). Returns 0, otherwise -1."""
|
||||
if platmacro.IS_WINDOWS:
|
||||
return _copy_win32(src, dst)
|
||||
return _copy_posix(src, dst)
|
||||
|
||||
|
||||
def _copy_win32(src: str, dst: str) -> int:
|
||||
"""Windows:拷贝文件(CopyFileA,Windows 权限模型简单,直接委托 copyfile)"""
|
||||
"""Windows: Copy file (using CopyFileA kernel implementation (simple, delegate to copyfile)."""
|
||||
return _copyfile_win32(src, dst)
|
||||
|
||||
|
||||
def _copy_posix(src: str, dst: str) -> int:
|
||||
"""POSIX:拷贝文件并保留权限(stat+chmod)"""
|
||||
"""POSIX: Copy file and preserve permissions (stat+chmod). Returns 0, otherwise -1."""
|
||||
result: int = _copyfile_posix(src, dst)
|
||||
if result != 0:
|
||||
return -1
|
||||
@@ -97,20 +97,20 @@ def _copy_posix(src: str, dst: str) -> int:
|
||||
|
||||
|
||||
# =============================================================================
|
||||
# rmtree:递归删除目录树
|
||||
# rmtree: Recursively remove directory tree (POSIX only)
|
||||
# =============================================================================
|
||||
|
||||
def rmtree(path: str) -> int:
|
||||
"""递归删除目录树。成功返回 0,失败返回 -1。"""
|
||||
"""Recursively delete a directory tree. Returns 0 on success and -1 on failure."""
|
||||
if platmacro.IS_WINDOWS:
|
||||
return _rmtree_win32(path)
|
||||
return _rmtree_posix(path)
|
||||
|
||||
|
||||
def _rmtree_win32(path: str) -> int:
|
||||
"""Windows:FindFirstFileA/FindNextFileA 递归删除"""
|
||||
"""Windows: Recursively delete a directory tree using FindFirstFileA/FindNextFileA."""
|
||||
path_len: t.CSizeT = len(path)
|
||||
# 构造搜索模式 path\*
|
||||
# Construct search pattern path\*
|
||||
pattern: bytes = _mbuddy.alloc(path_len + 3)
|
||||
if pattern == None:
|
||||
return -1
|
||||
@@ -136,7 +136,7 @@ def _rmtree_win32(path: str) -> int:
|
||||
has_more: int = 1
|
||||
while has_more == 1:
|
||||
name: str = find_data.cFileName
|
||||
# 跳过 . 和 ..
|
||||
# Skip . and ..
|
||||
skip: bool = False
|
||||
if name[0] == '.':
|
||||
if name[1] == 0:
|
||||
@@ -144,7 +144,7 @@ def _rmtree_win32(path: str) -> int:
|
||||
elif name[1] == '.' and name[2] == 0:
|
||||
skip = True
|
||||
if not skip:
|
||||
# 构造完整路径 path\name
|
||||
# Construct full path path\name
|
||||
name_len: t.CSizeT = len(name)
|
||||
full_path: bytes = _mbuddy.alloc(path_len + name_len + 2)
|
||||
if full_path == None:
|
||||
@@ -162,23 +162,23 @@ def _rmtree_win32(path: str) -> int:
|
||||
full_path[j] = ch
|
||||
j += 1
|
||||
full_path[j] = 0
|
||||
# 判断是文件还是目录
|
||||
# Check if it's a directory or a file
|
||||
if (find_data.dwFileAttributes & w32.win32file.FILE_ATTRIBUTE_DIRECTORY) != 0:
|
||||
# 递归删除子目录
|
||||
# Recursively delete subdirectory
|
||||
sub_result: int = _rmtree_win32(str(full_path))
|
||||
if sub_result != 0:
|
||||
result = -1
|
||||
else:
|
||||
# 删除文件
|
||||
# Delete file
|
||||
if w32.win32file.DeleteFileA(str(full_path)) == 0:
|
||||
result = -1
|
||||
_mbuddy.free(full_path)
|
||||
# 继续搜索下一个条目
|
||||
# Continue searching next entry
|
||||
if w32.win32file.FindNextFileA(handle, t.CPtr(c.Addr(find_data))) == 0:
|
||||
has_more = 0
|
||||
|
||||
w32.win32file.FindClose(handle)
|
||||
# 最后删除空目录本身
|
||||
# Delete empty directory itself
|
||||
if result == 0:
|
||||
if w32.win32file.RemoveDirectoryA(path) == 0:
|
||||
result = -1
|
||||
@@ -186,7 +186,7 @@ def _rmtree_win32(path: str) -> int:
|
||||
|
||||
|
||||
def _rmtree_posix(path: str) -> int:
|
||||
"""POSIX:opendir/readdir 递归删除"""
|
||||
"""POSIX: Recursively delete a directory tree using opendir/readdir."""
|
||||
dirp: posix.DIR = posix.opendir(path)
|
||||
if dirp == None:
|
||||
return -1
|
||||
@@ -196,7 +196,7 @@ def _rmtree_posix(path: str) -> int:
|
||||
entry: posix.Dirent = posix.readdir(dirp)
|
||||
while entry != None:
|
||||
name: str = entry.d_name
|
||||
# 跳过 . 和 ..
|
||||
# Skip . and ..
|
||||
skip: bool = False
|
||||
if name[0] == '.':
|
||||
if name[1] == 0:
|
||||
@@ -204,7 +204,7 @@ def _rmtree_posix(path: str) -> int:
|
||||
elif name[1] == '.' and name[2] == 0:
|
||||
skip = True
|
||||
if not skip:
|
||||
# 构造完整路径 path/name
|
||||
# Construct full path path/name
|
||||
name_len: t.CSizeT = len(name)
|
||||
full_path: bytes = _mbuddy.alloc(path_len + name_len + 2)
|
||||
if full_path == None:
|
||||
@@ -222,21 +222,21 @@ def _rmtree_posix(path: str) -> int:
|
||||
full_path[j] = ch
|
||||
j += 1
|
||||
full_path[j] = 0
|
||||
# 判断条目类型
|
||||
# Check entry type
|
||||
if entry.d_type == posix.DT_DIR:
|
||||
# 递归删除子目录
|
||||
# Recursively delete subdirectory
|
||||
sub_result: int = _rmtree_posix(str(full_path))
|
||||
if sub_result != 0:
|
||||
result = -1
|
||||
else:
|
||||
# 删除文件/符号链接等
|
||||
# Delete file or symbolic link etc.
|
||||
if posix.unlink(str(full_path)) != 0:
|
||||
result = -1
|
||||
_mbuddy.free(full_path)
|
||||
entry = posix.readdir(dirp)
|
||||
|
||||
posix.closedir(dirp)
|
||||
# 最后删除空目录本身
|
||||
# Delete empty directory itself
|
||||
if result == 0:
|
||||
if posix.rmdir(path) != 0:
|
||||
result = -1
|
||||
@@ -244,26 +244,26 @@ def _rmtree_posix(path: str) -> int:
|
||||
|
||||
|
||||
# =============================================================================
|
||||
# move:移动文件/目录
|
||||
# move:Move file/directory
|
||||
# =============================================================================
|
||||
|
||||
def move(src: str, dst: str) -> int:
|
||||
"""移动/重命名文件或目录。同分区时直接 rename,跨分区时 copy+delete。
|
||||
成功返回 0,失败返回 -1。"""
|
||||
"""Move/rename files or directories. If it's the same partition, just rename;
|
||||
if it's across partitions, copy then delete. Returns 0 on success, -1 on failure."""
|
||||
if platmacro.IS_WINDOWS:
|
||||
return _move_win32(src, dst)
|
||||
return _move_posix(src, dst)
|
||||
|
||||
|
||||
def _move_win32(src: str, dst: str) -> int:
|
||||
"""Windows:MoveFileExA(同分区 rename,跨分区 copy+delete)"""
|
||||
"""Windows: MoveFileExA (rename within the same partition, copy and delete across partitions)"""
|
||||
rename_result: BOOL = w32.win32file.MoveFileExA(
|
||||
src, dst,
|
||||
w32.win32file.MOVEFILE_REPLACE_EXISTING | w32.win32file.MOVEFILE_COPY_ALLOWED
|
||||
)
|
||||
if rename_result != 0:
|
||||
return 0
|
||||
# rename 失败,尝试 copy + remove
|
||||
# rename failed, try copy or remove
|
||||
if copyfile(src, dst) != 0:
|
||||
return -1
|
||||
if w32.win32file.DeleteFileA(src) == 0:
|
||||
@@ -272,10 +272,10 @@ def _move_win32(src: str, dst: str) -> int:
|
||||
|
||||
|
||||
def _move_posix(src: str, dst: str) -> int:
|
||||
"""POSIX:rename(同分区),跨分区 copy+unlink"""
|
||||
"""POSIX: rename (within the same partition), copy and unlink across partitions"""
|
||||
if posix.rename(src, dst) == 0:
|
||||
return 0
|
||||
# rename 失败(可能跨分区),尝试 copy + unlink
|
||||
# rename failed (possibly across partitions), try copy or remove
|
||||
if copyfile(src, dst) != 0:
|
||||
return -1
|
||||
if posix.unlink(src) != 0:
|
||||
|
||||
@@ -7,17 +7,17 @@ import w32.winsock2
|
||||
|
||||
|
||||
# ============================================================
|
||||
# socket.py — 跨平台 Socket 封装
|
||||
# Python 风格 OOP API + 兼容旧版过程式函数
|
||||
# socket.py — Cross-platform wrapper for Socket
|
||||
# Python-style OOP API + Compatibility with legacy procedural functions
|
||||
#
|
||||
# 用法示例:
|
||||
# Example:
|
||||
# sock = socket.Socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
# sock.connect("example.com", 80)
|
||||
# sock.send(data, length)
|
||||
# n = sock.recv(buf, bufsize)
|
||||
# sock.close()
|
||||
#
|
||||
# 仅 3 处平台差异(通过 platmacro.IS_WINDOWS 分支):
|
||||
# Only 3 platform differences (via platmacro.IS_WINDOWS branch):
|
||||
# 1. WSAStartup() / WSACleanup()
|
||||
# 2. closesocket() vs close()
|
||||
# 3. WSAGetLastError() vs errno
|
||||
@@ -25,7 +25,7 @@ import w32.winsock2
|
||||
|
||||
|
||||
# ============================================================
|
||||
# 常量
|
||||
# Constants
|
||||
# ============================================================
|
||||
AF_INET: t.CDefine = 2
|
||||
AF_INET6: t.CDefine = 10
|
||||
@@ -51,11 +51,11 @@ SOCKET_DEFAULT_TIMEOUT: t.CDefine = 0
|
||||
|
||||
|
||||
# ============================================================
|
||||
# 结构体
|
||||
# Structures
|
||||
# ============================================================
|
||||
|
||||
class SocketAddr:
|
||||
"""sockaddr_in — IPv4 地址(16 字节,POSIX 布局)"""
|
||||
"""sockaddr_in — IPv4 address (16 bytes layout)"""
|
||||
family: u16
|
||||
port: u16
|
||||
addr: u32
|
||||
@@ -63,7 +63,7 @@ class SocketAddr:
|
||||
|
||||
|
||||
class HostEnt:
|
||||
"""struct hostent — DNS 解析结果"""
|
||||
"""struct hostent — DNS resolution result"""
|
||||
h_name: CHARPTR
|
||||
h_aliases: CHARPTR
|
||||
h_addrtype: INT
|
||||
@@ -72,14 +72,14 @@ class HostEnt:
|
||||
|
||||
|
||||
class timeval:
|
||||
"""struct timeval — 超时设置"""
|
||||
"""struct timeval — Timeout setting"""
|
||||
tv_sec: INT
|
||||
tv_usec: INT
|
||||
|
||||
|
||||
# ============================================================
|
||||
# 外部 C 函数 — 使用 u64 句柄,跨平台兼容
|
||||
# (Windows SOCKET=u64, POSIX fd=int → u64 零扩展兼容)
|
||||
# External C Functions — Using u64 Handle, Cross-platform Compatibility
|
||||
# (Windows SOCKET=u64, POSIX fd=int → u64 Zero-Extension Compatible)
|
||||
# ============================================================
|
||||
|
||||
def socket(family: INT, type: INT, protocol: INT) -> u64 | t.CExtern | t.CExport: pass
|
||||
@@ -97,18 +97,20 @@ def close(fd: u64) -> INT | t.CExtern | t.CExport: pass
|
||||
|
||||
|
||||
# ============================================================
|
||||
# 内部辅助函数
|
||||
# Internal Auxiliary Functions
|
||||
# ============================================================
|
||||
|
||||
def _CloseFd(fd: INT) -> INT:
|
||||
"""平台差异:Windows 用 closesocket,POSIX 用 close。"""
|
||||
"""Platform differences: Windows uses closesocket, POSIX uses close。"""
|
||||
if platmacro.IS_WINDOWS:
|
||||
return w32.winsock2.closesocket(u64(fd))
|
||||
return close(fd)
|
||||
|
||||
|
||||
def _MakeAddr(host: str, port: INT) -> SocketAddr:
|
||||
"""构建 SocketAddr。先尝试点分十进制 IP,失败则 DNS 解析。"""
|
||||
"""Build SocketAddr. First try decimal IP, then DNS resolution.
|
||||
If decimal IP fails, try DNS resolution.
|
||||
If DNS resolution fails, return INADDR_ANY."""
|
||||
addr: SocketAddr
|
||||
string.memset(c.Addr(addr), 0, 16)
|
||||
addr.family = u16(AF_INET)
|
||||
@@ -119,8 +121,8 @@ def _MakeAddr(host: str, port: INT) -> SocketAddr:
|
||||
addr.addr = ip
|
||||
return addr
|
||||
|
||||
# DNS 解析 — gethostbyname 返回 struct hostent*
|
||||
# h_addr_list 是 char** → h_addr_list[0] 是 char* → *(uint32_t*)h_addr_list[0] 是 IP
|
||||
# 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: w32.winsock2.WSAHostEnt | t.CPtr = w32.winsock2.gethostbyname(host)
|
||||
if he_raw is not None:
|
||||
@@ -140,7 +142,7 @@ def _MakeAddr(host: str, port: INT) -> SocketAddr:
|
||||
|
||||
|
||||
def _ParseIPv4(ip_str: str, out_addr: u32 | t.CPtr) -> bool:
|
||||
"""解析点分十进制 IPv4 地址。"""
|
||||
"""Parse IPv4 address."""
|
||||
if ip_str is None or out_addr is None: return False
|
||||
|
||||
parts: t.CArray[INT, 4]
|
||||
@@ -179,13 +181,13 @@ def _ParseIPv4(ip_str: str, out_addr: u32 | t.CPtr) -> bool:
|
||||
|
||||
|
||||
# ============================================================
|
||||
# Socket 类 — Python 风格 OOP API
|
||||
# Socket class — Python OOP API
|
||||
# ============================================================
|
||||
|
||||
class Socket:
|
||||
"""跨平台 Socket 封装,贴近 Python socket.socket 用法。
|
||||
"""Cross-platform Socket class, similar to Python socket.socket.
|
||||
|
||||
用法:
|
||||
Usage:
|
||||
sock = Socket(AF_INET, SOCK_STREAM)
|
||||
sock.connect("example.com", 80)
|
||||
sock.send(data, length)
|
||||
@@ -198,12 +200,12 @@ class Socket:
|
||||
protocol: INT
|
||||
|
||||
def __init__(self, family: INT, type: INT, protocol: INT = 0):
|
||||
"""创建 Socket。
|
||||
"""Create Socket.
|
||||
|
||||
Args:
|
||||
family: 地址族 (AF_INET)
|
||||
type: 套接字类型 (SOCK_STREAM)
|
||||
protocol: 协议 (默认 0,自动匹配)
|
||||
family: Address family (AF_INET)
|
||||
type: Socket type (SOCK_STREAM)
|
||||
protocol: Protocol (default 0, auto-match)
|
||||
"""
|
||||
self.family = family
|
||||
self.type = type
|
||||
@@ -215,13 +217,13 @@ class Socket:
|
||||
self.fd = socket(family, type, protocol)
|
||||
|
||||
def connect(self, host: str, port: INT) -> INT:
|
||||
"""连接到远程主机。
|
||||
"""Connect to remote host.
|
||||
|
||||
Args:
|
||||
host: 主机名或 IP
|
||||
port: 端口号
|
||||
host: Hostname or IP
|
||||
port: Port number
|
||||
Returns:
|
||||
0 成功,非 0 失败
|
||||
0 success, non 0 otherwise
|
||||
"""
|
||||
if self.fd == INVALID_SOCKET: return -1
|
||||
addr: SocketAddr = _MakeAddr(host, port)
|
||||
@@ -236,10 +238,10 @@ class Socket:
|
||||
return result
|
||||
|
||||
def send(self, data: t.CVoid | t.CPtr, length: INT) -> INT:
|
||||
"""发送数据。
|
||||
"""Send data.
|
||||
|
||||
Returns:
|
||||
已发送字节数,SOCKET_ERROR 失败
|
||||
Sent bytes, SOCKET_ERROR on error
|
||||
"""
|
||||
if self.fd == INVALID_SOCKET: return SOCKET_ERROR
|
||||
if data is None or length <= 0: return 0
|
||||
@@ -249,10 +251,10 @@ class Socket:
|
||||
return send(self.fd, data, length, 0)
|
||||
|
||||
def recv(self, buf: t.CVoid | t.CPtr, bufsize: INT) -> INT:
|
||||
"""接收数据。
|
||||
"""Receive data.
|
||||
|
||||
Returns:
|
||||
已接收字节数,SOCKET_ERROR 失败,0 表示连接关闭
|
||||
Received bytes, SOCKET_ERROR on error, 0 on connection close
|
||||
"""
|
||||
if self.fd == INVALID_SOCKET: return SOCKET_ERROR
|
||||
if buf is None or bufsize <= 0: return 0
|
||||
@@ -262,10 +264,10 @@ class Socket:
|
||||
return recv(self.fd, buf, bufsize, 0)
|
||||
|
||||
def sendall(self, data: t.CVoid | t.CPtr, length: INT) -> INT:
|
||||
"""发送全部数据(循环发送直到完成或出错)。
|
||||
"""Send all data.
|
||||
|
||||
Returns:
|
||||
0 成功,SOCKET_ERROR 失败
|
||||
0 success, SOCKET_ERROR on error
|
||||
"""
|
||||
if self.fd == INVALID_SOCKET: return SOCKET_ERROR
|
||||
if data is None or length <= 0: return 0
|
||||
@@ -278,17 +280,17 @@ class Socket:
|
||||
return 0
|
||||
|
||||
def close(self) -> INT:
|
||||
"""关闭 Socket。"""
|
||||
"""Close Socket."""
|
||||
if self.fd == INVALID_SOCKET: return 0
|
||||
result: INT = _CloseFd(self.fd)
|
||||
self.fd = INVALID_SOCKET
|
||||
return result
|
||||
|
||||
def bind(self, host: str, port: INT) -> INT:
|
||||
"""绑定地址和端口(服务器端)。
|
||||
"""Bind address and port (server-side).
|
||||
|
||||
Returns:
|
||||
0 成功,非 0 失败
|
||||
0 success, non 0 otherwise
|
||||
"""
|
||||
if self.fd == INVALID_SOCKET: return -1
|
||||
addr: SocketAddr = _MakeAddr(host, port)
|
||||
@@ -298,10 +300,10 @@ class Socket:
|
||||
return bind(self.fd, c.Addr(addr), 16)
|
||||
|
||||
def listen(self, backlog: INT) -> INT:
|
||||
"""开始监听连接(服务器端)。
|
||||
"""Start for incoming connections (server-side).
|
||||
|
||||
Returns:
|
||||
0 成功,非 0 失败
|
||||
0 success, non 0 otherwise
|
||||
"""
|
||||
if self.fd == INVALID_SOCKET: return -1
|
||||
|
||||
@@ -310,12 +312,12 @@ class Socket:
|
||||
return listen(self.fd, backlog)
|
||||
|
||||
def accept(self, out_client: 'Socket' | t.CPtr) -> INT:
|
||||
"""接受一个客户端连接。
|
||||
"""Accept a client connection.
|
||||
|
||||
Args:
|
||||
out_client: 输出参数,接收客户端 Socket
|
||||
out_client: Output parameter, receives client Socket
|
||||
Returns:
|
||||
客户端 fd(>= 0 成功),SOCKET_ERROR 失败
|
||||
Client fd (>= 0 on success), SOCKET_ERROR on error
|
||||
"""
|
||||
if self.fd == INVALID_SOCKET: return SOCKET_ERROR
|
||||
if out_client is None: return SOCKET_ERROR
|
||||
@@ -344,10 +346,10 @@ class Socket:
|
||||
return client_fd
|
||||
|
||||
def settimeout(self, timeout_ms: INT) -> INT:
|
||||
"""设置接收和发送超时(毫秒)。0 表示无超时。
|
||||
"""Set timeout for receive and send operations (milliseconds).
|
||||
|
||||
Returns:
|
||||
0 成功,非 0 失败
|
||||
0 success, non 0 otherwise
|
||||
"""
|
||||
if self.fd == INVALID_SOCKET: return -1
|
||||
|
||||
@@ -367,16 +369,16 @@ class Socket:
|
||||
return r2
|
||||
|
||||
def fileno(self) -> INT:
|
||||
"""返回底层文件描述符 / SOCKET 句柄。"""
|
||||
"""Return underlying file descriptor / SOCKET handle."""
|
||||
return self.fd
|
||||
|
||||
|
||||
# ============================================================
|
||||
# 平台初始化
|
||||
# Platform initialization
|
||||
# ============================================================
|
||||
|
||||
def SocketInit() -> INT:
|
||||
"""初始化 Socket 库。Windows 下调用 WSAStartup,POSIX 无操作。"""
|
||||
"""Initialize the Socket library. On Windows, call WSAStartup; on POSIX, do nothing."""
|
||||
if platmacro.IS_WINDOWS:
|
||||
wsa_data: t.CArray[BYTE, 400]
|
||||
string.memset(c.Addr(wsa_data), 0, 400)
|
||||
@@ -385,18 +387,18 @@ def SocketInit() -> INT:
|
||||
|
||||
|
||||
def SocketCleanup() -> INT:
|
||||
"""清理 Socket 库。"""
|
||||
"""Cleanup the Socket library."""
|
||||
if platmacro.IS_WINDOWS:
|
||||
return w32.winsock2.WSACleanup()
|
||||
return 0
|
||||
|
||||
|
||||
# ============================================================
|
||||
# 兼容旧版过程式 API(委托到 Socket 方法)
|
||||
# Compatibility with old procedural API (delegates to Socket methods)
|
||||
# ============================================================
|
||||
|
||||
def SocketCreate(family: INT, type: INT, protocol: INT, out_sock: Socket | t.CPtr) -> INT:
|
||||
"""创建 Socket 句柄(兼容旧版 API)。建议使用 Socket(...) 构造。"""
|
||||
"""Create a Socket handle (compatible with old API). It is recommended to use Socket(...) constructor."""
|
||||
if out_sock is None: return -1
|
||||
out_sock.family = family
|
||||
out_sock.type = type
|
||||
@@ -412,6 +414,7 @@ def SocketCreate(family: INT, type: INT, protocol: INT, out_sock: Socket | t.CPt
|
||||
if fd == INVALID_SOCKET: return -1
|
||||
return 0
|
||||
|
||||
# But maybe using OOP would be better, though that can be wrapped up later.
|
||||
|
||||
def SocketConnect(sock: Socket | t.CPtr, host: str, port: INT) -> INT:
|
||||
return sock.connect(host, port)
|
||||
@@ -446,6 +449,6 @@ def SocketSetTimeout(sock: Socket | t.CPtr, timeout_ms: INT) -> INT:
|
||||
|
||||
|
||||
def SocketIsValid(sock: Socket | t.CPtr) -> bool:
|
||||
"""检查 Socket 是否有效。"""
|
||||
"""Check if a Socket is valid."""
|
||||
if sock is None: return False
|
||||
return sock.fd != INVALID_SOCKET
|
||||
@@ -2,7 +2,6 @@ import t, c
|
||||
import atom
|
||||
|
||||
|
||||
@t.Object
|
||||
class _spinlock:
|
||||
locked: t.CVolatile | t.CInt
|
||||
name: t.CArray[t.CChar, 32]
|
||||
@@ -11,8 +10,7 @@ class _spinlock:
|
||||
self.locked = 0
|
||||
|
||||
def lock(self):
|
||||
while atom.__atomic_test_and_set(c.Addr(self.locked), atom.ATOMIC_ACQUIRE):
|
||||
pass
|
||||
while atom.__atomic_test_and_set(c.Addr(self.locked), atom.ATOMIC_ACQUIRE): pass
|
||||
|
||||
def unlock(self):
|
||||
atom.__atomic_clear(c.Addr(self.locked), atom.ATOMIC_RELEASE)
|
||||
|
||||
@@ -1,16 +1,11 @@
|
||||
import t, c
|
||||
|
||||
|
||||
def printf(fmt: t.CConst | str, *args) -> t.CInt | t.State: pass
|
||||
def fprintf(stream: bytes, fmt: t.CConst | str, *args) -> t.CInt | t.State: pass
|
||||
def sprintf(buf: bytes, fmt: t.CConst | str, *args) -> t.CInt | t.State: pass
|
||||
def snprintf(buf: bytes, size: t.CSizeT, fmt: t.CConst | str, *args) -> t.CInt | t.State: pass
|
||||
def puts(s: t.CConst | str) -> t.CInt | t.State: pass
|
||||
def fputs(s: t.CConst | str, stream: bytes) -> t.CInt | t.State: pass
|
||||
def fgets(buf: bytes, size: t.CInt, stream: bytes) -> bytes | t.State: pass
|
||||
def fflush(stream: bytes) -> t.CInt | t.State: pass
|
||||
|
||||
# 标准流指针(全局变量,仅声明供 printf 等函数使用)
|
||||
stdin: bytes = 0
|
||||
stdout: bytes = 0
|
||||
stderr: bytes = 0
|
||||
def printf(fmt: t.CConst | str, *args) -> int | t.State: pass
|
||||
def fprintf(stream: bytes, fmt: t.CConst | str, *args) -> int | t.State: pass
|
||||
def sprintf(buf: bytes, fmt: t.CConst | str, *args) -> int | t.State: pass
|
||||
def snprintf(buf: bytes, size: t.CSizeT, fmt: t.CConst | str, *args) -> int | t.State: pass
|
||||
def puts(s: t.CConst | str) -> int | t.State: pass
|
||||
def fputs(s: t.CConst | str, stream: bytes) -> int | t.State: pass
|
||||
def fgets(buf: bytes, size: int, stream: bytes) -> bytes | t.State: pass
|
||||
def fflush(stream: bytes) -> int | t.State: pass
|
||||
|
||||
@@ -2,7 +2,6 @@ from stdint import *
|
||||
import t
|
||||
|
||||
|
||||
|
||||
def malloc(size: t.CSizeT) -> t.CVoid | t.CPtr | t.State: pass
|
||||
def calloc(nmemb: t.CSizeT, size: t.CSizeT) -> t.CVoid | t.CPtr | t.State: pass
|
||||
def realloc(p: t.CVoid | t.CPtr, size: t.CSizeT) -> t.CVoid | t.CPtr | t.State: pass
|
||||
|
||||
@@ -2,7 +2,7 @@ from stdint import *
|
||||
import t, c
|
||||
|
||||
|
||||
# 字符串复制函数
|
||||
# String copy function
|
||||
def strcpy(dest: str, src: str) -> str:
|
||||
if dest == None or src == None: return None
|
||||
original_dest: str = dest
|
||||
@@ -13,14 +13,14 @@ def strcpy(dest: str, src: str) -> str:
|
||||
return original_dest
|
||||
|
||||
|
||||
# 字符串拼接函数: 将 src 追加到 dest 末尾
|
||||
# String concatenate function
|
||||
def strcat(dest: str, src: str) -> str:
|
||||
if dest == None or src == None: return dest
|
||||
original_dest: str = dest
|
||||
# 找到 dest 末尾
|
||||
# Find end of dest
|
||||
while dest[0] != '\0':
|
||||
dest += 1
|
||||
# 复制 src
|
||||
# Copy src
|
||||
for s in src:
|
||||
dest[0] = s
|
||||
dest += 1
|
||||
@@ -28,7 +28,7 @@ def strcat(dest: str, src: str) -> str:
|
||||
return original_dest
|
||||
|
||||
|
||||
# 有限长度字符串复制函数
|
||||
# String copy function with limited length
|
||||
def strncpy(dest: str, src: str, n: t.CSizeT) -> str:
|
||||
if dest == None or src == None or n == 0: return dest
|
||||
original_dest: str = dest
|
||||
@@ -38,7 +38,7 @@ def strncpy(dest: str, src: str, n: t.CSizeT) -> str:
|
||||
dest[0] = s
|
||||
dest += 1
|
||||
i += 1
|
||||
# 填充剩余空间为 '\0'(只填充 n-i 个,避免缓冲区溢出)
|
||||
# Fill remaining space with '\0'
|
||||
while i < n:
|
||||
dest[0] = 0
|
||||
dest += 1
|
||||
@@ -46,14 +46,14 @@ def strncpy(dest: str, src: str, n: t.CSizeT) -> str:
|
||||
return original_dest
|
||||
|
||||
|
||||
# 字符串长度函数
|
||||
# String length function
|
||||
def strlen(src: str) -> t.CSizeT | t.CExport:
|
||||
length: t.CSizeT = 0
|
||||
for _ in src:
|
||||
length += 1
|
||||
return length
|
||||
|
||||
# 字符串比较函数
|
||||
# String comparison function
|
||||
def strcmp(str1: str, str2: str) -> t.CInt:
|
||||
while str1[0] != '\0' and str2[0] != '\0':
|
||||
if str1[0] != str2[0]:
|
||||
@@ -66,7 +66,7 @@ def samestr(str1: str, str2: str) -> bool:
|
||||
return str1 == str2
|
||||
|
||||
|
||||
# 有限长度字符串比较函数
|
||||
# String compare function with limited length
|
||||
def strncmp(str1: str, str2: str, n: t.CSizeT) -> t.CInt:
|
||||
i: t.CSizeT = 0
|
||||
while str1[0] != '\0' and str2[0] != '\0' and i < n:
|
||||
@@ -80,7 +80,7 @@ def strncmp(str1: str, str2: str, n: t.CSizeT) -> t.CInt:
|
||||
return 0
|
||||
|
||||
|
||||
# 内存比较函数
|
||||
# Memory compare function
|
||||
def memcmp(ptr1: t.CVoid | t.CPtr, ptr2: t.CVoid | t.CPtr, n: t.CSizeT) -> t.CInt:
|
||||
p1: BYTEPTR = BYTEPTR(ptr1)
|
||||
p2: BYTEPTR = BYTEPTR(ptr2)
|
||||
@@ -92,7 +92,7 @@ def memcmp(ptr1: t.CVoid | t.CPtr, ptr2: t.CVoid | t.CPtr, n: t.CSizeT) -> t.CIn
|
||||
return 0
|
||||
|
||||
|
||||
# 字符串查找函数
|
||||
# String find function
|
||||
def strchr(s: str, cr: t.CInt) -> str:
|
||||
while s[0] != '\0':
|
||||
if s[0] == t.CChar(cr):
|
||||
@@ -102,7 +102,7 @@ def strchr(s: str, cr: t.CInt) -> str:
|
||||
return str(s)
|
||||
return None
|
||||
|
||||
# 字符串反向查找函数(找最后一次出现的字符)
|
||||
# String reverse find function (find last occurrence of character)
|
||||
def strrchr(s: str, cr: t.CInt) -> str:
|
||||
last: str = None
|
||||
while s[0] != '\0':
|
||||
@@ -113,7 +113,7 @@ def strrchr(s: str, cr: t.CInt) -> str:
|
||||
return last
|
||||
|
||||
|
||||
# 子串查找函数(在 s 中查找 needle 第一次出现的位置,返回指向该位置的指针,未找到返回 None)
|
||||
# Substring search function (find first occurrence of needle in s, return pointer to that position, or None if not found)
|
||||
def strstr(s: str, needle: str) -> str:
|
||||
if needle[0] == 0:
|
||||
return s
|
||||
@@ -128,7 +128,7 @@ def strstr(s: str, needle: str) -> str:
|
||||
i += 1
|
||||
return None
|
||||
|
||||
# 跳过字符
|
||||
# String skip function
|
||||
def strspn(s: str, skip: str = " ") -> int:
|
||||
si: int = 0
|
||||
while s[si] != 0:
|
||||
@@ -144,9 +144,9 @@ def strspn(s: str, skip: str = " ") -> int:
|
||||
si += 1
|
||||
return si
|
||||
|
||||
# 内存设置函数
|
||||
# Memory set function
|
||||
def memset(ptr: t.CVoid | t.CPtr, value: t.CInt, num: t.CSizeT) -> t.CVoid | t.CPtr | t.CExport:
|
||||
# 原始实现:
|
||||
# Original implementation:
|
||||
# p: BYTEPTR = BYTEPTR(ptr)
|
||||
# i: t.CSizeT
|
||||
# for i in range(num):
|
||||
@@ -162,7 +162,7 @@ def memset(ptr: t.CVoid | t.CPtr, value: t.CInt, num: t.CSizeT) -> t.CVoid | t.C
|
||||
|
||||
|
||||
def memset32(ptr: t.CVoid | t.CPtr, value: t.CUInt32T, count: t.CSizeT) -> t.CVoid | t.CPtr:
|
||||
# 原始实现:
|
||||
# Original implementation:
|
||||
# p: UINT32PTR = UINT32PTR(ptr)
|
||||
# i: t.CSizeT
|
||||
# for i in range(count):
|
||||
@@ -177,9 +177,9 @@ def memset32(ptr: t.CVoid | t.CPtr, value: t.CUInt32T, count: t.CSizeT) -> t.CVo
|
||||
return ptr
|
||||
|
||||
|
||||
# 内存复制函数
|
||||
# Memory copy function
|
||||
def memcpy(dest: t.CVoid | t.CPtr, src: t.CVoid | t.CPtr, num: t.CSizeT) -> t.CVoid | t.CPtr | t.CExport:
|
||||
# 原始实现:
|
||||
# Original implementation:
|
||||
# d: BYTEPTR = BYTEPTR(dest)
|
||||
# s: BYTEPTR = BYTEPTR(src)
|
||||
# i: t.CSizeT
|
||||
|
||||
@@ -4,36 +4,36 @@ import platmacro
|
||||
import memhub
|
||||
import string
|
||||
|
||||
# Windows 后端依赖
|
||||
# Windows backend dependencies
|
||||
import w32.win32base
|
||||
import w32.win32file
|
||||
import w32.win32process
|
||||
import w32.win32sync
|
||||
|
||||
# POSIX 后端依赖
|
||||
# POSIX backend dependencies
|
||||
import posix
|
||||
|
||||
|
||||
# 子进程输出缓冲区大小
|
||||
# Subprocess output buffer size
|
||||
OUTPUT_BUF_SIZE: t.CDefine = 65536
|
||||
|
||||
# 模块级全局 MBuddy 指针(由用户在 main 中赋值初始化)
|
||||
# Module global MBuddy pointer (initialized in main)
|
||||
_mbuddy: memhub.MemBuddy | t.CPtr
|
||||
|
||||
|
||||
# =============================================================================
|
||||
# CompletedProcess 结果类
|
||||
# CompletedProcess result class
|
||||
# =============================================================================
|
||||
|
||||
class CompletedProcess:
|
||||
"""subprocess.run 的返回结果"""
|
||||
args: str # 原始命令行
|
||||
returncode: int # 进程退出码(0 表示成功)
|
||||
stdout: str # 标准输出(capture_output=True 时)
|
||||
stderr: str # 标准错误(capture_output=True 时)
|
||||
"""Result class for subprocess.run."""
|
||||
args: str # Original command line
|
||||
returncode: int # Process exit code (0 means success)
|
||||
stdout: str # Standard output (when capture_output=True)
|
||||
stderr: str # Standard error (when capture_output=True)
|
||||
|
||||
def __new__(self, args: str, returncode: int, stdout: str, stderr: str) -> t.CPtr:
|
||||
# 堆分配(避免返回栈地址导致 use-after-return)
|
||||
# Heap allocation (avoiding use-after-return)
|
||||
return t.CPtr(_mbuddy.alloc(CompletedProcess.__sizeof__()))
|
||||
|
||||
def __init__(self, args: str, returncode: int, stdout: str, stderr: str):
|
||||
@@ -44,27 +44,26 @@ class CompletedProcess:
|
||||
|
||||
|
||||
# =============================================================================
|
||||
# 入口函数
|
||||
# Entry function
|
||||
# =============================================================================
|
||||
|
||||
def run(args: str, capture_output: bool = True, text: bool = True) -> CompletedProcess | t.CPtr:
|
||||
"""同步执行子进程并等待完成。
|
||||
args 为完整命令行字符串。
|
||||
capture_output=True 时捕获 stdout/stderr。
|
||||
text=True 时输出为字符串(当前实现总是返回字符串)。
|
||||
返回 CompletedProcess 对象。"""
|
||||
"""Run a subprocess synchronously and wait for it to finish.
|
||||
The args are the full command line string.
|
||||
If capture_output=True, stdout/stderr will be captured. If text=True, the output will be a string (currently it always returns a string).
|
||||
Returns a CompletedProcess object."""
|
||||
if platmacro.IS_WINDOWS:
|
||||
return _run_win32(args, capture_output, text)
|
||||
return _run_posix(args, capture_output, text)
|
||||
|
||||
|
||||
# =============================================================================
|
||||
# Windows 后端实现
|
||||
# Windows backend implementation
|
||||
# =============================================================================
|
||||
|
||||
def _run_win32(args: str, capture_output: bool, text: bool) -> CompletedProcess | t.CPtr:
|
||||
"""Windows 平台子进程执行(CreateProcessA + 管道)"""
|
||||
# 复制命令行(CreateProcessA 需要可修改的 lpCommandLine)
|
||||
"""Windows platform subprocess execution (CreateProcessA pipe)"""
|
||||
# Copy command line (CreateProcessA requires a modifiable lpCommandLine)
|
||||
args_len: t.CSizeT = len(args)
|
||||
cmd_line: bytes = _mbuddy.alloc(args_len + 1)
|
||||
if cmd_line == None:
|
||||
@@ -75,13 +74,13 @@ def _run_win32(args: str, capture_output: bool, text: bool) -> CompletedProcess
|
||||
i += 1
|
||||
cmd_line[args_len] = 0
|
||||
|
||||
# 安全属性(允许句柄继承)
|
||||
# Security attributes (allow handle inheritance)
|
||||
sa: w32.win32base.SECURITY_ATTRIBUTES = w32.win32base.SECURITY_ATTRIBUTES()
|
||||
sa.nLength = w32.win32base.SECURITY_ATTRIBUTES.__sizeof__()
|
||||
sa.lpSecurityDescriptor = t.CPtr(0)
|
||||
sa.bInheritHandle = 1 # TRUE
|
||||
|
||||
# 创建 stdout 管道
|
||||
# Create stdout pipe
|
||||
stdout_read: w32.win32base.HANDLE = t.CPtr(0)
|
||||
stdout_write: w32.win32base.HANDLE = t.CPtr(0)
|
||||
if capture_output:
|
||||
@@ -93,50 +92,50 @@ def _run_win32(args: str, capture_output: bool, text: bool) -> CompletedProcess
|
||||
)
|
||||
if pipe_result == 0:
|
||||
return CompletedProcess(args, -1, None, None)
|
||||
# 防止读端被子进程继承
|
||||
# Prevent read end from being inherited by child process
|
||||
w32.win32file.SetHandleInformation(stdout_read, w32.win32file.HANDLE_FLAG_INHERIT, 0)
|
||||
|
||||
# 设置启动信息
|
||||
# Set startup information
|
||||
si: w32.win32process.STARTUPINFOA = w32.win32process.STARTUPINFOA()
|
||||
si.cb = w32.win32process.STARTUPINFOA.__sizeof__()
|
||||
if capture_output:
|
||||
si.dwFlags = w32.win32process.STARTF_USESTDHANDLES
|
||||
si.hStdOutput = stdout_write
|
||||
si.hStdError = stdout_write # stderr 合并到 stdout
|
||||
si.hStdError = stdout_write # stderr merged to stdout
|
||||
|
||||
pi: w32.win32process.PROCESS_INFORMATION = w32.win32process.PROCESS_INFORMATION()
|
||||
|
||||
# 创建进程
|
||||
# capture_output=True 时用 CREATE_NO_WINDOW(输出到管道,不需要控制台)
|
||||
# capture_output=False 时用 0(继承父进程控制台,让 stdout 直接显示)
|
||||
# Create process
|
||||
# use CREATE_NO_WINDOW when capture_output=True (output to pipe, no console)
|
||||
# use 0 when capture_output=False (inherit parent process console, let stdout directly display)
|
||||
create_flags: ULONG = w32.win32process.CREATE_NO_WINDOW if capture_output else 0
|
||||
create_result: BOOL = w32.win32process.CreateProcessA(
|
||||
t.CPtr(0), # lpApplicationName (NULL,从命令行解析)
|
||||
cmd_line, # lpCommandLine (可修改)
|
||||
t.CPtr(0), # lpApplicationName (NULL, parse from command line)
|
||||
cmd_line, # lpCommandLine (modifiable)
|
||||
t.CPtr(0), # lpProcessAttributes
|
||||
t.CPtr(0), # lpThreadAttributes
|
||||
1, # bInheritHandles = TRUE
|
||||
create_flags, # dwCreationFlags
|
||||
t.CPtr(0), # lpEnvironment (继承父进程)
|
||||
t.CPtr(0), # lpCurrentDirectory (继承父进程)
|
||||
t.CPtr(0), # lpEnvironment (inherit from parent process)
|
||||
t.CPtr(0), # lpCurrentDirectory (inherit from parent process)
|
||||
t.CPtr(c.Addr(si)),
|
||||
t.CPtr(c.Addr(pi))
|
||||
)
|
||||
|
||||
if create_result == 0:
|
||||
# 创建失败
|
||||
# Create process failed
|
||||
if capture_output:
|
||||
w32.win32base.CloseHandle(stdout_read)
|
||||
w32.win32base.CloseHandle(stdout_write)
|
||||
return CompletedProcess(args, -1, None, None)
|
||||
|
||||
# 关闭父进程的写端(子进程已有写端的继承副本)
|
||||
# Close parent process's write end (child process already has a copy of it)
|
||||
if capture_output:
|
||||
w32.win32base.CloseHandle(stdout_write)
|
||||
|
||||
# 读取 stdout + 等待进程结束
|
||||
# 注意:必须边读边等,否则子进程输出超过管道缓冲区时会死锁
|
||||
# (子进程阻塞在写 stdout,父进程阻塞在 WaitForSingleObject)
|
||||
# Read stdout + wait for process to exit
|
||||
# Note: must read and wait at the same time, or else deadlock will occur when child process outputs more than pipe buffer size
|
||||
# (child process blocks on writing stdout, parent process blocks on WaitForSingleObject)
|
||||
stdout_str: str = None
|
||||
if capture_output:
|
||||
buf_size: ULONG = OUTPUT_BUF_SIZE
|
||||
@@ -155,7 +154,7 @@ def _run_win32(args: str, capture_output: bool, text: bool) -> CompletedProcess
|
||||
if read_result == 0 or bytes_read == 0:
|
||||
break
|
||||
total += bytes_read
|
||||
# 缓冲区将满,扩容(翻倍)
|
||||
# Buffer will be full, double it
|
||||
if total >= buf_size - 1 - 4096:
|
||||
new_size: ULONG = buf_size * 2
|
||||
new_buf: bytes = _mbuddy.alloc(new_size)
|
||||
@@ -164,19 +163,19 @@ def _run_win32(args: str, capture_output: bool, text: bool) -> CompletedProcess
|
||||
buf = new_buf
|
||||
buf_size = new_size
|
||||
else:
|
||||
# 扩容失败,停止读取
|
||||
# Expand failed, stop reading
|
||||
break
|
||||
buf[total] = 0
|
||||
stdout_str = str(buf)
|
||||
|
||||
# 等待进程结束(如果还没退出的话)
|
||||
# Wait for process to exit
|
||||
w32.win32sync.WaitForSingleObject(pi.hProcess, w32.win32base.INFINITE)
|
||||
|
||||
# 获取退出码
|
||||
# Get exit code
|
||||
exit_code: ULONG = 0
|
||||
w32.win32process.GetExitCodeProcess(pi.hProcess, t.CPtr(c.Addr(exit_code)))
|
||||
|
||||
# 关闭句柄
|
||||
# Close handles
|
||||
w32.win32base.CloseHandle(pi.hProcess)
|
||||
w32.win32base.CloseHandle(pi.hThread)
|
||||
if capture_output:
|
||||
@@ -186,11 +185,12 @@ def _run_win32(args: str, capture_output: bool, text: bool) -> CompletedProcess
|
||||
|
||||
|
||||
# =============================================================================
|
||||
# POSIX 后端实现
|
||||
# POSIX backend implementation
|
||||
# =============================================================================
|
||||
|
||||
def _run_posix(args: str, capture_output: bool, text: bool) -> CompletedProcess | t.CPtr:
|
||||
"""POSIX 平台子进程执行(fork + execvp + pipe + waitpid)
|
||||
注意:当前为桩函数。POSIX 实现需要 pipe/fork/waitpid,
|
||||
这些函数在 Windows MinGW 上不可用,待 POSIX 平台测试时再完善。"""
|
||||
"""POSIX platform subprocess execution (fork, execvp, pipe, waitpid)
|
||||
Note: Currently this is a stub function.
|
||||
POSIX implementation requires pipe/fork/waitpid, which are not available on Windows MinGW.
|
||||
It will be completed when testing on a POSIX platform."""
|
||||
return CompletedProcess(args, -1, None, None)
|
||||
|
||||
@@ -5,46 +5,46 @@ import memhub
|
||||
import string
|
||||
import stdio
|
||||
|
||||
# Windows 后端依赖
|
||||
# Windows backend dependencies
|
||||
import w32.win32base
|
||||
import w32.win32process
|
||||
|
||||
# POSIX 后端依赖
|
||||
# POSIX backend dependencies
|
||||
import posix
|
||||
|
||||
# 模块级全局 MBuddy 指针(由用户在 main 中赋值初始化)
|
||||
# Module global MBuddy pointer (initialized in user main), Plans to ban
|
||||
_mbuddy: memhub.MemBuddy | t.CPtr
|
||||
|
||||
|
||||
# =============================================================================
|
||||
# C 标准库 IO 声明
|
||||
# C Standard Library IO Declarations
|
||||
# =============================================================================
|
||||
|
||||
def fgets(buf: t.CChar | t.CPtr, size: t.CInt, stream: t.CVoid | t.CPtr) -> t.CChar | t.CPtr | t.CExtern | t.CExport: pass
|
||||
def fgets(buf: bytes, size: int, stream: t.CVoid | t.CPtr) -> str | t.State: pass
|
||||
|
||||
def fflush(stream: t.CVoid | t.CPtr) -> t.CInt | t.CExtern | t.CExport: pass
|
||||
def fflush(stream: t.CVoid | t.CPtr) -> int | t.State: pass
|
||||
|
||||
# C 标准库 exit(刷新缓冲区后终止进程,跨平台)
|
||||
def exit(status: INT) -> VOID | t.CExtern | t.CExport: pass
|
||||
# C standard library exit (terminates the process after flushing the buffer, cross-platform)
|
||||
def exit(status: int) -> t.State: pass
|
||||
|
||||
|
||||
# =============================================================================
|
||||
# 平台信息
|
||||
# Platform Information
|
||||
# =============================================================================
|
||||
|
||||
# 最大整数值(64 位平台 ssize_t 上限)
|
||||
maxsize: t.CDefine = 9223372036854775807
|
||||
# Maximum integer value (64-bit platform ssize_t upper limit)
|
||||
maxsize: t.CDefine = 9223372036854775807 # 2^63 - 1
|
||||
|
||||
|
||||
def platform() -> str:
|
||||
"""返回平台标识字符串('win32' 或 'linux')"""
|
||||
"""Returns the platform identifier string ('win32' or 'linux')."""
|
||||
if platmacro.IS_WINDOWS:
|
||||
return "win32"
|
||||
return "linux"
|
||||
|
||||
|
||||
# =============================================================================
|
||||
# 进程信息
|
||||
# Process Information
|
||||
# =============================================================================
|
||||
|
||||
def get_pid() -> int:
|
||||
@@ -55,19 +55,19 @@ def get_pid() -> int:
|
||||
|
||||
|
||||
# =============================================================================
|
||||
# 命令行参数(argv)
|
||||
# Command Line Arguments (argv)
|
||||
# =============================================================================
|
||||
|
||||
# 全局 argv 状态(首次访问时初始化)
|
||||
_argc: INT = 0
|
||||
# _argv 是指针数组(char**),必须用 str | t.CPtr 使索引按 sizeof(char*) 步长
|
||||
# str 本身是 char*,| t.CPtr 再加一层指针 = char**
|
||||
# bytes | t.CPtr 也是 char**,可以同样用
|
||||
# global argv status (initialized on first access)
|
||||
_argc: int = 0
|
||||
# _argv is a pointer array (char**), must use str | t.CPtr to index with sizeof(char*)
|
||||
# str | t.CPtr is a pointer to char**
|
||||
# bytes | t.CPtr is a pointer to char**
|
||||
_argv: str | t.CPtr
|
||||
|
||||
|
||||
def _init_argv():
|
||||
"""初始化全局 argv(首次访问时调用一次)"""
|
||||
"""Initialize global argv once on first access"""
|
||||
global _argc, _argv
|
||||
if _argc != 0:
|
||||
return
|
||||
@@ -78,7 +78,7 @@ def _init_argv():
|
||||
|
||||
|
||||
def _init_argv_win32():
|
||||
"""Windows:GetCommandLineA + 手动解析(处理空格/双引号/反斜杠)"""
|
||||
"""Windows: GetCommandLineA + manual parsing (handle spaces/double quotes/backslashes)"""
|
||||
global _argc, _argv
|
||||
cmdline: CHARPTR = w32.win32base.GetCommandLineA()
|
||||
if cmdline == None:
|
||||
@@ -87,12 +87,12 @@ def _init_argv_win32():
|
||||
if cmdlen == 0:
|
||||
return
|
||||
|
||||
# 分配参数字符串缓冲区(最坏情况:整个命令行 + argc 个 \0)
|
||||
# Allocate buffer for parameter strings (worst case: entire command line + argc \0s)
|
||||
buf: bytes = _mbuddy.alloc(cmdlen + 1)
|
||||
if buf == None:
|
||||
return
|
||||
|
||||
# 分配指针数组(最坏情况:每个字符都是一个参数)
|
||||
# Allocate pointer array for argv (worst case: each character is a parameter)
|
||||
max_args: t.CSizeT = cmdlen + 1
|
||||
argv_arr: str | t.CPtr = (str | t.CPtr)(_mbuddy.alloc(max_args * platmacro.SIZEOF_POINTER))
|
||||
if argv_arr == None:
|
||||
@@ -106,14 +106,14 @@ def _init_argv_win32():
|
||||
|
||||
while i < cmdlen:
|
||||
ch: t.CInt = cmdline[i]
|
||||
if ch == 34: # 双引号
|
||||
if ch == 34: # Double quote
|
||||
in_quote = not in_quote
|
||||
if not in_arg:
|
||||
argv_arr[argc] = str(buf + j)
|
||||
argc += 1
|
||||
in_arg = True
|
||||
elif (ch == 32 or ch == 9) and not in_quote:
|
||||
# 空格或 Tab(引号外):参数分隔符
|
||||
# Space or Tab (outside quotes): parameter delimiter
|
||||
if in_arg:
|
||||
buf[j] = 0
|
||||
j += 1
|
||||
@@ -135,14 +135,14 @@ def _init_argv_win32():
|
||||
|
||||
|
||||
def _init_argv_posix():
|
||||
"""POSIX:读取 /proc/self/cmdline(参数以 \\0 分隔,末尾双 \\0)"""
|
||||
"""POSIX: Read cmdline from /proc/self/cmdline (\0) separated parameters"""
|
||||
global _argc, _argv
|
||||
fd: INT = posix.open("/proc/self/cmdline", posix.O_RDONLY, 0)
|
||||
if fd < 0:
|
||||
return
|
||||
|
||||
# 读取 cmdline(4KB 足够大多数情况)
|
||||
buf: bytes = _mbuddy.alloc(4096)
|
||||
# Read cmdline (4KB)
|
||||
buf: bytes = _mbuddy.alloc(4096) # Need to verify size of buffer
|
||||
if buf == None:
|
||||
posix.close(fd)
|
||||
return
|
||||
@@ -152,7 +152,7 @@ def _init_argv_posix():
|
||||
if total <= 0:
|
||||
return
|
||||
|
||||
# 计算参数个数(\0 分隔)
|
||||
# Calculate argument count (\0 delimited)
|
||||
argc: INT = 0
|
||||
i: t.CSizeT = 0
|
||||
total_size: t.CSizeT = t.CSizeT(total)
|
||||
@@ -164,12 +164,12 @@ def _init_argv_posix():
|
||||
if argc == 0:
|
||||
return
|
||||
|
||||
# 分配指针数组
|
||||
# Allocate pointer array for argv (argc pointers)
|
||||
argv_arr: str | t.CPtr = (str | t.CPtr)(_mbuddy.alloc(argc * platmacro.SIZEOF_POINTER))
|
||||
if argv_arr == None:
|
||||
return
|
||||
|
||||
# 填充指针(每个参数的起始地址)
|
||||
# Populate pointer array (start address of each parameter)
|
||||
argv_arr[0] = str(buf)
|
||||
idx: INT = 1
|
||||
i = 0
|
||||
@@ -184,15 +184,15 @@ def _init_argv_posix():
|
||||
|
||||
|
||||
def argc() -> int:
|
||||
"""返回命令行参数个数。首次调用时自动初始化。"""
|
||||
"""Returns the number of command line arguments. Automatically initializes on the first call."""
|
||||
if _argc == 0:
|
||||
_init_argv()
|
||||
return _argc
|
||||
|
||||
|
||||
def argv(index: int) -> str:
|
||||
"""返回第 index 个命令行参数(index 从 0 开始)。
|
||||
首次调用时自动初始化。索引越界返回 None。"""
|
||||
"""Returns the command line argument at index `index` (starting from 0).
|
||||
Automatically initializes on first call. Returns None if the index is out of range."""
|
||||
if _argc == 0:
|
||||
_init_argv()
|
||||
if index < 0 or index >= _argc:
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# testcheck - 回归测试格式化输出库
|
||||
# 提供 PASS/FAIL 计数、分节标题、汇总报告
|
||||
# testcheck - Regression test formatted output library
|
||||
# Provide PASS/FAIL counts, section headers, summary reports
|
||||
import t, c
|
||||
import stdio
|
||||
from w32.win32console import SetConsoleOutputCP, SetConsoleCP
|
||||
@@ -13,7 +13,7 @@ _total_fail: t.CInt = 0
|
||||
|
||||
|
||||
def begin(name: str):
|
||||
"""开始测试套件,打印头部并重置当前套件计数器(累计计数不变)"""
|
||||
"""Start the test suite, print the header, and reset the current suite counter (total count remains the same)"""
|
||||
global _pass_count, _fail_count
|
||||
_pass_count = 0
|
||||
_fail_count = 0
|
||||
@@ -23,26 +23,26 @@ def begin(name: str):
|
||||
|
||||
|
||||
def section(name: str):
|
||||
"""打印分节标题"""
|
||||
"""Print the section header"""
|
||||
stdio.printf("--- %s ---\n", name)
|
||||
|
||||
|
||||
def ok(msg: str):
|
||||
"""打印 PASS 并计数"""
|
||||
"""Print PASS and count"""
|
||||
global _pass_count
|
||||
_pass_count += 1
|
||||
stdio.printf("PASS: %s\n", msg)
|
||||
|
||||
|
||||
def fail(msg: str):
|
||||
"""打印 FAIL 并计数"""
|
||||
"""Print FAIL and count"""
|
||||
global _fail_count
|
||||
_fail_count += 1
|
||||
stdio.printf("FAIL: %s\n", msg)
|
||||
|
||||
|
||||
def check(cond: t.CInt, ok_msg: str, fail_msg: str):
|
||||
"""条件检查,自动选择 PASS/FAIL"""
|
||||
"""Conditional check, automatically select PASS/FAIL"""
|
||||
if cond:
|
||||
ok(ok_msg)
|
||||
else:
|
||||
@@ -50,12 +50,12 @@ def check(cond: t.CInt, ok_msg: str, fail_msg: str):
|
||||
|
||||
|
||||
def info(msg: str):
|
||||
"""打印信息消息(不计入 PASS/FAIL)"""
|
||||
"""Print information message (not counted in the PASS/FAIL messages)"""
|
||||
stdio.printf("%s\n", msg)
|
||||
|
||||
|
||||
def end() -> t.CInt:
|
||||
"""打印当前套件汇总,累加到总计,返回当前套件失败数"""
|
||||
"""Print the current suite summary, accumulate to total, return the current suite fail count"""
|
||||
global _total_pass, _total_fail
|
||||
_total_pass += _pass_count
|
||||
_total_fail += _fail_count
|
||||
@@ -65,7 +65,7 @@ def end() -> t.CInt:
|
||||
|
||||
|
||||
def summary() -> t.CInt:
|
||||
"""打印所有套件的总计汇总,返回总失败数"""
|
||||
"""Print the total summary of all suites, return the total fail count"""
|
||||
stdio.printf("\n=== Total Summary ===\n")
|
||||
stdio.printf("Total PASS: %d, Total FAIL: %d\n", _total_pass, _total_fail)
|
||||
return _total_fail
|
||||
|
||||
@@ -31,7 +31,7 @@ Anzrfcnprf ner vaperqvoyl inyhnoyr — hfr gurz trarebhfyl!"""
|
||||
|
||||
for k in l:
|
||||
for i in range(26):
|
||||
m[k + i] = (k + ((i + 13) % 26)) # 隐式类型转换
|
||||
m[k + i] = (k + ((i + 13) % 26)) # Implicit type conversion
|
||||
|
||||
for ch in s:
|
||||
_: t.CUInt8T = ch
|
||||
|
||||
@@ -24,8 +24,8 @@ def snprintf(buf: t.CChar | t.CPtr, size: t.CSizeT, fmt: str, *args) -> t.CInt |
|
||||
if buf is None or fmt is None or size == 0: return 0
|
||||
return vsnprintf(buf, size, fmt, args)
|
||||
|
||||
# 检测浮点特殊值(IEEE 754)
|
||||
# 返回: 0=normal, 1=+inf, 2=-inf, 3=nan
|
||||
# Check floating-point special values (IEEE 754)
|
||||
# Return: 0=normal, 1=+inf, 2=-inf, 3=nan
|
||||
def _check_special_float(fv: t.CDouble) -> t.CInt:
|
||||
fbits: t.CUInt64T = 0
|
||||
c.Load(c.Addr(fbits), c.Addr(fv))
|
||||
|
||||
@@ -2,7 +2,7 @@ import t, c
|
||||
|
||||
|
||||
# ============================================================
|
||||
# AVX2 双精度向量运算 (4 x double, 256-bit YMM)
|
||||
# AVX2 double precision vector operations (4 x double, 256-bit YMM)
|
||||
# ============================================================
|
||||
|
||||
def simd_add4d(a: t.CPtr, b: t.CPtr, out: t.CPtr) -> t.CVoid:
|
||||
@@ -140,7 +140,7 @@ vmovupd [{c.AsmInp(out, t.ASM_DESCR.REG_ANY)}], ymm0""",
|
||||
|
||||
|
||||
# ============================================================
|
||||
# SSE2 单精度向量运算 (4 x float, 128-bit XMM)
|
||||
# SSE2 single precision vector operations (4 x float, 128-bit XMM)
|
||||
# ============================================================
|
||||
|
||||
def simd_add4f(a: t.CPtr, b: t.CPtr, out: t.CPtr) -> t.CVoid:
|
||||
@@ -180,7 +180,7 @@ movups [{c.AsmInp(out, t.ASM_DESCR.REG_ANY)}], xmm0""",
|
||||
|
||||
|
||||
# ============================================================
|
||||
# 批量数组运算 (AVX2 循环, 处理 N 个 double)
|
||||
# Batch array operations (AVX2 loop, process N double values)
|
||||
# ============================================================
|
||||
|
||||
def simd_add_array(a: t.CPtr, b: t.CPtr, out: t.CPtr, n: t.CSizeT) -> t.CVoid:
|
||||
@@ -373,7 +373,7 @@ vzeroupper""",
|
||||
|
||||
|
||||
# ============================================================
|
||||
# LLVMIR 精确标量运算 (LLVM 内置函数)
|
||||
# LLVMIR precise scalar operations (LLVM intrinsic functions)
|
||||
# ============================================================
|
||||
|
||||
def simd_sqrt(x: t.CDouble) -> t.CDouble:
|
||||
|
||||
110
includes/vqt6 copy/CMakeLists.txt
Normal file
110
includes/vqt6 copy/CMakeLists.txt
Normal file
@@ -0,0 +1,110 @@
|
||||
# ============================================================
|
||||
# vqt6 CMakeLists.txt — 构建 vqt6 C 桥接层
|
||||
#
|
||||
# 默认产物: libvqt6_bridge.a (静态库)
|
||||
# 可选产物: vqt6_bridge.dll (动态库)
|
||||
#
|
||||
# 使用:
|
||||
# cmake -B build -S .
|
||||
# cmake --build build --config Release
|
||||
# ============================================================
|
||||
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
project(vqt6_bridge CXX C)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
set(CMAKE_AUTOMOC ON)
|
||||
|
||||
# 构建选项
|
||||
option(VQT6_BUILD_SHARED "Build vqt6 as shared library (DLL)" OFF)
|
||||
option(VQT6_BUILD_STATIC "Build vqt6 as static library" ON)
|
||||
option(VQT6_BUILD_EXAMPLES "Build example programs" OFF)
|
||||
|
||||
# Qt6 依赖
|
||||
find_package(Qt6 6.5 REQUIRED COMPONENTS
|
||||
Core
|
||||
Gui
|
||||
Widgets
|
||||
Network
|
||||
)
|
||||
|
||||
# Win32 GUI 应用不需要控制台
|
||||
if(WIN32)
|
||||
set(CMAKE_WIN32_EXECUTABLE OFF)
|
||||
endif()
|
||||
|
||||
# 公共源文件
|
||||
set(VQT6_SOURCES
|
||||
_bridge_core.cpp
|
||||
_bridge_widgets.cpp
|
||||
_bridge_gui.cpp
|
||||
_bridge_network.cpp
|
||||
)
|
||||
|
||||
set(VQT6_HEADERS
|
||||
_bridge.h
|
||||
_bridge_widgets.h
|
||||
_bridge_gui.h
|
||||
_bridge_network.h
|
||||
)
|
||||
|
||||
# Qt 模块
|
||||
set(VQT6_QT_MODULES
|
||||
Qt6::Core
|
||||
Qt6::Gui
|
||||
Qt6::Widgets
|
||||
Qt6::Network
|
||||
)
|
||||
|
||||
# ============================================================
|
||||
# 静态库
|
||||
# ============================================================
|
||||
if(VQT6_BUILD_STATIC)
|
||||
add_library(vqt6_bridge_static STATIC ${VQT6_SOURCES} ${VQT6_HEADERS})
|
||||
target_link_libraries(vqt6_bridge_static PUBLIC ${VQT6_QT_MODULES})
|
||||
target_compile_definitions(vqt6_bridge_static PUBLIC VQT6_BRIDGE_STATIC)
|
||||
target_include_directories(vqt6_bridge_static PUBLIC
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
)
|
||||
set_target_properties(vqt6_bridge_static PROPERTIES
|
||||
OUTPUT_NAME vqt6_bridge
|
||||
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
|
||||
)
|
||||
endif()
|
||||
|
||||
# ============================================================
|
||||
# 动态库
|
||||
# ============================================================
|
||||
if(VQT6_BUILD_SHARED)
|
||||
add_library(vqt6_bridge SHARED ${VQT6_SOURCES} ${VQT6_HEADERS})
|
||||
target_link_libraries(vqt6_bridge PUBLIC ${VQT6_QT_MODULES})
|
||||
target_compile_definitions(vqt6_bridge PRIVATE VQT6_BRIDGE_BUILD)
|
||||
target_include_directories(vqt6_bridge PUBLIC
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
)
|
||||
set_target_properties(vqt6_bridge PROPERTIES
|
||||
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
|
||||
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
|
||||
)
|
||||
endif()
|
||||
|
||||
# ============================================================
|
||||
# 安装
|
||||
# ============================================================
|
||||
install(TARGETS vqt6_bridge_static vqt6_bridge
|
||||
ARCHIVE DESTINATION lib
|
||||
LIBRARY DESTINATION lib
|
||||
RUNTIME DESTINATION bin
|
||||
)
|
||||
|
||||
install(FILES ${VQT6_HEADERS}
|
||||
DESTINATION include/vqt6
|
||||
)
|
||||
|
||||
# ============================================================
|
||||
# 示例
|
||||
# ============================================================
|
||||
if(VQT6_BUILD_EXAMPLES)
|
||||
add_subdirectory(examples)
|
||||
endif()
|
||||
90
includes/vqt6 copy/README.md
Normal file
90
includes/vqt6 copy/README.md
Normal file
@@ -0,0 +1,90 @@
|
||||
# vqt6 — Viper 的 Qt6 绑定包
|
||||
|
||||
`vqt6` 是 [Viper](https://git.gvsds.com/GVSDS/TransPyC) 语言的 **Qt6 GUI 框架绑定**,是 Viper 包管理器分发的"包"(类似于 Python 的 PyQt6、Node.js 的 node-gtk)。
|
||||
|
||||
> 注意:`vqt6` **不是** 包管理器,而是一个**被包管理器管理的包**(库)。
|
||||
> 包管理器负责下载、预编译、安装;`vqt6` 只负责把 Qt6 C++ API 暴露给 Viper 代码。
|
||||
|
||||
## 架构
|
||||
|
||||
```
|
||||
+--------------------+ +-----------------------+ +------------+
|
||||
| Viper 用户代码 | FFI | vqt6 桥接层 (libvqt6) | C++ | Qt6 C++ |
|
||||
| (app.py) | <----> | - t.State 声明 | <-----> | QtCore |
|
||||
| | | - C 桥接函数 | | QtGui |
|
||||
| vqt6.QApplication | | (extern "C") | | QtWidgets |
|
||||
| vqt6.QLabel | | - 静态库 / 动态库 | | QtNetwork |
|
||||
+--------------------+ +-----------------------+ +------------+
|
||||
```
|
||||
|
||||
**FFI 路径**:
|
||||
1. Viper 编译器把 `t.State` 声明的 `def xxx() -> t.State: pass` 解析为外部函数符号
|
||||
2. 链接时通过 `libvqt6_bridge.a`(静态)或 `vqt6_bridge.dll`(动态)解析符号
|
||||
3. 运行时 C 桥接层调用 Qt6 C++ API 完成实际工作
|
||||
|
||||
## 链接模式
|
||||
|
||||
| 模式 | 产物 | 优点 | 缺点 |
|
||||
|------|------|------|------|
|
||||
| **静态**(默认) | `libvqt6_bridge.a` | 部署简单(一个 exe),无需分发 dll | exe 体积较大 |
|
||||
| **动态** | `vqt6_bridge.dll` | 共享内存,多个程序共用 | 需随 exe 分发 dll |
|
||||
|
||||
vqt6 同一套 C 桥接源代码,可同时编译为两种产物。Viper 项目通过 `project.vpj` 切换。
|
||||
|
||||
## 目录结构
|
||||
|
||||
```
|
||||
includes/vqt6/
|
||||
├── README.md # 本文件
|
||||
├── __init__.py # 公共 Pythonic API(用户使用)
|
||||
├── _types.py # 公共类型(不透明指针 typedef)
|
||||
├── _qtcore.py # QtCore 的 t.State FFI 声明
|
||||
├── _qtwidgets.py # QtWidgets 的 t.State FFI 声明
|
||||
├── _qtgui.py # QtGui 的 t.State FFI 声明
|
||||
├── _qtnetwork.py # QtNetwork 的 t.State FFI 声明
|
||||
├── _bridge.h # C 桥接层头文件
|
||||
├── _bridge.cpp # C 桥接层实现(extern "C" 包装 Qt6 C++ API)
|
||||
└── CMakeLists.txt # 构建脚本(生成 libvqt6_bridge.a)
|
||||
```
|
||||
|
||||
## 使用示例
|
||||
|
||||
```python
|
||||
# App/main.py
|
||||
import t
|
||||
import c
|
||||
import vqt6
|
||||
|
||||
# 1. 创建 QApplication
|
||||
app: vqt6.QApplication | t.CPtr = vqt6.QApplication([])
|
||||
|
||||
# 2. 创建窗口
|
||||
window: vqt6.QWidget | t.CPtr = vqt6.QWidget()
|
||||
window.setWindowTitle("vqt6 Hello")
|
||||
window.resize(400, 300)
|
||||
|
||||
# 3. 创建标签
|
||||
label: vqt6.QLabel | t.CPtr = vqt6.QLabel("你好,Viper!", window)
|
||||
label.move(50, 50)
|
||||
|
||||
# 4. 显示并进入事件循环
|
||||
window.show()
|
||||
app.exec()
|
||||
```
|
||||
|
||||
## 设计原则
|
||||
|
||||
1. **不透明指针**:Viper 端不直接操作 Qt6 C++ 类(`QWidget*`、`QString*` 等),所有操作通过 C 桥接函数 `vqt6_xxx()` 转发。
|
||||
2. **t.State 声明**:所有 FFI 函数返回 `t.State`,C 桥接层函数实现负责实际操作。
|
||||
3. **句柄化对象模型**:Viper 端的对象是 `t.CPtr`(不透明指针),C 端管理生命周期(构造函数/析构函数)。
|
||||
4. **跨平台**:同一套 C 桥接代码可在 Windows / Linux / macOS 编译(差异在 Qt6 安装路径)。
|
||||
|
||||
## 当前状态
|
||||
|
||||
- [x] 架构设计
|
||||
- [x] FFI 覆盖:QtCore / QtWidgets / QtGui / QtNetwork
|
||||
- [x] FFI 粒度:仅暴露 C 桥接函数
|
||||
- [ ] FFI 声明文件编写中
|
||||
- [ ] C 桥接层实现
|
||||
- [ ] CMakeLists.txt 构建脚本
|
||||
- [ ] Hello World 示例验证
|
||||
208
includes/vqt6 copy/__init__.py
Normal file
208
includes/vqt6 copy/__init__.py
Normal file
@@ -0,0 +1,208 @@
|
||||
# ============================================================
|
||||
# vqt6 — Viper 的 Qt6 绑定包
|
||||
#
|
||||
# 公共 Pythonic API(基于 C 桥接层)
|
||||
# 用户用法:
|
||||
# import vqt6
|
||||
# app = vqt6.QApplication([])
|
||||
# win = vqt6.QWidget()
|
||||
# win.setWindowTitle("Hello")
|
||||
# win.show()
|
||||
# app.exec()
|
||||
# ============================================================
|
||||
|
||||
import t
|
||||
from stdint import *
|
||||
from vqt6._types import *
|
||||
from vqt6._qtcore import *
|
||||
from vqt6._qtwidgets import *
|
||||
from vqt6._qtgui import *
|
||||
from vqt6._qtnetwork import *
|
||||
|
||||
|
||||
# ============================================================
|
||||
# 高级 API 类(Pythonic 包装,不透明指针)
|
||||
# ============================================================
|
||||
@t.NoVTable
|
||||
class QApplication:
|
||||
"""QApplication 包装(不透明指针)"""
|
||||
_ptr: QtAppPtr
|
||||
|
||||
def __init__(self, argv: list[str] | t.CPtr):
|
||||
# 把 argv 转换为 argc/argv 数组
|
||||
argc: t.CInt = 1
|
||||
# Viper 端 argv 是 c_char_p 指针数组
|
||||
# 这里仅传空 argv,避免 C ABI 复杂性
|
||||
argv_ptr: t.CPtr = t.CPtr(0)
|
||||
self._ptr = vqt6_qapplication_create(argc, argv_ptr)
|
||||
if self._ptr is None:
|
||||
raise RuntimeError("Failed to create QApplication")
|
||||
|
||||
def exec(self) -> int:
|
||||
return vqt6_qapplication_exec(self._ptr)
|
||||
|
||||
def quit(self):
|
||||
vqt6_qapplication_quit(self._ptr)
|
||||
|
||||
def exit(self, code: int):
|
||||
vqt6_qapplication_exit(self._ptr, code)
|
||||
|
||||
def process_events(self):
|
||||
vqt6_qapplication_process_events(self._ptr)
|
||||
|
||||
def desktop_width(self) -> int:
|
||||
return vqt6_qapplication_desktop_width(self._ptr)
|
||||
|
||||
def desktop_height(self) -> int:
|
||||
return vqt6_qapplication_desktop_height(self._ptr)
|
||||
|
||||
|
||||
@t.NoVTable
|
||||
class QWidget:
|
||||
"""QWidget 包装"""
|
||||
_ptr: QtWidgetPtr
|
||||
|
||||
def __init__(self, parent: "QWidget | None" = None):
|
||||
if parent is not None and parent._ptr is not None:
|
||||
self._ptr = vqt6_qwidget_create_with_parent(parent._ptr)
|
||||
else:
|
||||
self._ptr = vqt6_qwidget_create()
|
||||
if self._ptr is None:
|
||||
raise RuntimeError("Failed to create QWidget")
|
||||
|
||||
def show(self):
|
||||
vqt6_qwidget_show(self._ptr)
|
||||
|
||||
def hide(self):
|
||||
vqt6_qwidget_hide(self._ptr)
|
||||
|
||||
def close(self) -> int:
|
||||
return vqt6_qwidget_close(self._ptr)
|
||||
|
||||
def setWindowTitle(self, title: str):
|
||||
title_qs: QtStringPtr = vqt6_qstring_create(title)
|
||||
vqt6_qwidget_set_window_title(self._ptr, title_qs)
|
||||
vqt6_qstring_free(title_qs)
|
||||
|
||||
def windowTitle(self) -> str:
|
||||
result: QtStringPtr = vqt6_qwidget_window_title(self._ptr)
|
||||
buf: bytes = stdlib.malloc(1024)
|
||||
vqt6_qstring_to_utf8(result, buf, 1024)
|
||||
s: str = string.strndup(buf, 1024)
|
||||
vqt6_qstring_free(result)
|
||||
return s
|
||||
|
||||
def resize(self, w: int, h: int):
|
||||
vqt6_qwidget_resize(self._ptr, w, h)
|
||||
|
||||
def move(self, x: int, y: int):
|
||||
vqt6_qwidget_move(self._ptr, x, y)
|
||||
|
||||
def setGeometry(self, x: int, y: int, w: int, h: int):
|
||||
vqt6_qwidget_set_geometry(self._ptr, x, y, w, h)
|
||||
|
||||
def setEnabled(self, enabled: int):
|
||||
vqt6_qwidget_set_enabled(self._ptr, enabled)
|
||||
|
||||
def setVisible(self, visible: int):
|
||||
vqt6_qwidget_set_visible(self._ptr, visible)
|
||||
|
||||
def isVisible(self) -> int:
|
||||
return vqt6_qwidget_is_visible(self._ptr)
|
||||
|
||||
def setToolTip(self, tip: str):
|
||||
tip_qs: QtStringPtr = vqt6_qstring_create(tip)
|
||||
vqt6_qwidget_set_tool_tip(self._ptr, tip_qs)
|
||||
vqt6_qstring_free(tip_qs)
|
||||
|
||||
|
||||
@t.NoVTable
|
||||
class QLabel:
|
||||
"""QLabel 包装"""
|
||||
_ptr: QtLabelPtr
|
||||
|
||||
def __init__(self, text: str = "", parent: "QWidget | None" = None):
|
||||
text_qs: QtStringPtr = vqt6_qstring_create(text)
|
||||
if parent is not None and parent._ptr is not None:
|
||||
self._ptr = vqt6_qlabel_create_with_text_parent(text_qs, parent._ptr)
|
||||
elif text_qs is not None:
|
||||
self._ptr = vqt6_qlabel_create_with_text(text_qs)
|
||||
else:
|
||||
self._ptr = vqt6_qlabel_create()
|
||||
vqt6_qstring_free(text_qs)
|
||||
if self._ptr is None:
|
||||
raise RuntimeError("Failed to create QLabel")
|
||||
|
||||
def setText(self, text: str):
|
||||
text_qs: QtStringPtr = vqt6_qstring_create(text)
|
||||
vqt6_qlabel_set_text(self._ptr, text_qs)
|
||||
vqt6_qstring_free(text_qs)
|
||||
|
||||
def text(self) -> str:
|
||||
result: QtStringPtr = vqt6_qlabel_text(self._ptr)
|
||||
buf: bytes = stdlib.malloc(1024)
|
||||
vqt6_qstring_to_utf8(result, buf, 1024)
|
||||
s: str = string.strndup(buf, 1024)
|
||||
vqt6_qstring_free(result)
|
||||
return s
|
||||
|
||||
def setAlignment(self, alignment: int):
|
||||
vqt6_qlabel_set_alignment(self._ptr, alignment)
|
||||
|
||||
|
||||
@t.NoVTable
|
||||
class QPushButton:
|
||||
"""QPushButton 包装"""
|
||||
_ptr: QtPushButtonPtr
|
||||
|
||||
def __init__(self, text: str = "", parent: "QWidget | None" = None):
|
||||
text_qs: QtStringPtr = vqt6_qstring_create(text)
|
||||
if parent is not None and parent._ptr is not None:
|
||||
self._ptr = vqt6_qpushbutton_create_with_text_parent(text_qs, parent._ptr)
|
||||
elif text_qs is not None:
|
||||
self._ptr = vqt6_qpushbutton_create_with_text(text_qs)
|
||||
else:
|
||||
self._ptr = vqt6_qpushbutton_create()
|
||||
vqt6_qstring_free(text_qs)
|
||||
if self._ptr is None:
|
||||
raise RuntimeError("Failed to create QPushButton")
|
||||
|
||||
def setText(self, text: str):
|
||||
text_qs: QtStringPtr = vqt6_qstring_create(text)
|
||||
vqt6_qpushbutton_set_text(self._ptr, text_qs)
|
||||
vqt6_qstring_free(text_qs)
|
||||
|
||||
def text(self) -> str:
|
||||
result: QtStringPtr = vqt6_qpushbutton_text(self._ptr)
|
||||
buf: bytes = stdlib.malloc(1024)
|
||||
vqt6_qstring_to_utf8(result, buf, 1024)
|
||||
s: str = string.strndup(buf, 1024)
|
||||
vqt6_qstring_free(result)
|
||||
return s
|
||||
|
||||
def click(self):
|
||||
vqt6_qpushbutton_click(self._ptr)
|
||||
|
||||
def setEnabled(self, enabled: int):
|
||||
vqt6_qwidget_set_enabled(self._ptr, enabled)
|
||||
|
||||
|
||||
# ============================================================
|
||||
# 模块导出
|
||||
# ============================================================
|
||||
__all__ = [
|
||||
# 高层类
|
||||
"QApplication", "QWidget", "QLabel", "QPushButton",
|
||||
# 类型
|
||||
"QtObjectPtr", "QtStringPtr", "QtByteArrayPtr", "QtWidgetPtr", "QtAppPtr",
|
||||
"QtLabelPtr", "QtPushButtonPtr",
|
||||
"QtColorPtr", "QtFontPtr", "QtPixmapPtr", "QtImagePtr", "QtPainterPtr",
|
||||
"QtTcpSocketPtr", "QtHostAddressPtr", "QtNetworkRequestPtr", "QtNetworkReplyPtr",
|
||||
# 常量
|
||||
"QT_KEY_ESCAPE", "QT_KEY_RETURN", "QT_KEY_A", "QT_KEY_Z",
|
||||
"QT_LEFT_BUTTON", "QT_RIGHT_BUTTON", "QT_MID_BUTTON",
|
||||
"QT_HORIZONTAL", "QT_VERTICAL",
|
||||
"QT_ALIGN_LEFT", "QT_ALIGN_CENTER", "QT_ALIGN_RIGHT",
|
||||
"QT_PORT_HTTP", "QT_PORT_HTTPS", "QT_PORT_FTP",
|
||||
"QT_OK", "QT_CANCEL", "QT_YES", "QT_NO", "QT_CLOSE",
|
||||
]
|
||||
151
includes/vqt6 copy/_bridge.h
Normal file
151
includes/vqt6 copy/_bridge.h
Normal file
@@ -0,0 +1,151 @@
|
||||
// ============================================================
|
||||
// vqt6/_bridge.h — C 桥接层头文件
|
||||
//
|
||||
// 作用: 把 Qt6 C++ API 包装成 extern "C" 函数,供 Viper FFI 调用
|
||||
// 编译: 作为静态库 libvqt6_bridge.a 或动态库 vqt6_bridge.dll
|
||||
// ============================================================
|
||||
|
||||
#ifndef VQT6_BRIDGE_H
|
||||
#define VQT6_BRIDGE_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#if defined(_WIN32)
|
||||
# if defined(VQT6_BRIDGE_STATIC)
|
||||
# define VQT6_API
|
||||
# elif defined(VQT6_BRIDGE_BUILD)
|
||||
# define VQT6_API __declspec(dllexport)
|
||||
# else
|
||||
# define VQT6_API __declspec(dllimport)
|
||||
# endif
|
||||
#else
|
||||
# if defined(__GNUC__) && (__GNUC__ >= 4)
|
||||
# define VQT6_API __attribute__((visibility("default")))
|
||||
# else
|
||||
# define VQT6_API
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// ============================================================
|
||||
// QString
|
||||
// ============================================================
|
||||
VQT6_API void* vqt6_qstring_create(const char* utf8);
|
||||
VQT6_API size_t vqt6_qstring_to_utf8(void* qstr, char* buf, size_t buf_size);
|
||||
VQT6_API void vqt6_qstring_free(void* qstr);
|
||||
VQT6_API int vqt6_qstring_length(void* qstr);
|
||||
VQT6_API int vqt6_qstring_is_empty(void* qstr);
|
||||
VQT6_API int vqt6_qstring_equals(void* qstr, void* other);
|
||||
VQT6_API void* vqt6_qstring_append(void* qstr, void* other);
|
||||
|
||||
// ============================================================
|
||||
// QByteArray
|
||||
// ============================================================
|
||||
VQT6_API void* vqt6_qbytearray_create(const void* data, size_t size);
|
||||
VQT6_API void* vqt6_qbytearray_data(void* qba, size_t* out_size);
|
||||
VQT6_API size_t vqt6_qbytearray_size(void* qba);
|
||||
VQT6_API void vqt6_qbytearray_free(void* qba);
|
||||
|
||||
// ============================================================
|
||||
// QObject
|
||||
// ============================================================
|
||||
VQT6_API void vqt6_qobject_delete(void* obj);
|
||||
VQT6_API void vqt6_qobject_delete_later(void* obj);
|
||||
VQT6_API void vqt6_qobject_set_object_name(void* obj, void* name);
|
||||
VQT6_API void* vqt6_qobject_object_name(void* obj);
|
||||
VQT6_API void vqt6_qobject_set_parent(void* child, void* parent);
|
||||
VQT6_API void* vqt6_qobject_parent(void* obj);
|
||||
VQT6_API int vqt6_qobject_connect(void* sender, const char* signal_name,
|
||||
void* receiver, const char* slot_name);
|
||||
VQT6_API int vqt6_qobject_disconnect(void* sender, const char* signal_name,
|
||||
void* receiver, const char* slot_name);
|
||||
VQT6_API void vqt6_qobject_install_event_filter(void* watched, void* filter);
|
||||
VQT6_API void vqt6_qobject_remove_event_filter(void* watched, void* filter);
|
||||
|
||||
// ============================================================
|
||||
// QCoreApplication
|
||||
// ============================================================
|
||||
VQT6_API void* vqt6_qcoreapp_create(const char* app_name);
|
||||
VQT6_API void* vqt6_qcoreapp_instance(void);
|
||||
VQT6_API int vqt6_qcoreapp_exec(void* app);
|
||||
VQT6_API void vqt6_qcoreapp_quit(void* app, int exit_code);
|
||||
VQT6_API void vqt6_qcoreapp_exit(void* app, int exit_code);
|
||||
VQT6_API void vqt6_qcoreapp_process_events(void* app, int flags);
|
||||
VQT6_API void vqt6_qcoreapp_post_event(void* receiver, void* event);
|
||||
VQT6_API int vqt6_qcoreapp_send_event(void* receiver, void* event);
|
||||
VQT6_API void* vqt6_qcoreapp_organization_name(void* app);
|
||||
VQT6_API void vqt6_qcoreapp_set_organization_name(void* app, void* name);
|
||||
VQT6_API void* vqt6_qcoreapp_application_name(void* app);
|
||||
VQT6_API void vqt6_qcoreapp_set_application_name(void* app, void* name);
|
||||
|
||||
// ============================================================
|
||||
// QTimer
|
||||
// ============================================================
|
||||
VQT6_API void* vqt6_qtimer_create(void);
|
||||
VQT6_API void* vqt6_qtimer_create_with_parent(void* parent);
|
||||
VQT6_API void vqt6_qtimer_start(void* timer, int interval_ms);
|
||||
VQT6_API void vqt6_qtimer_stop(void* timer);
|
||||
VQT6_API void vqt6_qtimer_set_interval(void* timer, int interval_ms);
|
||||
VQT6_API int vqt6_qtimer_interval(void* timer);
|
||||
VQT6_API int vqt6_qtimer_is_active(void* timer);
|
||||
VQT6_API void vqt6_qtimer_set_single_shot(void* timer, int single_shot);
|
||||
VQT6_API int vqt6_qtimer_is_single_shot(void* timer);
|
||||
|
||||
// ============================================================
|
||||
// QVariant
|
||||
// ============================================================
|
||||
VQT6_API void* vqt6_qvariant_create_int(int value);
|
||||
VQT6_API void* vqt6_qvariant_create_double(double value);
|
||||
VQT6_API void* vqt6_qvariant_create_bool(int value);
|
||||
VQT6_API void* vqt6_qvariant_create_string(void* s);
|
||||
VQT6_API int vqt6_qvariant_to_int(void* v, int* ok);
|
||||
VQT6_API double vqt6_qvariant_to_double(void* v, int* ok);
|
||||
VQT6_API int vqt6_qvariant_to_bool(void* v, int* ok);
|
||||
VQT6_API void* vqt6_qvariant_to_string(void* v);
|
||||
VQT6_API int vqt6_qvariant_type_id(void* v);
|
||||
VQT6_API int vqt6_qvariant_is_valid(void* v);
|
||||
VQT6_API void vqt6_qvariant_free(void* v);
|
||||
|
||||
// ============================================================
|
||||
// QEvent
|
||||
// ============================================================
|
||||
VQT6_API int vqt6_qevent_type(void* event);
|
||||
VQT6_API void vqt6_qevent_accept(void* event);
|
||||
VQT6_API void vqt6_qevent_ignore(void* event);
|
||||
VQT6_API int vqt6_qevent_is_accepted(void* event);
|
||||
|
||||
// ============================================================
|
||||
// QStringList
|
||||
// ============================================================
|
||||
VQT6_API void* vqt6_qstringlist_create(void);
|
||||
VQT6_API void vqt6_qstringlist_append(void* list, void* str);
|
||||
VQT6_API int vqt6_qstringlist_size(void* list);
|
||||
VQT6_API void* vqt6_qstringlist_at(void* list, int index);
|
||||
VQT6_API void vqt6_qstringlist_free(void* list);
|
||||
|
||||
// ============================================================
|
||||
// QByteArrayList
|
||||
// ============================================================
|
||||
VQT6_API void* vqt6_qbytearraylist_create(void);
|
||||
VQT6_API void vqt6_qbytearraylist_append(void* list, void* qba);
|
||||
VQT6_API int vqt6_qbytearraylist_size(void* list);
|
||||
VQT6_API void* vqt6_qbytearraylist_at(void* list, int index);
|
||||
VQT6_API void vqt6_qbytearraylist_free(void* list);
|
||||
|
||||
// ============================================================
|
||||
// 全局回调注册表
|
||||
// ============================================================
|
||||
typedef void (*vqt6_slot_callback_t)(int slot_id, void* user_data);
|
||||
VQT6_API void vqt6_register_slot(int slot_id, void* user_data);
|
||||
VQT6_API void vqt6_unregister_slot(int slot_id);
|
||||
VQT6_API void vqt6_trigger_slot(int slot_id);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // VQT6_BRIDGE_H
|
||||
433
includes/vqt6 copy/_bridge_core.cpp
Normal file
433
includes/vqt6 copy/_bridge_core.cpp
Normal file
@@ -0,0 +1,433 @@
|
||||
// ============================================================
|
||||
// vqt6/_bridge_core.cpp — QtCore C 桥接层实现
|
||||
// ============================================================
|
||||
|
||||
#include "_bridge.h"
|
||||
#include <QString>
|
||||
#include <QByteArray>
|
||||
#include <QObject>
|
||||
#include <QCoreApplication>
|
||||
#include <QTimer>
|
||||
#include <QVariant>
|
||||
#include <QEvent>
|
||||
#include <QStringList>
|
||||
#include <QList>
|
||||
#include <QHash>
|
||||
#include <QMutex>
|
||||
#include <cstring>
|
||||
|
||||
// 全局回调表(线程安全)
|
||||
namespace {
|
||||
QMutex g_slot_mutex;
|
||||
QHash<int, QPair<vqt6_slot_callback_t, void*>> g_slots;
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// QString
|
||||
// ============================================================
|
||||
extern "C" VQT6_API void* vqt6_qstring_create(const char* utf8) {
|
||||
if (utf8 == nullptr) return nullptr;
|
||||
return new QString(QString::fromUtf8(utf8));
|
||||
}
|
||||
|
||||
extern "C" VQT6_API size_t vqt6_qstring_to_utf8(void* qstr, char* buf, size_t buf_size) {
|
||||
if (qstr == nullptr || buf == nullptr || buf_size == 0) return 0;
|
||||
QString* s = static_cast<QString*>(qstr);
|
||||
QByteArray ba = s->toUtf8();
|
||||
size_t len = static_cast<size_t>(ba.size());
|
||||
if (len >= buf_size) len = buf_size - 1;
|
||||
std::memcpy(buf, ba.constData(), len);
|
||||
buf[len] = '\0';
|
||||
return len;
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qstring_free(void* qstr) {
|
||||
delete static_cast<QString*>(qstr);
|
||||
}
|
||||
|
||||
extern "C" VQT6_API int vqt6_qstring_length(void* qstr) {
|
||||
if (qstr == nullptr) return 0;
|
||||
return static_cast<QString*>(qstr)->length();
|
||||
}
|
||||
|
||||
extern "C" VQT6_API int vqt6_qstring_is_empty(void* qstr) {
|
||||
if (qstr == nullptr) return 1;
|
||||
return static_cast<QString*>(qstr)->isEmpty() ? 1 : 0;
|
||||
}
|
||||
|
||||
extern "C" VQT6_API int vqt6_qstring_equals(void* qstr, void* other) {
|
||||
if (qstr == nullptr || other == nullptr) return 0;
|
||||
return *static_cast<QString*>(qstr) == *static_cast<QString*>(other) ? 1 : 0;
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void* vqt6_qstring_append(void* qstr, void* other) {
|
||||
if (qstr == nullptr || other == nullptr) return nullptr;
|
||||
return new QString(*static_cast<QString*>(qstr) + *static_cast<QString*>(other));
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// QByteArray
|
||||
// ============================================================
|
||||
extern "C" VQT6_API void* vqt6_qbytearray_create(const void* data, size_t size) {
|
||||
if (data == nullptr) return new QByteArray();
|
||||
return new QByteArray(static_cast<const char*>(data), static_cast<int>(size));
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void* vqt6_qbytearray_data(void* qba, size_t* out_size) {
|
||||
if (qba == nullptr) return nullptr;
|
||||
QByteArray* ba = static_cast<QByteArray*>(qba);
|
||||
if (out_size != nullptr) *out_size = static_cast<size_t>(ba->size());
|
||||
return ba->data();
|
||||
}
|
||||
|
||||
extern "C" VQT6_API size_t vqt6_qbytearray_size(void* qba) {
|
||||
if (qba == nullptr) return 0;
|
||||
return static_cast<size_t>(static_cast<QByteArray*>(qba)->size());
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qbytearray_free(void* qba) {
|
||||
delete static_cast<QByteArray*>(qba);
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// QObject
|
||||
// ============================================================
|
||||
extern "C" VQT6_API void vqt6_qobject_delete(void* obj) {
|
||||
if (obj == nullptr) return;
|
||||
delete static_cast<QObject*>(obj);
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qobject_delete_later(void* obj) {
|
||||
if (obj == nullptr) return;
|
||||
static_cast<QObject*>(obj)->deleteLater();
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qobject_set_object_name(void* obj, void* name) {
|
||||
if (obj == nullptr || name == nullptr) return;
|
||||
static_cast<QObject*>(obj)->setObjectName(*static_cast<QString*>(name));
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void* vqt6_qobject_object_name(void* obj) {
|
||||
if (obj == nullptr) return nullptr;
|
||||
return new QString(static_cast<QObject*>(obj)->objectName());
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qobject_set_parent(void* child, void* parent) {
|
||||
if (child == nullptr) return;
|
||||
static_cast<QObject*>(child)->setParent(static_cast<QObject*>(parent));
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void* vqt6_qobject_parent(void* obj) {
|
||||
if (obj == nullptr) return nullptr;
|
||||
return static_cast<QObject*>(obj)->parent();
|
||||
}
|
||||
|
||||
extern "C" VQT6_API int vqt6_qobject_connect(void* sender, const char* signal_name,
|
||||
void* receiver, const char* slot_name) {
|
||||
if (sender == nullptr || receiver == nullptr || signal_name == nullptr || slot_name == nullptr)
|
||||
return 0;
|
||||
return QObject::connect(
|
||||
static_cast<QObject*>(sender), signal_name,
|
||||
static_cast<QObject*>(receiver), slot_name
|
||||
) ? 1 : 0;
|
||||
}
|
||||
|
||||
extern "C" VQT6_API int vqt6_qobject_disconnect(void* sender, const char* signal_name,
|
||||
void* receiver, const char* slot_name) {
|
||||
if (sender == nullptr || receiver == nullptr) return 0;
|
||||
return QObject::disconnect(
|
||||
static_cast<QObject*>(sender), signal_name,
|
||||
static_cast<QObject*>(receiver), slot_name
|
||||
) ? 1 : 0;
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qobject_install_event_filter(void* watched, void* filter) {
|
||||
if (watched == nullptr || filter == nullptr) return;
|
||||
static_cast<QObject*>(watched)->installEventFilter(static_cast<QObject*>(filter));
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qobject_remove_event_filter(void* watched, void* filter) {
|
||||
if (watched == nullptr || filter == nullptr) return;
|
||||
static_cast<QObject*>(watched)->removeEventFilter(static_cast<QObject*>(filter));
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// QCoreApplication
|
||||
// ============================================================
|
||||
extern "C" VQT6_API void* vqt6_qcoreapp_create(const char* app_name) {
|
||||
if (app_name == nullptr) return nullptr;
|
||||
int argc = 1;
|
||||
static char app_name_copy[1024];
|
||||
std::strncpy(app_name_copy, app_name, sizeof(app_name_copy) - 1);
|
||||
app_name_copy[sizeof(app_name_copy) - 1] = '\0';
|
||||
char* argv[] = { app_name_copy, nullptr };
|
||||
return new QCoreApplication(argc, argv);
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void* vqt6_qcoreapp_instance(void) {
|
||||
return QCoreApplication::instance();
|
||||
}
|
||||
|
||||
extern "C" VQT6_API int vqt6_qcoreapp_exec(void* app) {
|
||||
if (app == nullptr) return -1;
|
||||
return static_cast<QCoreApplication*>(app)->exec();
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qcoreapp_quit(void* app, int exit_code) {
|
||||
if (app == nullptr) return;
|
||||
// 优先使用 exit_code 重载
|
||||
QCoreApplication* a = static_cast<QCoreApplication*>(app);
|
||||
if (a == QCoreApplication::instance()) {
|
||||
a->exit(exit_code);
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qcoreapp_exit(void* app, int exit_code) {
|
||||
if (app == nullptr) return;
|
||||
static_cast<QCoreApplication*>(app)->exit(exit_code);
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qcoreapp_process_events(void* app, int flags) {
|
||||
if (app == nullptr) return;
|
||||
static_cast<QCoreApplication*>(app)->processEvents(static_cast<QEventLoop::ProcessEventsFlag>(flags));
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qcoreapp_post_event(void* receiver, void* event) {
|
||||
if (receiver == nullptr || event == nullptr) return;
|
||||
QCoreApplication::postEvent(static_cast<QObject*>(receiver), static_cast<QEvent*>(event));
|
||||
}
|
||||
|
||||
extern "C" VQT6_API int vqt6_qcoreapp_send_event(void* receiver, void* event) {
|
||||
if (receiver == nullptr || event == nullptr) return 0;
|
||||
return QCoreApplication::sendEvent(static_cast<QObject*>(receiver), static_cast<QEvent*>(event)) ? 1 : 0;
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void* vqt6_qcoreapp_organization_name(void* app) {
|
||||
if (app == nullptr) return nullptr;
|
||||
return new QString(QCoreApplication::organizationName());
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qcoreapp_set_organization_name(void* app, void* name) {
|
||||
if (app == nullptr || name == nullptr) return;
|
||||
QCoreApplication::setOrganizationName(*static_cast<QString*>(name));
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void* vqt6_qcoreapp_application_name(void* app) {
|
||||
if (app == nullptr) return nullptr;
|
||||
return new QString(QCoreApplication::applicationName());
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qcoreapp_set_application_name(void* app, void* name) {
|
||||
if (app == nullptr || name == nullptr) return;
|
||||
QCoreApplication::setApplicationName(*static_cast<QString*>(name));
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// QTimer
|
||||
// ============================================================
|
||||
extern "C" VQT6_API void* vqt6_qtimer_create(void) {
|
||||
return new QTimer();
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void* vqt6_qtimer_create_with_parent(void* parent) {
|
||||
if (parent == nullptr) return nullptr;
|
||||
return new QTimer(static_cast<QObject*>(parent));
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qtimer_start(void* timer, int interval_ms) {
|
||||
if (timer == nullptr) return;
|
||||
static_cast<QTimer*>(timer)->start(interval_ms);
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qtimer_stop(void* timer) {
|
||||
if (timer == nullptr) return;
|
||||
static_cast<QTimer*>(timer)->stop();
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qtimer_set_interval(void* timer, int interval_ms) {
|
||||
if (timer == nullptr) return;
|
||||
static_cast<QTimer*>(timer)->setInterval(interval_ms);
|
||||
}
|
||||
|
||||
extern "C" VQT6_API int vqt6_qtimer_interval(void* timer) {
|
||||
if (timer == nullptr) return 0;
|
||||
return static_cast<QTimer*>(timer)->interval();
|
||||
}
|
||||
|
||||
extern "C" VQT6_API int vqt6_qtimer_is_active(void* timer) {
|
||||
if (timer == nullptr) return 0;
|
||||
return static_cast<QTimer*>(timer)->isActive() ? 1 : 0;
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qtimer_set_single_shot(void* timer, int single_shot) {
|
||||
if (timer == nullptr) return;
|
||||
static_cast<QTimer*>(timer)->setSingleShot(single_shot != 0);
|
||||
}
|
||||
|
||||
extern "C" VQT6_API int vqt6_qtimer_is_single_shot(void* timer) {
|
||||
if (timer == nullptr) return 0;
|
||||
return static_cast<QTimer*>(timer)->isSingleShot() ? 1 : 0;
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// QVariant
|
||||
// ============================================================
|
||||
extern "C" VQT6_API void* vqt6_qvariant_create_int(int value) {
|
||||
return new QVariant(value);
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void* vqt6_qvariant_create_double(double value) {
|
||||
return new QVariant(value);
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void* vqt6_qvariant_create_bool(int value) {
|
||||
return new QVariant(value != 0);
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void* vqt6_qvariant_create_string(void* s) {
|
||||
if (s == nullptr) return new QVariant();
|
||||
return new QVariant(*static_cast<QString*>(s));
|
||||
}
|
||||
|
||||
extern "C" VQT6_API int vqt6_qvariant_to_int(void* v, int* ok) {
|
||||
if (v == nullptr) return 0;
|
||||
bool bok = false;
|
||||
int val = static_cast<QVariant*>(v)->toInt(&bok);
|
||||
if (ok != nullptr) *ok = bok ? 1 : 0;
|
||||
return val;
|
||||
}
|
||||
|
||||
extern "C" VQT6_API double vqt6_qvariant_to_double(void* v, int* ok) {
|
||||
if (v == nullptr) return 0.0;
|
||||
bool bok = false;
|
||||
double val = static_cast<QVariant*>(v)->toDouble(&bok);
|
||||
if (ok != nullptr) *ok = bok ? 1 : 0;
|
||||
return val;
|
||||
}
|
||||
|
||||
extern "C" VQT6_API int vqt6_qvariant_to_bool(void* v, int* ok) {
|
||||
if (v == nullptr) return 0;
|
||||
bool bok = false;
|
||||
bool val = static_cast<QVariant*>(v)->toBool();
|
||||
if (ok != nullptr) *ok = 1;
|
||||
return val ? 1 : 0;
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void* vqt6_qvariant_to_string(void* v) {
|
||||
if (v == nullptr) return nullptr;
|
||||
return new QString(static_cast<QVariant*>(v)->toString());
|
||||
}
|
||||
|
||||
extern "C" VQT6_API int vqt6_qvariant_type_id(void* v) {
|
||||
if (v == nullptr) return 0;
|
||||
return static_cast<int>(static_cast<QVariant*>(v)->typeId());
|
||||
}
|
||||
|
||||
extern "C" VQT6_API int vqt6_qvariant_is_valid(void* v) {
|
||||
if (v == nullptr) return 0;
|
||||
return static_cast<QVariant*>(v)->isValid() ? 1 : 0;
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qvariant_free(void* v) {
|
||||
delete static_cast<QVariant*>(v);
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// QEvent
|
||||
// ============================================================
|
||||
extern "C" VQT6_API int vqt6_qevent_type(void* event) {
|
||||
if (event == nullptr) return 0;
|
||||
return static_cast<int>(static_cast<QEvent*>(event)->type());
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qevent_accept(void* event) {
|
||||
if (event == nullptr) return;
|
||||
static_cast<QEvent*>(event)->accept();
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qevent_ignore(void* event) {
|
||||
if (event == nullptr) return;
|
||||
static_cast<QEvent*>(event)->ignore();
|
||||
}
|
||||
|
||||
extern "C" VQT6_API int vqt6_qevent_is_accepted(void* event) {
|
||||
if (event == nullptr) return 0;
|
||||
return static_cast<QEvent*>(event)->isAccepted() ? 1 : 0;
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// QStringList
|
||||
// ============================================================
|
||||
extern "C" VQT6_API void* vqt6_qstringlist_create(void) {
|
||||
return new QStringList();
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qstringlist_append(void* list, void* str) {
|
||||
if (list == nullptr || str == nullptr) return;
|
||||
static_cast<QStringList*>(list)->append(*static_cast<QString*>(str));
|
||||
}
|
||||
|
||||
extern "C" VQT6_API int vqt6_qstringlist_size(void* list) {
|
||||
if (list == nullptr) return 0;
|
||||
return static_cast<QStringList*>(list)->size();
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void* vqt6_qstringlist_at(void* list, int index) {
|
||||
if (list == nullptr) return nullptr;
|
||||
QStringList* sl = static_cast<QStringList*>(list);
|
||||
if (index < 0 || index >= sl->size()) return nullptr;
|
||||
return new QString(sl->at(index));
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qstringlist_free(void* list) {
|
||||
delete static_cast<QStringList*>(list);
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// QByteArrayList
|
||||
// ============================================================
|
||||
extern "C" VQT6_API void* vqt6_qbytearraylist_create(void) {
|
||||
return new QList<QByteArray>();
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qbytearraylist_append(void* list, void* qba) {
|
||||
if (list == nullptr || qba == nullptr) return;
|
||||
static_cast<QList<QByteArray>*>(list)->append(*static_cast<QByteArray*>(qba));
|
||||
}
|
||||
|
||||
extern "C" VQT6_API int vqt6_qbytearraylist_size(void* list) {
|
||||
if (list == nullptr) return 0;
|
||||
return static_cast<QList<QByteArray>*>(list)->size();
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void* vqt6_qbytearraylist_at(void* list, int index) {
|
||||
if (list == nullptr) return nullptr;
|
||||
QList<QByteArray>* qbl = static_cast<QList<QByteArray>*>(list);
|
||||
if (index < 0 || index >= qbl->size()) return nullptr;
|
||||
return new QByteArray(qbl->at(index));
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qbytearraylist_free(void* list) {
|
||||
delete static_cast<QList<QByteArray>*>(list);
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// 全局回调注册表
|
||||
// ============================================================
|
||||
extern "C" VQT6_API void vqt6_register_slot(int slot_id, void* user_data) {
|
||||
QMutexLocker locker(&g_slot_mutex);
|
||||
g_slots.insert(slot_id, QPair<vqt6_slot_callback_t, void*>(nullptr, user_data));
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_unregister_slot(int slot_id) {
|
||||
QMutexLocker locker(&g_slot_mutex);
|
||||
g_slots.remove(slot_id);
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_trigger_slot(int slot_id) {
|
||||
QMutexLocker locker(&g_slot_mutex);
|
||||
auto it = g_slots.find(slot_id);
|
||||
if (it != g_slots.end() && it.value().first != nullptr) {
|
||||
it.value().first(slot_id, it.value().second);
|
||||
}
|
||||
}
|
||||
868
includes/vqt6 copy/_bridge_gui.cpp
Normal file
868
includes/vqt6 copy/_bridge_gui.cpp
Normal file
@@ -0,0 +1,868 @@
|
||||
// ============================================================
|
||||
// vqt6/_bridge_gui.cpp — QtGui C 桥接层实现
|
||||
// ============================================================
|
||||
|
||||
#include "_bridge.h"
|
||||
#include "_bridge_gui.h"
|
||||
#include <QColor>
|
||||
#include <QFont>
|
||||
#include <QFontMetrics>
|
||||
#include <QPixmap>
|
||||
#include <QImage>
|
||||
#include <QPainter>
|
||||
#include <QPen>
|
||||
#include <QBrush>
|
||||
#include <QIcon>
|
||||
#include <QCursor>
|
||||
#include <QKeyEvent>
|
||||
#include <QMouseEvent>
|
||||
#include <QResizeEvent>
|
||||
#include <QPaintEvent>
|
||||
#include <QCloseEvent>
|
||||
#include <QPainterPath>
|
||||
#include <QPolygon>
|
||||
#include <QPoint>
|
||||
#include <QPointF>
|
||||
#include <QRect>
|
||||
#include <QRectF>
|
||||
#include <QGuiApplication>
|
||||
#include <QScreen>
|
||||
#include <QImageReader>
|
||||
#include <QBuffer>
|
||||
#include <QStyle>
|
||||
#include <QStringList>
|
||||
|
||||
// ============================================================
|
||||
// QColor
|
||||
// ============================================================
|
||||
extern "C" VQT6_API void* vqt6_qcolor_create_rgb(int r, int g, int b) {
|
||||
return new QColor(r, g, b);
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void* vqt6_qcolor_create_rgba(int r, int g, int b, int a) {
|
||||
return new QColor(r, g, b, a);
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void* vqt6_qcolor_create_name(void* name) {
|
||||
if (name == nullptr) return new QColor();
|
||||
return new QColor(*static_cast<QString*>(name));
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void* vqt6_qcolor_create_hex(void* hex_str) {
|
||||
if (hex_str == nullptr) return new QColor();
|
||||
return new QColor(*static_cast<QString*>(hex_str));
|
||||
}
|
||||
|
||||
extern "C" VQT6_API int vqt6_qcolor_red(void* c) {
|
||||
if (c == nullptr) return 0;
|
||||
return static_cast<QColor*>(c)->red();
|
||||
}
|
||||
|
||||
extern "C" VQT6_API int vqt6_qcolor_green(void* c) {
|
||||
if (c == nullptr) return 0;
|
||||
return static_cast<QColor*>(c)->green();
|
||||
}
|
||||
|
||||
extern "C" VQT6_API int vqt6_qcolor_blue(void* c) {
|
||||
if (c == nullptr) return 0;
|
||||
return static_cast<QColor*>(c)->blue();
|
||||
}
|
||||
|
||||
extern "C" VQT6_API int vqt6_qcolor_alpha(void* c) {
|
||||
if (c == nullptr) return 255;
|
||||
return static_cast<QColor*>(c)->alpha();
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qcolor_set_red(void* c, int r) {
|
||||
if (c == nullptr) return;
|
||||
static_cast<QColor*>(c)->setRed(r);
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qcolor_set_green(void* c, int g) {
|
||||
if (c == nullptr) return;
|
||||
static_cast<QColor*>(c)->setGreen(g);
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qcolor_set_blue(void* c, int b) {
|
||||
if (c == nullptr) return;
|
||||
static_cast<QColor*>(c)->setBlue(b);
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qcolor_set_alpha(void* c, int a) {
|
||||
if (c == nullptr) return;
|
||||
static_cast<QColor*>(c)->setAlpha(a);
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qcolor_set_rgb(void* c, int r, int g, int b) {
|
||||
if (c == nullptr) return;
|
||||
static_cast<QColor*>(c)->setRgb(r, g, b);
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qcolor_set_rgba(void* c, int r, int g, int b, int a) {
|
||||
if (c == nullptr) return;
|
||||
static_cast<QColor*>(c)->setRgba(r, g, b, a);
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void* vqt6_qcolor_name(void* c) {
|
||||
if (c == nullptr) return nullptr;
|
||||
return new QString(static_cast<QColor*>(c)->name());
|
||||
}
|
||||
|
||||
extern "C" VQT6_API int vqt6_qcolor_is_valid(void* c) {
|
||||
if (c == nullptr) return 0;
|
||||
return static_cast<QColor*>(c)->isValid() ? 1 : 0;
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qcolor_free(void* c) {
|
||||
delete static_cast<QColor*>(c);
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// QFont
|
||||
// ============================================================
|
||||
extern "C" VQT6_API void* vqt6_qfont_create(void) {
|
||||
return new QFont();
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void* vqt6_qfont_create_with_family(void* family) {
|
||||
if (family == nullptr) return new QFont();
|
||||
return new QFont(*static_cast<QString*>(family));
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void* vqt6_qfont_create_with_family_size(void* family, int point_size) {
|
||||
if (family == nullptr) return new QFont();
|
||||
return new QFont(*static_cast<QString*>(family), point_size);
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qfont_set_family(void* font, void* family) {
|
||||
if (font == nullptr || family == nullptr) return;
|
||||
static_cast<QFont*>(font)->setFamily(*static_cast<QString*>(family));
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void* vqt6_qfont_family(void* font) {
|
||||
if (font == nullptr) return nullptr;
|
||||
return new QString(static_cast<QFont*>(font)->family());
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qfont_set_point_size(void* font, int point_size) {
|
||||
if (font == nullptr) return;
|
||||
static_cast<QFont*>(font)->setPointSize(point_size);
|
||||
}
|
||||
|
||||
extern "C" VQT6_API int vqt6_qfont_point_size(void* font) {
|
||||
if (font == nullptr) return 0;
|
||||
return static_cast<QFont*>(font)->pointSize();
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qfont_set_pixel_size(void* font, int pixel_size) {
|
||||
if (font == nullptr) return;
|
||||
static_cast<QFont*>(font)->setPixelSize(pixel_size);
|
||||
}
|
||||
|
||||
extern "C" VQT6_API int vqt6_qfont_pixel_size(void* font) {
|
||||
if (font == nullptr) return 0;
|
||||
return static_cast<QFont*>(font)->pixelSize();
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qfont_set_bold(void* font, int bold) {
|
||||
if (font == nullptr) return;
|
||||
static_cast<QFont*>(font)->setBold(bold != 0);
|
||||
}
|
||||
|
||||
extern "C" VQT6_API int vqt6_qfont_bold(void* font) {
|
||||
if (font == nullptr) return 0;
|
||||
return static_cast<QFont*>(font)->bold() ? 1 : 0;
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qfont_set_italic(void* font, int italic) {
|
||||
if (font == nullptr) return;
|
||||
static_cast<QFont*>(font)->setItalic(italic != 0);
|
||||
}
|
||||
|
||||
extern "C" VQT6_API int vqt6_qfont_italic(void* font) {
|
||||
if (font == nullptr) return 0;
|
||||
return static_cast<QFont*>(font)->italic() ? 1 : 0;
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qfont_set_underline(void* font, int underline) {
|
||||
if (font == nullptr) return;
|
||||
static_cast<QFont*>(font)->setUnderline(underline != 0);
|
||||
}
|
||||
|
||||
extern "C" VQT6_API int vqt6_qfont_underline(void* font) {
|
||||
if (font == nullptr) return 0;
|
||||
return static_cast<QFont*>(font)->underline() ? 1 : 0;
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qfont_set_strike_out(void* font, int strike_out) {
|
||||
if (font == nullptr) return;
|
||||
static_cast<QFont*>(font)->setStrikeOut(strike_out != 0);
|
||||
}
|
||||
|
||||
extern "C" VQT6_API int vqt6_qfont_strike_out(void* font) {
|
||||
if (font == nullptr) return 0;
|
||||
return static_cast<QFont*>(font)->strikeOut() ? 1 : 0;
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qfont_set_weight(void* font, int weight) {
|
||||
if (font == nullptr) return;
|
||||
static_cast<QFont*>(font)->setWeight(static_cast<QFont::Weight>(weight));
|
||||
}
|
||||
|
||||
extern "C" VQT6_API int vqt6_qfont_weight(void* font) {
|
||||
if (font == nullptr) return 0;
|
||||
return static_cast<int>(static_cast<QFont*>(font)->weight());
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qfont_free(void* font) {
|
||||
delete static_cast<QFont*>(font);
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// QFontMetrics
|
||||
// ============================================================
|
||||
extern "C" VQT6_API void* vqt6_qfontmetrics_create(void* font) {
|
||||
if (font == nullptr) return nullptr;
|
||||
return new QFontMetrics(*static_cast<QFont*>(font));
|
||||
}
|
||||
|
||||
extern "C" VQT6_API int vqt6_qfontmetrics_width(void* fm, void* text) {
|
||||
if (fm == nullptr || text == nullptr) return 0;
|
||||
return static_cast<QFontMetrics*>(fm)->horizontalAdvance(*static_cast<QString*>(text));
|
||||
}
|
||||
|
||||
extern "C" VQT6_API int vqt6_qfontmetrics_height(void* fm) {
|
||||
if (fm == nullptr) return 0;
|
||||
return static_cast<QFontMetrics*>(fm)->height();
|
||||
}
|
||||
|
||||
extern "C" VQT6_API int vqt6_qfontmetrics_ascent(void* fm) {
|
||||
if (fm == nullptr) return 0;
|
||||
return static_cast<QFontMetrics*>(fm)->ascent();
|
||||
}
|
||||
|
||||
extern "C" VQT6_API int vqt6_qfontmetrics_descent(void* fm) {
|
||||
if (fm == nullptr) return 0;
|
||||
return static_cast<QFontMetrics*>(fm)->descent();
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qfontmetrics_free(void* fm) {
|
||||
delete static_cast<QFontMetrics*>(fm);
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// QPixmap
|
||||
// ============================================================
|
||||
extern "C" VQT6_API void* vqt6_qpixmap_create(void) {
|
||||
return new QPixmap();
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void* vqt6_qpixmap_create_with_size(int w, int h) {
|
||||
return new QPixmap(w, h);
|
||||
}
|
||||
|
||||
extern "C" VQT6_API int vqt6_qpixmap_load(void* pm, void* file_name) {
|
||||
if (pm == nullptr || file_name == nullptr) return 0;
|
||||
return static_cast<QPixmap*>(pm)->load(*static_cast<QString*>(file_name)) ? 1 : 0;
|
||||
}
|
||||
|
||||
extern "C" VQT6_API int vqt6_qpixmap_load_from_data(void* pm, const void* data, size_t size) {
|
||||
if (pm == nullptr || data == nullptr) return 0;
|
||||
return static_cast<QPixmap*>(pm)->loadFromData(static_cast<const uchar*>(data), static_cast<uint>(size)) ? 1 : 0;
|
||||
}
|
||||
|
||||
extern "C" VQT6_API int vqt6_qpixmap_save(void* pm, void* file_name) {
|
||||
if (pm == nullptr || file_name == nullptr) return 0;
|
||||
return static_cast<QPixmap*>(pm)->save(*static_cast<QString*>(file_name)) ? 1 : 0;
|
||||
}
|
||||
|
||||
extern "C" VQT6_API int vqt6_qpixmap_width(void* pm) {
|
||||
if (pm == nullptr) return 0;
|
||||
return static_cast<QPixmap*>(pm)->width();
|
||||
}
|
||||
|
||||
extern "C" VQT6_API int vqt6_qpixmap_height(void* pm) {
|
||||
if (pm == nullptr) return 0;
|
||||
return static_cast<QPixmap*>(pm)->height();
|
||||
}
|
||||
|
||||
extern "C" VQT6_API int vqt6_qpixmap_is_null(void* pm) {
|
||||
if (pm == nullptr) return 0;
|
||||
return static_cast<QPixmap*>(pm)->isNull() ? 1 : 0;
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void* vqt6_qpixmap_scaled(void* pm, int w, int h) {
|
||||
if (pm == nullptr) return nullptr;
|
||||
return new QPixmap(static_cast<QPixmap*>(pm)->scaled(w, h));
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qpixmap_fill(void* pm, void* color) {
|
||||
if (pm == nullptr) return;
|
||||
if (color != nullptr) {
|
||||
static_cast<QPixmap*>(pm)->fill(*static_cast<QColor*>(color));
|
||||
} else {
|
||||
static_cast<QPixmap*>(pm)->fill();
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qpixmap_free(void* pm) {
|
||||
delete static_cast<QPixmap*>(pm);
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// QImage
|
||||
// ============================================================
|
||||
extern "C" VQT6_API void* vqt6_qimage_create(void) {
|
||||
return new QImage();
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void* vqt6_qimage_create_with_size(int w, int h, int format) {
|
||||
return new QImage(w, h, static_cast<QImage::Format>(format));
|
||||
}
|
||||
|
||||
extern "C" VQT6_API int vqt6_qimage_load(void* img, void* file_name) {
|
||||
if (img == nullptr || file_name == nullptr) return 0;
|
||||
return static_cast<QImage*>(img)->load(*static_cast<QString*>(file_name)) ? 1 : 0;
|
||||
}
|
||||
|
||||
extern "C" VQT6_API int vqt6_qimage_save(void* img, void* file_name) {
|
||||
if (img == nullptr || file_name == nullptr) return 0;
|
||||
return static_cast<QImage*>(img)->save(*static_cast<QString*>(file_name)) ? 1 : 0;
|
||||
}
|
||||
|
||||
extern "C" VQT6_API int vqt6_qimage_width(void* img) {
|
||||
if (img == nullptr) return 0;
|
||||
return static_cast<QImage*>(img)->width();
|
||||
}
|
||||
|
||||
extern "C" VQT6_API int vqt6_qimage_height(void* img) {
|
||||
if (img == nullptr) return 0;
|
||||
return static_cast<QImage*>(img)->height();
|
||||
}
|
||||
|
||||
extern "C" VQT6_API int vqt6_qimage_format(void* img) {
|
||||
if (img == nullptr) return 0;
|
||||
return static_cast<int>(static_cast<QImage*>(img)->format());
|
||||
}
|
||||
|
||||
extern "C" VQT6_API int vqt6_qimage_is_null(void* img) {
|
||||
if (img == nullptr) return 0;
|
||||
return static_cast<QImage*>(img)->isNull() ? 1 : 0;
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qimage_fill(void* img, void* color) {
|
||||
if (img == nullptr) return;
|
||||
if (color != nullptr) {
|
||||
static_cast<QImage*>(img)->fill(*static_cast<QColor*>(color));
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void* vqt6_qimage_scaled(void* img, int w, int h) {
|
||||
if (img == nullptr) return nullptr;
|
||||
return new QImage(static_cast<QImage*>(img)->scaled(w, h));
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qimage_free(void* img) {
|
||||
delete static_cast<QImage*>(img);
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// QPainter
|
||||
// ============================================================
|
||||
extern "C" VQT6_API void* vqt6_qpainter_create(void) {
|
||||
return new QPainter();
|
||||
}
|
||||
|
||||
extern "C" VQT6_API int vqt6_qpainter_begin(void* p, void* device) {
|
||||
if (p == nullptr || device == nullptr) return 0;
|
||||
return static_cast<QPainter*>(p)->begin(static_cast<QPixmap*>(device)) ? 1 : 0;
|
||||
}
|
||||
|
||||
extern "C" VQT6_API int vqt6_qpainter_end(void* p) {
|
||||
if (p == nullptr) return 0;
|
||||
return static_cast<QPainter*>(p)->end() ? 1 : 0;
|
||||
}
|
||||
|
||||
extern "C" VQT6_API int vqt6_qpainter_is_active(void* p) {
|
||||
if (p == nullptr) return 0;
|
||||
return static_cast<QPainter*>(p)->isActive() ? 1 : 0;
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qpainter_set_pen(void* p, void* pen) {
|
||||
if (p == nullptr || pen == nullptr) return;
|
||||
static_cast<QPainter*>(p)->setPen(*static_cast<QPen*>(pen));
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qpainter_set_brush(void* p, void* brush) {
|
||||
if (p == nullptr || brush == nullptr) return;
|
||||
static_cast<QPainter*>(p)->setBrush(*static_cast<QBrush*>(brush));
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qpainter_set_font(void* p, void* font) {
|
||||
if (p == nullptr || font == nullptr) return;
|
||||
static_cast<QPainter*>(p)->setFont(*static_cast<QFont*>(font));
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void* vqt6_qpainter_pen(void* p) {
|
||||
if (p == nullptr) return nullptr;
|
||||
return new QPen(static_cast<QPainter*>(p)->pen());
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void* vqt6_qpainter_brush(void* p) {
|
||||
if (p == nullptr) return nullptr;
|
||||
return new QBrush(static_cast<QPainter*>(p)->brush());
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void* vqt6_qpainter_font(void* p) {
|
||||
if (p == nullptr) return nullptr;
|
||||
return new QFont(static_cast<QPainter*>(p)->font());
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qpainter_set_opacity(void* p, double opacity) {
|
||||
if (p == nullptr) return;
|
||||
static_cast<QPainter*>(p)->setOpacity(opacity);
|
||||
}
|
||||
|
||||
extern "C" VQT6_API double vqt6_qpainter_opacity(void* p) {
|
||||
if (p == nullptr) return 1.0;
|
||||
return static_cast<QPainter*>(p)->opacity();
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qpainter_draw_line(void* p, int x1, int y1, int x2, int y2) {
|
||||
if (p == nullptr) return;
|
||||
static_cast<QPainter*>(p)->drawLine(x1, y1, x2, y2);
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qpainter_draw_rect(void* p, int x, int y, int w, int h) {
|
||||
if (p == nullptr) return;
|
||||
static_cast<QPainter*>(p)->drawRect(x, y, w, h);
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qpainter_fill_rect(void* p, int x, int y, int w, int h, void* color) {
|
||||
if (p == nullptr || color == nullptr) return;
|
||||
static_cast<QPainter*>(p)->fillRect(x, y, w, h, *static_cast<QColor*>(color));
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qpainter_draw_ellipse(void* p, int x, int y, int w, int h) {
|
||||
if (p == nullptr) return;
|
||||
static_cast<QPainter*>(p)->drawEllipse(x, y, w, h);
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qpainter_draw_arc(void* p, int x, int y, int w, int h, int start_angle, int span_angle) {
|
||||
if (p == nullptr) return;
|
||||
static_cast<QPainter*>(p)->drawArc(x, y, w, h, start_angle, span_angle);
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qpainter_draw_chord(void* p, int x, int y, int w, int h, int start_angle, int span_angle) {
|
||||
if (p == nullptr) return;
|
||||
static_cast<QPainter*>(p)->drawChord(x, y, w, h, start_angle, span_angle);
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qpainter_draw_pie(void* p, int x, int y, int w, int h, int start_angle, int span_angle) {
|
||||
if (p == nullptr) return;
|
||||
static_cast<QPainter*>(p)->drawPie(x, y, w, h, start_angle, span_angle);
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qpainter_draw_polygon(void* p, int* points, int point_count) {
|
||||
if (p == nullptr || points == nullptr || point_count < 1) return;
|
||||
QPolygon polygon;
|
||||
for (int i = 0; i < point_count; ++i) {
|
||||
polygon << QPoint(points[i*2], points[i*2+1]);
|
||||
}
|
||||
static_cast<QPainter*>(p)->drawPolygon(polygon);
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qpainter_draw_polyline(void* p, int* points, int point_count) {
|
||||
if (p == nullptr || points == nullptr || point_count < 1) return;
|
||||
QPolygon polyline;
|
||||
for (int i = 0; i < point_count; ++i) {
|
||||
polyline << QPoint(points[i*2], points[i*2+1]);
|
||||
}
|
||||
static_cast<QPainter*>(p)->drawPolyline(polyline);
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qpainter_draw_point(void* p, int x, int y) {
|
||||
if (p == nullptr) return;
|
||||
static_cast<QPainter*>(p)->drawPoint(x, y);
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qpainter_draw_points(void* p, int* points, int point_count) {
|
||||
if (p == nullptr || points == nullptr || point_count < 1) return;
|
||||
QPolygon pts;
|
||||
for (int i = 0; i < point_count; ++i) {
|
||||
pts << QPoint(points[i*2], points[i*2+1]);
|
||||
}
|
||||
static_cast<QPainter*>(p)->drawPoints(pts);
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qpainter_draw_text(void* p, int x, int y, void* text) {
|
||||
if (p == nullptr || text == nullptr) return;
|
||||
static_cast<QPainter*>(p)->drawText(x, y, *static_cast<QString*>(text));
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qpainter_draw_text_in_rect(void* p, int x, int y, int w, int h, int flags, void* text) {
|
||||
if (p == nullptr || text == nullptr) return;
|
||||
static_cast<QPainter*>(p)->drawText(x, y, w, h, flags, *static_cast<QString*>(text));
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qpainter_draw_pixmap(void* p, int x, int y, void* pixmap) {
|
||||
if (p == nullptr || pixmap == nullptr) return;
|
||||
static_cast<QPainter*>(p)->drawPixmap(x, y, *static_cast<QPixmap*>(pixmap));
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qpainter_draw_image(void* p, int x, int y, void* image) {
|
||||
if (p == nullptr || image == nullptr) return;
|
||||
static_cast<QPainter*>(p)->drawImage(x, y, *static_cast<QImage*>(image));
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qpainter_draw_tiled_pixmap(void* p, int x, int y, int w, int h, void* pixmap) {
|
||||
if (p == nullptr || pixmap == nullptr) return;
|
||||
static_cast<QPainter*>(p)->drawTiledPixmap(x, y, w, h, *static_cast<QPixmap*>(pixmap));
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qpainter_translate(void* p, int dx, int dy) {
|
||||
if (p == nullptr) return;
|
||||
static_cast<QPainter*>(p)->translate(dx, dy);
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qpainter_rotate(void* p, double angle) {
|
||||
if (p == nullptr) return;
|
||||
static_cast<QPainter*>(p)->rotate(angle);
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qpainter_scale(void* p, double sx, double sy) {
|
||||
if (p == nullptr) return;
|
||||
static_cast<QPainter*>(p)->scale(sx, sy);
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qpainter_reset_transform(void* p) {
|
||||
if (p == nullptr) return;
|
||||
static_cast<QPainter*>(p)->resetTransform();
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qpainter_save(void* p) {
|
||||
if (p == nullptr) return;
|
||||
static_cast<QPainter*>(p)->save();
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qpainter_restore(void* p) {
|
||||
if (p == nullptr) return;
|
||||
static_cast<QPainter*>(p)->restore();
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qpainter_free(void* p) {
|
||||
delete static_cast<QPainter*>(p);
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// QPen
|
||||
// ============================================================
|
||||
extern "C" VQT6_API void* vqt6_qpen_create(void) {
|
||||
return new QPen();
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void* vqt6_qpen_create_with_color(void* color) {
|
||||
if (color == nullptr) return new QPen();
|
||||
return new QPen(*static_cast<QColor*>(color));
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void* vqt6_qpen_create_with_color_width(void* color, int width) {
|
||||
if (color == nullptr) return new QPen();
|
||||
return new QPen(*static_cast<QColor*>(color), width);
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qpen_set_color(void* pen, void* color) {
|
||||
if (pen == nullptr || color == nullptr) return;
|
||||
static_cast<QPen*>(pen)->setColor(*static_cast<QColor*>(color));
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void* vqt6_qpen_color(void* pen) {
|
||||
if (pen == nullptr) return nullptr;
|
||||
return new QColor(static_cast<QPen*>(pen)->color());
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qpen_set_width(void* pen, int width) {
|
||||
if (pen == nullptr) return;
|
||||
static_cast<QPen*>(pen)->setWidth(width);
|
||||
}
|
||||
|
||||
extern "C" VQT6_API int vqt6_qpen_width(void* pen) {
|
||||
if (pen == nullptr) return 0;
|
||||
return static_cast<QPen*>(pen)->width();
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qpen_set_style(void* pen, int style) {
|
||||
if (pen == nullptr) return;
|
||||
static_cast<QPen*>(pen)->setStyle(static_cast<Qt::PenStyle>(style));
|
||||
}
|
||||
|
||||
extern "C" VQT6_API int vqt6_qpen_style(void* pen) {
|
||||
if (pen == nullptr) return 0;
|
||||
return static_cast<int>(static_cast<QPen*>(pen)->style());
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qpen_free(void* pen) {
|
||||
delete static_cast<QPen*>(pen);
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// QBrush
|
||||
// ============================================================
|
||||
extern "C" VQT6_API void* vqt6_qbrush_create(void) {
|
||||
return new QBrush();
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void* vqt6_qbrush_create_with_color(void* color) {
|
||||
if (color == nullptr) return new QBrush();
|
||||
return new QBrush(*static_cast<QColor*>(color));
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void* vqt6_qbrush_create_with_style(int style) {
|
||||
return new QBrush(static_cast<Qt::BrushStyle>(style));
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qbrush_set_color(void* brush, void* color) {
|
||||
if (brush == nullptr || color == nullptr) return;
|
||||
static_cast<QBrush*>(brush)->setColor(*static_cast<QColor*>(color));
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void* vqt6_qbrush_color(void* brush) {
|
||||
if (brush == nullptr) return nullptr;
|
||||
return new QColor(static_cast<QBrush*>(brush)->color());
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qbrush_set_style(void* brush, int style) {
|
||||
if (brush == nullptr) return;
|
||||
static_cast<QBrush*>(brush)->setStyle(static_cast<Qt::BrushStyle>(style));
|
||||
}
|
||||
|
||||
extern "C" VQT6_API int vqt6_qbrush_style(void* brush) {
|
||||
if (brush == nullptr) return 0;
|
||||
return static_cast<int>(static_cast<QBrush*>(brush)->style());
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qbrush_free(void* brush) {
|
||||
delete static_cast<QBrush*>(brush);
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// QIcon
|
||||
// ============================================================
|
||||
extern "C" VQT6_API void* vqt6_qicon_create(void) {
|
||||
return new QIcon();
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void* vqt6_qicon_create_with_file(void* file_name) {
|
||||
if (file_name == nullptr) return new QIcon();
|
||||
return new QIcon(*static_cast<QString*>(file_name));
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qicon_add_file(void* icon, void* file_name) {
|
||||
if (icon == nullptr || file_name == nullptr) return;
|
||||
static_cast<QIcon*>(icon)->addFile(*static_cast<QString*>(file_name));
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qicon_add_pixmap(void* icon, void* pixmap) {
|
||||
if (icon == nullptr || pixmap == nullptr) return;
|
||||
static_cast<QIcon*>(icon)->addPixmap(*static_cast<QPixmap*>(pixmap));
|
||||
}
|
||||
|
||||
extern "C" VQT6_API int vqt6_qicon_is_null(void* icon) {
|
||||
if (icon == nullptr) return 0;
|
||||
return static_cast<QIcon*>(icon)->isNull() ? 1 : 0;
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void* vqt6_qicon_pixmap(void* icon, int w, int h) {
|
||||
if (icon == nullptr) return nullptr;
|
||||
return new QPixmap(static_cast<QIcon*>(icon)->pixmap(w, h));
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qicon_free(void* icon) {
|
||||
delete static_cast<QIcon*>(icon);
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// QCursor
|
||||
// ============================================================
|
||||
extern "C" VQT6_API void* vqt6_qcursor_create(void) {
|
||||
return new QCursor();
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void* vqt6_qcursor_create_with_shape(int shape) {
|
||||
return new QCursor(static_cast<Qt::CursorShape>(shape));
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qcursor_pos(int* x, int* y) {
|
||||
QPoint p = QCursor::pos();
|
||||
if (x != nullptr) *x = p.x();
|
||||
if (y != nullptr) *y = p.y();
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qcursor_set_pos(int x, int y) {
|
||||
QCursor::setPos(x, y);
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qcursor_set_shape(void* cursor, int shape) {
|
||||
if (cursor == nullptr) return;
|
||||
static_cast<QCursor*>(cursor)->setShape(static_cast<Qt::CursorShape>(shape));
|
||||
}
|
||||
|
||||
extern "C" VQT6_API int vqt6_qcursor_shape(void* cursor) {
|
||||
if (cursor == nullptr) return 0;
|
||||
return static_cast<int>(static_cast<QCursor*>(cursor)->shape());
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qcursor_free(void* cursor) {
|
||||
delete static_cast<QCursor*>(cursor);
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// QKeyEvent
|
||||
// ============================================================
|
||||
extern "C" VQT6_API void* vqt6_qkeyevent_create(int type, int key, int modifiers, void* text) {
|
||||
QString* t = static_cast<QString*>(text);
|
||||
return new QKeyEvent(static_cast<QEvent::Type>(type), key, static_cast<Qt::KeyboardModifiers>(modifiers),
|
||||
t != nullptr ? *t : QString());
|
||||
}
|
||||
|
||||
extern "C" VQT6_API int vqt6_qkeyevent_key(void* event) {
|
||||
if (event == nullptr) return 0;
|
||||
return static_cast<QKeyEvent*>(event)->key();
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void* vqt6_qkeyevent_text(void* event) {
|
||||
if (event == nullptr) return nullptr;
|
||||
return new QString(static_cast<QKeyEvent*>(event)->text());
|
||||
}
|
||||
|
||||
extern "C" VQT6_API int vqt6_qkeyevent_modifiers(void* event) {
|
||||
if (event == nullptr) return 0;
|
||||
return static_cast<int>(static_cast<QKeyEvent*>(event)->modifiers());
|
||||
}
|
||||
|
||||
extern "C" VQT6_API int vqt6_qkeyevent_is_auto_repeat(void* event) {
|
||||
if (event == nullptr) return 0;
|
||||
return static_cast<QKeyEvent*>(event)->isAutoRepeat() ? 1 : 0;
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qkeyevent_free(void* event) {
|
||||
delete static_cast<QKeyEvent*>(event);
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// QMouseEvent
|
||||
// ============================================================
|
||||
extern "C" VQT6_API void* vqt6_qmouseevent_create(int type, void* local_pos, int button, int buttons, int modifiers) {
|
||||
QPointF* lp = static_cast<QPointF*>(local_pos);
|
||||
return new QMouseEvent(
|
||||
static_cast<QEvent::Type>(type),
|
||||
lp != nullptr ? *lp : QPointF(0, 0),
|
||||
Qt::NoButton,
|
||||
static_cast<Qt::MouseButton>(button),
|
||||
static_cast<Qt::KeyboardModifiers>(modifiers)
|
||||
);
|
||||
}
|
||||
|
||||
extern "C" VQT6_API int vqt6_qmouseevent_button(void* event) {
|
||||
if (event == nullptr) return 0;
|
||||
return static_cast<int>(static_cast<QMouseEvent*>(event)->button());
|
||||
}
|
||||
|
||||
extern "C" VQT6_API int vqt6_qmouseevent_buttons(void* event) {
|
||||
if (event == nullptr) return 0;
|
||||
return static_cast<int>(static_cast<QMouseEvent*>(event)->buttons());
|
||||
}
|
||||
|
||||
extern "C" VQT6_API int vqt6_qmouseevent_x(void* event) {
|
||||
if (event == nullptr) return 0;
|
||||
return static_cast<int>(static_cast<QMouseEvent*>(event)->position().x());
|
||||
}
|
||||
|
||||
extern "C" VQT6_API int vqt6_qmouseevent_y(void* event) {
|
||||
if (event == nullptr) return 0;
|
||||
return static_cast<int>(static_cast<QMouseEvent*>(event)->position().y());
|
||||
}
|
||||
|
||||
extern "C" VQT6_API int vqt6_qmouseevent_global_x(void* event) {
|
||||
if (event == nullptr) return 0;
|
||||
return static_cast<int>(static_cast<QMouseEvent*>(event)->globalPosition().x());
|
||||
}
|
||||
|
||||
extern "C" VQT6_API int vqt6_qmouseevent_global_y(void* event) {
|
||||
if (event == nullptr) return 0;
|
||||
return static_cast<int>(static_cast<QMouseEvent*>(event)->globalPosition().y());
|
||||
}
|
||||
|
||||
extern "C" VQT6_API int vqt6_qmouseevent_modifiers(void* event) {
|
||||
if (event == nullptr) return 0;
|
||||
return static_cast<int>(static_cast<QMouseEvent*>(event)->modifiers());
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qmouseevent_free(void* event) {
|
||||
delete static_cast<QMouseEvent*>(event);
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// QResizeEvent / QPaintEvent / QCloseEvent
|
||||
// ============================================================
|
||||
extern "C" VQT6_API void* vqt6_qresizeevent_create(int width, int height, int old_width, int old_height) {
|
||||
return new QResizeEvent(QSize(width, height), QSize(old_width, old_height));
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qresizeevent_size(void* event, int* w, int* h) {
|
||||
if (event == nullptr) return;
|
||||
QSize s = static_cast<QResizeEvent*>(event)->size();
|
||||
if (w != nullptr) *w = s.width();
|
||||
if (h != nullptr) *h = s.height();
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qresizeevent_old_size(void* event, int* w, int* h) {
|
||||
if (event == nullptr) return;
|
||||
QSize s = static_cast<QResizeEvent*>(event)->oldSize();
|
||||
if (w != nullptr) *w = s.width();
|
||||
if (h != nullptr) *h = s.height();
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qresizeevent_free(void* event) {
|
||||
delete static_cast<QResizeEvent*>(event);
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void* vqt6_qpaintevent_create(int rect_x, int rect_y, int rect_w, int rect_h) {
|
||||
return new QPaintEvent(QRect(rect_x, rect_y, rect_w, rect_h));
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qpaintevent_rect(void* event, int* x, int* y, int* w, int* h) {
|
||||
if (event == nullptr) return;
|
||||
QRect r = static_cast<QPaintEvent*>(event)->rect();
|
||||
if (x != nullptr) *x = r.x();
|
||||
if (y != nullptr) *y = r.y();
|
||||
if (w != nullptr) *w = r.width();
|
||||
if (h != nullptr) *h = r.height();
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qpaintevent_free(void* event) {
|
||||
delete static_cast<QPaintEvent*>(event);
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void* vqt6_qcloseevent_create(void) {
|
||||
return new QCloseEvent();
|
||||
}
|
||||
|
||||
extern "C" VQT6_API int vqt6_qcloseevent_is_accepted(void* event) {
|
||||
if (event == nullptr) return 0;
|
||||
return static_cast<QCloseEvent*>(event)->isAccepted() ? 1 : 0;
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qcloseevent_accept(void* event) {
|
||||
if (event == nullptr) return;
|
||||
static_cast<QCloseEvent*>(event)->accept();
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qcloseevent_ignore(void* event) {
|
||||
if (event == nullptr) return;
|
||||
static_cast<QCloseEvent*>(event)->ignore();
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qcloseevent_free(void* event) {
|
||||
delete static_cast<QCloseEvent*>(event);
|
||||
}
|
||||
231
includes/vqt6 copy/_bridge_gui.h
Normal file
231
includes/vqt6 copy/_bridge_gui.h
Normal file
@@ -0,0 +1,231 @@
|
||||
// ============================================================
|
||||
// vqt6/_bridge_gui.h — QtGui C 桥接函数声明
|
||||
// ============================================================
|
||||
|
||||
#ifndef VQT6_BRIDGE_GUI_H
|
||||
#define VQT6_BRIDGE_GUI_H
|
||||
|
||||
#include "_bridge.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// ============================================================
|
||||
// QColor
|
||||
// ============================================================
|
||||
VQT6_API void* vqt6_qcolor_create_rgb(int r, int g, int b);
|
||||
VQT6_API void* vqt6_qcolor_create_rgba(int r, int g, int b, int a);
|
||||
VQT6_API void* vqt6_qcolor_create_name(void* name);
|
||||
VQT6_API void* vqt6_qcolor_create_hex(void* hex_str);
|
||||
VQT6_API int vqt6_qcolor_red(void* c);
|
||||
VQT6_API int vqt6_qcolor_green(void* c);
|
||||
VQT6_API int vqt6_qcolor_blue(void* c);
|
||||
VQT6_API int vqt6_qcolor_alpha(void* c);
|
||||
VQT6_API void vqt6_qcolor_set_red(void* c, int r);
|
||||
VQT6_API void vqt6_qcolor_set_green(void* c, int g);
|
||||
VQT6_API void vqt6_qcolor_set_blue(void* c, int b);
|
||||
VQT6_API void vqt6_qcolor_set_alpha(void* c, int a);
|
||||
VQT6_API void vqt6_qcolor_set_rgb(void* c, int r, int g, int b);
|
||||
VQT6_API void vqt6_qcolor_set_rgba(void* c, int r, int g, int b, int a);
|
||||
VQT6_API void* vqt6_qcolor_name(void* c);
|
||||
VQT6_API int vqt6_qcolor_is_valid(void* c);
|
||||
VQT6_API void vqt6_qcolor_free(void* c);
|
||||
|
||||
// ============================================================
|
||||
// QFont
|
||||
// ============================================================
|
||||
VQT6_API void* vqt6_qfont_create(void);
|
||||
VQT6_API void* vqt6_qfont_create_with_family(void* family);
|
||||
VQT6_API void* vqt6_qfont_create_with_family_size(void* family, int point_size);
|
||||
VQT6_API void vqt6_qfont_set_family(void* font, void* family);
|
||||
VQT6_API void* vqt6_qfont_family(void* font);
|
||||
VQT6_API void vqt6_qfont_set_point_size(void* font, int point_size);
|
||||
VQT6_API int vqt6_qfont_point_size(void* font);
|
||||
VQT6_API void vqt6_qfont_set_pixel_size(void* font, int pixel_size);
|
||||
VQT6_API int vqt6_qfont_pixel_size(void* font);
|
||||
VQT6_API void vqt6_qfont_set_bold(void* font, int bold);
|
||||
VQT6_API int vqt6_qfont_bold(void* font);
|
||||
VQT6_API void vqt6_qfont_set_italic(void* font, int italic);
|
||||
VQT6_API int vqt6_qfont_italic(void* font);
|
||||
VQT6_API void vqt6_qfont_set_underline(void* font, int underline);
|
||||
VQT6_API int vqt6_qfont_underline(void* font);
|
||||
VQT6_API void vqt6_qfont_set_strike_out(void* font, int strike_out);
|
||||
VQT6_API int vqt6_qfont_strike_out(void* font);
|
||||
VQT6_API void vqt6_qfont_set_weight(void* font, int weight);
|
||||
VQT6_API int vqt6_qfont_weight(void* font);
|
||||
VQT6_API void vqt6_qfont_free(void* font);
|
||||
|
||||
// ============================================================
|
||||
// QFontMetrics
|
||||
// ============================================================
|
||||
VQT6_API void* vqt6_qfontmetrics_create(void* font);
|
||||
VQT6_API int vqt6_qfontmetrics_width(void* fm, void* text);
|
||||
VQT6_API int vqt6_qfontmetrics_height(void* fm);
|
||||
VQT6_API int vqt6_qfontmetrics_ascent(void* fm);
|
||||
VQT6_API int vqt6_qfontmetrics_descent(void* fm);
|
||||
VQT6_API void vqt6_qfontmetrics_free(void* fm);
|
||||
|
||||
// ============================================================
|
||||
// QPixmap
|
||||
// ============================================================
|
||||
VQT6_API void* vqt6_qpixmap_create(void);
|
||||
VQT6_API void* vqt6_qpixmap_create_with_size(int w, int h);
|
||||
VQT6_API int vqt6_qpixmap_load(void* pm, void* file_name);
|
||||
VQT6_API int vqt6_qpixmap_load_from_data(void* pm, const void* data, size_t size);
|
||||
VQT6_API int vqt6_qpixmap_save(void* pm, void* file_name);
|
||||
VQT6_API int vqt6_qpixmap_width(void* pm);
|
||||
VQT6_API int vqt6_qpixmap_height(void* pm);
|
||||
VQT6_API int vqt6_qpixmap_is_null(void* pm);
|
||||
VQT6_API void* vqt6_qpixmap_scaled(void* pm, int w, int h);
|
||||
VQT6_API void vqt6_qpixmap_fill(void* pm, void* color);
|
||||
VQT6_API void vqt6_qpixmap_free(void* pm);
|
||||
|
||||
// ============================================================
|
||||
// QImage
|
||||
// ============================================================
|
||||
VQT6_API void* vqt6_qimage_create(void);
|
||||
VQT6_API void* vqt6_qimage_create_with_size(int w, int h, int format);
|
||||
VQT6_API int vqt6_qimage_load(void* img, void* file_name);
|
||||
VQT6_API int vqt6_qimage_save(void* img, void* file_name);
|
||||
VQT6_API int vqt6_qimage_width(void* img);
|
||||
VQT6_API int vqt6_qimage_height(void* img);
|
||||
VQT6_API int vqt6_qimage_format(void* img);
|
||||
VQT6_API int vqt6_qimage_is_null(void* img);
|
||||
VQT6_API void vqt6_qimage_fill(void* img, void* color);
|
||||
VQT6_API void* vqt6_qimage_scaled(void* img, int w, int h);
|
||||
VQT6_API void vqt6_qimage_free(void* img);
|
||||
|
||||
// ============================================================
|
||||
// QPainter
|
||||
// ============================================================
|
||||
VQT6_API void* vqt6_qpainter_create(void);
|
||||
VQT6_API int vqt6_qpainter_begin(void* p, void* device);
|
||||
VQT6_API int vqt6_qpainter_end(void* p);
|
||||
VQT6_API int vqt6_qpainter_is_active(void* p);
|
||||
VQT6_API void vqt6_qpainter_set_pen(void* p, void* pen);
|
||||
VQT6_API void vqt6_qpainter_set_brush(void* p, void* brush);
|
||||
VQT6_API void vqt6_qpainter_set_font(void* p, void* font);
|
||||
VQT6_API void* vqt6_qpainter_pen(void* p);
|
||||
VQT6_API void* vqt6_qpainter_brush(void* p);
|
||||
VQT6_API void* vqt6_qpainter_font(void* p);
|
||||
VQT6_API void vqt6_qpainter_set_opacity(void* p, double opacity);
|
||||
VQT6_API double vqt6_qpainter_opacity(void* p);
|
||||
VQT6_API void vqt6_qpainter_draw_line(void* p, int x1, int y1, int x2, int y2);
|
||||
VQT6_API void vqt6_qpainter_draw_rect(void* p, int x, int y, int w, int h);
|
||||
VQT6_API void vqt6_qpainter_fill_rect(void* p, int x, int y, int w, int h, void* color);
|
||||
VQT6_API void vqt6_qpainter_draw_ellipse(void* p, int x, int y, int w, int h);
|
||||
VQT6_API void vqt6_qpainter_draw_arc(void* p, int x, int y, int w, int h, int start_angle, int span_angle);
|
||||
VQT6_API void vqt6_qpainter_draw_chord(void* p, int x, int y, int w, int h, int start_angle, int span_angle);
|
||||
VQT6_API void vqt6_qpainter_draw_pie(void* p, int x, int y, int w, int h, int start_angle, int span_angle);
|
||||
VQT6_API void vqt6_qpainter_draw_polygon(void* p, int* points, int point_count);
|
||||
VQT6_API void vqt6_qpainter_draw_polyline(void* p, int* points, int point_count);
|
||||
VQT6_API void vqt6_qpainter_draw_point(void* p, int x, int y);
|
||||
VQT6_API void vqt6_qpainter_draw_points(void* p, int* points, int point_count);
|
||||
VQT6_API void vqt6_qpainter_draw_text(void* p, int x, int y, void* text);
|
||||
VQT6_API void vqt6_qpainter_draw_text_in_rect(void* p, int x, int y, int w, int h, int flags, void* text);
|
||||
VQT6_API void vqt6_qpainter_draw_pixmap(void* p, int x, int y, void* pixmap);
|
||||
VQT6_API void vqt6_qpainter_draw_image(void* p, int x, int y, void* image);
|
||||
VQT6_API void vqt6_qpainter_draw_tiled_pixmap(void* p, int x, int y, int w, int h, void* pixmap);
|
||||
VQT6_API void vqt6_qpainter_translate(void* p, int dx, int dy);
|
||||
VQT6_API void vqt6_qpainter_rotate(void* p, double angle);
|
||||
VQT6_API void vqt6_qpainter_scale(void* p, double sx, double sy);
|
||||
VQT6_API void vqt6_qpainter_reset_transform(void* p);
|
||||
VQT6_API void vqt6_qpainter_save(void* p);
|
||||
VQT6_API void vqt6_qpainter_restore(void* p);
|
||||
VQT6_API void vqt6_qpainter_free(void* p);
|
||||
|
||||
// ============================================================
|
||||
// QPen
|
||||
// ============================================================
|
||||
VQT6_API void* vqt6_qpen_create(void);
|
||||
VQT6_API void* vqt6_qpen_create_with_color(void* color);
|
||||
VQT6_API void* vqt6_qpen_create_with_color_width(void* color, int width);
|
||||
VQT6_API void vqt6_qpen_set_color(void* pen, void* color);
|
||||
VQT6_API void* vqt6_qpen_color(void* pen);
|
||||
VQT6_API void vqt6_qpen_set_width(void* pen, int width);
|
||||
VQT6_API int vqt6_qpen_width(void* pen);
|
||||
VQT6_API void vqt6_qpen_set_style(void* pen, int style);
|
||||
VQT6_API int vqt6_qpen_style(void* pen);
|
||||
VQT6_API void vqt6_qpen_free(void* pen);
|
||||
|
||||
// ============================================================
|
||||
// QBrush
|
||||
// ============================================================
|
||||
VQT6_API void* vqt6_qbrush_create(void);
|
||||
VQT6_API void* vqt6_qbrush_create_with_color(void* color);
|
||||
VQT6_API void* vqt6_qbrush_create_with_style(int style);
|
||||
VQT6_API void vqt6_qbrush_set_color(void* brush, void* color);
|
||||
VQT6_API void* vqt6_qbrush_color(void* brush);
|
||||
VQT6_API void vqt6_qbrush_set_style(void* brush, int style);
|
||||
VQT6_API int vqt6_qbrush_style(void* brush);
|
||||
VQT6_API void vqt6_qbrush_free(void* brush);
|
||||
|
||||
// ============================================================
|
||||
// QIcon
|
||||
// ============================================================
|
||||
VQT6_API void* vqt6_qicon_create(void);
|
||||
VQT6_API void* vqt6_qicon_create_with_file(void* file_name);
|
||||
VQT6_API void vqt6_qicon_add_file(void* icon, void* file_name);
|
||||
VQT6_API void vqt6_qicon_add_pixmap(void* icon, void* pixmap);
|
||||
VQT6_API int vqt6_qicon_is_null(void* icon);
|
||||
VQT6_API void* vqt6_qicon_pixmap(void* icon, int w, int h);
|
||||
VQT6_API void vqt6_qicon_free(void* icon);
|
||||
|
||||
// ============================================================
|
||||
// QCursor
|
||||
// ============================================================
|
||||
VQT6_API void* vqt6_qcursor_create(void);
|
||||
VQT6_API void* vqt6_qcursor_create_with_shape(int shape);
|
||||
VQT6_API void vqt6_qcursor_pos(int* x, int* y);
|
||||
VQT6_API void vqt6_qcursor_set_pos(int x, int y);
|
||||
VQT6_API void vqt6_qcursor_set_shape(void* cursor, int shape);
|
||||
VQT6_API int vqt6_qcursor_shape(void* cursor);
|
||||
VQT6_API void vqt6_qcursor_free(void* cursor);
|
||||
|
||||
// ============================================================
|
||||
// QKeyEvent
|
||||
// ============================================================
|
||||
VQT6_API void* vqt6_qkeyevent_create(int type, int key, int modifiers, void* text);
|
||||
VQT6_API int vqt6_qkeyevent_key(void* event);
|
||||
VQT6_API void* vqt6_qkeyevent_text(void* event);
|
||||
VQT6_API int vqt6_qkeyevent_modifiers(void* event);
|
||||
VQT6_API int vqt6_qkeyevent_is_auto_repeat(void* event);
|
||||
VQT6_API void vqt6_qkeyevent_free(void* event);
|
||||
|
||||
// ============================================================
|
||||
// QMouseEvent
|
||||
// ============================================================
|
||||
VQT6_API void* vqt6_qmouseevent_create(int type, void* local_pos, int button, int buttons, int modifiers);
|
||||
VQT6_API int vqt6_qmouseevent_button(void* event);
|
||||
VQT6_API int vqt6_qmouseevent_buttons(void* event);
|
||||
VQT6_API int vqt6_qmouseevent_x(void* event);
|
||||
VQT6_API int vqt6_qmouseevent_y(void* event);
|
||||
VQT6_API int vqt6_qmouseevent_global_x(void* event);
|
||||
VQT6_API int vqt6_qmouseevent_global_y(void* event);
|
||||
VQT6_API int vqt6_qmouseevent_modifiers(void* event);
|
||||
VQT6_API void vqt6_qmouseevent_free(void* event);
|
||||
|
||||
// ============================================================
|
||||
// QResizeEvent / QPaintEvent / QCloseEvent
|
||||
// ============================================================
|
||||
VQT6_API void* vqt6_qresizeevent_create(int width, int height, int old_width, int old_height);
|
||||
VQT6_API void vqt6_qresizeevent_size(void* event, int* w, int* h);
|
||||
VQT6_API void vqt6_qresizeevent_old_size(void* event, int* w, int* h);
|
||||
VQT6_API void vqt6_qresizeevent_free(void* event);
|
||||
|
||||
VQT6_API void* vqt6_qpaintevent_create(int rect_x, int rect_y, int rect_w, int rect_h);
|
||||
VQT6_API void vqt6_qpaintevent_rect(void* event, int* x, int* y, int* w, int* h);
|
||||
VQT6_API void vqt6_qpaintevent_free(void* event);
|
||||
|
||||
VQT6_API void* vqt6_qcloseevent_create(void);
|
||||
VQT6_API int vqt6_qcloseevent_is_accepted(void* event);
|
||||
VQT6_API void vqt6_qcloseevent_accept(void* event);
|
||||
VQT6_API void vqt6_qcloseevent_ignore(void* event);
|
||||
VQT6_API void vqt6_qcloseevent_free(void* event);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // VQT6_BRIDGE_GUI_H
|
||||
519
includes/vqt6 copy/_bridge_network.cpp
Normal file
519
includes/vqt6 copy/_bridge_network.cpp
Normal file
@@ -0,0 +1,519 @@
|
||||
// ============================================================
|
||||
// vqt6/_bridge_network.cpp — QtNetwork C 桥接层实现
|
||||
// ============================================================
|
||||
|
||||
#include "_bridge.h"
|
||||
#include "_bridge_network.h"
|
||||
#include <QHostAddress>
|
||||
#include <QAbstractSocket>
|
||||
#include <QTcpSocket>
|
||||
#include <QUdpSocket>
|
||||
#include <QNetworkRequest>
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QNetworkReply>
|
||||
#include <QHttpHeaders>
|
||||
#include <QHttp2Configuration>
|
||||
#include <QNetworkCookieJar>
|
||||
|
||||
// ============================================================
|
||||
// QHostAddress
|
||||
// ============================================================
|
||||
extern "C" VQT6_API void* vqt6_qhostaddress_create(void) {
|
||||
return new QHostAddress();
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void* vqt6_qhostaddress_create_with_ipv4(uint32_t ipv4) {
|
||||
return new QHostAddress(static_cast<quint32>(ipv4));
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void* vqt6_qhostaddress_create_with_string(void* address) {
|
||||
if (address == nullptr) return new QHostAddress();
|
||||
return new QHostAddress(*static_cast<QString*>(address));
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void* vqt6_qhostaddress_create_with_local_host(void) {
|
||||
return new QHostAddress(QHostAddress::LocalHost);
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void* vqt6_qhostaddress_create_with_local_ipv4(void) {
|
||||
return new QHostAddress(QHostAddress::LocalHostIPv4);
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void* vqt6_qhostaddress_create_with_broadcast(void) {
|
||||
return new QHostAddress(QHostAddress::Broadcast);
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void* vqt6_qhostaddress_create_with_any_ipv4(void) {
|
||||
return new QHostAddress(QHostAddress::AnyIPv4);
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void* vqt6_qhostaddress_to_string(void* addr) {
|
||||
if (addr == nullptr) return nullptr;
|
||||
return new QString(static_cast<QHostAddress*>(addr)->toString());
|
||||
}
|
||||
|
||||
extern "C" VQT6_API uint32_t vqt6_qhostaddress_to_ipv4(void* addr) {
|
||||
if (addr == nullptr) return 0;
|
||||
return static_cast<uint32_t>(static_cast<QHostAddress*>(addr)->toIPv4Address());
|
||||
}
|
||||
|
||||
extern "C" VQT6_API int vqt6_qhostaddress_is_null(void* addr) {
|
||||
if (addr == nullptr) return 0;
|
||||
return static_cast<QHostAddress*>(addr)->isNull() ? 1 : 0;
|
||||
}
|
||||
|
||||
extern "C" VQT6_API int vqt6_qhostaddress_is_loopback(void* addr) {
|
||||
if (addr == nullptr) return 0;
|
||||
return static_cast<QHostAddress*>(addr)->isLoopback() ? 1 : 0;
|
||||
}
|
||||
|
||||
extern "C" VQT6_API int vqt6_qhostaddress_is_broadcast(void* addr) {
|
||||
if (addr == nullptr) return 0;
|
||||
return static_cast<QHostAddress*>(addr)->isBroadcast() ? 1 : 0;
|
||||
}
|
||||
|
||||
extern "C" VQT6_API int vqt6_qhostaddress_protocol(void* addr) {
|
||||
if (addr == nullptr) return 0;
|
||||
return static_cast<int>(static_cast<QHostAddress*>(addr)->protocol());
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qhostaddress_free(void* addr) {
|
||||
delete static_cast<QHostAddress*>(addr);
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// QAbstractSocket
|
||||
// ============================================================
|
||||
extern "C" VQT6_API int vqt6_qabstractsocket_state(void* socket) {
|
||||
if (socket == nullptr) return 0;
|
||||
return static_cast<int>(static_cast<QAbstractSocket*>(socket)->state());
|
||||
}
|
||||
|
||||
extern "C" VQT6_API int vqt6_qabstractsocket_error(void* socket) {
|
||||
if (socket == nullptr) return 0;
|
||||
return static_cast<int>(static_cast<QAbstractSocket*>(socket)->error());
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void* vqt6_qabstractsocket_error_string(void* socket) {
|
||||
if (socket == nullptr) return nullptr;
|
||||
return new QString(static_cast<QAbstractSocket*>(socket)->errorString());
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qabstractsocket_connect_to_host(void* socket, void* host_name, uint16_t port) {
|
||||
if (socket == nullptr || host_name == nullptr) return;
|
||||
static_cast<QAbstractSocket*>(socket)->connectToHost(*static_cast<QString*>(host_name), port);
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qabstractsocket_connect_to_host_with_addr(void* socket, void* address, uint16_t port) {
|
||||
if (socket == nullptr || address == nullptr) return;
|
||||
static_cast<QAbstractSocket*>(socket)->connectToHost(*static_cast<QHostAddress*>(address), port);
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qabstractsocket_disconnect_from_host(void* socket) {
|
||||
if (socket == nullptr) return;
|
||||
static_cast<QAbstractSocket*>(socket)->disconnectFromHost();
|
||||
}
|
||||
|
||||
extern "C" VQT6_API int vqt6_qabstractsocket_wait_for_connected(void* socket, int timeout_ms) {
|
||||
if (socket == nullptr) return 0;
|
||||
return static_cast<QAbstractSocket*>(socket)->waitForConnected(timeout_ms) ? 1 : 0;
|
||||
}
|
||||
|
||||
extern "C" VQT6_API int vqt6_qabstractsocket_wait_for_ready_read(void* socket, int timeout_ms) {
|
||||
if (socket == nullptr) return 0;
|
||||
return static_cast<QAbstractSocket*>(socket)->waitForReadyRead(timeout_ms) ? 1 : 0;
|
||||
}
|
||||
|
||||
extern "C" VQT6_API int vqt6_qabstractsocket_wait_for_bytes_written(void* socket, int timeout_ms) {
|
||||
if (socket == nullptr) return 0;
|
||||
return static_cast<QAbstractSocket*>(socket)->waitForBytesWritten(timeout_ms) ? 1 : 0;
|
||||
}
|
||||
|
||||
extern "C" VQT6_API int vqt6_qabstractsocket_wait_for_disconnected(void* socket, int timeout_ms) {
|
||||
if (socket == nullptr) return 0;
|
||||
return static_cast<QAbstractSocket*>(socket)->waitForDisconnected(timeout_ms) ? 1 : 0;
|
||||
}
|
||||
|
||||
extern "C" VQT6_API int vqt6_qabstractsocket_is_valid(void* socket) {
|
||||
if (socket == nullptr) return 0;
|
||||
return static_cast<QAbstractSocket*>(socket)->isValid() ? 1 : 0;
|
||||
}
|
||||
|
||||
extern "C" VQT6_API int vqt6_qabstractsocket_is_open(void* socket) {
|
||||
if (socket == nullptr) return 0;
|
||||
return static_cast<QAbstractSocket*>(socket)->isOpen() ? 1 : 0;
|
||||
}
|
||||
|
||||
extern "C" VQT6_API int vqt6_qabstractsocket_flush(void* socket) {
|
||||
if (socket == nullptr) return 0;
|
||||
return static_cast<QAbstractSocket*>(socket)->flush() ? 1 : 0;
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qabstractsocket_close(void* socket) {
|
||||
if (socket == nullptr) return;
|
||||
static_cast<QAbstractSocket*>(socket)->close();
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qabstractsocket_abort(void* socket) {
|
||||
if (socket == nullptr) return;
|
||||
static_cast<QAbstractSocket*>(socket)->abort();
|
||||
}
|
||||
|
||||
extern "C" VQT6_API size_t vqt6_qabstractsocket_read(void* socket, void* buf, size_t max_size) {
|
||||
if (socket == nullptr || buf == nullptr) return 0;
|
||||
return static_cast<size_t>(static_cast<QAbstractSocket*>(socket)->read(static_cast<char*>(buf), static_cast<qint64>(max_size)));
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void* vqt6_qabstractsocket_read_all(void* socket, size_t* out_size) {
|
||||
if (socket == nullptr) return nullptr;
|
||||
QByteArray ba = static_cast<QAbstractSocket*>(socket)->readAll();
|
||||
if (out_size != nullptr) *out_size = static_cast<size_t>(ba.size());
|
||||
return ba.data();
|
||||
}
|
||||
|
||||
extern "C" VQT6_API size_t vqt6_qabstractsocket_write(void* socket, const void* data, size_t size) {
|
||||
if (socket == nullptr || data == nullptr) return 0;
|
||||
return static_cast<size_t>(static_cast<QAbstractSocket*>(socket)->write(static_cast<const char*>(data), static_cast<qint64>(size)));
|
||||
}
|
||||
|
||||
extern "C" VQT6_API size_t vqt6_qabstractsocket_bytes_available(void* socket) {
|
||||
if (socket == nullptr) return 0;
|
||||
return static_cast<size_t>(static_cast<QAbstractSocket*>(socket)->bytesAvailable());
|
||||
}
|
||||
|
||||
extern "C" VQT6_API size_t vqt6_qabstractsocket_bytes_to_write(void* socket) {
|
||||
if (socket == nullptr) return 0;
|
||||
return static_cast<size_t>(static_cast<QAbstractSocket*>(socket)->bytesToWrite());
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void* vqt6_qabstractsocket_peer_address(void* socket) {
|
||||
if (socket == nullptr) return nullptr;
|
||||
return new QHostAddress(static_cast<QAbstractSocket*>(socket)->peerAddress());
|
||||
}
|
||||
|
||||
extern "C" VQT6_API uint16_t vqt6_qabstractsocket_peer_port(void* socket) {
|
||||
if (socket == nullptr) return 0;
|
||||
return static_cast<uint16_t>(static_cast<QAbstractSocket*>(socket)->peerPort());
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void* vqt6_qabstractsocket_local_address(void* socket) {
|
||||
if (socket == nullptr) return nullptr;
|
||||
return new QHostAddress(static_cast<QAbstractSocket*>(socket)->localAddress());
|
||||
}
|
||||
|
||||
extern "C" VQT6_API uint16_t vqt6_qabstractsocket_local_port(void* socket) {
|
||||
if (socket == nullptr) return 0;
|
||||
return static_cast<uint16_t>(static_cast<QAbstractSocket*>(socket)->localPort());
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// QTcpSocket
|
||||
// ============================================================
|
||||
extern "C" VQT6_API void* vqt6_qtcpsocket_create(void) {
|
||||
return new QTcpSocket();
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void* vqt6_qtcpsocket_create_with_parent(void* parent) {
|
||||
if (parent == nullptr) return nullptr;
|
||||
return new QTcpSocket(static_cast<QObject*>(parent));
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qtcpsocket_connect_to_host(void* socket, void* host_name, uint16_t port, int mode) {
|
||||
if (socket == nullptr || host_name == nullptr) return;
|
||||
static_cast<QTcpSocket*>(socket)->connectToHost(*static_cast<QString*>(host_name), port,
|
||||
static_cast<QIODevice::OpenMode>(mode));
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qtcpsocket_connect_to_host_with_addr(void* socket, void* address, uint16_t port, int mode) {
|
||||
if (socket == nullptr || address == nullptr) return;
|
||||
static_cast<QTcpSocket*>(socket)->connectToHost(*static_cast<QHostAddress*>(address), port,
|
||||
static_cast<QIODevice::OpenMode>(mode));
|
||||
}
|
||||
|
||||
extern "C" VQT6_API int vqt6_qtcpsocket_set_socket_descriptor(void* socket, intptr_t socket_descriptor) {
|
||||
if (socket == nullptr) return 0;
|
||||
return static_cast<QTcpSocket*>(socket)->setSocketDescriptor(static_cast<qintptr>(socket_descriptor)) ? 1 : 0;
|
||||
}
|
||||
|
||||
extern "C" VQT6_API intptr_t vqt6_qtcpsocket_socket_descriptor(void* socket) {
|
||||
if (socket == nullptr) return -1;
|
||||
return static_cast<intptr_t>(static_cast<QTcpSocket*>(socket)->socketDescriptor());
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qtcpsocket_set_proxy(void* socket, int proxy_type) {
|
||||
Q_UNUSED(socket);
|
||||
Q_UNUSED(proxy_type);
|
||||
// QNetworkProxy 配置在更高层
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qtcpsocket_abort(void* socket) {
|
||||
if (socket == nullptr) return;
|
||||
static_cast<QTcpSocket*>(socket)->abort();
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// QUdpSocket
|
||||
// ============================================================
|
||||
extern "C" VQT6_API void* vqt6_qudpsocket_create(void) {
|
||||
return new QUdpSocket();
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void* vqt6_qudpsocket_create_with_parent(void* parent) {
|
||||
if (parent == nullptr) return nullptr;
|
||||
return new QUdpSocket(static_cast<QObject*>(parent));
|
||||
}
|
||||
|
||||
extern "C" VQT6_API int vqt6_qudpsocket_bind(void* socket, uint16_t port) {
|
||||
if (socket == nullptr) return 0;
|
||||
return static_cast<QUdpSocket*>(socket)->bind(port) ? 1 : 0;
|
||||
}
|
||||
|
||||
extern "C" VQT6_API int vqt6_qudpsocket_bind_with_addr(void* socket, void* address, uint16_t port) {
|
||||
if (socket == nullptr || address == nullptr) return 0;
|
||||
return static_cast<QUdpSocket*>(socket)->bind(*static_cast<QHostAddress*>(address), port) ? 1 : 0;
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qudpsocket_close(void* socket) {
|
||||
if (socket == nullptr) return;
|
||||
static_cast<QUdpSocket*>(socket)->close();
|
||||
}
|
||||
|
||||
extern "C" VQT6_API size_t vqt6_qudpsocket_write_datagram(void* socket, const void* data, size_t size, void* host, uint16_t port) {
|
||||
if (socket == nullptr || data == nullptr || host == nullptr) return 0;
|
||||
return static_cast<size_t>(static_cast<QUdpSocket*>(socket)->writeDatagram(
|
||||
static_cast<const char*>(data), static_cast<qint64>(size),
|
||||
*static_cast<QHostAddress*>(host), port));
|
||||
}
|
||||
|
||||
extern "C" VQT6_API size_t vqt6_qudpsocket_read_datagram(void* socket, void* data, size_t max_size, void* host, uint16_t* port) {
|
||||
if (socket == nullptr || data == nullptr) return 0;
|
||||
QHostAddress sender;
|
||||
quint16 sender_port = 0;
|
||||
qint64 n = static_cast<QUdpSocket*>(socket)->readDatagram(
|
||||
static_cast<char*>(data), static_cast<qint64>(max_size), &sender, &sender_port);
|
||||
if (host != nullptr) {
|
||||
QHostAddress* dst = static_cast<QHostAddress*>(host);
|
||||
*dst = sender;
|
||||
}
|
||||
if (port != nullptr) {
|
||||
*port = sender_port;
|
||||
}
|
||||
return static_cast<size_t>(n);
|
||||
}
|
||||
|
||||
extern "C" VQT6_API int vqt6_qudpsocket_has_pending_datagrams(void* socket) {
|
||||
if (socket == nullptr) return 0;
|
||||
return static_cast<QUdpSocket*>(socket)->hasPendingDatagrams() ? 1 : 0;
|
||||
}
|
||||
|
||||
extern "C" VQT6_API size_t vqt6_qudpsocket_pending_datagram_size(void* socket) {
|
||||
if (socket == nullptr) return 0;
|
||||
return static_cast<size_t>(static_cast<QUdpSocket*>(socket)->pendingDatagramSize());
|
||||
}
|
||||
|
||||
extern "C" VQT6_API int vqt6_qudpsocket_join_multicast_group(void* socket, void* group_address) {
|
||||
if (socket == nullptr || group_address == nullptr) return 0;
|
||||
return static_cast<QUdpSocket*>(socket)->joinMulticastGroup(*static_cast<QHostAddress*>(group_address)) ? 1 : 0;
|
||||
}
|
||||
|
||||
extern "C" VQT6_API int vqt6_qudpsocket_leave_multicast_group(void* socket, void* group_address) {
|
||||
if (socket == nullptr || group_address == nullptr) return 0;
|
||||
return static_cast<QUdpSocket*>(socket)->leaveMulticastGroup(*static_cast<QHostAddress*>(group_address)) ? 1 : 0;
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// QNetworkRequest
|
||||
// ============================================================
|
||||
extern "C" VQT6_API void* vqt6_qnetworkrequest_create(void) {
|
||||
return new QNetworkRequest();
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void* vqt6_qnetworkrequest_create_with_url(void* url) {
|
||||
if (url == nullptr) return new QNetworkRequest();
|
||||
return new QNetworkRequest(QUrl(*static_cast<QString*>(url)));
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qnetworkrequest_set_url(void* req, void* url) {
|
||||
if (req == nullptr || url == nullptr) return;
|
||||
static_cast<QNetworkRequest*>(req)->setUrl(QUrl(*static_cast<QString*>(url)));
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void* vqt6_qnetworkrequest_url(void* req) {
|
||||
if (req == nullptr) return nullptr;
|
||||
return new QString(static_cast<QNetworkRequest*>(req)->url().toString());
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qnetworkrequest_set_header(void* req, int header_type, void* value) {
|
||||
if (req == nullptr || value == nullptr) return;
|
||||
static_cast<QNetworkRequest*>(req)->setHeader(static_cast<QNetworkRequest::KnownHeaders>(header_type),
|
||||
*static_cast<QVariant*>(value));
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void* vqt6_qnetworkrequest_header(void* req, int header_type) {
|
||||
if (req == nullptr) return nullptr;
|
||||
return new QVariant(static_cast<QNetworkRequest*>(req)->header(static_cast<QNetworkRequest::KnownHeaders>(header_type)));
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qnetworkrequest_set_raw_header(void* req, const char* header_name, const void* value, size_t value_size) {
|
||||
if (req == nullptr || header_name == nullptr) return;
|
||||
static_cast<QNetworkRequest*>(req)->setRawHeader(QByteArray(header_name),
|
||||
QByteArray(static_cast<const char*>(value), static_cast<int>(value_size)));
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void* vqt6_qnetworkrequest_raw_header(void* req, const char* header_name, size_t* out_size) {
|
||||
if (req == nullptr || header_name == nullptr) return nullptr;
|
||||
QByteArray ba = static_cast<QNetworkRequest*>(req)->rawHeader(QByteArray(header_name));
|
||||
if (out_size != nullptr) *out_size = static_cast<size_t>(ba.size());
|
||||
return ba.data();
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qnetworkrequest_set_attribute(void* req, int attr_type, void* value) {
|
||||
if (req == nullptr || value == nullptr) return;
|
||||
static_cast<QNetworkRequest*>(req)->setAttribute(static_cast<QNetworkRequest::Attribute>(attr_type),
|
||||
*static_cast<QVariant*>(value));
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void* vqt6_qnetworkrequest_attribute(void* req, int attr_type) {
|
||||
if (req == nullptr) return nullptr;
|
||||
return new QVariant(static_cast<QNetworkRequest*>(req)->attribute(static_cast<QNetworkRequest::Attribute>(attr_type)));
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qnetworkrequest_free(void* req) {
|
||||
delete static_cast<QNetworkRequest*>(req);
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// QNetworkAccessManager
|
||||
// ============================================================
|
||||
extern "C" VQT6_API void* vqt6_qnetworkaccessmanager_create(void) {
|
||||
return new QNetworkAccessManager();
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void* vqt6_qnetworkaccessmanager_create_with_parent(void* parent) {
|
||||
if (parent == nullptr) return nullptr;
|
||||
return new QNetworkAccessManager(static_cast<QObject*>(parent));
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void* vqt6_qnetworkaccessmanager_get(void* nam, void* req) {
|
||||
if (nam == nullptr || req == nullptr) return nullptr;
|
||||
return static_cast<QNetworkAccessManager*>(nam)->get(*static_cast<QNetworkRequest*>(req));
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void* vqt6_qnetworkaccessmanager_post(void* nam, void* req, const void* data, size_t size) {
|
||||
if (nam == nullptr || req == nullptr) return nullptr;
|
||||
QByteArray payload;
|
||||
if (data != nullptr && size > 0) {
|
||||
payload = QByteArray(static_cast<const char*>(data), static_cast<int>(size));
|
||||
}
|
||||
return static_cast<QNetworkAccessManager*>(nam)->post(*static_cast<QNetworkRequest*>(req), payload);
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void* vqt6_qnetworkaccessmanager_put(void* nam, void* req, const void* data, size_t size) {
|
||||
if (nam == nullptr || req == nullptr) return nullptr;
|
||||
QByteArray payload;
|
||||
if (data != nullptr && size > 0) {
|
||||
payload = QByteArray(static_cast<const char*>(data), static_cast<int>(size));
|
||||
}
|
||||
return static_cast<QNetworkAccessManager*>(nam)->put(*static_cast<QNetworkRequest*>(req), payload);
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void* vqt6_qnetworkaccessmanager_delete_resource(void* nam, void* req) {
|
||||
if (nam == nullptr || req == nullptr) return nullptr;
|
||||
return static_cast<QNetworkAccessManager*>(nam)->deleteResource(*static_cast<QNetworkRequest*>(req));
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void* vqt6_qnetworkaccessmanager_head(void* nam, void* req) {
|
||||
if (nam == nullptr || req == nullptr) return nullptr;
|
||||
return static_cast<QNetworkAccessManager*>(nam)->head(*static_cast<QNetworkRequest*>(req));
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qnetworkaccessmanager_set_cookie_store(void* nam, void* store) {
|
||||
if (nam == nullptr || store == nullptr) return;
|
||||
QNetworkCookieJar* jar = qobject_cast<QNetworkCookieJar*>(static_cast<QObject*>(store));
|
||||
if (jar != nullptr) {
|
||||
static_cast<QNetworkAccessManager*>(nam)->setCookieJar(jar);
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// QNetworkReply
|
||||
// ============================================================
|
||||
extern "C" VQT6_API void* vqt6_qnetworkreply_url(void* reply) {
|
||||
if (reply == nullptr) return nullptr;
|
||||
return new QString(static_cast<QNetworkReply*>(reply)->url().toString());
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void* vqt6_qnetworkreply_request(void* reply) {
|
||||
if (reply == nullptr) return nullptr;
|
||||
return new QNetworkRequest(static_cast<QNetworkReply*>(reply)->request());
|
||||
}
|
||||
|
||||
extern "C" VQT6_API int vqt6_qnetworkreply_error(void* reply) {
|
||||
if (reply == nullptr) return 0;
|
||||
return static_cast<int>(static_cast<QNetworkReply*>(reply)->error());
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void* vqt6_qnetworkreply_error_string(void* reply) {
|
||||
if (reply == nullptr) return nullptr;
|
||||
return new QString(static_cast<QNetworkReply*>(reply)->errorString());
|
||||
}
|
||||
|
||||
extern "C" VQT6_API int vqt6_qnetworkreply_is_finished(void* reply) {
|
||||
if (reply == nullptr) return 0;
|
||||
return static_cast<QNetworkReply*>(reply)->isFinished() ? 1 : 0;
|
||||
}
|
||||
|
||||
extern "C" VQT6_API int vqt6_qnetworkreply_is_running(void* reply) {
|
||||
if (reply == nullptr) return 0;
|
||||
return static_cast<QNetworkReply*>(reply)->isRunning() ? 1 : 0;
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qnetworkreply_abort(void* reply) {
|
||||
if (reply == nullptr) return;
|
||||
static_cast<QNetworkReply*>(reply)->abort();
|
||||
}
|
||||
|
||||
extern "C" VQT6_API size_t vqt6_qnetworkreply_read(void* reply, void* buf, size_t max_size) {
|
||||
if (reply == nullptr || buf == nullptr) return 0;
|
||||
return static_cast<size_t>(static_cast<QNetworkReply*>(reply)->read(static_cast<char*>(buf), static_cast<qint64>(max_size)));
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void* vqt6_qnetworkreply_read_all(void* reply, size_t* out_size) {
|
||||
if (reply == nullptr) return nullptr;
|
||||
QByteArray ba = static_cast<QNetworkReply*>(reply)->readAll();
|
||||
if (out_size != nullptr) *out_size = static_cast<size_t>(ba.size());
|
||||
return ba.data();
|
||||
}
|
||||
|
||||
extern "C" VQT6_API size_t vqt6_qnetworkreply_bytes_available(void* reply) {
|
||||
if (reply == nullptr) return 0;
|
||||
return static_cast<size_t>(static_cast<QNetworkReply*>(reply)->bytesAvailable());
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void* vqt6_qnetworkreply_header(void* reply, int header_type) {
|
||||
if (reply == nullptr) return nullptr;
|
||||
return new QVariant(static_cast<QNetworkReply*>(reply)->header(static_cast<QNetworkRequest::KnownHeaders>(header_type)));
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void* vqt6_qnetworkreply_raw_header(void* reply, const char* header_name, size_t* out_size) {
|
||||
if (reply == nullptr || header_name == nullptr) return nullptr;
|
||||
QByteArray ba = static_cast<QNetworkReply*>(reply)->rawHeader(QByteArray(header_name));
|
||||
if (out_size != nullptr) *out_size = static_cast<size_t>(ba.size());
|
||||
return ba.data();
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void* vqt6_qnetworkreply_attribute(void* reply, int attribute_code) {
|
||||
if (reply == nullptr) return nullptr;
|
||||
return new QVariant(static_cast<QNetworkReply*>(reply)->attribute(static_cast<QNetworkRequest::Attribute>(attribute_code)));
|
||||
}
|
||||
|
||||
extern "C" VQT6_API int vqt6_qnetworkreply_attribute_int(void* reply, int attribute_code, int default_value) {
|
||||
if (reply == nullptr) return default_value;
|
||||
return static_cast<QNetworkReply*>(reply)->attribute(static_cast<QNetworkRequest::Attribute>(attribute_code)).toInt(default_value);
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qnetworkreply_set_raw_header(void* reply, const char* header_name, const void* value, size_t value_size) {
|
||||
if (reply == nullptr || header_name == nullptr) return;
|
||||
static_cast<QNetworkReply*>(reply)->setRawHeader(QByteArray(header_name),
|
||||
QByteArray(static_cast<const char*>(value), static_cast<int>(value_size)));
|
||||
}
|
||||
137
includes/vqt6 copy/_bridge_network.h
Normal file
137
includes/vqt6 copy/_bridge_network.h
Normal file
@@ -0,0 +1,137 @@
|
||||
// ============================================================
|
||||
// vqt6/_bridge_network.h — QtNetwork C 桥接函数声明
|
||||
// ============================================================
|
||||
|
||||
#ifndef VQT6_BRIDGE_NETWORK_H
|
||||
#define VQT6_BRIDGE_NETWORK_H
|
||||
|
||||
#include "_bridge.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// ============================================================
|
||||
// QHostAddress
|
||||
// ============================================================
|
||||
VQT6_API void* vqt6_qhostaddress_create(void);
|
||||
VQT6_API void* vqt6_qhostaddress_create_with_ipv4(uint32_t ipv4);
|
||||
VQT6_API void* vqt6_qhostaddress_create_with_string(void* address);
|
||||
VQT6_API void* vqt6_qhostaddress_create_with_local_host(void);
|
||||
VQT6_API void* vqt6_qhostaddress_create_with_local_ipv4(void);
|
||||
VQT6_API void* vqt6_qhostaddress_create_with_broadcast(void);
|
||||
VQT6_API void* vqt6_qhostaddress_create_with_any_ipv4(void);
|
||||
VQT6_API void* vqt6_qhostaddress_to_string(void* addr);
|
||||
VQT6_API uint32_t vqt6_qhostaddress_to_ipv4(void* addr);
|
||||
VQT6_API int vqt6_qhostaddress_is_null(void* addr);
|
||||
VQT6_API int vqt6_qhostaddress_is_loopback(void* addr);
|
||||
VQT6_API int vqt6_qhostaddress_is_broadcast(void* addr);
|
||||
VQT6_API int vqt6_qhostaddress_protocol(void* addr);
|
||||
VQT6_API void vqt6_qhostaddress_free(void* addr);
|
||||
|
||||
// ============================================================
|
||||
// QAbstractSocket
|
||||
// ============================================================
|
||||
VQT6_API int vqt6_qabstractsocket_state(void* socket);
|
||||
VQT6_API int vqt6_qabstractsocket_error(void* socket);
|
||||
VQT6_API void* vqt6_qabstractsocket_error_string(void* socket);
|
||||
VQT6_API void vqt6_qabstractsocket_connect_to_host(void* socket, void* host_name, uint16_t port);
|
||||
VQT6_API void vqt6_qabstractsocket_connect_to_host_with_addr(void* socket, void* address, uint16_t port);
|
||||
VQT6_API void vqt6_qabstractsocket_disconnect_from_host(void* socket);
|
||||
VQT6_API int vqt6_qabstractsocket_wait_for_connected(void* socket, int timeout_ms);
|
||||
VQT6_API int vqt6_qabstractsocket_wait_for_ready_read(void* socket, int timeout_ms);
|
||||
VQT6_API int vqt6_qabstractsocket_wait_for_bytes_written(void* socket, int timeout_ms);
|
||||
VQT6_API int vqt6_qabstractsocket_wait_for_disconnected(void* socket, int timeout_ms);
|
||||
VQT6_API int vqt6_qabstractsocket_is_valid(void* socket);
|
||||
VQT6_API int vqt6_qabstractsocket_is_open(void* socket);
|
||||
VQT6_API int vqt6_qabstractsocket_flush(void* socket);
|
||||
VQT6_API void vqt6_qabstractsocket_close(void* socket);
|
||||
VQT6_API void vqt6_qabstractsocket_abort(void* socket);
|
||||
VQT6_API size_t vqt6_qabstractsocket_read(void* socket, void* buf, size_t max_size);
|
||||
VQT6_API void* vqt6_qabstractsocket_read_all(void* socket, size_t* out_size);
|
||||
VQT6_API size_t vqt6_qabstractsocket_write(void* socket, const void* data, size_t size);
|
||||
VQT6_API size_t vqt6_qabstractsocket_bytes_available(void* socket);
|
||||
VQT6_API size_t vqt6_qabstractsocket_bytes_to_write(void* socket);
|
||||
VQT6_API void* vqt6_qabstractsocket_peer_address(void* socket);
|
||||
VQT6_API uint16_t vqt6_qabstractsocket_peer_port(void* socket);
|
||||
VQT6_API void* vqt6_qabstractsocket_local_address(void* socket);
|
||||
VQT6_API uint16_t vqt6_qabstractsocket_local_port(void* socket);
|
||||
|
||||
// ============================================================
|
||||
// QTcpSocket
|
||||
// ============================================================
|
||||
VQT6_API void* vqt6_qtcpsocket_create(void);
|
||||
VQT6_API void* vqt6_qtcpsocket_create_with_parent(void* parent);
|
||||
VQT6_API void vqt6_qtcpsocket_connect_to_host(void* socket, void* host_name, uint16_t port, int mode);
|
||||
VQT6_API void vqt6_qtcpsocket_connect_to_host_with_addr(void* socket, void* address, uint16_t port, int mode);
|
||||
VQT6_API int vqt6_qtcpsocket_set_socket_descriptor(void* socket, intptr_t socket_descriptor);
|
||||
VQT6_API intptr_t vqt6_qtcpsocket_socket_descriptor(void* socket);
|
||||
VQT6_API void vqt6_qtcpsocket_set_proxy(void* socket, int proxy_type);
|
||||
VQT6_API void vqt6_qtcpsocket_abort(void* socket);
|
||||
|
||||
// ============================================================
|
||||
// QUdpSocket
|
||||
// ============================================================
|
||||
VQT6_API void* vqt6_qudpsocket_create(void);
|
||||
VQT6_API void* vqt6_qudpsocket_create_with_parent(void* parent);
|
||||
VQT6_API int vqt6_qudpsocket_bind(void* socket, uint16_t port);
|
||||
VQT6_API int vqt6_qudpsocket_bind_with_addr(void* socket, void* address, uint16_t port);
|
||||
VQT6_API void vqt6_qudpsocket_close(void* socket);
|
||||
VQT6_API size_t vqt6_qudpsocket_write_datagram(void* socket, const void* data, size_t size, void* host, uint16_t port);
|
||||
VQT6_API size_t vqt6_qudpsocket_read_datagram(void* socket, void* data, size_t max_size, void* host, uint16_t* port);
|
||||
VQT6_API int vqt6_qudpsocket_has_pending_datagrams(void* socket);
|
||||
VQT6_API size_t vqt6_qudpsocket_pending_datagram_size(void* socket);
|
||||
VQT6_API int vqt6_qudpsocket_join_multicast_group(void* socket, void* group_address);
|
||||
VQT6_API int vqt6_qudpsocket_leave_multicast_group(void* socket, void* group_address);
|
||||
|
||||
// ============================================================
|
||||
// QNetworkRequest
|
||||
// ============================================================
|
||||
VQT6_API void* vqt6_qnetworkrequest_create(void);
|
||||
VQT6_API void* vqt6_qnetworkrequest_create_with_url(void* url);
|
||||
VQT6_API void vqt6_qnetworkrequest_set_url(void* req, void* url);
|
||||
VQT6_API void* vqt6_qnetworkrequest_url(void* req);
|
||||
VQT6_API void vqt6_qnetworkrequest_set_header(void* req, int header_type, void* value);
|
||||
VQT6_API void* vqt6_qnetworkrequest_header(void* req, int header_type);
|
||||
VQT6_API void vqt6_qnetworkrequest_set_raw_header(void* req, const char* header_name, const void* value, size_t value_size);
|
||||
VQT6_API void* vqt6_qnetworkrequest_raw_header(void* req, const char* header_name, size_t* out_size);
|
||||
VQT6_API void vqt6_qnetworkrequest_set_attribute(void* req, int attr_type, void* value);
|
||||
VQT6_API void* vqt6_qnetworkrequest_attribute(void* req, int attr_type);
|
||||
VQT6_API void vqt6_qnetworkrequest_free(void* req);
|
||||
|
||||
// ============================================================
|
||||
// QNetworkAccessManager
|
||||
// ============================================================
|
||||
VQT6_API void* vqt6_qnetworkaccessmanager_create(void);
|
||||
VQT6_API void* vqt6_qnetworkaccessmanager_create_with_parent(void* parent);
|
||||
VQT6_API void* vqt6_qnetworkaccessmanager_get(void* nam, void* req);
|
||||
VQT6_API void* vqt6_qnetworkaccessmanager_post(void* nam, void* req, const void* data, size_t size);
|
||||
VQT6_API void* vqt6_qnetworkaccessmanager_put(void* nam, void* req, const void* data, size_t size);
|
||||
VQT6_API void* vqt6_qnetworkaccessmanager_delete_resource(void* nam, void* req);
|
||||
VQT6_API void* vqt6_qnetworkaccessmanager_head(void* nam, void* req);
|
||||
VQT6_API void vqt6_qnetworkaccessmanager_set_cookie_store(void* nam, void* store);
|
||||
|
||||
// ============================================================
|
||||
// QNetworkReply
|
||||
// ============================================================
|
||||
VQT6_API void* vqt6_qnetworkreply_url(void* reply);
|
||||
VQT6_API void* vqt6_qnetworkreply_request(void* reply);
|
||||
VQT6_API int vqt6_qnetworkreply_error(void* reply);
|
||||
VQT6_API void* vqt6_qnetworkreply_error_string(void* reply);
|
||||
VQT6_API int vqt6_qnetworkreply_is_finished(void* reply);
|
||||
VQT6_API int vqt6_qnetworkreply_is_running(void* reply);
|
||||
VQT6_API void vqt6_qnetworkreply_abort(void* reply);
|
||||
VQT6_API size_t vqt6_qnetworkreply_read(void* reply, void* buf, size_t max_size);
|
||||
VQT6_API void* vqt6_qnetworkreply_read_all(void* reply, size_t* out_size);
|
||||
VQT6_API size_t vqt6_qnetworkreply_bytes_available(void* reply);
|
||||
VQT6_API void* vqt6_qnetworkreply_header(void* reply, int header_type);
|
||||
VQT6_API void* vqt6_qnetworkreply_raw_header(void* reply, const char* header_name, size_t* out_size);
|
||||
VQT6_API void* vqt6_qnetworkreply_attribute(void* reply, int attribute_code);
|
||||
VQT6_API int vqt6_qnetworkreply_attribute_int(void* reply, int attribute_code, int default_value);
|
||||
VQT6_API void vqt6_qnetworkreply_set_raw_header(void* reply, const char* header_name, const void* value, size_t value_size);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // VQT6_BRIDGE_NETWORK_H
|
||||
1745
includes/vqt6 copy/_bridge_widgets.cpp
Normal file
1745
includes/vqt6 copy/_bridge_widgets.cpp
Normal file
File diff suppressed because it is too large
Load Diff
432
includes/vqt6 copy/_bridge_widgets.h
Normal file
432
includes/vqt6 copy/_bridge_widgets.h
Normal file
@@ -0,0 +1,432 @@
|
||||
// ============================================================
|
||||
// vqt6/_bridge_widgets.h — QtWidgets C 桥接函数声明
|
||||
// ============================================================
|
||||
|
||||
#ifndef VQT6_BRIDGE_WIDGETS_H
|
||||
#define VQT6_BRIDGE_WIDGETS_H
|
||||
|
||||
#include "_bridge.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// ============================================================
|
||||
// QApplication
|
||||
// ============================================================
|
||||
VQT6_API void* vqt6_qapplication_create(int argc, char** argv);
|
||||
VQT6_API void* vqt6_qapplication_instance(void);
|
||||
VQT6_API int vqt6_qapplication_exec(void* app);
|
||||
VQT6_API void vqt6_qapplication_quit(void* app);
|
||||
VQT6_API void vqt6_qapplication_exit(void* app, int exit_code);
|
||||
VQT6_API void vqt6_qapplication_process_events(void* app);
|
||||
VQT6_API int vqt6_qapplication_desktop_width(void* app);
|
||||
VQT6_API int vqt6_qapplication_desktop_height(void* app);
|
||||
VQT6_API void vqt6_qapplication_set_quit_on_last_window_closed(void* app, int quit);
|
||||
VQT6_API int vqt6_qapplication_quit_on_last_window_closed(void* app);
|
||||
|
||||
// ============================================================
|
||||
// QWidget
|
||||
// ============================================================
|
||||
VQT6_API void* vqt6_qwidget_create(void);
|
||||
VQT6_API void* vqt6_qwidget_create_with_parent(void* parent);
|
||||
VQT6_API void vqt6_qwidget_show(void* widget);
|
||||
VQT6_API void vqt6_qwidget_hide(void* widget);
|
||||
VQT6_API int vqt6_qwidget_close(void* widget);
|
||||
VQT6_API int vqt6_qwidget_is_visible(void* widget);
|
||||
VQT6_API void vqt6_qwidget_set_visible(void* widget, int visible);
|
||||
VQT6_API void vqt6_qwidget_set_geometry(void* widget, int x, int y, int w, int h);
|
||||
VQT6_API void vqt6_qwidget_geometry(void* widget, int* x, int* y, int* w, int* h);
|
||||
VQT6_API void vqt6_qwidget_resize(void* widget, int w, int h);
|
||||
VQT6_API void vqt6_qwidget_size(void* widget, int* w, int* h);
|
||||
VQT6_API void vqt6_qwidget_move(void* widget, int x, int y);
|
||||
VQT6_API void vqt6_qwidget_pos(void* widget, int* x, int* y);
|
||||
VQT6_API int vqt6_qwidget_width(void* widget);
|
||||
VQT6_API int vqt6_qwidget_height(void* widget);
|
||||
VQT6_API int vqt6_qwidget_x(void* widget);
|
||||
VQT6_API int vqt6_qwidget_y(void* widget);
|
||||
VQT6_API void vqt6_qwidget_set_window_title(void* widget, void* title);
|
||||
VQT6_API void* vqt6_qwidget_window_title(void* widget);
|
||||
VQT6_API void vqt6_qwidget_set_text(void* widget, void* text);
|
||||
VQT6_API void* vqt6_qwidget_text(void* widget);
|
||||
VQT6_API void vqt6_qwidget_set_enabled(void* widget, int enabled);
|
||||
VQT6_API int vqt6_qwidget_is_enabled(void* widget);
|
||||
VQT6_API void vqt6_qwidget_set_parent(void* widget, void* parent);
|
||||
VQT6_API void* vqt6_qwidget_parent_widget(void* widget);
|
||||
VQT6_API void vqt6_qwidget_set_focus(void* widget);
|
||||
VQT6_API void vqt6_qwidget_clear_focus(void* widget);
|
||||
VQT6_API int vqt6_qwidget_has_focus(void* widget);
|
||||
VQT6_API void vqt6_qwidget_set_focus_policy(void* widget, int policy);
|
||||
VQT6_API void vqt6_qwidget_update(void* widget);
|
||||
VQT6_API void vqt6_qwidget_repaint(void* widget);
|
||||
VQT6_API void vqt6_qwidget_set_update_enabled(void* widget, int enabled);
|
||||
VQT6_API void vqt6_qwidget_set_window_flags(void* widget, int flags);
|
||||
VQT6_API int vqt6_qwidget_window_flags(void* widget);
|
||||
VQT6_API void vqt6_qwidget_set_cursor(void* widget, void* cursor);
|
||||
VQT6_API void* vqt6_qwidget_cursor(void* widget);
|
||||
VQT6_API void vqt6_qwidget_unset_cursor(void* widget);
|
||||
VQT6_API void vqt6_qwidget_set_tool_tip(void* widget, void* tip);
|
||||
VQT6_API void* vqt6_qwidget_tool_tip(void* widget);
|
||||
VQT6_API void vqt6_qwidget_set_status_tip(void* widget, void* tip);
|
||||
VQT6_API void* vqt6_qwidget_status_tip(void* widget);
|
||||
VQT6_API void vqt6_qwidget_set_minimum_size(void* widget, int w, int h);
|
||||
VQT6_API void vqt6_qwidget_set_maximum_size(void* widget, int w, int h);
|
||||
VQT6_API void vqt6_qwidget_set_fixed_size(void* widget, int w, int h);
|
||||
VQT6_API void vqt6_qwidget_minimum_size(void* widget, int* w, int* h);
|
||||
VQT6_API void vqt6_qwidget_maximum_size(void* widget, int* w, int* h);
|
||||
|
||||
// ============================================================
|
||||
// QDialog
|
||||
// ============================================================
|
||||
VQT6_API void* vqt6_qdialog_create(void);
|
||||
VQT6_API void* vqt6_qdialog_create_with_parent(void* parent);
|
||||
VQT6_API int vqt6_qdialog_exec(void* dialog);
|
||||
VQT6_API void vqt6_qdialog_done(void* dialog, int result);
|
||||
VQT6_API void vqt6_qdialog_accept(void* dialog);
|
||||
VQT6_API void vqt6_qdialog_reject(void* dialog);
|
||||
VQT6_API void vqt6_qdialog_set_result(void* dialog, int result);
|
||||
VQT6_API int vqt6_qdialog_result(void* dialog);
|
||||
VQT6_API void vqt6_qdialog_set_modal(void* dialog, int modal);
|
||||
VQT6_API int vqt6_qdialog_is_modal(void* dialog);
|
||||
|
||||
// ============================================================
|
||||
// QMainWindow
|
||||
// ============================================================
|
||||
VQT6_API void* vqt6_qmainwindow_create(void);
|
||||
VQT6_API void* vqt6_qmainwindow_create_with_parent(void* parent);
|
||||
VQT6_API void vqt6_qmainwindow_set_central_widget(void* mw, void* widget);
|
||||
VQT6_API void* vqt6_qmainwindow_central_widget(void* mw);
|
||||
VQT6_API void* vqt6_qmainwindow_menu_bar(void* mw);
|
||||
VQT6_API void vqt6_qmainwindow_set_menu_bar(void* mw, void* menubar);
|
||||
VQT6_API void* vqt6_qmainwindow_status_bar(void* mw);
|
||||
VQT6_API void vqt6_qmainwindow_set_status_bar(void* mw, void* statusbar);
|
||||
VQT6_API void vqt6_qmainwindow_add_tool_bar(void* mw, void* toolbar);
|
||||
VQT6_API void vqt6_qmainwindow_add_tool_bar_break(void* mw);
|
||||
|
||||
// ============================================================
|
||||
// QLabel
|
||||
// ============================================================
|
||||
VQT6_API void* vqt6_qlabel_create(void);
|
||||
VQT6_API void* vqt6_qlabel_create_with_text(void* text);
|
||||
VQT6_API void* vqt6_qlabel_create_with_text_parent(void* text, void* parent);
|
||||
VQT6_API void vqt6_qlabel_set_text(void* label, void* text);
|
||||
VQT6_API void* vqt6_qlabel_text(void* label);
|
||||
VQT6_API void vqt6_qlabel_set_alignment(void* label, int alignment);
|
||||
VQT6_API int vqt6_qlabel_alignment(void* label);
|
||||
VQT6_API void vqt6_qlabel_set_pixmap(void* label, void* pixmap);
|
||||
VQT6_API void* vqt6_qlabel_pixmap(void* label);
|
||||
VQT6_API void vqt6_qlabel_set_indent(void* label, int indent);
|
||||
VQT6_API void vqt6_qlabel_set_margin(void* label, int margin);
|
||||
VQT6_API void vqt6_qlabel_set_word_wrap(void* label, int wrap);
|
||||
VQT6_API int vqt6_qlabel_word_wrap(void* label);
|
||||
|
||||
// ============================================================
|
||||
// QPushButton
|
||||
// ============================================================
|
||||
VQT6_API void* vqt6_qpushbutton_create(void);
|
||||
VQT6_API void* vqt6_qpushbutton_create_with_text(void* text);
|
||||
VQT6_API void* vqt6_qpushbutton_create_with_text_parent(void* text, void* parent);
|
||||
VQT6_API void vqt6_qpushbutton_set_text(void* btn, void* text);
|
||||
VQT6_API void* vqt6_qpushbutton_text(void* btn);
|
||||
VQT6_API void vqt6_qpushbutton_set_icon(void* btn, void* icon);
|
||||
VQT6_API void* vqt6_qpushbutton_icon(void* btn);
|
||||
VQT6_API void vqt6_qpushbutton_set_default(void* btn, int is_default);
|
||||
VQT6_API int vqt6_qpushbutton_is_default(void* btn);
|
||||
VQT6_API void vqt6_qpushbutton_set_flat(void* btn, int flat);
|
||||
VQT6_API int vqt6_qpushbutton_is_flat(void* btn);
|
||||
VQT6_API void vqt6_qpushbutton_set_checkable(void* btn, int checkable);
|
||||
VQT6_API int vqt6_qpushbutton_is_checkable(void* btn);
|
||||
VQT6_API void vqt6_qpushbutton_set_checked(void* btn, int checked);
|
||||
VQT6_API int vqt6_qpushbutton_is_checked(void* btn);
|
||||
VQT6_API void vqt6_qpushbutton_click(void* btn);
|
||||
|
||||
// ============================================================
|
||||
// QLineEdit
|
||||
// ============================================================
|
||||
VQT6_API void* vqt6_qlineedit_create(void);
|
||||
VQT6_API void* vqt6_qlineedit_create_with_text(void* text);
|
||||
VQT6_API void* vqt6_qlineedit_create_with_text_parent(void* text, void* parent);
|
||||
VQT6_API void* vqt6_qlineedit_text(void* le);
|
||||
VQT6_API void vqt6_qlineedit_set_text(void* le, void* text);
|
||||
VQT6_API void* vqt6_qlineedit_placeholder_text(void* le);
|
||||
VQT6_API void vqt6_qlineedit_set_placeholder_text(void* le, void* text);
|
||||
VQT6_API void vqt6_qlineedit_set_max_length(void* le, int max);
|
||||
VQT6_API int vqt6_qlineedit_max_length(void* le);
|
||||
VQT6_API void vqt6_qlineedit_set_read_only(void* le, int ro);
|
||||
VQT6_API int vqt6_qlineedit_is_read_only(void* le);
|
||||
VQT6_API void vqt6_qlineedit_set_echo_mode(void* le, int mode);
|
||||
VQT6_API int vqt6_qlineedit_echo_mode(void* le);
|
||||
VQT6_API void vqt6_qlineedit_select_all(void* le);
|
||||
VQT6_API void vqt6_qlineedit_clear(void* le);
|
||||
|
||||
// ============================================================
|
||||
// QTextEdit / QPlainTextEdit
|
||||
// ============================================================
|
||||
VQT6_API void* vqt6_qtextedit_create(void);
|
||||
VQT6_API void* vqt6_qtextedit_create_with_parent(void* parent);
|
||||
VQT6_API void* vqt6_qtextedit_to_plain_text(void* te);
|
||||
VQT6_API void vqt6_qtextedit_set_plain_text(void* te, void* text);
|
||||
VQT6_API void vqt6_qtextedit_set_html(void* te, void* html);
|
||||
VQT6_API void* vqt6_qtextedit_to_html(void* te);
|
||||
VQT6_API void vqt6_qtextedit_append(void* te, void* text);
|
||||
VQT6_API void vqt6_qtextedit_clear(void* te);
|
||||
VQT6_API void vqt6_qtextedit_set_read_only(void* te, int ro);
|
||||
VQT6_API int vqt6_qtextedit_is_read_only(void* te);
|
||||
|
||||
VQT6_API void* vqt6_qplaintextedit_create(void);
|
||||
VQT6_API void* vqt6_qplaintextedit_create_with_parent(void* parent);
|
||||
VQT6_API void* vqt6_qplaintextedit_to_plain_text(void* pte);
|
||||
VQT6_API void vqt6_qplaintextedit_set_plain_text(void* pte, void* text);
|
||||
VQT6_API void vqt6_qplaintextedit_append(void* pte, void* text);
|
||||
VQT6_API void vqt6_qplaintextedit_clear(void* pte);
|
||||
VQT6_API void vqt6_qplaintextedit_set_read_only(void* pte, int ro);
|
||||
VQT6_API int vqt6_qplaintextedit_line_count(void* pte);
|
||||
|
||||
// ============================================================
|
||||
// QCheckBox / QRadioButton
|
||||
// ============================================================
|
||||
VQT6_API void* vqt6_qcheckbox_create(void);
|
||||
VQT6_API void* vqt6_qcheckbox_create_with_text(void* text);
|
||||
VQT6_API void* vqt6_qcheckbox_create_with_text_parent(void* text, void* parent);
|
||||
VQT6_API void vqt6_qcheckbox_set_checked(void* cb, int checked);
|
||||
VQT6_API int vqt6_qcheckbox_is_checked(void* cb);
|
||||
VQT6_API void vqt6_qcheckbox_set_text(void* cb, void* text);
|
||||
VQT6_API void* vqt6_qcheckbox_text(void* cb);
|
||||
VQT6_API void vqt6_qcheckbox_set_tristate(void* cb, int tristate);
|
||||
VQT6_API int vqt6_qcheckbox_is_tristate(void* cb);
|
||||
|
||||
VQT6_API void* vqt6_qradiobutton_create(void);
|
||||
VQT6_API void* vqt6_qradiobutton_create_with_text(void* text);
|
||||
VQT6_API void* vqt6_qradiobutton_create_with_text_parent(void* text, void* parent);
|
||||
VQT6_API void vqt6_qradiobutton_set_checked(void* rb, int checked);
|
||||
VQT6_API int vqt6_qradiobutton_is_checked(void* rb);
|
||||
VQT6_API void vqt6_qradiobutton_set_text(void* rb, void* text);
|
||||
VQT6_API void* vqt6_qradiobutton_text(void* rb);
|
||||
|
||||
// ============================================================
|
||||
// QComboBox
|
||||
// ============================================================
|
||||
VQT6_API void* vqt6_qcombobox_create(void);
|
||||
VQT6_API void* vqt6_qcombobox_create_with_parent(void* parent);
|
||||
VQT6_API void vqt6_qcombobox_add_item(void* cb, void* text);
|
||||
VQT6_API void vqt6_qcombobox_add_items(void* cb, void* items);
|
||||
VQT6_API void vqt6_qcombobox_insert_item(void* cb, int index, void* text);
|
||||
VQT6_API void vqt6_qcombobox_remove_item(void* cb, int index);
|
||||
VQT6_API void vqt6_qcombobox_clear(void* cb);
|
||||
VQT6_API int vqt6_qcombobox_count(void* cb);
|
||||
VQT6_API int vqt6_qcombobox_current_index(void* cb);
|
||||
VQT6_API void vqt6_qcombobox_set_current_index(void* cb, int index);
|
||||
VQT6_API void* vqt6_qcombobox_current_text(void* cb);
|
||||
VQT6_API void* vqt6_qcombobox_item_text(void* cb, int index);
|
||||
VQT6_API void vqt6_qcombobox_set_editable(void* cb, int editable);
|
||||
VQT6_API int vqt6_qcombobox_is_editable(void* cb);
|
||||
|
||||
// ============================================================
|
||||
// QListWidget
|
||||
// ============================================================
|
||||
VQT6_API void* vqt6_qlistwidget_create(void);
|
||||
VQT6_API void* vqt6_qlistwidget_create_with_parent(void* parent);
|
||||
VQT6_API void vqt6_qlistwidget_add_item(void* lw, void* text);
|
||||
VQT6_API void vqt6_qlistwidget_add_items(void* lw, void* items);
|
||||
VQT6_API void vqt6_qlistwidget_insert_item(void* lw, int row, void* text);
|
||||
VQT6_API void vqt6_qlistwidget_remove_item_widget(void* lw, int row);
|
||||
VQT6_API void* vqt6_qlistwidget_take_item(void* lw, int row);
|
||||
VQT6_API void vqt6_qlistwidget_clear(void* lw);
|
||||
VQT6_API int vqt6_qlistwidget_count(void* lw);
|
||||
VQT6_API int vqt6_qlistwidget_current_row(void* lw);
|
||||
VQT6_API void vqt6_qlistwidget_set_current_row(void* lw, int row);
|
||||
VQT6_API void* vqt6_qlistwidget_current_item_text(void* lw);
|
||||
VQT6_API void* vqt6_qlistwidget_item_text(void* lw, int row);
|
||||
VQT6_API void vqt6_qlistwidget_set_item_text(void* lw, int row, void* text);
|
||||
|
||||
// ============================================================
|
||||
// QProgressBar
|
||||
// ============================================================
|
||||
VQT6_API void* vqt6_qprogressbar_create(void);
|
||||
VQT6_API void* vqt6_qprogressbar_create_with_parent(void* parent);
|
||||
VQT6_API void vqt6_qprogressbar_set_value(void* pb, int value);
|
||||
VQT6_API int vqt6_qprogressbar_value(void* pb);
|
||||
VQT6_API void vqt6_qprogressbar_set_minimum(void* pb, int min);
|
||||
VQT6_API void vqt6_qprogressbar_set_maximum(void* pb, int max);
|
||||
VQT6_API void vqt6_qprogressbar_set_range(void* pb, int min, int max);
|
||||
VQT6_API int vqt6_qprogressbar_minimum(void* pb);
|
||||
VQT6_API int vqt6_qprogressbar_maximum(void* pb);
|
||||
VQT6_API void vqt6_qprogressbar_set_text_visible(void* pb, int visible);
|
||||
VQT6_API void vqt6_qprogressbar_set_format(void* pb, void* format);
|
||||
VQT6_API void vqt6_qprogressbar_reset(void* pb);
|
||||
|
||||
// ============================================================
|
||||
// QSlider
|
||||
// ============================================================
|
||||
VQT6_API void* vqt6_qslider_create(void);
|
||||
VQT6_API void* vqt6_qslider_create_with_orientation(int orientation);
|
||||
VQT6_API void* vqt6_qslider_create_with_orientation_parent(int orientation, void* parent);
|
||||
VQT6_API void vqt6_qslider_set_value(void* s, int value);
|
||||
VQT6_API int vqt6_qslider_value(void* s);
|
||||
VQT6_API void vqt6_qslider_set_minimum(void* s, int min);
|
||||
VQT6_API void vqt6_qslider_set_maximum(void* s, int max);
|
||||
VQT6_API void vqt6_qslider_set_range(void* s, int min, int max);
|
||||
VQT6_API void vqt6_qslider_set_orientation(void* s, int orientation);
|
||||
VQT6_API int vqt6_qslider_orientation(void* s);
|
||||
VQT6_API void vqt6_qslider_set_single_step(void* s, int step);
|
||||
VQT6_API void vqt6_qslider_set_page_step(void* s, int step);
|
||||
|
||||
// ============================================================
|
||||
// QSpinBox
|
||||
// ============================================================
|
||||
VQT6_API void* vqt6_qspinbox_create(void);
|
||||
VQT6_API void* vqt6_qspinbox_create_with_parent(void* parent);
|
||||
VQT6_API int vqt6_qspinbox_value(void* sb);
|
||||
VQT6_API void vqt6_qspinbox_set_value(void* sb, int value);
|
||||
VQT6_API void vqt6_qspinbox_set_minimum(void* sb, int min);
|
||||
VQT6_API void vqt6_qspinbox_set_maximum(void* sb, int max);
|
||||
VQT6_API void vqt6_qspinbox_set_range(void* sb, int min, int max);
|
||||
VQT6_API int vqt6_qspinbox_minimum(void* sb);
|
||||
VQT6_API int vqt6_qspinbox_maximum(void* sb);
|
||||
VQT6_API void vqt6_qspinbox_set_single_step(void* sb, int step);
|
||||
VQT6_API void vqt6_qspinbox_set_prefix(void* sb, void* prefix);
|
||||
VQT6_API void vqt6_qspinbox_set_suffix(void* sb, void* suffix);
|
||||
VQT6_API void* vqt6_qspinbox_prefix(void* sb);
|
||||
VQT6_API void* vqt6_qspinbox_suffix(void* sb);
|
||||
|
||||
// ============================================================
|
||||
// Layouts
|
||||
// ============================================================
|
||||
VQT6_API void vqt6_qlayout_add_widget(void* layout, void* widget);
|
||||
VQT6_API void vqt6_qlayout_remove_widget(void* layout, void* widget);
|
||||
VQT6_API int vqt6_qlayout_count(void* layout);
|
||||
VQT6_API void* vqt6_qlayout_item_at(void* layout, int index);
|
||||
VQT6_API void vqt6_qlayout_set_contents_margins(void* layout, int left, int top, int right, int bottom);
|
||||
VQT6_API void vqt6_qlayout_set_spacing(void* layout, int spacing);
|
||||
VQT6_API int vqt6_qlayout_spacing(void* layout);
|
||||
VQT6_API void vqt6_qlayout_invalidate(void* layout);
|
||||
|
||||
VQT6_API void* vqt6_qhboxlayout_create(void);
|
||||
VQT6_API void* vqt6_qhboxlayout_create_with_parent(void* parent);
|
||||
VQT6_API void vqt6_qhboxlayout_add_layout(void* layout, void* child);
|
||||
VQT6_API void vqt6_qhboxlayout_add_stretch(void* layout, int stretch);
|
||||
VQT6_API void vqt6_qhboxlayout_add_spacing(void* layout, int size);
|
||||
|
||||
VQT6_API void* vqt6_qvboxlayout_create(void);
|
||||
VQT6_API void* vqt6_qvboxlayout_create_with_parent(void* parent);
|
||||
VQT6_API void vqt6_qvboxlayout_add_layout(void* layout, void* child);
|
||||
VQT6_API void vqt6_qvboxlayout_add_stretch(void* layout, int stretch);
|
||||
VQT6_API void vqt6_qvboxlayout_add_spacing(void* layout, int size);
|
||||
|
||||
VQT6_API void* vqt6_qgridlayout_create(void);
|
||||
VQT6_API void* vqt6_qgridlayout_create_with_parent(void* parent);
|
||||
VQT6_API void vqt6_qgridlayout_add_widget(void* gl, void* w, int row, int col);
|
||||
VQT6_API void vqt6_qgridlayout_add_widget_with_span(void* gl, void* w, int row, int col, int row_span, int col_span);
|
||||
|
||||
VQT6_API void* vqt6_qformlayout_create(void);
|
||||
VQT6_API void* vqt6_qformlayout_create_with_parent(void* parent);
|
||||
VQT6_API void vqt6_qformlayout_add_row(void* fl, void* label, void* field);
|
||||
VQT6_API void vqt6_qformlayout_add_row_widget_pair(void* fl, void* label, void* field);
|
||||
|
||||
// ============================================================
|
||||
// QStackedWidget / QTabWidget
|
||||
// ============================================================
|
||||
VQT6_API void* vqt6_qstackedwidget_create(void);
|
||||
VQT6_API void* vqt6_qstackedwidget_create_with_parent(void* parent);
|
||||
VQT6_API int vqt6_qstackedwidget_add_widget(void* sw, void* w);
|
||||
VQT6_API void vqt6_qstackedwidget_remove_widget(void* sw, void* w);
|
||||
VQT6_API int vqt6_qstackedwidget_count(void* sw);
|
||||
VQT6_API int vqt6_qstackedwidget_current_index(void* sw);
|
||||
VQT6_API void vqt6_qstackedwidget_set_current_index(void* sw, int index);
|
||||
VQT6_API void* vqt6_qstackedwidget_current_widget(void* sw);
|
||||
VQT6_API void* vqt6_qstackedwidget_widget(void* sw, int index);
|
||||
|
||||
VQT6_API void* vqt6_qtabwidget_create(void);
|
||||
VQT6_API void* vqt6_qtabwidget_create_with_parent(void* parent);
|
||||
VQT6_API int vqt6_qtabwidget_add_tab(void* tw, void* w, void* label);
|
||||
VQT6_API int vqt6_qtabwidget_insert_tab(void* tw, int index, void* w, void* label);
|
||||
VQT6_API void vqt6_qtabwidget_remove_tab(void* tw, int index);
|
||||
VQT6_API int vqt6_qtabwidget_count(void* tw);
|
||||
VQT6_API int vqt6_qtabwidget_current_index(void* tw);
|
||||
VQT6_API void vqt6_qtabwidget_set_current_index(void* tw, int index);
|
||||
VQT6_API void* vqt6_qtabwidget_tab_text(void* tw, int index);
|
||||
VQT6_API void vqt6_qtabwidget_set_tab_text(void* tw, int index, void* text);
|
||||
VQT6_API void vqt6_qtabwidget_set_tabs_closable(void* tw, int closable);
|
||||
VQT6_API int vqt6_qtabwidget_tabs_closable(void* tw);
|
||||
|
||||
// ============================================================
|
||||
// QMenuBar / QMenu / QAction
|
||||
// ============================================================
|
||||
VQT6_API void* vqt6_qmenubar_create(void);
|
||||
VQT6_API void* vqt6_qmenubar_create_with_parent(void* parent);
|
||||
VQT6_API void* vqt6_qmenubar_add_menu(void* mb, void* title);
|
||||
VQT6_API void vqt6_qmenubar_add_menu_with_menu(void* mb, void* menu);
|
||||
VQT6_API void vqt6_qmenubar_add_action(void* mb, void* action);
|
||||
VQT6_API void vqt6_qmenubar_clear(void* mb);
|
||||
|
||||
VQT6_API void* vqt6_qmenu_create(void);
|
||||
VQT6_API void* vqt6_qmenu_create_with_title(void* title);
|
||||
VQT6_API void* vqt6_qmenu_create_with_title_parent(void* title, void* parent);
|
||||
VQT6_API void* vqt6_qmenu_add_menu(void* menu, void* title);
|
||||
VQT6_API void vqt6_qmenu_add_action(void* menu, void* action);
|
||||
VQT6_API void vqt6_qmenu_add_separator(void* menu);
|
||||
VQT6_API void vqt6_qmenu_clear(void* menu);
|
||||
VQT6_API void vqt6_qmenu_set_title(void* menu, void* title);
|
||||
VQT6_API void* vqt6_qmenu_title(void* menu);
|
||||
VQT6_API void* vqt6_qmenu_add_action_with_text(void* menu, void* text);
|
||||
|
||||
VQT6_API void* vqt6_qaction_create(void);
|
||||
VQT6_API void* vqt6_qaction_create_with_text(void* text);
|
||||
VQT6_API void* vqt6_qaction_create_with_text_parent(void* text, void* parent);
|
||||
VQT6_API void vqt6_qaction_set_text(void* action, void* text);
|
||||
VQT6_API void* vqt6_qaction_text(void* action);
|
||||
VQT6_API void vqt6_qaction_set_icon(void* action, void* icon);
|
||||
VQT6_API void* vqt6_qaction_icon(void* action);
|
||||
VQT6_API void vqt6_qaction_set_shortcut(void* action, void* key_sequence);
|
||||
VQT6_API void* vqt6_qaction_shortcut(void* action);
|
||||
VQT6_API void vqt6_qaction_set_checkable(void* action, int checkable);
|
||||
VQT6_API int vqt6_qaction_is_checkable(void* action);
|
||||
VQT6_API void vqt6_qaction_set_checked(void* action, int checked);
|
||||
VQT6_API int vqt6_qaction_is_checked(void* action);
|
||||
VQT6_API void vqt6_qaction_set_enabled(void* action, int enabled);
|
||||
VQT6_API int vqt6_qaction_is_enabled(void* action);
|
||||
VQT6_API void vqt6_qaction_trigger(void* action);
|
||||
|
||||
// ============================================================
|
||||
// QStatusBar / QToolBar
|
||||
// ============================================================
|
||||
VQT6_API void* vqt6_qstatusbar_create(void);
|
||||
VQT6_API void* vqt6_qstatusbar_create_with_parent(void* parent);
|
||||
VQT6_API void vqt6_qstatusbar_show_message(void* sb, void* message, int timeout_ms);
|
||||
VQT6_API void vqt6_qstatusbar_clear_message(void* sb);
|
||||
VQT6_API void* vqt6_qstatusbar_current_message(void* sb);
|
||||
VQT6_API void vqt6_qstatusbar_add_widget(void* sb, void* w, int stretch);
|
||||
VQT6_API void vqt6_qstatusbar_add_permanent_widget(void* sb, void* w, int stretch);
|
||||
|
||||
VQT6_API void* vqt6_qtoolbar_create(void);
|
||||
VQT6_API void* vqt6_qtoolbar_create_with_parent(void* parent);
|
||||
VQT6_API void* vqt6_qtoolbar_add_widget(void* tb, void* w);
|
||||
VQT6_API void vqt6_qtoolbar_add_action(void* tb, void* action);
|
||||
VQT6_API void vqt6_qtoolbar_add_separator(void* tb);
|
||||
VQT6_API void vqt6_qtoolbar_set_icon_size(void* tb, int w, int h);
|
||||
VQT6_API void vqt6_qtoolbar_set_orientation(void* tb, int orientation);
|
||||
VQT6_API int vqt6_qtoolbar_orientation(void* tb);
|
||||
|
||||
// ============================================================
|
||||
// QMessageBox
|
||||
// ============================================================
|
||||
VQT6_API int vqt6_qmessagebox_information(void* parent, void* title, void* text, int buttons);
|
||||
VQT6_API int vqt6_qmessagebox_warning(void* parent, void* title, void* text, int buttons);
|
||||
VQT6_API int vqt6_qmessagebox_critical(void* parent, void* title, void* text, int buttons);
|
||||
VQT6_API int vqt6_qmessagebox_question(void* parent, void* title, void* text, int buttons);
|
||||
VQT6_API void vqt6_qmessagebox_about(void* parent, void* title, void* text);
|
||||
VQT6_API void vqt6_qmessagebox_about_qt(void* parent);
|
||||
|
||||
// ============================================================
|
||||
// QFileDialog
|
||||
// ============================================================
|
||||
VQT6_API void* vqt6_qfiledialog_get_open_file_name(void* parent, void* caption, void* dir, void* filter);
|
||||
VQT6_API void* vqt6_qfiledialog_get_save_file_name(void* parent, void* caption, void* dir, void* filter);
|
||||
VQT6_API void* vqt6_qfiledialog_get_existing_directory(void* parent, void* caption, void* dir);
|
||||
VQT6_API void* vqt6_qfiledialog_get_open_file_names(void* parent, void* caption, void* dir, void* filter);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // VQT6_BRIDGE_WIDGETS_H
|
||||
157
includes/vqt6 copy/_qtcore.py
Normal file
157
includes/vqt6 copy/_qtcore.py
Normal file
@@ -0,0 +1,157 @@
|
||||
import t, c
|
||||
from stdint import *
|
||||
from vqt6._types import *
|
||||
|
||||
# ============================================================
|
||||
# vqt6/_qtcore.py — QtCore 的 t.State FFI 声明
|
||||
#
|
||||
# 所有函数都是 C 桥接层 (libvqt6_bridge.a) 的 extern "C" 函数
|
||||
# 命名规范: vqt6_<class>_<action>
|
||||
# ============================================================
|
||||
|
||||
# ============================================================
|
||||
# QString — UTF-16 字符串
|
||||
# ============================================================
|
||||
# 创建 QString(从 UTF-8 C 字符串)
|
||||
def vqt6_qstring_create(utf8: t.CChar | t.CPtr) -> QtStringPtr | t.State: pass
|
||||
|
||||
# 获取 QString 的 UTF-8 表示(写入 buf,返回实际长度,不含 \0)
|
||||
# buf 需足够大(建议 4 * qstring.length() + 1)
|
||||
def vqt6_qstring_to_utf8(qstr: QtStringPtr, buf: t.CChar | t.CPtr, buf_size: t.CSizeT) -> t.CSizeT | t.State: pass
|
||||
|
||||
# 释放 QString
|
||||
def vqt6_qstring_free(qstr: QtStringPtr) -> t.State: pass
|
||||
|
||||
# 获取 QString 字符数
|
||||
def vqt6_qstring_length(qstr: QtStringPtr) -> t.CInt | t.State: pass
|
||||
|
||||
# QString 是否为空
|
||||
def vqt6_qstring_is_empty(qstr: QtStringPtr) -> t.CInt | t.State: pass
|
||||
|
||||
# QString 比较
|
||||
def vqt6_qstring_equals(qstr: QtStringPtr, other: QtStringPtr) -> t.CInt | t.State: pass
|
||||
|
||||
# QString 拼接(返回新 QString)
|
||||
def vqt6_qstring_append(qstr: QtStringPtr, other: QtStringPtr) -> QtStringPtr | t.State: pass
|
||||
|
||||
|
||||
# ============================================================
|
||||
# QByteArray — 字节数组
|
||||
# ============================================================
|
||||
def vqt6_qbytearray_create(data: t.CVoid | t.CPtr, size: t.CSizeT) -> QtByteArrayPtr | t.State: pass
|
||||
def vqt6_qbytearray_data(qba: QtByteArrayPtr, out_size: t.CSizeT | t.CPtr) -> t.CVoid | t.CPtr | t.State: pass
|
||||
def vqt6_qbytearray_size(qba: QtByteArrayPtr) -> t.CSizeT | t.State: pass
|
||||
def vqt6_qbytearray_free(qba: QtByteArrayPtr) -> t.State: pass
|
||||
|
||||
|
||||
# ============================================================
|
||||
# QObject — 所有 Qt 对象的基类
|
||||
# ============================================================
|
||||
# 注意: Qt 对象的内存由 C++ 管理,Viper 端不应直接 free
|
||||
def vqt6_qobject_delete(obj: QtObjectPtr) -> t.State: pass
|
||||
def vqt6_qobject_delete_later(obj: QtObjectPtr) -> t.State: pass
|
||||
def vqt6_qobject_set_object_name(obj: QtObjectPtr, name: QtStringPtr) -> t.State: pass
|
||||
def vqt6_qobject_object_name(obj: QtObjectPtr) -> QtStringPtr | t.State: pass
|
||||
def vqt6_qobject_set_parent(child: QtObjectPtr, parent: QtObjectPtr) -> t.State: pass
|
||||
def vqt6_qobject_parent(obj: QtObjectPtr) -> QtObjectPtr | t.State: pass
|
||||
|
||||
# 信号/槽连接 (简化版: 函数指针形式)
|
||||
# typedef void (*vqt6_callback_t)(void* user_data);
|
||||
# vqt6_qobject_connect_typed(sender, signal_id, receiver, slot_id, type) 由 C++ 桥接层处理
|
||||
# 由于函数指针在 C ABI 中复杂,我们采用字符串 signal/slot 名 + 全局回调注册表
|
||||
def vqt6_qobject_connect(sender: QtObjectPtr, signal_name: t.CChar | t.CPtr,
|
||||
receiver: QtObjectPtr, slot_name: t.CChar | t.CPtr) -> t.CInt | t.State: pass
|
||||
|
||||
def vqt6_qobject_disconnect(sender: QtObjectPtr, signal_name: t.CChar | t.CPtr,
|
||||
receiver: QtObjectPtr, slot_name: t.CChar | t.CPtr) -> t.CInt | t.State: pass
|
||||
|
||||
# 事件过滤器
|
||||
def vqt6_qobject_install_event_filter(watched: QtObjectPtr, filter: QtObjectPtr) -> t.State: pass
|
||||
def vqt6_qobject_remove_event_filter(watched: QtObjectPtr, filter: QtObjectPtr) -> t.State: pass
|
||||
|
||||
|
||||
# ============================================================
|
||||
# QCoreApplication — 事件循环基类
|
||||
# ============================================================
|
||||
def vqt6_qcoreapp_create(app_name: t.CChar | t.CPtr) -> QtCoreAppPtr | t.State: pass
|
||||
def vqt6_qcoreapp_instance() -> QtCoreAppPtr | t.State: pass
|
||||
def vqt6_qcoreapp_exec(app: QtCoreAppPtr) -> t.CInt | t.State: pass
|
||||
def vqt6_qcoreapp_quit(app: QtCoreAppPtr, exit_code: t.CInt) -> t.State: pass
|
||||
def vqt6_qcoreapp_exit(app: QtCoreAppPtr, exit_code: t.CInt) -> t.State: pass
|
||||
def vqt6_qcoreapp_process_events(app: QtCoreAppPtr, flags: t.CInt) -> t.State: pass
|
||||
def vqt6_qcoreapp_post_event(receiver: QtObjectPtr, event: QtEventPtr) -> t.State: pass
|
||||
def vqt6_qcoreapp_send_event(receiver: QtObjectPtr, event: QtEventPtr) -> t.CInt | t.State: pass
|
||||
def vqt6_qcoreapp_organization_name(app: QtCoreAppPtr) -> QtStringPtr | t.State: pass
|
||||
def vqt6_qcoreapp_set_organization_name(app: QtCoreAppPtr, name: QtStringPtr) -> t.State: pass
|
||||
def vqt6_qcoreapp_application_name(app: QtCoreAppPtr) -> QtStringPtr | t.State: pass
|
||||
def vqt6_qcoreapp_set_application_name(app: QtCoreAppPtr, name: QtStringPtr) -> t.State: pass
|
||||
|
||||
|
||||
# ============================================================
|
||||
# QTimer — 定时器
|
||||
# ============================================================
|
||||
def vqt6_qtimer_create() -> QtTimerPtr | t.State: pass
|
||||
def vqt6_qtimer_create_with_parent(parent: QtObjectPtr) -> QtTimerPtr | t.State: pass
|
||||
def vqt6_qtimer_start(timer: QtTimerPtr, interval_ms: t.CInt) -> t.State: pass
|
||||
def vqt6_qtimer_stop(timer: QtTimerPtr) -> t.State: pass
|
||||
def vqt6_qtimer_set_interval(timer: QtTimerPtr, interval_ms: t.CInt) -> t.State: pass
|
||||
def vqt6_qtimer_interval(timer: QtTimerPtr) -> t.CInt | t.State: pass
|
||||
def vqt6_qtimer_is_active(timer: QtTimerPtr) -> t.CInt | t.State: pass
|
||||
def vqt6_qtimer_set_single_shot(timer: QtTimerPtr, single_shot: t.CInt) -> t.State: pass
|
||||
def vqt6_qtimer_is_single_shot(timer: QtTimerPtr) -> t.CInt | t.State: pass
|
||||
|
||||
|
||||
# ============================================================
|
||||
# QVariant — 通用数据容器
|
||||
# ============================================================
|
||||
def vqt6_qvariant_create_int(value: t.CInt) -> QtVariantPtr | t.State: pass
|
||||
def vqt6_qvariant_create_double(value: t.CDouble) -> QtVariantPtr | t.State: pass
|
||||
def vqt6_qvariant_create_bool(value: t.CInt) -> QtVariantPtr | t.State: pass
|
||||
def vqt6_qvariant_create_string(s: QtStringPtr) -> QtVariantPtr | t.State: pass
|
||||
def vqt6_qvariant_to_int(v: QtVariantPtr, ok: t.CInt | t.CPtr) -> t.CInt | t.State: pass
|
||||
def vqt6_qvariant_to_double(v: QtVariantPtr, ok: t.CInt | t.CPtr) -> t.CDouble | t.State: pass
|
||||
def vqt6_qvariant_to_bool(v: QtVariantPtr, ok: t.CInt | t.CPtr) -> t.CInt | t.State: pass
|
||||
def vqt6_qvariant_to_string(v: QtVariantPtr) -> QtStringPtr | t.State: pass
|
||||
def vqt6_qvariant_type_id(v: QtVariantPtr) -> t.CInt | t.State: pass
|
||||
def vqt6_qvariant_is_valid(v: QtVariantPtr) -> t.CInt | t.State: pass
|
||||
def vqt6_qvariant_free(v: QtVariantPtr) -> t.State: pass
|
||||
|
||||
|
||||
# ============================================================
|
||||
# QEvent — 事件基类
|
||||
# ============================================================
|
||||
def vqt6_qevent_type(event: QtEventPtr) -> t.CInt | t.State: pass
|
||||
def vqt6_qevent_accept(event: QtEventPtr) -> t.State: pass
|
||||
def vqt6_qevent_ignore(event: QtEventPtr) -> t.State: pass
|
||||
def vqt6_qevent_is_accepted(event: QtEventPtr) -> t.CInt | t.State: pass
|
||||
|
||||
|
||||
# ============================================================
|
||||
# 字符串列表 (QStringList / QList<QString>)
|
||||
# ============================================================
|
||||
def vqt6_qstringlist_create() -> QtStringListPtr | t.State: pass
|
||||
def vqt6_qstringlist_append(list: QtStringListPtr, str: QtStringPtr) -> t.State: pass
|
||||
def vqt6_qstringlist_size(list: QtStringListPtr) -> t.CInt | t.State: pass
|
||||
def vqt6_qstringlist_at(list: QtStringListPtr, index: t.CInt) -> QtStringPtr | t.State: pass
|
||||
def vqt6_qstringlist_free(list: QtStringListPtr) -> t.State: pass
|
||||
|
||||
|
||||
# ============================================================
|
||||
# 字节数组列表 (QList<QByteArray>)
|
||||
# ============================================================
|
||||
def vqt6_qbytearraylist_create() -> QtByteArrayListPtr | t.State: pass
|
||||
def vqt6_qbytearraylist_append(list: QtByteArrayListPtr, qba: QtByteArrayPtr) -> t.State: pass
|
||||
def vqt6_qbytearraylist_size(list: QtByteArrayListPtr) -> t.CInt | t.State: pass
|
||||
def vqt6_qbytearraylist_at(list: QtByteArrayListPtr, index: t.CInt) -> QtByteArrayPtr | t.State: pass
|
||||
def vqt6_qbytearraylist_free(list: QtByteArrayListPtr) -> t.State: pass
|
||||
|
||||
|
||||
# ============================================================
|
||||
# 全局回调注册表
|
||||
# ============================================================
|
||||
# 用于从 C++ 端回调 Viper 代码
|
||||
# Viper 注册一个 slot 函数(用整数 ID 标识),C++ 在触发信号时通过 ID 查找
|
||||
# typedef void (*vqt6_slot_callback_t)(int slot_id, void* user_data);
|
||||
def vqt6_register_slot(slot_id: t.CInt, user_data: t.CVoid | t.CPtr) -> t.State: pass
|
||||
def vqt6_unregister_slot(slot_id: t.CInt) -> t.State: pass
|
||||
def vqt6_trigger_slot(slot_id: t.CInt) -> t.State: pass # 测试用
|
||||
237
includes/vqt6 copy/_qtgui.py
Normal file
237
includes/vqt6 copy/_qtgui.py
Normal file
@@ -0,0 +1,237 @@
|
||||
import t, c
|
||||
from stdint import *
|
||||
from vqt6._types import *
|
||||
|
||||
# ============================================================
|
||||
# vqt6/_qtgui.py — QtGui 的 t.State FFI 声明
|
||||
# ============================================================
|
||||
|
||||
# ============================================================
|
||||
# QColor — 颜色
|
||||
# ============================================================
|
||||
def vqt6_qcolor_create_rgb(r: t.CInt, g: t.CInt, b: t.CInt) -> QtColorPtr | t.State: pass
|
||||
def vqt6_qcolor_create_rgba(r: t.CInt, g: t.CInt, b: t.CInt, a: t.CInt) -> QtColorPtr | t.State: pass
|
||||
def vqt6_qcolor_create_name(name: QtStringPtr) -> QtColorPtr | t.State: pass
|
||||
def vqt6_qcolor_create_hex(hex_str: QtStringPtr) -> QtColorPtr | t.State: pass
|
||||
def vqt6_qcolor_red(c: QtColorPtr) -> t.CInt | t.State: pass
|
||||
def vqt6_qcolor_green(c: QtColorPtr) -> t.CInt | t.State: pass
|
||||
def vqt6_qcolor_blue(c: QtColorPtr) -> t.CInt | t.State: pass
|
||||
def vqt6_qcolor_alpha(c: QtColorPtr) -> t.CInt | t.State: pass
|
||||
def vqt6_qcolor_set_red(c: QtColorPtr, r: t.CInt) -> t.State: pass
|
||||
def vqt6_qcolor_set_green(c: QtColorPtr, g: t.CInt) -> t.State: pass
|
||||
def vqt6_qcolor_set_blue(c: QtColorPtr, b: t.CInt) -> t.State: pass
|
||||
def vqt6_qcolor_set_alpha(c: QtColorPtr, a: t.CInt) -> t.State: pass
|
||||
def vqt6_qcolor_set_rgb(c: QtColorPtr, r: t.CInt, g: t.CInt, b: t.CInt) -> t.State: pass
|
||||
def vqt6_qcolor_set_rgba(c: QtColorPtr, r: t.CInt, g: t.CInt, b: t.CInt, a: t.CInt) -> t.State: pass
|
||||
def vqt6_qcolor_name(c: QtColorPtr) -> QtStringPtr | t.State: pass
|
||||
def vqt6_qcolor_is_valid(c: QtColorPtr) -> t.CInt | t.State: pass
|
||||
def vqt6_qcolor_free(c: QtColorPtr) -> t.State: pass
|
||||
|
||||
|
||||
# ============================================================
|
||||
# QFont — 字体
|
||||
# ============================================================
|
||||
def vqt6_qfont_create() -> QtFontPtr | t.State: pass
|
||||
def vqt6_qfont_create_with_family(family: QtStringPtr) -> QtFontPtr | t.State: pass
|
||||
def vqt6_qfont_create_with_family_size(family: QtStringPtr, point_size: t.CInt) -> QtFontPtr | t.State: pass
|
||||
def vqt6_qfont_set_family(font: QtFontPtr, family: QtStringPtr) -> t.State: pass
|
||||
def vqt6_qfont_family(font: QtFontPtr) -> QtStringPtr | t.State: pass
|
||||
def vqt6_qfont_set_point_size(font: QtFontPtr, point_size: t.CInt) -> t.State: pass
|
||||
def vqt6_qfont_point_size(font: QtFontPtr) -> t.CInt | t.State: pass
|
||||
def vqt6_qfont_set_pixel_size(font: QtFontPtr, pixel_size: t.CInt) -> t.State: pass
|
||||
def vqt6_qfont_pixel_size(font: QtFontPtr) -> t.CInt | t.State: pass
|
||||
def vqt6_qfont_set_bold(font: QtFontPtr, bold: t.CInt) -> t.State: pass
|
||||
def vqt6_qfont_bold(font: QtFontPtr) -> t.CInt | t.State: pass
|
||||
def vqt6_qfont_set_italic(font: QtFontPtr, italic: t.CInt) -> t.State: pass
|
||||
def vqt6_qfont_italic(font: QtFontPtr) -> t.CInt | t.State: pass
|
||||
def vqt6_qfont_set_underline(font: QtFontPtr, underline: t.CInt) -> t.State: pass
|
||||
def vqt6_qfont_underline(font: QtFontPtr) -> t.CInt | t.State: pass
|
||||
def vqt6_qfont_set_strike_out(font: QtFontPtr, strike_out: t.CInt) -> t.State: pass
|
||||
def vqt6_qfont_strike_out(font: QtFontPtr) -> t.CInt | t.State: pass
|
||||
def vqt6_qfont_set_weight(font: QtFontPtr, weight: t.CInt) -> t.State: pass
|
||||
def vqt6_qfont_weight(font: QtFontPtr) -> t.CInt | t.State: pass
|
||||
def vqt6_qfont_free(font: QtFontPtr) -> t.State: pass
|
||||
|
||||
|
||||
# ============================================================
|
||||
# QFontMetrics — 字体度量
|
||||
# ============================================================
|
||||
def vqt6_qfontmetrics_create(font: QtFontPtr) -> QtFontMetricsPtr | t.State: pass
|
||||
def vqt6_qfontmetrics_width(fm: QtFontMetricsPtr, text: QtStringPtr) -> t.CInt | t.State: pass
|
||||
def vqt6_qfontmetrics_height(fm: QtFontMetricsPtr) -> t.CInt | t.State: pass
|
||||
def vqt6_qfontmetrics_ascent(fm: QtFontMetricsPtr) -> t.CInt | t.State: pass
|
||||
def vqt6_qfontmetrics_descent(fm: QtFontMetricsPtr) -> t.CInt | t.State: pass
|
||||
def vqt6_qfontmetrics_free(fm: QtFontMetricsPtr) -> t.State: pass
|
||||
|
||||
|
||||
# ============================================================
|
||||
# QPixmap — 像素图
|
||||
# ============================================================
|
||||
def vqt6_qpixmap_create() -> QtPixmapPtr | t.State: pass
|
||||
def vqt6_qpixmap_create_with_size(w: t.CInt, h: t.CInt) -> QtPixmapPtr | t.State: pass
|
||||
def vqt6_qpixmap_load(pm: QtPixmapPtr, file_name: QtStringPtr) -> t.CInt | t.State: pass
|
||||
def vqt6_qpixmap_load_from_data(pm: QtPixmapPtr, data: t.CVoid | t.CPtr, size: t.CSizeT) -> t.CInt | t.State: pass
|
||||
def vqt6_qpixmap_save(pm: QtPixmapPtr, file_name: QtStringPtr) -> t.CInt | t.State: pass
|
||||
def vqt6_qpixmap_width(pm: QtPixmapPtr) -> t.CInt | t.State: pass
|
||||
def vqt6_qpixmap_height(pm: QtPixmapPtr) -> t.CInt | t.State: pass
|
||||
def vqt6_qpixmap_is_null(pm: QtPixmapPtr) -> t.CInt | t.State: pass
|
||||
def vqt6_qpixmap_scaled(pm: QtPixmapPtr, w: t.CInt, h: t.CInt) -> QtPixmapPtr | t.State: pass
|
||||
def vqt6_qpixmap_fill(pm: QtPixmapPtr, color: QtColorPtr) -> t.State: pass
|
||||
def vqt6_qpixmap_free(pm: QtPixmapPtr) -> t.State: pass
|
||||
|
||||
|
||||
# ============================================================
|
||||
# QImage — 图像
|
||||
# ============================================================
|
||||
def vqt6_qimage_create() -> QtImagePtr | t.State: pass
|
||||
def vqt6_qimage_create_with_size(w: t.CInt, h: t.CInt, format: t.CInt) -> QtImagePtr | t.State: pass
|
||||
def vqt6_qimage_load(img: QtImagePtr, file_name: QtStringPtr) -> t.CInt | t.State: pass
|
||||
def vqt6_qimage_save(img: QtImagePtr, file_name: QtStringPtr) -> t.CInt | t.State: pass
|
||||
def vqt6_qimage_width(img: QtImagePtr) -> t.CInt | t.State: pass
|
||||
def vqt6_qimage_height(img: QtImagePtr) -> t.CInt | t.State: pass
|
||||
def vqt6_qimage_format(img: QtImagePtr) -> t.CInt | t.State: pass
|
||||
def vqt6_qimage_is_null(img: QtImagePtr) -> t.CInt | t.State: pass
|
||||
def vqt6_qimage_fill(img: QtImagePtr, color: QtColorPtr) -> t.State: pass
|
||||
def vqt6_qimage_scaled(img: QtImagePtr, w: t.CInt, h: t.CInt) -> QtImagePtr | t.State: pass
|
||||
def vqt6_qimage_free(img: QtImagePtr) -> t.State: pass
|
||||
|
||||
|
||||
# ============================================================
|
||||
# QPainter — 绘画器
|
||||
# ============================================================
|
||||
def vqt6_qpainter_create() -> QtPainterPtr | t.State: pass
|
||||
def vqt6_qpainter_begin(p: QtPainterPtr, device: QtPixmapPtr) -> t.CInt | t.State: pass
|
||||
def vqt6_qpainter_end(p: QtPainterPtr) -> t.CInt | t.State: pass
|
||||
def vqt6_qpainter_is_active(p: QtPainterPtr) -> t.CInt | t.State: pass
|
||||
def vqt6_qpainter_set_pen(p: QtPainterPtr, pen: QtPenPtr) -> t.State: pass
|
||||
def vqt6_qpainter_set_brush(p: QtPainterPtr, brush: QtBrushPtr) -> t.State: pass
|
||||
def vqt6_qpainter_set_font(p: QtPainterPtr, font: QtFontPtr) -> t.State: pass
|
||||
def vqt6_qpainter_pen(p: QtPainterPtr) -> QtPenPtr | t.State: pass
|
||||
def vqt6_qpainter_brush(p: QtPainterPtr) -> QtBrushPtr | t.State: pass
|
||||
def vqt6_qpainter_font(p: QtPainterPtr) -> QtFontPtr | t.State: pass
|
||||
def vqt6_qpainter_set_opacity(p: QtPainterPtr, opacity: t.CDouble) -> t.State: pass
|
||||
def vqt6_qpainter_opacity(p: QtPainterPtr) -> t.CDouble | t.State: pass
|
||||
|
||||
# 绘图原语
|
||||
def vqt6_qpainter_draw_line(p: QtPainterPtr, x1: t.CInt, y1: t.CInt, x2: t.CInt, y2: t.CInt) -> t.State: pass
|
||||
def vqt6_qpainter_draw_rect(p: QtPainterPtr, x: t.CInt, y: t.CInt, w: t.CInt, h: t.CInt) -> t.State: pass
|
||||
def vqt6_qpainter_fill_rect(p: QtPainterPtr, x: t.CInt, y: t.CInt, w: t.CInt, h: t.CInt, color: QtColorPtr) -> t.State: pass
|
||||
def vqt6_qpainter_draw_ellipse(p: QtPainterPtr, x: t.CInt, y: t.CInt, w: t.CInt, h: t.CInt) -> t.State: pass
|
||||
def vqt6_qpainter_draw_arc(p: QtPainterPtr, x: t.CInt, y: t.CInt, w: t.CInt, h: t.CInt, start_angle: t.CInt, span_angle: t.CInt) -> t.State: pass
|
||||
def vqt6_qpainter_draw_chord(p: QtPainterPtr, x: t.CInt, y: t.CInt, w: t.CInt, h: t.CInt, start_angle: t.CInt, span_angle: t.CInt) -> t.State: pass
|
||||
def vqt6_qpainter_draw_pie(p: QtPainterPtr, x: t.CInt, y: t.CInt, w: t.CInt, h: t.CInt, start_angle: t.CInt, span_angle: t.CInt) -> t.State: pass
|
||||
def vqt6_qpainter_draw_polygon(p: QtPainterPtr, points: t.CInt | t.CPtr, point_count: t.CInt) -> t.State: pass
|
||||
def vqt6_qpainter_draw_polyline(p: QtPainterPtr, points: t.CInt | t.CPtr, point_count: t.CInt) -> t.State: pass
|
||||
def vqt6_qpainter_draw_point(p: QtPainterPtr, x: t.CInt, y: t.CInt) -> t.State: pass
|
||||
def vqt6_qpainter_draw_points(p: QtPainterPtr, points: t.CInt | t.CPtr, point_count: t.CInt) -> t.State: pass
|
||||
def vqt6_qpainter_draw_text(p: QtPainterPtr, x: t.CInt, y: t.CInt, text: QtStringPtr) -> t.State: pass
|
||||
def vqt6_qpainter_draw_text_in_rect(p: QtPainterPtr, x: t.CInt, y: t.CInt, w: t.CInt, h: t.CInt, flags: t.CInt, text: QtStringPtr) -> t.State: pass
|
||||
def vqt6_qpainter_draw_pixmap(p: QtPainterPtr, x: t.CInt, y: t.CInt, pixmap: QtPixmapPtr) -> t.State: pass
|
||||
def vqt6_qpainter_draw_image(p: QtPainterPtr, x: t.CInt, y: t.CInt, image: QtImagePtr) -> t.State: pass
|
||||
def vqt6_qpainter_draw_tiled_pixmap(p: QtPainterPtr, x: t.CInt, y: t.CInt, w: t.CInt, h: t.CInt, pixmap: QtPixmapPtr) -> t.State: pass
|
||||
|
||||
# 变换
|
||||
def vqt6_qpainter_translate(p: QtPainterPtr, dx: t.CInt, dy: t.CInt) -> t.State: pass
|
||||
def vqt6_qpainter_rotate(p: QtPainterPtr, angle: t.CDouble) -> t.State: pass
|
||||
def vqt6_qpainter_scale(p: QtPainterPtr, sx: t.CDouble, sy: t.CDouble) -> t.State: pass
|
||||
def vqt6_qpainter_reset_transform(p: QtPainterPtr) -> t.State: pass
|
||||
def vqt6_qpainter_save(p: QtPainterPtr) -> t.State: pass
|
||||
def vqt6_qpainter_restore(p: QtPainterPtr) -> t.State: pass
|
||||
|
||||
def vqt6_qpainter_free(p: QtPainterPtr) -> t.State: pass
|
||||
|
||||
|
||||
# ============================================================
|
||||
# QPen — 画笔
|
||||
# ============================================================
|
||||
def vqt6_qpen_create() -> QtPenPtr | t.State: pass
|
||||
def vqt6_qpen_create_with_color(color: QtColorPtr) -> QtPenPtr | t.State: pass
|
||||
def vqt6_qpen_create_with_color_width(color: QtColorPtr, width: t.CInt) -> QtPenPtr | t.State: pass
|
||||
def vqt6_qpen_set_color(pen: QtPenPtr, color: QtColorPtr) -> t.State: pass
|
||||
def vqt6_qpen_color(pen: QtPenPtr) -> QtColorPtr | t.State: pass
|
||||
def vqt6_qpen_set_width(pen: QtPenPtr, width: t.CInt) -> t.State: pass
|
||||
def vqt6_qpen_width(pen: QtPenPtr) -> t.CInt | t.State: pass
|
||||
def vqt6_qpen_set_style(pen: QtPenPtr, style: t.CInt) -> t.State: pass
|
||||
def vqt6_qpen_style(pen: QtPenPtr) -> t.CInt | t.State: pass
|
||||
def vqt6_qpen_free(pen: QtPenPtr) -> t.State: pass
|
||||
|
||||
|
||||
# ============================================================
|
||||
# QBrush — 画刷
|
||||
# ============================================================
|
||||
def vqt6_qbrush_create() -> QtBrushPtr | t.State: pass
|
||||
def vqt6_qbrush_create_with_color(color: QtColorPtr) -> QtBrushPtr | t.State: pass
|
||||
def vqt6_qbrush_create_with_style(style: t.CInt) -> QtBrushPtr | t.State: pass
|
||||
def vqt6_qbrush_set_color(brush: QtBrushPtr, color: QtColorPtr) -> t.State: pass
|
||||
def vqt6_qbrush_color(brush: QtBrushPtr) -> QtColorPtr | t.State: pass
|
||||
def vqt6_qbrush_set_style(brush: QtBrushPtr, style: t.CInt) -> t.State: pass
|
||||
def vqt6_qbrush_style(brush: QtBrushPtr) -> t.CInt | t.State: pass
|
||||
def vqt6_qbrush_free(brush: QtBrushPtr) -> t.State: pass
|
||||
|
||||
|
||||
# ============================================================
|
||||
# QIcon — 图标
|
||||
# ============================================================
|
||||
def vqt6_qicon_create() -> QtIconPtr | t.State: pass
|
||||
def vqt6_qicon_create_with_file(file_name: QtStringPtr) -> QtIconPtr | t.State: pass
|
||||
def vqt6_qicon_add_file(icon: QtIconPtr, file_name: QtStringPtr) -> t.State: pass
|
||||
def vqt6_qicon_add_pixmap(icon: QtIconPtr, pixmap: QtPixmapPtr) -> t.State: pass
|
||||
def vqt6_qicon_is_null(icon: QtIconPtr) -> t.CInt | t.State: pass
|
||||
def vqt6_qicon_pixmap(icon: QtIconPtr, w: t.CInt, h: t.CInt) -> QtPixmapPtr | t.State: pass
|
||||
def vqt6_qicon_free(icon: QtIconPtr) -> t.State: pass
|
||||
|
||||
|
||||
# ============================================================
|
||||
# QCursor — 鼠标光标
|
||||
# ============================================================
|
||||
def vqt6_qcursor_create() -> QtCursorPtr | t.State: pass
|
||||
def vqt6_qcursor_create_with_shape(shape: t.CInt) -> QtCursorPtr | t.State: pass
|
||||
def vqt6_qcursor_pos(x: t.CInt | t.CPtr, y: t.CInt | t.CPtr) -> t.State: pass
|
||||
def vqt6_qcursor_set_pos(x: t.CInt, y: t.CInt) -> t.State: pass
|
||||
def vqt6_qcursor_set_shape(cursor: QtCursorPtr, shape: t.CInt) -> t.State: pass
|
||||
def vqt6_qcursor_shape(cursor: QtCursorPtr) -> t.CInt | t.State: pass
|
||||
def vqt6_qcursor_free(cursor: QtCursorPtr) -> t.State: pass
|
||||
|
||||
|
||||
# ============================================================
|
||||
# QKeyEvent — 键盘事件
|
||||
# ============================================================
|
||||
def vqt6_qkeyevent_create(type: t.CInt, key: t.CInt, modifiers: t.CInt, text: QtStringPtr) -> QtKeyEventPtr | t.State: pass
|
||||
def vqt6_qkeyevent_key(event: QtKeyEventPtr) -> t.CInt | t.State: pass
|
||||
def vqt6_qkeyevent_text(event: QtKeyEventPtr) -> QtStringPtr | t.State: pass
|
||||
def vqt6_qkeyevent_modifiers(event: QtKeyEventPtr) -> t.CInt | t.State: pass
|
||||
def vqt6_qkeyevent_is_auto_repeat(event: QtKeyEventPtr) -> t.CInt | t.State: pass
|
||||
def vqt6_qkeyevent_free(event: QtKeyEventPtr) -> t.State: pass
|
||||
|
||||
|
||||
# ============================================================
|
||||
# QMouseEvent — 鼠标事件
|
||||
# ============================================================
|
||||
def vqt6_qmouseevent_create(type: t.CInt, local_pos: QtObjectPtr, button: t.CInt, buttons: t.CInt, modifiers: t.CInt) -> QtMouseEventPtr | t.State: pass
|
||||
def vqt6_qmouseevent_button(event: QtMouseEventPtr) -> t.CInt | t.State: pass
|
||||
def vqt6_qmouseevent_buttons(event: QtMouseEventPtr) -> t.CInt | t.State: pass
|
||||
def vqt6_qmouseevent_x(event: QtMouseEventPtr) -> t.CInt | t.State: pass
|
||||
def vqt6_qmouseevent_y(event: QtMouseEventPtr) -> t.CInt | t.State: pass
|
||||
def vqt6_qmouseevent_global_x(event: QtMouseEventPtr) -> t.CInt | t.State: pass
|
||||
def vqt6_qmouseevent_global_y(event: QtMouseEventPtr) -> t.CInt | t.State: pass
|
||||
def vqt6_qmouseevent_modifiers(event: QtMouseEventPtr) -> t.CInt | t.State: pass
|
||||
def vqt6_qmouseevent_free(event: QtMouseEventPtr) -> t.State: pass
|
||||
|
||||
|
||||
# ============================================================
|
||||
# QResizeEvent / QPaintEvent / QCloseEvent
|
||||
# ============================================================
|
||||
def vqt6_qresizeevent_create(width: t.CInt, height: t.CInt, old_width: t.CInt, old_height: t.CInt) -> QtResizeEventPtr | t.State: pass
|
||||
def vqt6_qresizeevent_size(event: QtResizeEventPtr, w: t.CInt | t.CPtr, h: t.CInt | t.CPtr) -> t.State: pass
|
||||
def vqt6_qresizeevent_old_size(event: QtResizeEventPtr, w: t.CInt | t.CPtr, h: t.CInt | t.CPtr) -> t.State: pass
|
||||
def vqt6_qresizeevent_free(event: QtResizeEventPtr) -> t.State: pass
|
||||
|
||||
def vqt6_qpaintevent_create(rect_x: t.CInt, rect_y: t.CInt, rect_w: t.CInt, rect_h: t.CInt) -> QtPaintEventPtr | t.State: pass
|
||||
def vqt6_qpaintevent_rect(event: QtPaintEventPtr, x: t.CInt | t.CPtr, y: t.CInt | t.CPtr, w: t.CInt | t.CPtr, h: t.CInt | t.CPtr) -> t.State: pass
|
||||
def vqt6_qpaintevent_free(event: QtPaintEventPtr) -> t.State: pass
|
||||
|
||||
def vqt6_qcloseevent_create() -> QtCloseEventPtr | t.State: pass
|
||||
def vqt6_qcloseevent_is_accepted(event: QtCloseEventPtr) -> t.CInt | t.State: pass
|
||||
def vqt6_qcloseevent_accept(event: QtCloseEventPtr) -> t.State: pass
|
||||
def vqt6_qcloseevent_ignore(event: QtCloseEventPtr) -> t.State: pass
|
||||
def vqt6_qcloseevent_free(event: QtCloseEventPtr) -> t.State: pass
|
||||
184
includes/vqt6 copy/_qtnetwork.py
Normal file
184
includes/vqt6 copy/_qtnetwork.py
Normal file
@@ -0,0 +1,184 @@
|
||||
import t, c
|
||||
from stdint import *
|
||||
from vqt6._types import *
|
||||
|
||||
# ============================================================
|
||||
# vqt6/_qtnetwork.py — QtNetwork 的 t.State FFI 声明
|
||||
# ============================================================
|
||||
|
||||
# ============================================================
|
||||
# QHostAddress — IP 地址
|
||||
# ============================================================
|
||||
def vqt6_qhostaddress_create() -> QtHostAddressPtr | t.State: pass
|
||||
def vqt6_qhostaddress_create_with_ipv4(ipv4: t.CUInt32T) -> QtHostAddressPtr | t.State: pass
|
||||
def vqt6_qhostaddress_create_with_string(address: QtStringPtr) -> QtHostAddressPtr | t.State: pass
|
||||
def vqt6_qhostaddress_create_with_local_host() -> QtHostAddressPtr | t.State: pass
|
||||
def vqt6_qhostaddress_create_with_local_ipv4() -> QtHostAddressPtr | t.State: pass
|
||||
def vqt6_qhostaddress_create_with_broadcast() -> QtHostAddressPtr | t.State: pass
|
||||
def vqt6_qhostaddress_create_with_any_ipv4() -> QtHostAddressPtr | t.State: pass
|
||||
def vqt6_qhostaddress_to_string(addr: QtHostAddressPtr) -> QtStringPtr | t.State: pass
|
||||
def vqt6_qhostaddress_to_ipv4(addr: QtHostAddressPtr) -> t.CUInt32T | t.State: pass
|
||||
def vqt6_qhostaddress_is_null(addr: QtHostAddressPtr) -> t.CInt | t.State: pass
|
||||
def vqt6_qhostaddress_is_loopback(addr: QtHostAddressPtr) -> t.CInt | t.State: pass
|
||||
def vqt6_qhostaddress_is_broadcast(addr: QtHostAddressPtr) -> t.CInt | t.State: pass
|
||||
def vqt6_qhostaddress_protocol(addr: QtHostAddressPtr) -> t.CInt | t.State: pass
|
||||
def vqt6_qhostaddress_free(addr: QtHostAddressPtr) -> t.State: pass
|
||||
|
||||
|
||||
# ============================================================
|
||||
# QAbstractSocket — TCP/UDP 套接字基类
|
||||
# ============================================================
|
||||
# 套接字状态
|
||||
QT_SOCKET_UNCONNECTED_STATE: t.CDefine = 0
|
||||
QT_SOCKET_HOST_LOOKUP_STATE: t.CDefine = 1
|
||||
QT_SOCKET_CONNECTING_STATE: t.CDefine = 2
|
||||
QT_SOCKET_CONNECTED_STATE: t.CDefine = 3
|
||||
QT_SOCKET_BOUND_STATE: t.CDefine = 4
|
||||
QT_SOCKET_LISTENING_STATE: t.CDefine = 5
|
||||
QT_SOCKET_CLOSING_STATE: t.CDefine = 6
|
||||
|
||||
# 套接字类型
|
||||
QT_SOCKET_TCP: t.CDefine = 0
|
||||
QT_SOCKET_UDP: t.CDefine = 1
|
||||
|
||||
# 套接字错误
|
||||
QT_SOCKET_NO_ERROR: t.CDefine = 0
|
||||
|
||||
# 通用方法
|
||||
def vqt6_qabstractsocket_state(socket: QtAbstractSocketPtr) -> t.CInt | t.State: pass
|
||||
def vqt6_qabstractsocket_error(socket: QtAbstractSocketPtr) -> t.CInt | t.State: pass
|
||||
def vqt6_qabstractsocket_error_string(socket: QtAbstractSocketPtr) -> QtStringPtr | t.State: pass
|
||||
def vqt6_qabstractsocket_connect_to_host(socket: QtAbstractSocketPtr, host_name: QtStringPtr, port: t.CUInt16T) -> t.State: pass
|
||||
def vqt6_qabstractsocket_connect_to_host_with_addr(socket: QtAbstractSocketPtr, address: QtHostAddressPtr, port: t.CUInt16T) -> t.State: pass
|
||||
def vqt6_qabstractsocket_disconnect_from_host(socket: QtAbstractSocketPtr) -> t.State: pass
|
||||
def vqt6_qabstractsocket_wait_for_connected(socket: QtAbstractSocketPtr, timeout_ms: t.CInt) -> t.CInt | t.State: pass
|
||||
def vqt6_qabstractsocket_wait_for_ready_read(socket: QtAbstractSocketPtr, timeout_ms: t.CInt) -> t.CInt | t.State: pass
|
||||
def vqt6_qabstractsocket_wait_for_bytes_written(socket: QtAbstractSocketPtr, timeout_ms: t.CInt) -> t.CInt | t.State: pass
|
||||
def vqt6_qabstractsocket_wait_for_disconnected(socket: QtAbstractSocketPtr, timeout_ms: t.CInt) -> t.CInt | t.State: pass
|
||||
def vqt6_qabstractsocket_is_valid(socket: QtAbstractSocketPtr) -> t.CInt | t.State: pass
|
||||
def vqt6_qabstractsocket_is_open(socket: QtAbstractSocketPtr) -> t.CInt | t.State: pass
|
||||
def vqt6_qabstractsocket_flush(socket: QtAbstractSocketPtr) -> t.CInt | t.State: pass
|
||||
def vqt6_qabstractsocket_close(socket: QtAbstractSocketPtr) -> t.State: pass
|
||||
def vqt6_qabstractsocket_abort(socket: QtAbstractSocketPtr) -> t.State: pass
|
||||
def vqt6_qabstractsocket_read(socket: QtAbstractSocketPtr, buf: t.CVoid | t.CPtr, max_size: t.CSizeT) -> t.CSizeT | t.State: pass
|
||||
def vqt6_qabstractsocket_read_all(socket: QtAbstractSocketPtr, out_size: t.CSizeT | t.CPtr) -> t.CVoid | t.CPtr | t.State: pass
|
||||
def vqt6_qabstractsocket_write(socket: QtAbstractSocketPtr, data: t.CVoid | t.CPtr, size: t.CSizeT) -> t.CSizeT | t.State: pass
|
||||
def vqt6_qabstractsocket_bytes_available(socket: QtAbstractSocketPtr) -> t.CSizeT | t.State: pass
|
||||
def vqt6_qabstractsocket_bytes_to_write(socket: QtAbstractSocketPtr) -> t.CSizeT | t.State: pass
|
||||
def vqt6_qabstractsocket_peer_address(socket: QtAbstractSocketPtr) -> QtHostAddressPtr | t.State: pass
|
||||
def vqt6_qabstractsocket_peer_port(socket: QtAbstractSocketPtr) -> t.CUInt16T | t.State: pass
|
||||
def vqt6_qabstractsocket_local_address(socket: QtAbstractSocketPtr) -> QtHostAddressPtr | t.State: pass
|
||||
def vqt6_qabstractsocket_local_port(socket: QtAbstractSocketPtr) -> t.CUInt16T | t.State: pass
|
||||
|
||||
|
||||
# ============================================================
|
||||
# QTcpSocket — TCP 套接字
|
||||
# ============================================================
|
||||
def vqt6_qtcpsocket_create() -> QtTcpSocketPtr | t.State: pass
|
||||
def vqt6_qtcpsocket_create_with_parent(parent: QtObjectPtr) -> QtTcpSocketPtr | t.State: pass
|
||||
def vqt6_qtcpsocket_connect_to_host(socket: QtTcpSocketPtr, host_name: QtStringPtr, port: t.CUInt16T, mode: t.CInt) -> t.State: pass
|
||||
def vqt6_qtcpsocket_connect_to_host_with_addr(socket: QtTcpSocketPtr, address: QtHostAddressPtr, port: t.CUInt16T, mode: t.CInt) -> t.State: pass
|
||||
def vqt6_qtcpsocket_set_socket_descriptor(socket: QtTcpSocketPtr, socket_descriptor: t.CInt) -> t.CInt | t.State: pass
|
||||
def vqt6_qtcpsocket_socket_descriptor(socket: QtTcpSocketPtr) -> t.CInt | t.State: pass
|
||||
def vqt6_qtcpsocket_set_proxy(socket: QtTcpSocketPtr, proxy_type: t.CInt) -> t.State: pass
|
||||
def vqt6_qtcpsocket_abort(socket: QtTcpSocketPtr) -> t.State: pass
|
||||
|
||||
|
||||
# ============================================================
|
||||
# QUdpSocket — UDP 套接字
|
||||
# ============================================================
|
||||
def vqt6_qudpsocket_create() -> QtUdpSocketPtr | t.State: pass
|
||||
def vqt6_qudpsocket_create_with_parent(parent: QtObjectPtr) -> QtUdpSocketPtr | t.State: pass
|
||||
def vqt6_qudpsocket_bind(socket: QtUdpSocketPtr, port: t.CUInt16T) -> t.CInt | t.State: pass
|
||||
def vqt6_qudpsocket_bind_with_addr(socket: QtUdpSocketPtr, address: QtHostAddressPtr, port: t.CUInt16T) -> t.CInt | t.State: pass
|
||||
def vqt6_qudpsocket_close(socket: QtUdpSocketPtr) -> t.State: pass
|
||||
def vqt6_qudpsocket_write_datagram(socket: QtUdpSocketPtr, data: t.CVoid | t.CPtr, size: t.CSizeT, host: QtHostAddressPtr, port: t.CUInt16T) -> t.CSizeT | t.State: pass
|
||||
def vqt6_qudpsocket_read_datagram(socket: QtUdpSocketPtr, data: t.CVoid | t.CPtr, max_size: t.CSizeT, host: QtHostAddressPtr, port: t.CUInt16T | t.CPtr) -> t.CSizeT | t.State: pass
|
||||
def vqt6_qudpsocket_has_pending_datagrams(socket: QtUdpSocketPtr) -> t.CInt | t.State: pass
|
||||
def vqt6_qudpsocket_pending_datagram_size(socket: QtUdpSocketPtr) -> t.CSizeT | t.State: pass
|
||||
def vqt6_qudpsocket_join_multicast_group(socket: QtUdpSocketPtr, group_address: QtHostAddressPtr) -> t.CInt | t.State: pass
|
||||
def vqt6_qudpsocket_leave_multicast_group(socket: QtUdpSocketPtr, group_address: QtHostAddressPtr) -> t.CInt | t.State: pass
|
||||
|
||||
|
||||
# ============================================================
|
||||
# QNetworkRequest — 网络请求
|
||||
# ============================================================
|
||||
def vqt6_qnetworkrequest_create() -> QtNetworkRequestPtr | t.State: pass
|
||||
def vqt6_qnetworkrequest_create_with_url(url: QtStringPtr) -> QtNetworkRequestPtr | t.State: pass
|
||||
def vqt6_qnetworkrequest_set_url(req: QtNetworkRequestPtr, url: QtStringPtr) -> t.State: pass
|
||||
def vqt6_qnetworkrequest_url(req: QtNetworkRequestPtr) -> QtStringPtr | t.State: pass
|
||||
def vqt6_qnetworkrequest_set_header(req: QtNetworkRequestPtr, header_type: t.CInt, value: QtVariantPtr) -> t.State: pass
|
||||
def vqt6_qnetworkrequest_header(req: QtNetworkRequestPtr, header_type: t.CInt) -> QtVariantPtr | t.State: pass
|
||||
def vqt6_qnetworkrequest_set_raw_header(req: QtNetworkRequestPtr, header_name: t.CChar | t.CPtr, value: t.CVoid | t.CPtr, value_size: t.CSizeT) -> t.State: pass
|
||||
def vqt6_qnetworkrequest_raw_header(req: QtNetworkRequestPtr, header_name: t.CChar | t.CPtr, out_size: t.CSizeT | t.CPtr) -> t.CVoid | t.CPtr | t.State: pass
|
||||
def vqt6_qnetworkrequest_set_attribute(req: QtNetworkRequestPtr, attr_type: t.CInt, value: QtVariantPtr) -> t.State: pass
|
||||
def vqt6_qnetworkrequest_attribute(req: QtNetworkRequestPtr, attr_type: t.CInt) -> QtVariantPtr | t.State: pass
|
||||
def vqt6_qnetworkrequest_free(req: QtNetworkRequestPtr) -> t.State: pass
|
||||
|
||||
|
||||
# ============================================================
|
||||
# QNetworkAccessManager — HTTP 客户端管理器
|
||||
# ============================================================
|
||||
def vqt6_qnetworkaccessmanager_create() -> QtNetworkAccessManagerPtr | t.State: pass
|
||||
def vqt6_qnetworkaccessmanager_create_with_parent(parent: QtObjectPtr) -> QtNetworkAccessManagerPtr | t.State: pass
|
||||
def vqt6_qnetworkaccessmanager_get(nam: QtNetworkAccessManagerPtr, req: QtNetworkRequestPtr) -> QtNetworkReplyPtr | t.State: pass
|
||||
def vqt6_qnetworkaccessmanager_post(nam: QtNetworkAccessManagerPtr, req: QtNetworkRequestPtr, data: t.CVoid | t.CPtr, size: t.CSizeT) -> QtNetworkReplyPtr | t.State: pass
|
||||
def vqt6_qnetworkaccessmanager_put(nam: QtNetworkAccessManagerPtr, req: QtNetworkRequestPtr, data: t.CVoid | t.CPtr, size: t.CSizeT) -> QtNetworkReplyPtr | t.State: pass
|
||||
def vqt6_qnetworkaccessmanager_delete_resource(nam: QtNetworkAccessManagerPtr, req: QtNetworkRequestPtr) -> QtNetworkReplyPtr | t.State: pass
|
||||
def vqt6_qnetworkaccessmanager_head(nam: QtNetworkAccessManagerPtr, req: QtNetworkRequestPtr) -> QtNetworkReplyPtr | t.State: pass
|
||||
def vqt6_qnetworkaccessmanager_set_cookie_store(nam: QtNetworkAccessManagerPtr, store: QtObjectPtr) -> t.State: pass
|
||||
|
||||
|
||||
# ============================================================
|
||||
# QNetworkReply — 网络响应
|
||||
# ============================================================
|
||||
def vqt6_qnetworkreply_url(reply: QtNetworkReplyPtr) -> QtStringPtr | t.State: pass
|
||||
def vqt6_qnetworkreply_request(reply: QtNetworkReplyPtr) -> QtNetworkRequestPtr | t.State: pass
|
||||
def vqt6_qnetworkreply_error(reply: QtNetworkReplyPtr) -> t.CInt | t.State: pass
|
||||
def vqt6_qnetworkreply_error_string(reply: QtNetworkReplyPtr) -> QtStringPtr | t.State: pass
|
||||
def vqt6_qnetworkreply_is_finished(reply: QtNetworkReplyPtr) -> t.CInt | t.State: pass
|
||||
def vqt6_qnetworkreply_is_running(reply: QtNetworkReplyPtr) -> t.CInt | t.State: pass
|
||||
def vqt6_qnetworkreply_abort(reply: QtNetworkReplyPtr) -> t.State: pass
|
||||
def vqt6_qnetworkreply_read(reply: QtNetworkReplyPtr, buf: t.CVoid | t.CPtr, max_size: t.CSizeT) -> t.CSizeT | t.State: pass
|
||||
def vqt6_qnetworkreply_read_all(reply: QtNetworkReplyPtr, out_size: t.CSizeT | t.CPtr) -> t.CVoid | t.CPtr | t.State: pass
|
||||
def vqt6_qnetworkreply_bytes_available(reply: QtNetworkReplyPtr) -> t.CSizeT | t.State: pass
|
||||
def vqt6_qnetworkreply_header(reply: QtNetworkReplyPtr, header_type: t.CInt) -> QtVariantPtr | t.State: pass
|
||||
def vqt6_qnetworkreply_raw_header(reply: QtNetworkReplyPtr, header_name: t.CChar | t.CPtr, out_size: t.CSizeT | t.CPtr) -> t.CVoid | t.CPtr | t.State: pass
|
||||
def vqt6_qnetworkreply_attribute(reply: QtNetworkReplyPtr, attribute_code: t.CInt) -> QtVariantPtr | t.State: pass
|
||||
def vqt6_qnetworkreply_attribute_int(reply: QtNetworkReplyPtr, attribute_code: t.CInt, default_value: t.CInt) -> t.CInt | t.State: pass
|
||||
def vqt6_qnetworkreply_set_raw_header(reply: QtNetworkReplyPtr, header_name: t.CChar | t.CPtr, value: t.CVoid | t.CPtr, value_size: t.CSizeT) -> t.State: pass
|
||||
|
||||
|
||||
# ============================================================
|
||||
# 套接字类型枚举
|
||||
# ============================================================
|
||||
# 套接字类型
|
||||
QT_ABSTRACT_SOCKET_TCP: t.CDefine = 0
|
||||
QT_ABSTRACT_SOCKET_UDP: t.CDefine = 1
|
||||
|
||||
# 网络层协议
|
||||
QT_NETWORK_IPV4_PROTOCOL: t.CDefine = 0
|
||||
QT_NETWORK_IPV6_PROTOCOL: t.CDefine = 1
|
||||
QT_NETWORK_ANY_IP_PROTOCOL: t.CDefine = 2
|
||||
|
||||
# 主机地址特殊情况
|
||||
QT_HOST_ADDRESS_LOCAL_HOST: t.CDefine = 0x00000000
|
||||
QT_HOST_ADDRESS_LOCAL_HOST_IPV6: t.CDefine = 0x00000001
|
||||
QT_HOST_ADDRESS_BROADCAST: t.CDefine = 0x00000002
|
||||
QT_HOST_ADDRESS_ANY_IPV4: t.CDefine = 0x00000004
|
||||
QT_HOST_ADDRESS_ANY_IPV6: t.CDefine = 0x00000005
|
||||
|
||||
|
||||
# ============================================================
|
||||
# 已知端口常量
|
||||
# ============================================================
|
||||
QT_PORT_FTP: t.CDefine = 21
|
||||
QT_PORT_SSH: t.CDefine = 22
|
||||
QT_PORT_TELNET: t.CDefine = 23
|
||||
QT_PORT_SMTP: t.CDefine = 25
|
||||
QT_PORT_DNS: t.CDefine = 53
|
||||
QT_PORT_HTTP: t.CDefine = 80
|
||||
QT_PORT_POP3: t.CDefine = 110
|
||||
QT_PORT_IMAP: t.CDefine = 143
|
||||
QT_PORT_HTTPS: t.CDefine = 443
|
||||
QT_PORT_SMB: t.CDefine = 445
|
||||
478
includes/vqt6 copy/_qtwidgets.py
Normal file
478
includes/vqt6 copy/_qtwidgets.py
Normal file
@@ -0,0 +1,478 @@
|
||||
import t, c
|
||||
from stdint import *
|
||||
from vqt6._types import *
|
||||
|
||||
# ============================================================
|
||||
# vqt6/_qtwidgets.py — QtWidgets 的 t.State FFI 声明
|
||||
# ============================================================
|
||||
|
||||
# ============================================================
|
||||
# QApplication — GUI 应用入口
|
||||
# ============================================================
|
||||
# argc/argv 通过单独的 buffer 数组传入(Viper 中 C 数组使用指针+长度)
|
||||
def vqt6_qapplication_create(argc: t.CInt, argv: t.CPtr | t.CPtr) -> QtAppPtr | t.State: pass
|
||||
def vqt6_qapplication_instance() -> QtAppPtr | t.State: pass
|
||||
def vqt6_qapplication_exec(app: QtAppPtr) -> t.CInt | t.State: pass
|
||||
def vqt6_qapplication_quit(app: QtAppPtr) -> t.State: pass
|
||||
def vqt6_qapplication_exit(app: QtAppPtr, exit_code: t.CInt) -> t.State: pass
|
||||
def vqt6_qapplication_process_events(app: QtAppPtr) -> t.State: pass
|
||||
def vqt6_qapplication_desktop_width(app: QtAppPtr) -> t.CInt | t.State: pass
|
||||
def vqt6_qapplication_desktop_height(app: QtAppPtr) -> t.CInt | t.State: pass
|
||||
def vqt6_qapplication_set_quit_on_last_window_closed(app: QtAppPtr, quit: t.CInt) -> t.State: pass
|
||||
def vqt6_qapplication_quit_on_last_window_closed(app: QtAppPtr) -> t.CInt | t.State: pass
|
||||
|
||||
|
||||
# ============================================================
|
||||
# QWidget — 所有窗口的基类
|
||||
# ============================================================
|
||||
def vqt6_qwidget_create() -> QtWidgetPtr | t.State: pass
|
||||
def vqt6_qwidget_create_with_parent(parent: QtWidgetPtr) -> QtWidgetPtr | t.State: pass
|
||||
def vqt6_qwidget_show(widget: QtWidgetPtr) -> t.State: pass
|
||||
def vqt6_qwidget_hide(widget: QtWidgetPtr) -> t.State: pass
|
||||
def vqt6_qwidget_close(widget: QtWidgetPtr) -> t.CInt | t.State: pass
|
||||
def vqt6_qwidget_is_visible(widget: QtWidgetPtr) -> t.CInt | t.State: pass
|
||||
def vqt6_qwidget_set_visible(widget: QtWidgetPtr, visible: t.CInt) -> t.State: pass
|
||||
|
||||
# 几何
|
||||
def vqt6_qwidget_set_geometry(widget: QtWidgetPtr, x: t.CInt, y: t.CInt, w: t.CInt, h: t.CInt) -> t.State: pass
|
||||
def vqt6_qwidget_geometry(widget: QtWidgetPtr, x: t.CInt | t.CPtr, y: t.CInt | t.CPtr, w: t.CInt | t.CPtr, h: t.CInt | t.CPtr) -> t.State: pass
|
||||
def vqt6_qwidget_resize(widget: QtWidgetPtr, w: t.CInt, h: t.CInt) -> t.State: pass
|
||||
def vqt6_qwidget_size(widget: QtWidgetPtr, w: t.CInt | t.CPtr, h: t.CInt | t.CPtr) -> t.State: pass
|
||||
def vqt6_qwidget_move(widget: QtWidgetPtr, x: t.CInt, y: t.CInt) -> t.State: pass
|
||||
def vqt6_qwidget_pos(widget: QtWidgetPtr, x: t.CInt | t.CPtr, y: t.CInt | t.CPtr) -> t.State: pass
|
||||
def vqt6_qwidget_width(widget: QtWidgetPtr) -> t.CInt | t.State: pass
|
||||
def vqt6_qwidget_height(widget: QtWidgetPtr) -> t.CInt | t.State: pass
|
||||
def vqt6_qwidget_x(widget: QtWidgetPtr) -> t.CInt | t.State: pass
|
||||
def vqt6_qwidget_y(widget: QtWidgetPtr) -> t.CInt | t.State: pass
|
||||
|
||||
# 文本与标题
|
||||
def vqt6_qwidget_set_window_title(widget: QtWidgetPtr, title: QtStringPtr) -> t.State: pass
|
||||
def vqt6_qwidget_window_title(widget: QtWidgetPtr) -> QtStringPtr | t.State: pass
|
||||
def vqt6_qwidget_set_text(widget: QtWidgetPtr, text: QtStringPtr) -> t.State: pass
|
||||
def vqt6_qwidget_text(widget: QtWidgetPtr) -> QtStringPtr | t.State: pass
|
||||
|
||||
# 启用
|
||||
def vqt6_qwidget_set_enabled(widget: QtWidgetPtr, enabled: t.CInt) -> t.State: pass
|
||||
def vqt6_qwidget_is_enabled(widget: QtWidgetPtr) -> t.CInt | t.State: pass
|
||||
|
||||
# 父对象
|
||||
def vqt6_qwidget_set_parent(widget: QtWidgetPtr, parent: QtWidgetPtr) -> t.State: pass
|
||||
def vqt6_qwidget_parent_widget(widget: QtWidgetPtr) -> QtWidgetPtr | t.State: pass
|
||||
|
||||
# 焦点
|
||||
def vqt6_qwidget_set_focus(widget: QtWidgetPtr) -> t.State: pass
|
||||
def vqt6_qwidget_clear_focus(widget: QtWidgetPtr) -> t.State: pass
|
||||
def vqt6_qwidget_has_focus(widget: QtWidgetPtr) -> t.CInt | t.State: pass
|
||||
def vqt6_qwidget_set_focus_policy(widget: QtWidgetPtr, policy: t.CInt) -> t.State: pass
|
||||
|
||||
# 更新
|
||||
def vqt6_qwidget_update(widget: QtWidgetPtr) -> t.State: pass
|
||||
def vqt6_qwidget_repaint(widget: QtWidgetPtr) -> t.State: pass
|
||||
def vqt6_qwidget_set_update_enabled(widget: QtWidgetPtr, enabled: t.CInt) -> t.State: pass
|
||||
|
||||
# 窗口标志
|
||||
def vqt6_qwidget_set_window_flags(widget: QtWidgetPtr, flags: t.CInt) -> t.State: pass
|
||||
def vqt6_qwidget_window_flags(widget: QtWidgetPtr) -> t.CInt | t.State: pass
|
||||
|
||||
# 鼠标光标
|
||||
def vqt6_qwidget_set_cursor(widget: QtWidgetPtr, cursor: QtCursorPtr) -> t.State: pass
|
||||
def vqt6_qwidget_cursor(widget: QtWidgetPtr) -> QtCursorPtr | t.State: pass
|
||||
def vqt6_qwidget_unset_cursor(widget: QtWidgetPtr) -> t.State: pass
|
||||
|
||||
# 工具提示
|
||||
def vqt6_qwidget_set_tool_tip(widget: QtWidgetPtr, tip: QtStringPtr) -> t.State: pass
|
||||
def vqt6_qwidget_tool_tip(widget: QtWidgetPtr) -> QtStringPtr | t.State: pass
|
||||
|
||||
# 状态栏提示
|
||||
def vqt6_qwidget_set_status_tip(widget: QtWidgetPtr, tip: QtStringPtr) -> t.State: pass
|
||||
def vqt6_qwidget_status_tip(widget: QtWidgetPtr) -> QtStringPtr | t.State: pass
|
||||
|
||||
# 最小/最大尺寸
|
||||
def vqt6_qwidget_set_minimum_size(widget: QtWidgetPtr, w: t.CInt, h: t.CInt) -> t.State: pass
|
||||
def vqt6_qwidget_set_maximum_size(widget: QtWidgetPtr, w: t.CInt, h: t.CInt) -> t.State: pass
|
||||
def vqt6_qwidget_set_fixed_size(widget: QtWidgetPtr, w: t.CInt, h: t.CInt) -> t.State: pass
|
||||
def vqt6_qwidget_minimum_size(widget: QtWidgetPtr, w: t.CInt | t.CPtr, h: t.CInt | t.CPtr) -> t.State: pass
|
||||
def vqt6_qwidget_maximum_size(widget: QtWidgetPtr, w: t.CInt | t.CPtr, h: t.CInt | t.CPtr) -> t.State: pass
|
||||
|
||||
|
||||
# ============================================================
|
||||
# QDialog — 对话框
|
||||
# ============================================================
|
||||
def vqt6_qdialog_create() -> QtDialogPtr | t.State: pass
|
||||
def vqt6_qdialog_create_with_parent(parent: QtWidgetPtr) -> QtDialogPtr | t.State: pass
|
||||
def vqt6_qdialog_exec(dialog: QtDialogPtr) -> t.CInt | t.State: pass
|
||||
def vqt6_qdialog_done(dialog: QtDialogPtr, result: t.CInt) -> t.State: pass
|
||||
def vqt6_qdialog_accept(dialog: QtDialogPtr) -> t.State: pass
|
||||
def vqt6_qdialog_reject(dialog: QtDialogPtr) -> t.State: pass
|
||||
def vqt6_qdialog_set_result(dialog: QtDialogPtr, result: t.CInt) -> t.State: pass
|
||||
def vqt6_qdialog_result(dialog: QtDialogPtr) -> t.CInt | t.State: pass
|
||||
def vqt6_qdialog_set_modal(dialog: QtDialogPtr, modal: t.CInt) -> t.State: pass
|
||||
def vqt6_qdialog_is_modal(dialog: QtDialogPtr) -> t.CInt | t.State: pass
|
||||
|
||||
|
||||
# ============================================================
|
||||
# QMainWindow — 主窗口
|
||||
# ============================================================
|
||||
def vqt6_qmainwindow_create() -> QtMainWindowPtr | t.State: pass
|
||||
def vqt6_qmainwindow_create_with_parent(parent: QtWidgetPtr) -> QtMainWindowPtr | t.State: pass
|
||||
def vqt6_qmainwindow_set_central_widget(mw: QtMainWindowPtr, widget: QtWidgetPtr) -> t.State: pass
|
||||
def vqt6_qmainwindow_central_widget(mw: QtMainWindowPtr) -> QtWidgetPtr | t.State: pass
|
||||
def vqt6_qmainwindow_menu_bar(mw: QtMainWindowPtr) -> QtMenuBarPtr | t.State: pass
|
||||
def vqt6_qmainwindow_set_menu_bar(mw: QtMainWindowPtr, menubar: QtMenuBarPtr) -> t.State: pass
|
||||
def vqt6_qmainwindow_status_bar(mw: QtMainWindowPtr) -> QtStatusBarPtr | t.State: pass
|
||||
def vqt6_qmainwindow_set_status_bar(mw: QtMainWindowPtr, statusbar: QtStatusBarPtr) -> t.State: pass
|
||||
def vqt6_qmainwindow_add_tool_bar(mw: QtMainWindowPtr, toolbar: QtToolBarPtr) -> t.State: pass
|
||||
def vqt6_qmainwindow_add_tool_bar_break(mw: QtMainWindowPtr) -> t.State: pass
|
||||
|
||||
|
||||
# ============================================================
|
||||
# QLabel — 标签
|
||||
# ============================================================
|
||||
def vqt6_qlabel_create() -> QtLabelPtr | t.State: pass
|
||||
def vqt6_qlabel_create_with_text(text: QtStringPtr) -> QtLabelPtr | t.State: pass
|
||||
def vqt6_qlabel_create_with_text_parent(text: QtStringPtr, parent: QtWidgetPtr) -> QtLabelPtr | t.State: pass
|
||||
def vqt6_qlabel_set_text(label: QtLabelPtr, text: QtStringPtr) -> t.State: pass
|
||||
def vqt6_qlabel_text(label: QtLabelPtr) -> QtStringPtr | t.State: pass
|
||||
def vqt6_qlabel_set_alignment(label: QtLabelPtr, alignment: t.CInt) -> t.State: pass
|
||||
def vqt6_qlabel_alignment(label: QtLabelPtr) -> t.CInt | t.State: pass
|
||||
def vqt6_qlabel_set_pixmap(label: QtLabelPtr, pixmap: QtPixmapPtr) -> t.State: pass
|
||||
def vqt6_qlabel_pixmap(label: QtLabelPtr) -> QtPixmapPtr | t.State: pass
|
||||
def vqt6_qlabel_set_indent(label: QtLabelPtr, indent: t.CInt) -> t.State: pass
|
||||
def vqt6_qlabel_set_margin(label: QtLabelPtr, margin: t.CInt) -> t.State: pass
|
||||
def vqt6_qlabel_set_word_wrap(label: QtLabelPtr, wrap: t.CInt) -> t.State: pass
|
||||
def vqt6_qlabel_word_wrap(label: QtLabelPtr) -> t.CInt | t.State: pass
|
||||
|
||||
|
||||
# ============================================================
|
||||
# QPushButton — 按钮
|
||||
# ============================================================
|
||||
def vqt6_qpushbutton_create() -> QtPushButtonPtr | t.State: pass
|
||||
def vqt6_qpushbutton_create_with_text(text: QtStringPtr) -> QtPushButtonPtr | t.State: pass
|
||||
def vqt6_qpushbutton_create_with_text_parent(text: QtStringPtr, parent: QtWidgetPtr) -> QtPushButtonPtr | t.State: pass
|
||||
def vqt6_qpushbutton_set_text(btn: QtPushButtonPtr, text: QtStringPtr) -> t.State: pass
|
||||
def vqt6_qpushbutton_text(btn: QtPushButtonPtr) -> QtStringPtr | t.State: pass
|
||||
def vqt6_qpushbutton_set_icon(btn: QtPushButtonPtr, icon: QtIconPtr) -> t.State: pass
|
||||
def vqt6_qpushbutton_icon(btn: QtPushButtonPtr) -> QtIconPtr | t.State: pass
|
||||
def vqt6_qpushbutton_set_default(btn: QtPushButtonPtr, is_default: t.CInt) -> t.State: pass
|
||||
def vqt6_qpushbutton_is_default(btn: QtPushButtonPtr) -> t.CInt | t.State: pass
|
||||
def vqt6_qpushbutton_set_flat(btn: QtPushButtonPtr, flat: t.CInt) -> t.State: pass
|
||||
def vqt6_qpushbutton_is_flat(btn: QtPushButtonPtr) -> t.CInt | t.State: pass
|
||||
def vqt6_qpushbutton_set_checkable(btn: QtPushButtonPtr, checkable: t.CInt) -> t.State: pass
|
||||
def vqt6_qpushbutton_is_checkable(btn: QtPushButtonPtr) -> t.CInt | t.State: pass
|
||||
def vqt6_qpushbutton_set_checked(btn: QtPushButtonPtr, checked: t.CInt) -> t.State: pass
|
||||
def vqt6_qpushbutton_is_checked(btn: QtPushButtonPtr) -> t.CInt | t.State: pass
|
||||
def vqt6_qpushbutton_click(btn: QtPushButtonPtr) -> t.State: pass
|
||||
|
||||
|
||||
# ============================================================
|
||||
# QLineEdit — 单行输入框
|
||||
# ============================================================
|
||||
def vqt6_qlineedit_create() -> QtLineEditPtr | t.State: pass
|
||||
def vqt6_qlineedit_create_with_text(text: QtStringPtr) -> QtLineEditPtr | t.State: pass
|
||||
def vqt6_qlineedit_create_with_text_parent(text: QtStringPtr, parent: QtWidgetPtr) -> QtLineEditPtr | t.State: pass
|
||||
def vqt6_qlineedit_text(le: QtLineEditPtr) -> QtStringPtr | t.State: pass
|
||||
def vqt6_qlineedit_set_text(le: QtLineEditPtr, text: QtStringPtr) -> t.State: pass
|
||||
def vqt6_qlineedit_placeholder_text(le: QtLineEditPtr) -> QtStringPtr | t.State: pass
|
||||
def vqt6_qlineedit_set_placeholder_text(le: QtLineEditPtr, text: QtStringPtr) -> t.State: pass
|
||||
def vqt6_qlineedit_set_max_length(le: QtLineEditPtr, max: t.CInt) -> t.State: pass
|
||||
def vqt6_qlineedit_max_length(le: QtLineEditPtr) -> t.CInt | t.State: pass
|
||||
def vqt6_qlineedit_set_read_only(le: QtLineEditPtr, ro: t.CInt) -> t.State: pass
|
||||
def vqt6_qlineedit_is_read_only(le: QtLineEditPtr) -> t.CInt | t.State: pass
|
||||
def vqt6_qlineedit_set_echo_mode(le: QtLineEditPtr, mode: t.CInt) -> t.State: pass
|
||||
def vqt6_qlineedit_echo_mode(le: QtLineEditPtr) -> t.CInt | t.State: pass
|
||||
def vqt6_qlineedit_select_all(le: QtLineEditPtr) -> t.State: pass
|
||||
def vqt6_qlineedit_clear(le: QtLineEditPtr) -> t.State: pass
|
||||
|
||||
|
||||
# ============================================================
|
||||
# QTextEdit / QPlainTextEdit — 多行文本编辑器
|
||||
# ============================================================
|
||||
def vqt6_qtextedit_create() -> QtTextEditPtr | t.State: pass
|
||||
def vqt6_qtextedit_create_with_parent(parent: QtWidgetPtr) -> QtTextEditPtr | t.State: pass
|
||||
def vqt6_qtextedit_to_plain_text(te: QtTextEditPtr) -> QtStringPtr | t.State: pass
|
||||
def vqt6_qtextedit_set_plain_text(te: QtTextEditPtr, text: QtStringPtr) -> t.State: pass
|
||||
def vqt6_qtextedit_set_html(te: QtTextEditPtr, html: QtStringPtr) -> t.State: pass
|
||||
def vqt6_qtextedit_to_html(te: QtTextEditPtr) -> QtStringPtr | t.State: pass
|
||||
def vqt6_qtextedit_append(te: QtTextEditPtr, text: QtStringPtr) -> t.State: pass
|
||||
def vqt6_qtextedit_clear(te: QtTextEditPtr) -> t.State: pass
|
||||
def vqt6_qtextedit_set_read_only(te: QtTextEditPtr, ro: t.CInt) -> t.State: pass
|
||||
def vqt6_qtextedit_is_read_only(te: QtTextEditPtr) -> t.CInt | t.State: pass
|
||||
|
||||
def vqt6_qplaintextedit_create() -> QtPlainTextEditPtr | t.State: pass
|
||||
def vqt6_qplaintextedit_create_with_parent(parent: QtWidgetPtr) -> QtPlainTextEditPtr | t.State: pass
|
||||
def vqt6_qplaintextedit_to_plain_text(pte: QtPlainTextEditPtr) -> QtStringPtr | t.State: pass
|
||||
def vqt6_qplaintextedit_set_plain_text(pte: QtPlainTextEditPtr, text: QtStringPtr) -> t.State: pass
|
||||
def vqt6_qplaintextedit_append(pte: QtPlainTextEditPtr, text: QtStringPtr) -> t.State: pass
|
||||
def vqt6_qplaintextedit_clear(pte: QtPlainTextEditPtr) -> t.State: pass
|
||||
def vqt6_qplaintextedit_set_read_only(pte: QtPlainTextEditPtr, ro: t.CInt) -> t.State: pass
|
||||
def vqt6_qplaintextedit_line_count(pte: QtPlainTextEditPtr) -> t.CInt | t.State: pass
|
||||
|
||||
|
||||
# ============================================================
|
||||
# QCheckBox / QRadioButton — 复选/单选
|
||||
# ============================================================
|
||||
def vqt6_qcheckbox_create() -> QtCheckBoxPtr | t.State: pass
|
||||
def vqt6_qcheckbox_create_with_text(text: QtStringPtr) -> QtCheckBoxPtr | t.State: pass
|
||||
def vqt6_qcheckbox_create_with_text_parent(text: QtStringPtr, parent: QtWidgetPtr) -> QtCheckBoxPtr | t.State: pass
|
||||
def vqt6_qcheckbox_set_checked(cb: QtCheckBoxPtr, checked: t.CInt) -> t.State: pass
|
||||
def vqt6_qcheckbox_is_checked(cb: QtCheckBoxPtr) -> t.CInt | t.State: pass
|
||||
def vqt6_qcheckbox_set_text(cb: QtCheckBoxPtr, text: QtStringPtr) -> t.State: pass
|
||||
def vqt6_qcheckbox_text(cb: QtCheckBoxPtr) -> QtStringPtr | t.State: pass
|
||||
def vqt6_qcheckbox_set_tristate(cb: QtCheckBoxPtr, tristate: t.CInt) -> t.State: pass
|
||||
def vqt6_qcheckbox_is_tristate(cb: QtCheckBoxPtr) -> t.CInt | t.State: pass
|
||||
|
||||
def vqt6_qradiobutton_create() -> QtRadioButtonPtr | t.State: pass
|
||||
def vqt6_qradiobutton_create_with_text(text: QtStringPtr) -> QtRadioButtonPtr | t.State: pass
|
||||
def vqt6_qradiobutton_create_with_text_parent(text: QtStringPtr, parent: QtWidgetPtr) -> QtRadioButtonPtr | t.State: pass
|
||||
def vqt6_qradiobutton_set_checked(rb: QtRadioButtonPtr, checked: t.CInt) -> t.State: pass
|
||||
def vqt6_qradiobutton_is_checked(rb: QtRadioButtonPtr) -> t.CInt | t.State: pass
|
||||
def vqt6_qradiobutton_set_text(rb: QtRadioButtonPtr, text: QtStringPtr) -> t.State: pass
|
||||
def vqt6_qradiobutton_text(rb: QtRadioButtonPtr) -> QtStringPtr | t.State: pass
|
||||
|
||||
|
||||
# ============================================================
|
||||
# QComboBox — 下拉框
|
||||
# ============================================================
|
||||
def vqt6_qcombobox_create() -> QtComboBoxPtr | t.State: pass
|
||||
def vqt6_qcombobox_create_with_parent(parent: QtWidgetPtr) -> QtComboBoxPtr | t.State: pass
|
||||
def vqt6_qcombobox_add_item(cb: QtComboBoxPtr, text: QtStringPtr) -> t.State: pass
|
||||
def vqt6_qcombobox_add_items(cb: QtComboBoxPtr, items: QtStringListPtr) -> t.State: pass
|
||||
def vqt6_qcombobox_insert_item(cb: QtComboBoxPtr, index: t.CInt, text: QtStringPtr) -> t.State: pass
|
||||
def vqt6_qcombobox_remove_item(cb: QtComboBoxPtr, index: t.CInt) -> t.State: pass
|
||||
def vqt6_qcombobox_clear(cb: QtComboBoxPtr) -> t.State: pass
|
||||
def vqt6_qcombobox_count(cb: QtComboBoxPtr) -> t.CInt | t.State: pass
|
||||
def vqt6_qcombobox_current_index(cb: QtComboBoxPtr) -> t.CInt | t.State: pass
|
||||
def vqt6_qcombobox_set_current_index(cb: QtComboBoxPtr, index: t.CInt) -> t.State: pass
|
||||
def vqt6_qcombobox_current_text(cb: QtComboBoxPtr) -> QtStringPtr | t.State: pass
|
||||
def vqt6_qcombobox_item_text(cb: QtComboBoxPtr, index: t.CInt) -> QtStringPtr | t.State: pass
|
||||
def vqt6_qcombobox_set_editable(cb: QtComboBoxPtr, editable: t.CInt) -> t.State: pass
|
||||
def vqt6_qcombobox_is_editable(cb: QtComboBoxPtr) -> t.CInt | t.State: pass
|
||||
|
||||
|
||||
# ============================================================
|
||||
# QListWidget — 列表控件
|
||||
# ============================================================
|
||||
def vqt6_qlistwidget_create() -> QtListWidgetPtr | t.State: pass
|
||||
def vqt6_qlistwidget_create_with_parent(parent: QtWidgetPtr) -> QtListWidgetPtr | t.State: pass
|
||||
def vqt6_qlistwidget_add_item(lw: QtListWidgetPtr, text: QtStringPtr) -> t.State: pass
|
||||
def vqt6_qlistwidget_add_items(lw: QtListWidgetPtr, items: QtStringListPtr) -> t.State: pass
|
||||
def vqt6_qlistwidget_insert_item(lw: QtListWidgetPtr, row: t.CInt, text: QtStringPtr) -> t.State: pass
|
||||
def vqt6_qlistwidget_remove_item_widget(lw: QtListWidgetPtr, row: t.CInt) -> t.State: pass
|
||||
def vqt6_qlistwidget_take_item(lw: QtListWidgetPtr, row: t.CInt) -> QtListWidgetItemPtr | t.State: pass
|
||||
def vqt6_qlistwidget_clear(lw: QtListWidgetPtr) -> t.State: pass
|
||||
def vqt6_qlistwidget_count(lw: QtListWidgetPtr) -> t.CInt | t.State: pass
|
||||
def vqt6_qlistwidget_current_row(lw: QtListWidgetPtr) -> t.CInt | t.State: pass
|
||||
def vqt6_qlistwidget_set_current_row(lw: QtListWidgetPtr, row: t.CInt) -> t.State: pass
|
||||
def vqt6_qlistwidget_current_item_text(lw: QtListWidgetPtr) -> QtStringPtr | t.State: pass
|
||||
def vqt6_qlistwidget_item_text(lw: QtListWidgetPtr, row: t.CInt) -> QtStringPtr | t.State: pass
|
||||
def vqt6_qlistwidget_set_item_text(lw: QtListWidgetPtr, row: t.CInt, text: QtStringPtr) -> t.State: pass
|
||||
|
||||
|
||||
# ============================================================
|
||||
# QProgressBar — 进度条
|
||||
# ============================================================
|
||||
def vqt6_qprogressbar_create() -> QtProgressBarPtr | t.State: pass
|
||||
def vqt6_qprogressbar_create_with_parent(parent: QtWidgetPtr) -> QtProgressBarPtr | t.State: pass
|
||||
def vqt6_qprogressbar_set_value(pb: QtProgressBarPtr, value: t.CInt) -> t.State: pass
|
||||
def vqt6_qprogressbar_value(pb: QtProgressBarPtr) -> t.CInt | t.State: pass
|
||||
def vqt6_qprogressbar_set_minimum(pb: QtProgressBarPtr, min: t.CInt) -> t.State: pass
|
||||
def vqt6_qprogressbar_set_maximum(pb: QtProgressBarPtr, max: t.CInt) -> t.State: pass
|
||||
def vqt6_qprogressbar_set_range(pb: QtProgressBarPtr, min: t.CInt, max: t.CInt) -> t.State: pass
|
||||
def vqt6_qprogressbar_minimum(pb: QtProgressBarPtr) -> t.CInt | t.State: pass
|
||||
def vqt6_qprogressbar_maximum(pb: QtProgressBarPtr) -> t.CInt | t.State: pass
|
||||
def vqt6_qprogressbar_set_text_visible(pb: QtProgressBarPtr, visible: t.CInt) -> t.State: pass
|
||||
def vqt6_qprogressbar_set_format(pb: QtProgressBarPtr, format: QtStringPtr) -> t.State: pass
|
||||
def vqt6_qprogressbar_reset(pb: QtProgressBarPtr) -> t.State: pass
|
||||
|
||||
|
||||
# ============================================================
|
||||
# QSlider — 滑块
|
||||
# ============================================================
|
||||
def vqt6_qslider_create() -> QtSliderPtr | t.State: pass
|
||||
def vqt6_qslider_create_with_orientation(orientation: t.CInt) -> QtSliderPtr | t.State: pass
|
||||
def vqt6_qslider_create_with_orientation_parent(orientation: t.CInt, parent: QtWidgetPtr) -> QtSliderPtr | t.State: pass
|
||||
def vqt6_qslider_set_value(s: QtSliderPtr, value: t.CInt) -> t.State: pass
|
||||
def vqt6_qslider_value(s: QtSliderPtr) -> t.CInt | t.State: pass
|
||||
def vqt6_qslider_set_minimum(s: QtSliderPtr, min: t.CInt) -> t.State: pass
|
||||
def vqt6_qslider_set_maximum(s: QtSliderPtr, max: t.CInt) -> t.State: pass
|
||||
def vqt6_qslider_set_range(s: QtSliderPtr, min: t.CInt, max: t.CInt) -> t.State: pass
|
||||
def vqt6_qslider_set_orientation(s: QtSliderPtr, orientation: t.CInt) -> t.State: pass
|
||||
def vqt6_qslider_orientation(s: QtSliderPtr) -> t.CInt | t.State: pass
|
||||
def vqt6_qslider_set_single_step(s: QtSliderPtr, step: t.CInt) -> t.State: pass
|
||||
def vqt6_qslider_set_page_step(s: QtSliderPtr, step: t.CInt) -> t.State: pass
|
||||
|
||||
|
||||
# ============================================================
|
||||
# QSpinBox — 数字输入框
|
||||
# ============================================================
|
||||
def vqt6_qspinbox_create() -> QtSpinBoxPtr | t.State: pass
|
||||
def vqt6_qspinbox_create_with_parent(parent: QtWidgetPtr) -> QtSpinBoxPtr | t.State: pass
|
||||
def vqt6_qspinbox_value(sb: QtSpinBoxPtr) -> t.CInt | t.State: pass
|
||||
def vqt6_qspinbox_set_value(sb: QtSpinBoxPtr, value: t.CInt) -> t.State: pass
|
||||
def vqt6_qspinbox_set_minimum(sb: QtSpinBoxPtr, min: t.CInt) -> t.State: pass
|
||||
def vqt6_qspinbox_set_maximum(sb: QtSpinBoxPtr, max: t.CInt) -> t.State: pass
|
||||
def vqt6_qspinbox_set_range(sb: QtSpinBoxPtr, min: t.CInt, max: t.CInt) -> t.State: pass
|
||||
def vqt6_qspinbox_minimum(sb: QtSpinBoxPtr) -> t.CInt | t.State: pass
|
||||
def vqt6_qspinbox_maximum(sb: QtSpinBoxPtr) -> t.CInt | t.State: pass
|
||||
def vqt6_qspinbox_set_single_step(sb: QtSpinBoxPtr, step: t.CInt) -> t.State: pass
|
||||
def vqt6_qspinbox_set_prefix(sb: QtSpinBoxPtr, prefix: QtStringPtr) -> t.State: pass
|
||||
def vqt6_qspinbox_set_suffix(sb: QtSpinBoxPtr, suffix: QtStringPtr) -> t.State: pass
|
||||
def vqt6_qspinbox_prefix(sb: QtSpinBoxPtr) -> QtStringPtr | t.State: pass
|
||||
def vqt6_qspinbox_suffix(sb: QtSpinBoxPtr) -> QtStringPtr | t.State: pass
|
||||
|
||||
|
||||
# ============================================================
|
||||
# 布局 - QLayout / QBoxLayout / QGridLayout / QFormLayout
|
||||
# ============================================================
|
||||
def vqt6_qlayout_add_widget(layout: QtLayoutPtr, widget: QtWidgetPtr) -> t.State: pass
|
||||
def vqt6_qlayout_remove_widget(layout: QtLayoutPtr, widget: QtWidgetPtr) -> t.State: pass
|
||||
def vqt6_qlayout_count(layout: QtLayoutPtr) -> t.CInt | t.State: pass
|
||||
def vqt6_qlayout_item_at(layout: QtLayoutPtr, index: t.CInt) -> QtWidgetPtr | t.State: pass
|
||||
def vqt6_qlayout_set_contents_margins(layout: QtLayoutPtr, left: t.CInt, top: t.CInt, right: t.CInt, bottom: t.CInt) -> t.State: pass
|
||||
def vqt6_qlayout_set_spacing(layout: QtLayoutPtr, spacing: t.CInt) -> t.State: pass
|
||||
def vqt6_qlayout_spacing(layout: QtLayoutPtr) -> t.CInt | t.State: pass
|
||||
def vqt6_qlayout_invalidate(layout: QtLayoutPtr) -> t.State: pass
|
||||
|
||||
# QHBoxLayout
|
||||
def vqt6_qhboxlayout_create() -> QtBoxLayoutPtr | t.State: pass
|
||||
def vqt6_qhboxlayout_create_with_parent(parent: QtWidgetPtr) -> QtBoxLayoutPtr | t.State: pass
|
||||
def vqt6_qhboxlayout_add_layout(layout: QtBoxLayoutPtr, child: QtLayoutPtr) -> t.State: pass
|
||||
def vqt6_qhboxlayout_add_stretch(layout: QtBoxLayoutPtr, stretch: t.CInt) -> t.State: pass
|
||||
def vqt6_qhboxlayout_add_spacing(layout: QtBoxLayoutPtr, size: t.CInt) -> t.State: pass
|
||||
|
||||
# QVBoxLayout
|
||||
def vqt6_qvboxlayout_create() -> QtBoxLayoutPtr | t.State: pass
|
||||
def vqt6_qvboxlayout_create_with_parent(parent: QtWidgetPtr) -> QtBoxLayoutPtr | t.State: pass
|
||||
def vqt6_qvboxlayout_add_layout(layout: QtBoxLayoutPtr, child: QtLayoutPtr) -> t.State: pass
|
||||
def vqt6_qvboxlayout_add_stretch(layout: QtBoxLayoutPtr, stretch: t.CInt) -> t.State: pass
|
||||
def vqt6_qvboxlayout_add_spacing(layout: QtBoxLayoutPtr, size: t.CInt) -> t.State: pass
|
||||
|
||||
# QGridLayout
|
||||
def vqt6_qgridlayout_create() -> QtGridLayoutPtr | t.State: pass
|
||||
def vqt6_qgridlayout_create_with_parent(parent: QtWidgetPtr) -> QtGridLayoutPtr | t.State: pass
|
||||
def vqt6_qgridlayout_add_widget(gl: QtGridLayoutPtr, w: QtWidgetPtr, row: t.CInt, col: t.CInt) -> t.State: pass
|
||||
def vqt6_qgridlayout_add_widget_with_span(gl: QtGridLayoutPtr, w: QtWidgetPtr, row: t.CInt, col: t.CInt, row_span: t.CInt, col_span: t.CInt) -> t.State: pass
|
||||
|
||||
# QFormLayout
|
||||
def vqt6_qformlayout_create() -> QtFormLayoutPtr | t.State: pass
|
||||
def vqt6_qformlayout_create_with_parent(parent: QtWidgetPtr) -> QtFormLayoutPtr | t.State: pass
|
||||
def vqt6_qformlayout_add_row(fl: QtFormLayoutPtr, label: QtStringPtr, field: QtWidgetPtr) -> t.State: pass
|
||||
def vqt6_qformlayout_add_row_widget_pair(fl: QtFormLayoutPtr, label: QtWidgetPtr, field: QtWidgetPtr) -> t.State: pass
|
||||
|
||||
|
||||
# ============================================================
|
||||
# QStackedWidget / QTabWidget
|
||||
# ============================================================
|
||||
def vqt6_qstackedwidget_create() -> QtStackedWidgetPtr | t.State: pass
|
||||
def vqt6_qstackedwidget_create_with_parent(parent: QtWidgetPtr) -> QtStackedWidgetPtr | t.State: pass
|
||||
def vqt6_qstackedwidget_add_widget(sw: QtStackedWidgetPtr, w: QtWidgetPtr) -> t.CInt | t.State: pass
|
||||
def vqt6_qstackedwidget_remove_widget(sw: QtStackedWidgetPtr, w: QtWidgetPtr) -> t.State: pass
|
||||
def vqt6_qstackedwidget_count(sw: QtStackedWidgetPtr) -> t.CInt | t.State: pass
|
||||
def vqt6_qstackedwidget_current_index(sw: QtStackedWidgetPtr) -> t.CInt | t.State: pass
|
||||
def vqt6_qstackedwidget_set_current_index(sw: QtStackedWidgetPtr, index: t.CInt) -> t.State: pass
|
||||
def vqt6_qstackedwidget_current_widget(sw: QtStackedWidgetPtr) -> QtWidgetPtr | t.State: pass
|
||||
def vqt6_qstackedwidget_widget(sw: QtStackedWidgetPtr, index: t.CInt) -> QtWidgetPtr | t.State: pass
|
||||
|
||||
def vqt6_qtabwidget_create() -> QtTabWidgetPtr | t.State: pass
|
||||
def vqt6_qtabwidget_create_with_parent(parent: QtWidgetPtr) -> QtTabWidgetPtr | t.State: pass
|
||||
def vqt6_qtabwidget_add_tab(tw: QtTabWidgetPtr, w: QtWidgetPtr, label: QtStringPtr) -> t.CInt | t.State: pass
|
||||
def vqt6_qtabwidget_insert_tab(tw: QtTabWidgetPtr, index: t.CInt, w: QtWidgetPtr, label: QtStringPtr) -> t.CInt | t.State: pass
|
||||
def vqt6_qtabwidget_remove_tab(tw: QtTabWidgetPtr, index: t.CInt) -> t.State: pass
|
||||
def vqt6_qtabwidget_count(tw: QtTabWidgetPtr) -> t.CInt | t.State: pass
|
||||
def vqt6_qtabwidget_current_index(tw: QtTabWidgetPtr) -> t.CInt | t.State: pass
|
||||
def vqt6_qtabwidget_set_current_index(tw: QtTabWidgetPtr, index: t.CInt) -> t.State: pass
|
||||
def vqt6_qtabwidget_tab_text(tw: QtTabWidgetPtr, index: t.CInt) -> QtStringPtr | t.State: pass
|
||||
def vqt6_qtabwidget_set_tab_text(tw: QtTabWidgetPtr, index: t.CInt, text: QtStringPtr) -> t.State: pass
|
||||
def vqt6_qtabwidget_set_tabs_closable(tw: QtTabWidgetPtr, closable: t.CInt) -> t.State: pass
|
||||
def vqt6_qtabwidget_tabs_closable(tw: QtTabWidgetPtr) -> t.CInt | t.State: pass
|
||||
|
||||
|
||||
# ============================================================
|
||||
# QMenuBar / QMenu / QAction
|
||||
# ============================================================
|
||||
def vqt6_qmenubar_create() -> QtMenuBarPtr | t.State: pass
|
||||
def vqt6_qmenubar_create_with_parent(parent: QtWidgetPtr) -> QtMenuBarPtr | t.State: pass
|
||||
def vqt6_qmenubar_add_menu(mb: QtMenuBarPtr, title: QtStringPtr) -> QtMenuPtr | t.State: pass
|
||||
def vqt6_qmenubar_add_menu_with_menu(mb: QtMenuBarPtr, menu: QtMenuPtr) -> t.State: pass
|
||||
def vqt6_qmenubar_add_action(mb: QtMenuBarPtr, action: QtActionPtr) -> t.State: pass
|
||||
def vqt6_qmenubar_clear(mb: QtMenuBarPtr) -> t.State: pass
|
||||
|
||||
def vqt6_qmenu_create() -> QtMenuPtr | t.State: pass
|
||||
def vqt6_qmenu_create_with_title(title: QtStringPtr) -> QtMenuPtr | t.State: pass
|
||||
def vqt6_qmenu_create_with_title_parent(title: QtStringPtr, parent: QtWidgetPtr) -> QtMenuPtr | t.State: pass
|
||||
def vqt6_qmenu_add_menu(menu: QtMenuPtr, title: QtStringPtr) -> QtMenuPtr | t.State: pass
|
||||
def vqt6_qmenu_add_action(menu: QtMenuPtr, action: QtActionPtr) -> t.State: pass
|
||||
def vqt6_qmenu_add_separator(menu: QtMenuPtr) -> t.State: pass
|
||||
def vqt6_qmenu_clear(menu: QtMenuPtr) -> t.State: pass
|
||||
def vqt6_qmenu_set_title(menu: QtMenuPtr, title: QtStringPtr) -> t.State: pass
|
||||
def vqt6_qmenu_title(menu: QtMenuPtr) -> QtStringPtr | t.State: pass
|
||||
def vqt6_qmenu_add_action_with_text(menu: QtMenuPtr, text: QtStringPtr) -> QtActionPtr | t.State: pass
|
||||
|
||||
def vqt6_qaction_create() -> QtActionPtr | t.State: pass
|
||||
def vqt6_qaction_create_with_text(text: QtStringPtr) -> QtActionPtr | t.State: pass
|
||||
def vqt6_qaction_create_with_text_parent(text: QtStringPtr, parent: QtWidgetPtr) -> QtActionPtr | t.State: pass
|
||||
def vqt6_qaction_set_text(action: QtActionPtr, text: QtStringPtr) -> t.State: pass
|
||||
def vqt6_qaction_text(action: QtActionPtr) -> QtStringPtr | t.State: pass
|
||||
def vqt6_qaction_set_icon(action: QtActionPtr, icon: QtIconPtr) -> t.State: pass
|
||||
def vqt6_qaction_icon(action: QtActionPtr) -> QtIconPtr | t.State: pass
|
||||
def vqt6_qaction_set_shortcut(action: QtActionPtr, key_sequence: QtStringPtr) -> t.State: pass
|
||||
def vqt6_qaction_shortcut(action: QtActionPtr) -> QtStringPtr | t.State: pass
|
||||
def vqt6_qaction_set_checkable(action: QtActionPtr, checkable: t.CInt) -> t.State: pass
|
||||
def vqt6_qaction_is_checkable(action: QtActionPtr) -> t.CInt | t.State: pass
|
||||
def vqt6_qaction_set_checked(action: QtActionPtr, checked: t.CInt) -> t.State: pass
|
||||
def vqt6_qaction_is_checked(action: QtActionPtr) -> t.CInt | t.State: pass
|
||||
def vqt6_qaction_set_enabled(action: QtActionPtr, enabled: t.CInt) -> t.State: pass
|
||||
def vqt6_qaction_is_enabled(action: QtActionPtr) -> t.CInt | t.State: pass
|
||||
def vqt6_qaction_trigger(action: QtActionPtr) -> t.State: pass
|
||||
|
||||
|
||||
# ============================================================
|
||||
# QStatusBar / QToolBar
|
||||
# ============================================================
|
||||
def vqt6_qstatusbar_create() -> QtStatusBarPtr | t.State: pass
|
||||
def vqt6_qstatusbar_create_with_parent(parent: QtWidgetPtr) -> QtStatusBarPtr | t.State: pass
|
||||
def vqt6_qstatusbar_show_message(sb: QtStatusBarPtr, message: QtStringPtr, timeout_ms: t.CInt) -> t.State: pass
|
||||
def vqt6_qstatusbar_clear_message(sb: QtStatusBarPtr) -> t.State: pass
|
||||
def vqt6_qstatusbar_current_message(sb: QtStatusBarPtr) -> QtStringPtr | t.State: pass
|
||||
def vqt6_qstatusbar_add_widget(sb: QtStatusBarPtr, w: QtWidgetPtr, stretch: t.CInt) -> t.State: pass
|
||||
def vqt6_qstatusbar_add_permanent_widget(sb: QtStatusBarPtr, w: QtWidgetPtr, stretch: t.CInt) -> t.State: pass
|
||||
|
||||
def vqt6_qtoolbar_create() -> QtToolBarPtr | t.State: pass
|
||||
def vqt6_qtoolbar_create_with_parent(parent: QtWidgetPtr) -> QtToolBarPtr | t.State: pass
|
||||
def vqt6_qtoolbar_add_widget(tb: QtToolBarPtr, w: QtWidgetPtr) -> QtActionPtr | t.State: pass
|
||||
def vqt6_qtoolbar_add_action(tb: QtToolBarPtr, action: QtActionPtr) -> t.State: pass
|
||||
def vqt6_qtoolbar_add_separator(tb: QtToolBarPtr) -> t.State: pass
|
||||
def vqt6_qtoolbar_set_icon_size(tb: QtToolBarPtr, w: t.CInt, h: t.CInt) -> t.State: pass
|
||||
def vqt6_qtoolbar_set_orientation(tb: QtToolBarPtr, orientation: t.CInt) -> t.State: pass
|
||||
def vqt6_qtoolbar_orientation(tb: QtToolBarPtr) -> t.CInt | t.State: pass
|
||||
|
||||
|
||||
# ============================================================
|
||||
# QMessageBox — 消息对话框(静态方法)
|
||||
# ============================================================
|
||||
def vqt6_qmessagebox_information(parent: QtWidgetPtr, title: QtStringPtr, text: QtStringPtr, buttons: t.CInt) -> t.CInt | t.State: pass
|
||||
def vqt6_qmessagebox_warning(parent: QtWidgetPtr, title: QtStringPtr, text: QtStringPtr, buttons: t.CInt) -> t.CInt | t.State: pass
|
||||
def vqt6_qmessagebox_critical(parent: QtWidgetPtr, title: QtStringPtr, text: QtStringPtr, buttons: t.CInt) -> t.CInt | t.State: pass
|
||||
def vqt6_qmessagebox_question(parent: QtWidgetPtr, title: QtStringPtr, text: QtStringPtr, buttons: t.CInt) -> t.CInt | t.State: pass
|
||||
def vqt6_qmessagebox_about(parent: QtWidgetPtr, title: QtStringPtr, text: QtStringPtr) -> t.State: pass
|
||||
def vqt6_qmessagebox_about_qt(parent: QtWidgetPtr) -> t.State: pass
|
||||
|
||||
|
||||
# ============================================================
|
||||
# QFileDialog — 文件选择对话框(静态方法)
|
||||
# ============================================================
|
||||
def vqt6_qfiledialog_get_open_file_name(parent: QtWidgetPtr, caption: QtStringPtr, dir: QtStringPtr, filter: QtStringPtr) -> QtStringPtr | t.State: pass
|
||||
def vqt6_qfiledialog_get_save_file_name(parent: QtWidgetPtr, caption: QtStringPtr, dir: QtStringPtr, filter: QtStringPtr) -> QtStringPtr | t.State: pass
|
||||
def vqt6_qfiledialog_get_existing_directory(parent: QtWidgetPtr, caption: QtStringPtr, dir: QtStringPtr) -> QtStringPtr | t.State: pass
|
||||
def vqt6_qfiledialog_get_open_file_names(parent: QtWidgetPtr, caption: QtStringPtr, dir: QtStringPtr, filter: QtStringPtr) -> QtStringListPtr | t.State: pass
|
||||
|
||||
|
||||
# ============================================================
|
||||
# QColorDialog / QFontDialog / QInputDialog — 各种对话框
|
||||
# ============================================================
|
||||
def vqt6_qcolordialog_get_color(initial: QtColorPtr, parent: QtWidgetPtr, title: QtStringPtr) -> QtColorPtr | t.State: pass
|
||||
def vqt6_qfontdialog_get_font(initial: QtFontPtr, parent: QtWidgetPtr, title: QtStringPtr) -> QtFontPtr | t.State: pass
|
||||
def vqt6_qinputdialog_get_text(parent: QtWidgetPtr, title: QtStringPtr, label: QtStringPtr, echo_mode: t.CInt, text: QtStringPtr, ok_pressed: t.CInt | t.CPtr) -> QtStringPtr | t.State: pass
|
||||
def vqt6_qinputdialog_get_int(parent: QtWidgetPtr, title: QtStringPtr, label: QtStringPtr, value: t.CInt, min_val: t.CInt, max_val: t.CInt, step: t.CInt, ok_pressed: t.CInt | t.CPtr) -> t.CInt | t.State: pass
|
||||
def vqt6_qinputdialog_get_double(parent: QtWidgetPtr, title: QtStringPtr, label: QtStringPtr, value: t.CDouble, min_val: t.CDouble, max_val: t.CDouble, decimals: t.CInt, ok_pressed: t.CInt | t.CPtr) -> t.CDouble | t.State: pass
|
||||
def vqt6_qinputdialog_get_item(parent: QtWidgetPtr, title: QtStringPtr, label: QtStringPtr, items: QtStringListPtr, current: t.CInt, editable: t.CInt, ok_pressed: t.CInt | t.CPtr) -> QtStringPtr | t.State: pass
|
||||
186
includes/vqt6 copy/_types.py
Normal file
186
includes/vqt6 copy/_types.py
Normal file
@@ -0,0 +1,186 @@
|
||||
import t
|
||||
from stdint import *
|
||||
|
||||
# ============================================================
|
||||
# vqt6/_types.py — 公共类型定义
|
||||
#
|
||||
# Qt6 C++ 类在 Viper 端都是不透明指针 (void*)
|
||||
# 不暴露 C++ 类的内部布局,只暴露指针
|
||||
# ============================================================
|
||||
|
||||
# 不透明指针 typedef(Qt6 C++ 类的 Viper 端表示)
|
||||
QtObjectPtr: t.CTypedef = t.CVoid | t.CPtr # void* 通用不透明指针
|
||||
QtStringPtr: t.CTypedef = t.CVoid | t.CPtr # QString*
|
||||
QtByteArrayPtr: t.CTypedef = t.CVoid | t.CPtr # QByteArray*
|
||||
QtVariantPtr: t.CTypedef = t.CVoid | t.CPtr # QVariant*
|
||||
QtObjectListPtr: t.CTypedef = t.CVoid | t.CPtr # QList<QObject*>*
|
||||
QtStringListPtr: t.CTypedef = t.CVoid | t.CPtr # QStringList*
|
||||
QtByteArrayListPtr: t.CTypedef = t.CVoid | t.CPtr # QList<QByteArray>*
|
||||
QtEventPtr: t.CTypedef = t.CVoid | t.CPtr # QEvent*
|
||||
|
||||
# QtCore
|
||||
QtCoreAppPtr: t.CTypedef = t.CVoid | t.CPtr # QCoreApplication*
|
||||
QtTimerPtr: t.CTypedef = t.CVoid | t.CPtr # QTimer*
|
||||
QtObjectPtr: t.CTypedef = t.CVoid | t.CPtr # QObject*
|
||||
QtThreadPtr: t.CTypedef = t.CVoid | t.CPtr # QThread*
|
||||
QtMutexPtr: t.CTypedef = t.CVoid | t.CPtr # QMutex*
|
||||
QtWaitConditionPtr: t.CTypedef = t.CVoid | t.CPtr # QWaitCondition*
|
||||
|
||||
# QtGui
|
||||
QtColorPtr: t.CTypedef = t.CVoid | t.CPtr # QColor*
|
||||
QtFontPtr: t.CTypedef = t.CVoid | t.CPtr # QFont*
|
||||
QtFontMetricsPtr: t.CTypedef = t.CVoid | t.CPtr # QFontMetrics*
|
||||
QtPixmapPtr: t.CTypedef = t.CVoid | t.CPtr # QPixmap*
|
||||
QtImagePtr: t.CTypedef = t.CVoid | t.CPtr # QImage*
|
||||
QtPainterPtr: t.CTypedef = t.CVoid | t.CPtr # QPainter*
|
||||
QtPenPtr: t.CTypedef = t.CVoid | t.CPtr # QPen*
|
||||
QtBrushPtr: t.CTypedef = t.CVoid | t.CPtr # QBrush*
|
||||
QtIconPtr: t.CTypedef = t.CVoid | t.CPtr # QIcon*
|
||||
QtKeyEventPtr: t.CTypedef = t.CVoid | t.CPtr # QKeyEvent*
|
||||
QtMouseEventPtr: t.CTypedef = t.CVoid | t.CPtr # QMouseEvent*
|
||||
QtResizeEventPtr: t.CTypedef = t.CVoid | t.CPtr # QResizeEvent*
|
||||
QtPaintEventPtr: t.CTypedef = t.CVoid | t.CPtr # QPaintEvent*
|
||||
QtCloseEventPtr: t.CTypedef = t.CVoid | t.CPtr # QCloseEvent*
|
||||
QtCursorPtr: t.CTypedef = t.CVoid | t.CPtr # QCursor*
|
||||
|
||||
# QtWidgets
|
||||
QtAppPtr: t.CTypedef = t.CVoid | t.CPtr # QApplication*
|
||||
QtWidgetPtr: t.CTypedef = t.CVoid | t.CPtr # QWidget*
|
||||
QtDialogPtr: t.CTypedef = t.CVoid | t.CPtr # QDialog*
|
||||
QtMainWindowPtr: t.CTypedef = t.CVoid | t.CPtr # QMainWindow*
|
||||
QtLabelPtr: t.CTypedef = t.CVoid | t.CPtr # QLabel*
|
||||
QtPushButtonPtr: t.CTypedef = t.CVoid | t.CPtr # QPushButton*
|
||||
QtLineEditPtr: t.CTypedef = t.CVoid | t.CPtr # QLineEdit*
|
||||
QtTextEditPtr: t.CTypedef = t.CVoid | t.CPtr # QTextEdit*
|
||||
QtPlainTextEditPtr: t.CTypedef = t.CVoid | t.CPtr # QPlainTextEdit*
|
||||
QtCheckBoxPtr: t.CTypedef = t.CVoid | t.CPtr # QCheckBox*
|
||||
QtRadioButtonPtr: t.CTypedef = t.CVoid | t.CPtr # QRadioButton*
|
||||
QtComboBoxPtr: t.CTypedef = t.CVoid | t.CPtr # QComboBox*
|
||||
QtListWidgetPtr: t.CTypedef = t.CVoid | t.CPtr # QListWidget*
|
||||
QtListWidgetItemPtr: t.CTypedef = t.CVoid | t.CPtr # QListWidgetItem*
|
||||
QtProgressBarPtr: t.CTypedef = t.CVoid | t.CPtr # QProgressBar*
|
||||
QtSliderPtr: t.CTypedef = t.CVoid | t.CPtr # QSlider*
|
||||
QtSpinBoxPtr: t.CTypedef = t.CVoid | t.CPtr # QSpinBox*
|
||||
QtLayoutPtr: t.CTypedef = t.CVoid | t.CPtr # QLayout*
|
||||
QtBoxLayoutPtr: t.CTypedef = t.CVoid | t.CPtr # QHBoxLayout / QVBoxLayout*
|
||||
QtGridLayoutPtr: t.CTypedef = t.CVoid | t.CPtr # QGridLayout*
|
||||
QtFormLayoutPtr: t.CTypedef = t.CVoid | t.CPtr # QFormLayout*
|
||||
QtStackedWidgetPtr: t.CTypedef = t.CVoid | t.CPtr # QStackedWidget*
|
||||
QtTabWidgetPtr: t.CTypedef = t.CVoid | t.CPtr # QTabWidget*
|
||||
QtMenuBarPtr: t.CTypedef = t.CVoid | t.CPtr # QMenuBar*
|
||||
QtMenuPtr: t.CTypedef = t.CVoid | t.CPtr # QMenu*
|
||||
QtActionPtr: t.CTypedef = t.CVoid | t.CPtr # QAction*
|
||||
QtStatusBarPtr: t.CTypedef = t.CVoid | t.CPtr # QStatusBar*
|
||||
QtToolBarPtr: t.CTypedef = t.CVoid | t.CPtr # QToolBar*
|
||||
QtMessageBoxPtr: t.CTypedef = t.CVoid | t.CPtr # QMessageBox*
|
||||
QtFileDialogPtr: t.CTypedef = t.CVoid | t.CPtr # QFileDialog*
|
||||
QtColorDialogPtr: t.CTypedef = t.CVoid | t.CPtr # QColorDialog*
|
||||
QtFontDialogPtr: t.CTypedef = t.CVoid | t.CPtr # QFontDialog*
|
||||
QtInputDialogPtr: t.CTypedef = t.CVoid | t.CPtr # QInputDialog*
|
||||
|
||||
# QtNetwork
|
||||
QtTcpSocketPtr: t.CTypedef = t.CVoid | t.CPtr # QTcpSocket*
|
||||
QtUdpSocketPtr: t.CTypedef = t.CVoid | t.CPtr # QUdpSocket*
|
||||
QtHostAddressPtr: t.CTypedef = t.CVoid | t.CPtr # QHostAddress*
|
||||
QtAbstractSocketPtr: t.CTypedef = t.CVoid | t.CPtr # QAbstractSocket*
|
||||
QtNetworkAccessManagerPtr: t.CTypedef = t.CVoid | t.CPtr # QNetworkAccessManager*
|
||||
QtNetworkReplyPtr: t.CTypedef = t.CVoid | t.CPtr # QNetworkReply*
|
||||
QtNetworkRequestPtr: t.CTypedef = t.CVoid | t.CPtr # QNetworkRequest*
|
||||
|
||||
# ============================================================
|
||||
# Qt 通用常量(C++ 枚举值的 C 兼容定义)
|
||||
# ============================================================
|
||||
|
||||
# Qt 键盘按键 (Qt::Key)
|
||||
QT_KEY_ESCAPE: t.CDefine = 0x01000000
|
||||
QT_KEY_TAB: t.CDefine = 0x01000001
|
||||
QT_KEY_BACKTAB: t.CDefine = 0x01000002
|
||||
QT_KEY_BACKSPACE: t.CDefine = 0x01000003
|
||||
QT_KEY_RETURN: t.CDefine = 0x01000004
|
||||
QT_KEY_ENTER: t.CDefine = 0x01000005
|
||||
QT_KEY_INSERT: t.CDefine = 0x01000006
|
||||
QT_KEY_DELETE: t.CDefine = 0x01000007
|
||||
QT_KEY_PAUSE: t.CDefine = 0x01000008
|
||||
QT_KEY_PRINT: t.CDefine = 0x01000009
|
||||
QT_KEY_HOME: t.CDefine = 0x01000010
|
||||
QT_KEY_END: t.CDefine = 0x01000011
|
||||
QT_KEY_LEFT: t.CDefine = 0x01000012
|
||||
QT_KEY_UP: t.CDefine = 0x01000013
|
||||
QT_KEY_RIGHT: t.CDefine = 0x01000014
|
||||
QT_KEY_DOWN: t.CDefine = 0x01000015
|
||||
QT_KEY_PAGEUP: t.CDefine = 0x01000016
|
||||
QT_KEY_PAGEDOWN: t.CDefine = 0x01000017
|
||||
QT_KEY_SHIFT: t.CDefine = 0x01000020
|
||||
QT_KEY_CONTROL: t.CDefine = 0x01000021
|
||||
QT_KEY_META: t.CDefine = 0x01000022
|
||||
QT_KEY_ALT: t.CDefine = 0x01000023
|
||||
QT_KEY_F1: t.CDefine = 0x01000030
|
||||
QT_KEY_F2: t.CDefine = 0x01000031
|
||||
QT_KEY_F12: t.CDefine = 0x0100003b
|
||||
QT_KEY_SPACE: t.CDefine = 0x20
|
||||
QT_KEY_A: t.CDefine = 0x41
|
||||
QT_KEY_Z: t.CDefine = 0x5a
|
||||
QT_KEY_0: t.CDefine = 0x30
|
||||
QT_KEY_9: t.CDefine = 0x39
|
||||
|
||||
# Qt 鼠标按键 (Qt::MouseButton)
|
||||
QT_NO_BUTTON: t.CDefine = 0x00000000
|
||||
QT_LEFT_BUTTON: t.CDefine = 0x00000001
|
||||
QT_RIGHT_BUTTON: t.CDefine = 0x00000002
|
||||
QT_MID_BUTTON: t.CDefine = 0x00000004
|
||||
|
||||
# Qt::AlignmentFlag
|
||||
QT_ALIGN_LEFT: t.CDefine = 0x0001
|
||||
QT_ALIGN_RIGHT: t.CDefine = 0x0002
|
||||
QT_ALIGN_HCENTER: t.CDefine = 0x0004
|
||||
QT_ALIGN_TOP: t.CDefine = 0x0020
|
||||
QT_ALIGN_BOTTOM: t.CDefine = 0x0040
|
||||
QT_ALIGN_VCENTER: t.CDefine = 0x0080
|
||||
QT_ALIGN_CENTER: t.CDefine = QT_ALIGN_HCENTER | QT_ALIGN_VCENTER
|
||||
|
||||
# Qt::Orientation
|
||||
QT_HORIZONTAL: t.CDefine = 0x1
|
||||
QT_VERTICAL: t.CDefine = 0x2
|
||||
|
||||
# Qt 焦点
|
||||
QT_NO_FOCUS: t.CDefine = 0x00
|
||||
QT_TAB_FOCUS: t.CDefine = 0x01
|
||||
QT_CLICK_FOCUS: t.CDefine = 0x02
|
||||
QT_STRONG_FOCUS: t.CDefine = QT_TAB_FOCUS | QT_CLICK_FOCUS
|
||||
QT_WHEEL_FOCUS: t.CDefine = 0x04
|
||||
QT_ALL_FOCUS: t.CDefine = QT_STRONG_FOCUS | QT_WHEEL_FOCUS
|
||||
|
||||
# Qt::WindowFlag
|
||||
QT_WINDOW: t.CDefine = 0x00000001
|
||||
QT_DIALOG: t.CDefine = 0x00000002 | QT_WINDOW
|
||||
QT_SHEET: t.CDefine = 0x00000004 | QT_WINDOW
|
||||
QT_DRAWER: t.CDefine = QT_SHEET | 0x00000008
|
||||
QT_POPUP: t.CDefine = 0x00000008 | QT_WINDOW
|
||||
QT_TOOL: t.CDefine = 0x0000000a | QT_WINDOW
|
||||
QT_TOOLTIP: t.CDefine = 0x0000000c | QT_WINDOW
|
||||
QT_SPLASH_SCREEN: t.CDefine = 0x0000000e | QT_WINDOW
|
||||
|
||||
QT_WINDOW_TITLE: t.CDefine = 0x00000001
|
||||
QT_WINDOW_SYSTEM_MENU: t.CDefine = 0x00000002
|
||||
QT_WINDOW_MIN_MAX_BUTTONS: t.CDefine = 0x00000004
|
||||
QT_WINDOW_CLOSE_BUTTON: t.CDefine = 0x08000000
|
||||
QT_WINDOW_CONTEXT_HELP_BUTTON: t.CDefine = 0x00000008
|
||||
|
||||
# QMessageBox 标准按钮
|
||||
QT_OK: t.CDefine = 0x00000400
|
||||
QT_CANCEL: t.CDefine = 0x00400000
|
||||
QT_YES: t.CDefine = 0x00004000
|
||||
QT_NO: t.CDefine = 0x00010000
|
||||
QT_CLOSE: t.CDefine = 0x00200000
|
||||
|
||||
# 事件类型
|
||||
QT_EVENT_NONE: t.CDefine = 0
|
||||
QT_EVENT_KEY: t.CDefine = 6
|
||||
QT_EVENT_MOUSE_BUTTON_PRESS: t.CDefine = 2
|
||||
QT_EVENT_MOUSE_BUTTON_RELEASE: t.CDefine = 3
|
||||
QT_EVENT_MOUSE_MOVE: t.CDefine = 5
|
||||
QT_EVENT_PAINT: t.CDefine = 12
|
||||
QT_EVENT_RESIZE: t.CDefine = 14
|
||||
QT_EVENT_CLOSE: t.CDefine = 19
|
||||
QT_EVENT_SHOW: t.CDefine = 17
|
||||
QT_EVENT_HIDE: t.CDefine = 18
|
||||
@@ -1,16 +1,16 @@
|
||||
# vrandom - 硬件随机数生成库
|
||||
# 基于 x86 RDRAND / RDSEED 指令,使用内嵌汇编实现
|
||||
# vrandom - Hardware Random Number Generation Library
|
||||
# Implemented using inline assembly based on x86 RDRAND / RDSEED instructions
|
||||
import t, c
|
||||
import vipermath
|
||||
|
||||
|
||||
# 重试次数限制(RDRAND 通常不需要重试,RDSEED 可能需要)
|
||||
# Retry limit (RDRAND usually doesn't need retries, RDSEED might)
|
||||
RDRAND_RETRY_LIMIT: t.CDefine = 10
|
||||
RDSEED_RETRY_LIMIT: t.CDefine = 100
|
||||
|
||||
|
||||
# ============================================================
|
||||
# RDRAND - 硬件随机数(伪随机数发生器输出)
|
||||
# RDRAND - Hardware random numbers (output from a pseudo-random number generator)
|
||||
# ============================================================
|
||||
|
||||
def rdrand16() -> t.CUInt16T:
|
||||
@@ -38,7 +38,7 @@ def rdrand64() -> t.CUInt64T:
|
||||
|
||||
|
||||
# ============================================================
|
||||
# RDSEED - 硬件随机种子(熵源直接输出)
|
||||
# RDSEED - Hardware random seeds (direct output from entropy source)
|
||||
# ============================================================
|
||||
|
||||
def rdseed16() -> t.CUInt16T:
|
||||
@@ -66,8 +66,8 @@ def rdseed64() -> t.CUInt64T:
|
||||
|
||||
|
||||
# ============================================================
|
||||
# Step 版本(带成功标志,匹配 GCC builtin 接口)
|
||||
# 返回 1 表示成功,0 表示失败;随机值写入 *p
|
||||
# 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: t.CUInt16T | t.CPtr) -> t.CInt:
|
||||
@@ -143,7 +143,7 @@ def rdseed64_step(p: t.CUInt64T | t.CPtr) -> t.CInt:
|
||||
|
||||
|
||||
# ============================================================
|
||||
# 带重试的便捷接口(自动重试直到成功或达到上限)
|
||||
# Convenient interface with retry (automatically retries until it succeeds or reaches the limit)
|
||||
# ============================================================
|
||||
|
||||
def random_u16() -> t.CUInt16T:
|
||||
@@ -207,11 +207,11 @@ def seed_u64() -> t.CUInt64T:
|
||||
|
||||
|
||||
# ============================================================
|
||||
# Python random 标准库函数实现
|
||||
# 默认类型:t.CUInt64T (u64), t.CDouble (f64), t.CInt (i32)
|
||||
# Python random standard library function implementations
|
||||
# Default types: t.CUInt64T (u64), t.CDouble (f64), t.CInt (i32)
|
||||
# ============================================================
|
||||
|
||||
# ---------- 一、随机整数 ----------
|
||||
# ---------- ONE, Random integers ----------
|
||||
|
||||
def randint(a: t.CInt, b: t.CInt) -> t.CInt:
|
||||
return t.CInt(a + t.CInt(random_u64() % t.CUInt64T(b - a + 1)))
|
||||
@@ -234,7 +234,7 @@ def getrandbits(k: t.CInt) -> t.CUInt64T:
|
||||
return r & mask
|
||||
|
||||
|
||||
# ---------- 二、随机浮点数 ----------
|
||||
# ---------- TWO, Random floating-point numbers ----------
|
||||
|
||||
def random() -> t.CDouble:
|
||||
return t.CDouble(rdrand64() >> 11) * (t.CDouble(1.0) / t.CDouble(9007199254740992.0))
|
||||
|
||||
@@ -4,24 +4,23 @@ from w32.win32base import *
|
||||
from w32.win32process import CreateThread, GetExitCodeThread, GetCurrentThreadId, TlsAlloc, TlsFree, TlsGetValue, TlsSetValue
|
||||
from w32.win32sync import WaitForSingleObject
|
||||
|
||||
# 全部导入锁类,用户也可按需导入
|
||||
# All lock classes are imported, and users can also import them as needed.
|
||||
from lock import Lock
|
||||
from event import Event
|
||||
from condition import Condition
|
||||
from rwlock import RWLock
|
||||
|
||||
|
||||
@t.Object
|
||||
class Thread:
|
||||
"""线程类,封装 Windows CreateThread。
|
||||
"""Thread class, wraps Windows CreateThread.
|
||||
|
||||
线程回调签名: def thread_func(arg: t.CPtr) -> t.CPtr
|
||||
注意: Windows API 限制返回值为 DWORD(32位),64位指针会被截断。
|
||||
如需返回 64 位结果,请通过 arg 参数结构体传递。
|
||||
Thread callback signature: def thread_func(arg: t.CPtr) -> t.CPtr
|
||||
Note: Windows API limits the return value to DWORD (32-bit), so 64-bit pointers will be truncated.
|
||||
If you need to return a 64-bit result, pass it via the arg parameter struct.
|
||||
|
||||
用法:
|
||||
Usage:
|
||||
def worker(arg: t.CPtr) -> t.CPtr:
|
||||
# 线程逻辑
|
||||
# thread logic
|
||||
return NULL
|
||||
|
||||
t: Thread = Thread(worker, arg_ptr)
|
||||
@@ -70,11 +69,10 @@ class Thread:
|
||||
self.handle = NULL
|
||||
|
||||
|
||||
@t.Object
|
||||
class local:
|
||||
"""TLS (Thread Local Storage) 封装。
|
||||
"""TLS (Thread Local Storage) encapsulation.
|
||||
|
||||
用法:
|
||||
Usage:
|
||||
tls: local = local()
|
||||
tls.set(value_ptr)
|
||||
val: t.CPtr = tls.get()
|
||||
@@ -95,10 +93,10 @@ class local:
|
||||
|
||||
|
||||
def get_current_thread_id() -> ULONG:
|
||||
"""获取当前线程 ID"""
|
||||
"""Get current thread ID"""
|
||||
return GetCurrentThreadId()
|
||||
|
||||
|
||||
def sleep_ms(ms: ULONG):
|
||||
"""让当前线程休眠指定毫秒数"""
|
||||
"""Make the current thread sleep for a specified number of milliseconds"""
|
||||
Sleep(ms)
|
||||
|
||||
Reference in New Issue
Block a user