- 修改编译流程,添加对象文件路径管理功能 - 实现缓存检查机制,跳过已存在的编译文件 - 重命名MethodDef中的def属性为functionDef - 提取表达式类型转换逻辑到独立方法convertExprFromType - 添加扩展模板文件extension.cc.php,使用模板渲染替代手动代码生成 - 修改main.cc文件结构,使用模块注册方式替代函数注册 - 更新编译参数,添加-Wall编译选项 - 实现方法调用参数传递的动态构建机制 - 优化全局变量初始化和清理函数的实现pull/1/head
parent
e4505c2ef1
commit
f3944a5259
6 changed files with 203 additions and 124 deletions
@ -0,0 +1,120 @@ |
||||
<?php |
||||
/** |
||||
* @var $this Translator |
||||
*/ |
||||
use PhpAot\Php\Translator; |
||||
echo $this->genIncludeHeaderFiles(); |
||||
?> |
||||
|
||||
// global vars |
||||
<?php |
||||
// 全局变量只能是 var 类型 |
||||
foreach ($this->globalVars as $name => $type): |
||||
?> |
||||
<?= Translator::TYPE_VAR ?> <?= $name ?>;
|
||||
<?php endforeach; ?> |
||||
|
||||
// class entries |
||||
<?php |
||||
foreach ($this->classes as $classDef) : |
||||
?> |
||||
zend_class_entry * <?= $this->getClassCe($classDef) ?>;
|
||||
<?php endforeach; ?> |
||||
|
||||
// class register functions |
||||
<?php |
||||
foreach ($this->classes as $classDef): |
||||
$name = $classDef->getNamespacedName(); |
||||
$parentCe = $classDef->extends ? 'zend_class_entry *parent_ce' : ''; |
||||
?> |
||||
extern zend_class_entry *<?= $this->getRegisterClassFunction($name) ?>(<?= $parentCe ?>);
|
||||
<?php endforeach; ?> |
||||
|
||||
// literal strings |
||||
php::Var <?=Translator::LITERAL_STRINGS?>[] = {
|
||||
<?php |
||||
foreach ($this->literalStrings as $str => $index): |
||||
?> |
||||
php::String{ZEND_STRL("<?=$this->escapeString($str)?>"), true},
|
||||
<?php endforeach; ?> |
||||
}; |
||||
|
||||
// constants |
||||
<?php |
||||
foreach ($this->nativeConstants as $name => $constant): |
||||
?> |
||||
<?=$constant->type?> <?=$name?>;
|
||||
<?php endforeach; ?> |
||||
|
||||
static ZEND_FUNCTION(main) { |
||||
php_main(); |
||||
} |
||||
|
||||
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_void, 0, 0, IS_VOID, 0) |
||||
ZEND_END_ARG_INFO() |
||||
|
||||
static const zend_function_entry ext_functions[] = { |
||||
ZEND_FE(main, arginfo_void) |
||||
ZEND_FE_END |
||||
}; |
||||
|
||||
static PHP_MINIT_FUNCTION(app) { |
||||
<?php |
||||
foreach ($this->classes as $classDef): |
||||
$name = $classDef->getNamespacedName(); |
||||
$parentCe = $this->getParentClassCe($classDef); |
||||
$fn = $this->getRegisterClassFunction($name); |
||||
?> |
||||
<?=$this->getClassCe($classDef)?> = <?= $fn ?>(<?= $parentCe ?>);
|
||||
<?php endforeach; ?> |
||||
|
||||
return SUCCESS; |
||||
} |
||||
|
||||
void php_app_init() { |
||||
// register constants |
||||
<?php |
||||
foreach ($this->nativeConstants as $name => $constant): |
||||
?> |
||||
<?=$name?> = <?= $constant->value ?>;
|
||||
php::define("<?=$name?>", <?= $name ?>);
|
||||
<?php endforeach; ?> |
||||
|
||||
// global vars |
||||
<?php |
||||
foreach ($this->globalVars as $name => $type): |
||||
?> |
||||
<?= $name ?> = php::global("<?=$name?>");
|
||||
<?php endforeach; ?> |
||||
} |
||||
|
||||
void php_app_clean() { |
||||
<?php |
||||
foreach ($this->globalVars as $name => $type) : |
||||
?> |
||||
<?= $name ?>.unset();
|
||||
<?php endforeach; ?> |
||||
<?php |
||||
foreach ($this->nativeConstants as $name => $constant): |
||||
if ($constant->type !== Translator::TYPE_VAR) { |
||||
continue; |
||||
} |
||||
?> |
||||
<?= $name ?>.unset();
|
||||
<?php endforeach; ?> |
||||
} |
||||
|
||||
static zend_module_entry app_module_entry = { |
||||
STANDARD_MODULE_HEADER, |
||||
"app", |
||||
ext_functions, |
||||
PHP_MINIT(app), |
||||
nullptr, |
||||
nullptr, |
||||
nullptr, |
||||
nullptr, |
||||
nullptr, |
||||
STANDARD_MODULE_PROPERTIES, |
||||
}; |
||||
|
||||
ZEND_GET_MODULE(app); |
||||
Loading…
Reference in new issue