TypePHP 编译器
https://swoole.com/aot/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
2.3 KiB
50 lines
2.3 KiB
<blog>
|
|
|
|
# PHPX 运行时集成
|
|
|
|
TypePHP 不是从零实现 PHP 语义,而是站在 **PHPX**(Swoole 的 C++ PHP 绑定库)与 **Zend 引擎 embed** 之上。生成的 C++ 大量调用 `phpx.h` 提供的 `php::` 命名空间 API,最终把 Zend 引擎链接进产物。
|
|
|
|
Sources: [src/Translator.php](src/Translator.php#L79-L89) · [README.md](README.md#L44-L61)
|
|
|
|
## 全局头文件
|
|
|
|
`Translator::$globalHeaders` 列出每个编译单元默认包含的头:
|
|
|
|
```php
|
|
['cstring', 'phpx.h', 'phpx_helper.h', 'phpx_big_int.h',
|
|
'phpx_big_float.h', 'phpx_decimal.h', 'typephp_helper.h',
|
|
'typephp_fiber_generator.h', 'phpx_std.h']
|
|
```
|
|
|
|
高精度类型(`BigInt`/`BigFloat`/`Decimal`)的头正是此处引入;`typephp_*` 是 TypePHP 自带的扩展头(Fiber/Generator、helper)。
|
|
|
|
Sources: [src/Translator.php](src/Translator.php#L79-L89)
|
|
|
|
## 运行时依赖源
|
|
|
|
`compile()` 会追加 phpx 的 `src/misc/` 源文件(C++ 运行时实现),以及 embed 模式下的 `typephp_main.cc`、bin 模式下的 cli 标题源。这些 misc 源受 [增量编译缓存](incremental-cache) 的 ABI 指纹保护。
|
|
|
|
Sources: [src/Translator.php](src/Translator.php#L1423-L1434)
|
|
|
|
## 关键运行时能力
|
|
|
|
- **Fiber / Generator**:`typephp_fiber_generator.cc/.h` 提供协程与生成器支持,详见 `docs/YIELD_GENERATOR.md`;
|
|
- **混合 C++/PHP**:可在工程中直接写 C++ 并与 PHP 互调,见 `docs/MIXED_CPP_PHP.md`;
|
|
- **反射**:`typephp_install_reflection_attribute_handlers()` 在 MINIT 安装反射/属性处理器;
|
|
- **类继承**:PHP 类到 C++ 的映射与 `extends` 处理见 `docs/CLASS_INHERITANCE.md`。
|
|
|
|
Sources: [src/Translator.php](src/Translator.php#L887-L890) · [docs/YIELD_GENERATOR.md](docs/YIELD_GENERATOR.md) · [docs/MIXED_CPP_PHP.md](docs/MIXED_CPP_PHP.md) · [docs/CLASS_INHERITANCE.md](docs/CLASS_INHERITANCE.md)
|
|
|
|
## 动态链接库
|
|
|
|
运行时要求 `libphp.so`(Linux)/ `php8ts.lib`(Windows)与 `libphpx.so` 就位;缺库时可用 `docs/LIBPHP_INSTALLER.md` 自动构建。
|
|
|
|
Sources: [README.md](README.md#L57-L70) · [docs/LIBPHP_INSTALLER.md](docs/LIBPHP_INSTALLER.md)
|
|
|
|
## 相关阅读
|
|
|
|
- 产物如何被链接 → [构建流水线](build-pipeline)
|
|
- 跨平台库差异 → [跨平台支持](platform)
|
|
- 哪些 PHP 特性尚不支持 → [不支持的 PHP 特性](incompatible-features)
|
|
|
|
</blog>
|
|
|