diff --git a/examples/error/impl.php b/examples/error/impl.php new file mode 100644 index 00000000..5d230c7c --- /dev/null +++ b/examples/error/impl.php @@ -0,0 +1,12 @@ +foo(); +} \ No newline at end of file diff --git a/project.yml b/project.yml index aba23544..59ebd5c0 100644 --- a/project.yml +++ b/project.yml @@ -1,6 +1,6 @@ name: swoole-compiler -type: ext -version: 0.0.1 +type: bin +version: 0.1.0 cxxflags: | -std=c++14 -Wall @@ -9,4 +9,6 @@ sources: - ./src/Core - ./src/functions.php - ./src/gen_stub.php - - ./vendor/nikic/php-parser/lib/PhpParser/NodeVisitorAbstract.php + - ./src/compiler-build.php + - vendor/nikic/php-parser/lib/PhpParser/NodeVisitor.php + - vendor/nikic/php-parser/lib/PhpParser/NodeVisitorAbstract.php diff --git a/src/Php/Symbol.php b/src/Php/Symbol.php index 6ce94c11..df5d3200 100644 --- a/src/Php/Symbol.php +++ b/src/Php/Symbol.php @@ -44,4 +44,9 @@ class Symbol { return 'php::constant'; } + + public static function getClassEntrySafe(): string + { + return 'php::getClassEntrySafe'; + } } diff --git a/src/Php/Translator.php b/src/Php/Translator.php index 371702dc..e81d5476 100644 --- a/src/Php/Translator.php +++ b/src/Php/Translator.php @@ -30,6 +30,7 @@ class Translator extends Preprocessor { public const string VERSION = '0.1.0'; public const string APP_NAME = 'Swoole-Compiler (AOT)'; + protected string $targetName = 'app'; protected array $sourceDirs = []; protected bool $verbose = false; @@ -801,7 +802,7 @@ class Translator extends Preprocessor protected function getInternalCeInfo(string $ce): array { return [ - 'func' => 'php::getClassEntry', + 'func' => Symbol::getClassEntrySafe(), 'args' => '"' . substr($ce, strlen(self::PREFIX . 'class_entry_')) . '"', ]; } diff --git a/src/compiler-build.php b/src/compiler-build.php new file mode 100644 index 00000000..2be1eaf8 --- /dev/null +++ b/src/compiler-build.php @@ -0,0 +1,26 @@ +setIndent(' '); + // 扫描所有 PHP 文件,预处理 + $files = $translator->prepare($path); + // 生成 C++ 文件 + $sourceFiles = $translator->convert($files); + // 编译所有 C++ 文件 + $objectFiles = $translator->compile($sourceFiles); + // 连接所有目标文件,生成可执行文件 + $translator->build($objectFiles); +} diff --git a/src/gen_stub.php b/src/gen_stub.php index 4ad837a2..13debda9 100755 --- a/src/gen_stub.php +++ b/src/gen_stub.php @@ -690,7 +690,7 @@ class Type { return true; } - public function __toString() { + public function __toString() : string { $char = $this->isIntersection ? '&' : '|'; return implode($char, array_map( function ($type) { return $type->name; }, diff --git a/src/template/extension.cc.php b/src/template/extension.cc.php index c3d93de6..2fa4ed5c 100644 --- a/src/template/extension.cc.php +++ b/src/template/extension.cc.php @@ -119,15 +119,17 @@ foreach ($this->functions as $functionDef): // clang-format on PHP_MINIT_FUNCTION(getModuleName()?>) { - // class/interface class entries - genClassPropertyInit()?> - -// register symbols -registerSymbols as $registerSymbolFn): -?> - (module_number); - + zend_first_try { + // class/interface class entries + genClassPropertyInit()?> + + // register symbols + registerSymbols as $registerSymbolFn): + ?> + (module_number); + + } zend_end_try(); return SUCCESS; }