diff --git a/.gitignore b/.gitignore index ede6074d..5ea96f6b 100644 --- a/.gitignore +++ b/.gitignore @@ -18,6 +18,8 @@ *.exe *.obj *.pdb +*.lib +*.exp *.class /swoole_compiler /tpc diff --git a/src/Backend/Msvc.php b/src/Backend/Msvc.php index 66beff8c..d7ab2387 100644 --- a/src/Backend/Msvc.php +++ b/src/Backend/Msvc.php @@ -38,7 +38,7 @@ class Msvc extends CompilerBackend { $cmd = ''; - $cmd .= ' /DZEND_WIN32 /DPHP_WIN32 /DZEND_DEBUG=0'; + $cmd .= ' /utf-8 /DZEND_WIN32 /DPHP_WIN32 /DZEND_DEBUG=0 /DENABLE_INTSAFE_SIGNED_FUNCTIONS'; if (!empty($config['is_zts'])) { $cmd .= ' /DZTS'; @@ -288,7 +288,7 @@ class Msvc extends CompilerBackend $cmd = ''; // 平台宏定义 - $cmd .= ' /DZEND_WIN32 /DPHP_WIN32 /DZEND_DEBUG=0'; + $cmd .= ' /utf-8 /DZEND_WIN32 /DPHP_WIN32 /DZEND_DEBUG=0 /DENABLE_INTSAFE_SIGNED_FUNCTIONS'; // ZTS if ($this->platform instanceof Windows && $this->platform->isZts()) { diff --git a/src/Generator/ClosureGenerator.php b/src/Generator/ClosureGenerator.php index 886cdc47..c93281cd 100644 --- a/src/Generator/ClosureGenerator.php +++ b/src/Generator/ClosureGenerator.php @@ -174,7 +174,7 @@ trait ClosureGenerator $this->addArgument($var, Type::VAR); } - if ($this->methodDef) { + if ($this->methodDef && !$expr->static) { $this->addArgument('this_', Type::OBJECT); } @@ -211,7 +211,7 @@ trait ClosureGenerator $this->context = $oriContext; $this->context->beforeStmtLines[] = $code; - if ($this->methodDef) { + if ($this->methodDef && !$expr->static) { return 'php::newClosure(' . $tmpVar . ', { ' . implode(', ', $useVars) . ' }, this_)'; } else { return 'php::newClosure(' . $tmpVar . ', { ' . implode(', ', $useVars) . ' })'; diff --git a/src/Platform/Windows.php b/src/Platform/Windows.php index f88ecc0c..ad16d6f5 100644 --- a/src/Platform/Windows.php +++ b/src/Platform/Windows.php @@ -177,10 +177,6 @@ class Windows extends PlatformBase public function getBuildLibraryWarnings(string $phpDir, string $phpxDir, string $buildMode): array { - if ($buildMode !== 'bin' && $buildMode !== 'lib') { - return []; - } - $warnings = []; $phpDirs = [ $phpDir . '\SDK\lib', @@ -201,10 +197,30 @@ class Windows extends PlatformBase ]; } - if (!is_file($phpxDir . '\lib\phpx.lib') && !is_file($phpxDir . '\lib\phpx.dll')) { + $phpxLibPath = $phpxDir . '\lib\phpx.lib'; + if (!is_file($phpxLibPath)) { + $warnings[] = [ + 'warning' => 'The PHPX import library was not found at: ' . $phpxLibPath, + 'info' => 'Create the PHPX lib directory, reconfigure CMake if needed, then rebuild the phpx target', + ]; + } + + $phpxDllPaths = [ + $phpxDir . '\build\phpx.dll', + $phpxDir . '\lib\phpx.dll', + $phpxDir . '\phpx.dll', + ]; + $hasPhpxDll = false; + foreach ($phpxDllPaths as $phpxDllPath) { + if (is_file($phpxDllPath)) { + $hasPhpxDll = true; + break; + } + } + if (!$hasPhpxDll) { $warnings[] = [ - 'warning' => 'The `phpx.lib` or `phpx.dll` is not found in PHX directory', - 'info' => 'Note: If you are building an extension (-m ext), this is OK. For binary mode, please run `make` to build it', + 'warning' => 'The PHPX runtime library `phpx.dll` was not found under: ' . $phpxDir, + 'info' => 'Reconfigure CMake if needed, then rebuild the phpx target', ]; } @@ -292,6 +308,7 @@ class Windows extends PlatformBase $phpDirs = [ $phpDir . '\\SDK\\lib', $phpDir . '\\lib', + $phpDir, ]; $embedLibPath = ''; diff --git a/src/Transform/ConstantExpressionValidator.php b/src/Transform/ConstantExpressionValidator.php index 16bcec3d..972b45dc 100644 --- a/src/Transform/ConstantExpressionValidator.php +++ b/src/Transform/ConstantExpressionValidator.php @@ -321,11 +321,7 @@ final class ConstantExpressionValidator private function tryEvaluate(Expr $expression): array { try { - $value = (new ConstExprEvaluator( - static function (): never { - throw new \LogicException('Expression is not statically known'); - }, - ))->evaluateDirectly($expression); + $value = (new ConstExprEvaluator())->evaluateDirectly($expression); return [true, $value]; } catch (\Throwable) { return [false, null]; diff --git a/src/compiler.php b/src/compiler.php index ce7977ae..255c5bd1 100644 --- a/src/compiler.php +++ b/src/compiler.php @@ -3,6 +3,10 @@ use TypePhp\Translator; function main(int $argc, array $argv): void { + // Compiling a complete project keeps the parsed AST and generated sources in + // memory. The default CLI limit (commonly 128M) is too small for larger builds. + ini_set('memory_limit', '-1'); + if (!defined('ROOT_PATH')) { define("ROOT_PATH", getcwd()); }