取消了 i8* == i8* 实际使用 strcmp 的规则

This commit is contained in:
2026-07-30 21:56:41 +08:00
parent cfc30d735c
commit 377b60fd67
54 changed files with 129 additions and 3730 deletions

View File

@@ -61,7 +61,7 @@ class dict:
"""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
if string.strcmp(key_ptr[0], key) == 0: return i
return self.__count__
def __getitem__(self, key: str) -> t.CPtr:

View File

@@ -111,7 +111,7 @@ class HashTable:
else:
if sh == h:
sk: str = self._slot_key(idx)
if sk == key:
if string.strcmp(sk, key) == 0:
return idx
idx = (idx + 1) & mask
i += 1

View File

@@ -86,7 +86,7 @@ class JsonValue:
cur: JsonValue | t.CPtr = self.child
while cur != None:
if cur.key != None:
if cur.key == key:
if string.strcmp(cur.key, key) == 0:
return cur
cur = cur.next
return None
@@ -98,7 +98,7 @@ class JsonValue:
cur: JsonValue | t.CPtr = self.child
while cur != None:
if cur.key != None:
if cur.key == key:
if string.strcmp(cur.key, key) == 0:
cur.vtype = val.vtype
cur.bool_val = val.bool_val
cur.int_val = val.int_val
@@ -212,7 +212,7 @@ def object_set(pool: memhub.MemManager | t.CPtr, obj: JsonValue | t.CPtr, key: t
cur: JsonValue | t.CPtr = obj.child
while cur != None:
if cur.key != None:
if cur.key == key:
if string.strcmp(cur.key, key) == 0:
cur.vtype = val.vtype
cur.bool_val = val.bool_val
cur.int_val = val.int_val

View File

@@ -25,7 +25,7 @@ LLVM 类型变体少、无通用字段、字段都是指针/小整数、操作
### 2.4 对象分配用普通类 + `mpool`
`mbuddy` 一样用普通类(无 `__new__`),由调用方注入 `mpool.MPool` 做批量分配。库内部不持有全局 `mbuddy`,遵循项目约定(`_mbuddy` 指针由 `os.py` 或调用方设置)。
`mbuddy` 一样用普通类(无 `__new__`),由调用方注入 `mpool.MPool` 做批量分配。库内部不持有全局 `mbuddy`,遵循项目约定(`_mbuddy` 指针由 `os.vp` 或调用方设置)。
---
@@ -68,22 +68,22 @@ AST 采用"胖节点"设计(所有节点共用一个 `AST` struct用 `vtype
```
includes/llvmlite/
├── __init__.py # 公共导出 + 便捷工厂函数
├── __types.py # LLVMType (REnum) + 类型构造/打印
├── __values.py # Value/Constant/SSA 值表示
├── __module.py # Module 容器(函数列表 + 目标三元组 + 输出 .ll
├── __function.py # Function + BasicBlock + 参数管理
├── __builder.py # IRBuilder指令发射 + SSA 命名 + 块跳转)
├── __init__.vp # 公共导出 + 便捷工厂函数
├── __types.vp # LLVMType (REnum) + 类型构造/打印
├── __values.vp # Value/Constant/SSA 值表示
├── __module.vp # Module 容器(函数列表 + 目标三元组 + 输出 .ll
├── __function.vp # Function + BasicBlock + 参数管理
├── __builder.vp # IRBuilder指令发射 + SSA 命名 + 块跳转)
└── README.md # 本文件
```
### 职责划分
- `__types.py``LLVMType` REnum 定义 + `TypePrint(buf, ty)` 将类型序列化为 IR 文本(如 `i32`/`i32*`/`{i32, i8*}`
- `__values.py``Value` 表示一个 SSA 值(`%0`/`%result`/常量),含类型指针 + 名字 + 是否常量
- `__module.py``Module` 持有函数链表 + 目标三元组 + 数据布局,`ModulePrint` 输出完整 `.ll`
- `__function.py``Function` 持有基本块链表 + 参数 + 返回类型;`BasicBlock` 持有指令文本缓冲
- `__builder.py``IRBuilder` 游标式 API`build_add`/`build_load`/`build_br`/... 发射指令到当前块
- `__types.vp``LLVMType` REnum 定义 + `TypePrint(buf, ty)` 将类型序列化为 IR 文本(如 `i32`/`i32*`/`{i32, i8*}`
- `__values.vp``Value` 表示一个 SSA 值(`%0`/`%result`/常量),含类型指针 + 名字 + 是否常量
- `__module.vp``Module` 持有函数链表 + 目标三元组 + 数据布局,`ModulePrint` 输出完整 `.ll`
- `__function.vp``Function` 持有基本块链表 + 参数 + 返回类型;`BasicBlock` 持有指令文本缓冲
- `__builder.vp``IRBuilder` 游标式 API`build_add`/`build_load`/`build_br`/... 发射指令到当前块
---
@@ -120,7 +120,7 @@ class LLVMType(t.REnum):
# REnum 允许空变体,仅靠 __tag 区分)
```
### 类型工厂(`__init__.py` 导出)
### 类型工厂(`__init__.vp` 导出)
```python
def Int1() -> LLVMType | t.CPtr: ... # i1
@@ -295,7 +295,7 @@ def ModulePrint(mod: Module | t.CPtr, out_path: t.CChar | t.CPtr):
## 12. 与现有架构的对接点
- **`lib/core/Codegen/LLVMCG.py`**:当前用 Python `llvmlite` 生成 IR自举时改用本库
- **`includes/viperlib.py`**:提供 `snprintf` / `sprintf`
- **`includes/mpool.py`**:提供 `MPool` 内存池
- **`includes/string.py`**:提供 `strcpy`/`strlen`/`memcpy`
- **`includes/viperlib.vp`**:提供 `snprintf` / `sprintf`
- **`includes/mpool.vp`**:提供 `MPool` 内存池
- **`includes/string.vp`**:提供 `strcpy`/`strlen`/`memcpy`
- **`includes/ast/`**:参考其"胖节点 + mpool + CEnum 常量"的组织方式(但类型系统用 REnum 而非胖节点)

View File

@@ -63,7 +63,7 @@ def strcmp(str1: str, str2: str) -> t.CInt:
return str1[0] - str2[0]
def samestr(str1: str, str2: str) -> bool:
return str1 == str2
return strcmp(str1, str2) == 0
# String compare function with limited length

View File

@@ -10,7 +10,7 @@
```
+--------------------+ +-----------------------+ +------------+
| Viper 用户代码 | FFI | vqt6 桥接层 (libvqt6) | C++ | Qt6 C++ |
| (app.py) | <----> | - t.State 声明 | <-----> | QtCore |
| (app.vp) | <----> | - t.State 声明 | <-----> | QtCore |
| | | - C 桥接函数 | | QtGui |
| vqt6.QApplication | | (extern "C") | | QtWidgets |
| vqt6.QLabel | | - 静态库 / 动态库 | | QtNetwork |
@@ -36,12 +36,12 @@ vqt6 同一套 C 桥接源代码可同时编译为两种产物。Viper 项目
```
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 声明
├── __init__.vp # 公共 Pythonic API用户使用
├── _types.vp # 公共类型(不透明指针 typedef
├── _qtcore.vp # QtCore 的 t.State FFI 声明
├── _qtwidgets.vp # QtWidgets 的 t.State FFI 声明
├── _qtgui.vp # QtGui 的 t.State FFI 声明
├── _qtnetwork.vp # QtNetwork 的 t.State FFI 声明
├── _bridge.h # C 桥接层头文件
├── _bridge.cpp # C 桥接层实现extern "C" 包装 Qt6 C++ API
└── CMakeLists.txt # 构建脚本(生成 libvqt6_bridge.a
@@ -50,7 +50,7 @@ includes/vqt6/
## 使用示例
```python
# App/main.py
# App/main.vp
import t
import c
import vqt6

View File

@@ -10,7 +10,7 @@
```
+--------------------+ +-----------------------+ +------------+
| Viper 用户代码 | FFI | vqt6 桥接层 (libvqt6) | C++ | Qt6 C++ |
| (app.py) | <----> | - t.State 声明 | <-----> | QtCore |
| (app.vp) | <----> | - t.State 声明 | <-----> | QtCore |
| | | - C 桥接函数 | | QtGui |
| vqt6.QApplication | | (extern "C") | | QtWidgets |
| vqt6.QLabel | | - 静态库 / 动态库 | | QtNetwork |
@@ -36,12 +36,12 @@ vqt6 同一套 C 桥接源代码可同时编译为两种产物。Viper 项目
```
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 声明
├── __init__.vp # 公共 Pythonic API用户使用
├── _types.vp # 公共类型(不透明指针 typedef
├── _qtcore.vp # QtCore 的 t.State FFI 声明
├── _qtwidgets.vp # QtWidgets 的 t.State FFI 声明
├── _qtgui.vp # QtGui 的 t.State FFI 声明
├── _qtnetwork.vp # QtNetwork 的 t.State FFI 声明
├── _bridge.h # C 桥接层头文件
├── _bridge.cpp # C 桥接层实现extern "C" 包装 Qt6 C++ API
└── CMakeLists.txt # 构建脚本(生成 libvqt6_bridge.a
@@ -50,7 +50,7 @@ includes/vqt6/
## 使用示例
```python
# App/main.py
# App/main.vp
import t
import c
import vqt6