feat(compiler): 添加原生类型支持和属性获取功能

- 在编译器基础类中添加了 Expr_PropertyFetch 表达式处理逻辑
- 实现了原生属性变量检测和类型推断功能
- 新增了属性获取表达式的原生属性变量标记机制
- 更新了多个示例文件以使用 native_types 命名空间
- 添加了默认数组属性测试用例验证功能
- 集成了 polyfills 支持并在主入口点传递命令行参数
pull/1/head
韩天峰 4 months ago
parent 089ae56f0b
commit 2912b40b0f
  1. 1
      bin/compiler.php
  2. 2
      cli.php
  3. 2
      examples/bench.php
  4. 2
      examples/pi.php
  5. 11
      src/Php/CompilerBase.php
  6. 25
      tests/aot/object_property/003.phpt

@ -1,6 +1,7 @@
#!/usr/bin/env php
<?php
require __DIR__ . '/bootstrap.php';
require __DIR__ . '/../src/polyfills.php';
require __DIR__ . '/../src/gen_stub.php';
use PhpAot\Php\Translator;

@ -1,4 +1,4 @@
#!/usr/bin/env php
<?php
include $argv[1];
main();
main($argc, $argv);

@ -1,4 +1,6 @@
<?php
use native_types;
function simple()
{
$a = 0;

@ -1,4 +1,6 @@
<?php
use native_types;
function main()
{
ini_set("precision", 17);

@ -1905,6 +1905,16 @@ class CompilerBase extends \PhpAot\Core\Translator
}
}
break;
case 'Expr_PropertyFetch':
if ($this->isVarExpr($expr->var) and $this->isIdExpr($expr->name)) {
$this->parsePropertyFetch($expr);
if ($expr->getAttribute('nativePropertyVar')) {
$propVar = $expr->getAttribute('nativePropertyVar');
$info = $this->context->objectProps[$propVar];
return $info['type'];
}
}
break;
case 'Expr_New':
return self::TYPE_OBJECT;
case 'Expr_Assign':
@ -3465,6 +3475,7 @@ class CompilerBase extends \PhpAot\Core\Translator
'getter' => $getProperty,
];
}
$expr->setAttribute('nativePropertyVar', $propVar);
return $propVar;
}
}

@ -0,0 +1,25 @@
--TEST--
default array property
--FILE--
<?php
use native_types;
class Test {
protected int $x = 100;
function bar() {
$x = $this->x;
$x += 23;
$this->x += 12;
var_dump($x, $this->x);
}
}
function main() {
$obj = new Test;
$obj->bar();
}
?>
--EXPECT--
int(123)
int(112)
Loading…
Cancel
Save