refactor(php): 将内置函数调用改为符号表调用方式

- 添加 funcSymbols 数组存储函数符号
- 修改 shell_exec 调用为通过符号表调用
- 修改 define 函数调用为通过符号表调用
- 在 prepare 方法中初始化 shell_exec 和 define 的函数指针
pull/1/head
韩天峰 3 months ago
parent 6c74f1c8b5
commit 81272cf7fb
  1. 3
      src/Php/CompilerBase.php
  2. 5
      src/Php/Translator.php

@ -162,6 +162,7 @@ class CompilerBase extends \PhpAot\Core\Translator
];
protected array $localHeaders = [];
protected array $internalFunctions = [];
protected array $funcSymbols = [];
protected array $internalConstants = [];
/**
@ -5182,7 +5183,7 @@ class CompilerBase extends \PhpAot\Core\Translator
foreach ($expr->parts as $part) {
$list[] = $this->identifierToStr($part);
}
return 'php::shell_exec(php::concat({' . implode(', ', $list) . '}))';
return 'php::call(' . $this->funcSymbols['shell_exec'] . ', { php::concat({' . implode(', ', $list) . '}) })';
}
protected function parseGoto(Node\Stmt\Goto_ $v): string

@ -285,6 +285,9 @@ class Translator extends Preprocessor
public function prepare(string $path): array
{
$this->funcSymbols['shell_exec'] = $this->getFuncPtr('shell_exec');
$this->funcSymbols['define'] = $this->getFuncPtr('define');
// 根据平台检查库文件(仅在构建二进制文件时需要)
if ($this->isBuildModeBin()) {
foreach ($this->getPlatform()->getBuildLibraryWarnings($this->getPhpDir(), $this->getPhpxDir(), $this->buildMode) as $message) {
@ -564,7 +567,7 @@ CODE;
$code .= '// register constants' . PHP_EOL;
foreach ($this->constants as $name => $const) {
$code .= "{$name} = {$const->value};\n";
$code .= 'php::define(' . $this->genCharPtr($const->name, true) . ', ' . $name . ');' . PHP_EOL;
$code .= 'php::call(' . $this->funcSymbols['define'] . ', { ' . $this->genCharPtr($const->name, true) . ', ' . $name . ' });' . PHP_EOL;
}
$code .= '// global vars ' . PHP_EOL;
foreach ($this->globalVars as $name => $type) {

Loading…
Cancel
Save