- 在CompilerBase中添加Stmt_Block解析支持 - 新增global-int测试用例验证全局变量整型操作 - 新增globals-null-arithmetic测试用例处理NULL全局变量算术运算 - 修复switch语句缩进格式问题 - 初始化micro_bench中last_time变量 - 注释掉部分性能测试以聚焦核心功能pull/1/head
parent
48a8ddd8b5
commit
9eec3e7483
5 changed files with 214 additions and 88 deletions
@ -0,0 +1,51 @@ |
|||||||
|
--TEST-- |
||||||
|
global vars with native types |
||||||
|
--FILE-- |
||||||
|
<?php |
||||||
|
use native_types; |
||||||
|
|
||||||
|
function increment_global_int(int $n): void { |
||||||
|
global $global_int; |
||||||
|
for ($i = 0; $i < $n; $i++) { |
||||||
|
$global_int += 1; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
function increment_global_float(float $v): void { |
||||||
|
global $global_float; |
||||||
|
$global_float += $v; |
||||||
|
} |
||||||
|
|
||||||
|
function read_global_int(): int { |
||||||
|
global $global_int; |
||||||
|
return $global_int; |
||||||
|
} |
||||||
|
|
||||||
|
function read_global_float(): float { |
||||||
|
global $global_float; |
||||||
|
return $global_float; |
||||||
|
} |
||||||
|
|
||||||
|
function main(): void { |
||||||
|
global $global_int, $global_float; |
||||||
|
$global_int = 0; |
||||||
|
$global_float = 0.0; |
||||||
|
|
||||||
|
increment_global_int(5); |
||||||
|
var_dump(read_global_int()); |
||||||
|
|
||||||
|
increment_global_int(3); |
||||||
|
var_dump(read_global_int()); |
||||||
|
|
||||||
|
increment_global_float(1.5); |
||||||
|
var_dump(read_global_float()); |
||||||
|
|
||||||
|
increment_global_float(2.25); |
||||||
|
var_dump(read_global_float()); |
||||||
|
} |
||||||
|
?> |
||||||
|
--EXPECT-- |
||||||
|
int(5) |
||||||
|
int(8) |
||||||
|
float(1.5) |
||||||
|
float(3.75) |
||||||
@ -0,0 +1,71 @@ |
|||||||
|
--TEST-- |
||||||
|
NULL globals in arithmetic should treat NULL as 0 |
||||||
|
--FILE-- |
||||||
|
<?php |
||||||
|
declare(strict_types=1); |
||||||
|
|
||||||
|
// Test 1: NULL global += float |
||||||
|
function test_global_add() { |
||||||
|
global $a; |
||||||
|
$a += 0.575; |
||||||
|
var_dump($a); |
||||||
|
} |
||||||
|
|
||||||
|
// Test 2: NULL global = float |
||||||
|
function test_global_assign() { |
||||||
|
global $b; |
||||||
|
$b = 0.575; |
||||||
|
var_dump($b); |
||||||
|
} |
||||||
|
|
||||||
|
// Test 3: Read NULL global, use in subtraction |
||||||
|
function test_null_subtraction() { |
||||||
|
global $c; |
||||||
|
var_dump($c - 0.5); // NULL - float, NULL should be treated as 0 |
||||||
|
} |
||||||
|
|
||||||
|
// Test 4: NULL global += int |
||||||
|
function test_add_int() { |
||||||
|
global $d; |
||||||
|
$d += 5; |
||||||
|
var_dump($d); |
||||||
|
} |
||||||
|
|
||||||
|
// Test 5: Full micro_bench simulation |
||||||
|
function test_bench_sim() { |
||||||
|
global $total, $last_time; |
||||||
|
|
||||||
|
// First "end_test" call |
||||||
|
$last_time = 0.575; |
||||||
|
$total += $last_time; |
||||||
|
var_dump($total); |
||||||
|
var_dump($last_time); |
||||||
|
|
||||||
|
// Read overhead |
||||||
|
$overhead = $last_time; |
||||||
|
|
||||||
|
// Second "end_test" call |
||||||
|
$last_time = 0.014; |
||||||
|
$total += $last_time; |
||||||
|
$adjusted = $last_time - $overhead; |
||||||
|
var_dump($total); |
||||||
|
var_dump($adjusted); |
||||||
|
} |
||||||
|
|
||||||
|
function main(): void { |
||||||
|
test_global_add(); |
||||||
|
test_global_assign(); |
||||||
|
test_null_subtraction(); |
||||||
|
test_add_int(); |
||||||
|
test_bench_sim(); |
||||||
|
} |
||||||
|
?> |
||||||
|
--EXPECT-- |
||||||
|
float(0.575) |
||||||
|
float(0.575) |
||||||
|
float(-0.5) |
||||||
|
int(5) |
||||||
|
float(0.575) |
||||||
|
float(0.575) |
||||||
|
float(0.589) |
||||||
|
float(-0.5609999999999999) |
||||||
Loading…
Reference in new issue