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.
2.3 KiB
2.3 KiB
PHPX 运行时集成
TypePHP 不是从零实现 PHP 语义,而是站在 PHPX(Swoole 的 C++ PHP 绑定库)与 Zend 引擎 embed 之上。生成的 C++ 大量调用 phpx.h 提供的 php:: 命名空间 API,最终把 Zend 引擎链接进产物。
Sources: src/Translator.php · README.md
全局头文件
Translator::$globalHeaders 列出每个编译单元默认包含的头:
['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
运行时依赖源
compile() 会追加 phpx 的 src/misc/ 源文件(C++ 运行时实现),以及 embed 模式下的 typephp_main.cc、bin 模式下的 cli 标题源。这些 misc 源受 增量编译缓存 的 ABI 指纹保护。
Sources: src/Translator.php
关键运行时能力
- 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 · docs/YIELD_GENERATOR.md · docs/MIXED_CPP_PHP.md · docs/CLASS_INHERITANCE.md
动态链接库
运行时要求 libphp.so(Linux)/ php8ts.lib(Windows)与 libphpx.so 就位;缺库时可用 docs/LIBPHP_INSTALLER.md 自动构建。
Sources: README.md · docs/LIBPHP_INSTALLER.md
相关阅读
- 产物如何被链接 → 构建流水线
- 跨平台库差异 → 跨平台支持
- 哪些 PHP 特性尚不支持 → 不支持的 PHP 特性