diff --git a/examples/test/project.yml b/examples/test/project.yml new file mode 100644 index 00000000..e2000142 --- /dev/null +++ b/examples/test/project.yml @@ -0,0 +1,9 @@ +name: test +type: ext +version: 0.0.1 +ignore: + - ext-redis + - ext-POD_MYSQL +sources: + - call.php + - main.php \ No newline at end of file diff --git a/src/Php/Translator.php b/src/Php/Translator.php index 9bb67887..dbb1ff9f 100644 --- a/src/Php/Translator.php +++ b/src/Php/Translator.php @@ -35,6 +35,7 @@ class Translator extends Preprocessor protected bool $verbose = false; protected array $phpSrcFiles = []; protected array $ignorePaths = []; + protected array $ignoreExtensions = []; protected array $argInfoHeaderFiles = []; protected array $registerSymbols = []; @@ -60,6 +61,7 @@ class Translator extends Preprocessor $this->noLiteralStrings = $this->climate->arguments->get('noLiteralStrings'); $this->enableProfiler = $this->climate->arguments->defined('profile'); $this->internalFunctions = array_flip(get_defined_functions()['internal']); + unset($this->internalFunctions['main']); $this->internalConstants = get_defined_constants(); if ($this->climate->arguments->defined('help')) { $this->showUsage(); @@ -604,7 +606,7 @@ class Translator extends Preprocessor $code .= $classDef->ctorInit; $code .= "auto obj = create_object_{$className}(class_type);\n"; foreach ($classDef->properties as $property) { - $fullPropName = $classDef->getNamespacedName() . '::' . $property->name; + $fullPropName = $classDef->getNamespacedName(false) . '::' . $property->name; if (isset($this->defaultPropertyList[$fullPropName])) { $code .= "do {\n"; $code .= "auto value = {$this->defaultPropertyList[$fullPropName]};\n"; @@ -787,6 +789,10 @@ class Translator extends Preprocessor $this->error('`ignore` must be array'); } foreach ($cfg['ignore'] as $src) { + if (preg_match('/ext-([a-z0-9_]+)/i', $src, $matches)) { + $this->ignoreExtensions[] = $matches[1]; + continue; + } $realPath = $this->getAbsolutePath($src, $projectDir); if (!$realPath) { $this->error('Source file not exists: `' . $src . '`'); diff --git a/src/compiler-build.php b/src/compiler-build.php index 2be1eaf8..772b951b 100644 --- a/src/compiler-build.php +++ b/src/compiler-build.php @@ -12,6 +12,8 @@ function main(int $argc, array $argv): void die("php compiler.php [file]\n"); } + global $translator; + $path = $argv[1]; $translator = new Translator(ROOT_PATH); $translator->setIndent(' '); diff --git a/tests/aot/object_ctor/001.phpt b/tests/aot/object_ctor/001.phpt new file mode 100644 index 00000000..2c617043 --- /dev/null +++ b/tests/aot/object_ctor/001.phpt @@ -0,0 +1,52 @@ +--TEST-- +default array property +--FILE-- + self::TYPE_INT, + 'float' => self::TYPE_FLOAT, + 'bool' => self::TYPE_BOOL, + ]; + + protected $array2; + + function __construct() { + $this->array2 = ['php', 'java',]; + } + + function bar() { + var_dump($this->array1); + var_dump($this->array2); + } +} +} + +namespace { +function main() { + $obj = new App\Test; + $obj->bar(); +} +} +?> +--EXPECT-- +array(3) { + ["int"]=> + string(8) "php::Int" + ["float"]=> + string(10) "php::Float" + ["bool"]=> + string(9) "php::Bool" +} +array(2) { + [0]=> + string(3) "php" + [1]=> + string(4) "java" +} \ No newline at end of file diff --git a/tests/aot/ref/008.phpt b/tests/aot/ref/008.phpt new file mode 100644 index 00000000..4135787c --- /dev/null +++ b/tests/aot/ref/008.phpt @@ -0,0 +1,35 @@ +--TEST-- +class const 001 +--FILE-- +sort($ref); + return $list; + } + + public function sort(array &$list) { + sort($list); + } +} + +function main() +{ + $o = new WorkerA; + var_dump($o->foo()); +} +?> +--EXPECT-- +array(4) { + [0]=> + int(2) + [1]=> + int(64) + [2]=> + int(377) + [3]=> + int(688) +} \ No newline at end of file