Skip to content

Commit 7caf0e9

Browse files
committed
Merge branch 'master' into feature/clone-with
2 parents 7aba1b9 + 33cc068 commit 7caf0e9

File tree

4 files changed

+86
-0
lines changed

4 files changed

+86
-0
lines changed

ChangeLog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ XP Compiler ChangeLog
33

44
## ?.?.? / ????-??-??
55

6+
* Merged PR #187: Add PHP 8.5 emitter - @thekid
7+
68
## 9.5.0 / 2025-05-28
79

810
* Merged PR #181: Add support for pipelines with `|>` and `?|>`, see

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ lang.ast.emit.PHP81
9494
lang.ast.emit.PHP82
9595
lang.ast.emit.PHP83 [*]
9696
lang.ast.emit.PHP84
97+
lang.ast.emit.PHP85
9798
lang.ast.syntax.php.Using [*]
9899

99100
@FileSystemCL<./vendor/xp-lang/php-is-operator/src/main/php>
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php namespace lang\ast\emit;
2+
3+
use lang\ast\types\{
4+
IsArray,
5+
IsFunction,
6+
IsGeneric,
7+
IsIntersection,
8+
IsLiteral,
9+
IsMap,
10+
IsNullable,
11+
IsUnion,
12+
IsValue
13+
};
14+
15+
/**
16+
* PHP 8.5 syntax
17+
*
18+
* @test lang.ast.unittest.emit.PHP85Test
19+
* @see https://wiki.php.net/rfc#php_85
20+
*/
21+
class PHP85 extends PHP {
22+
use RewriteBlockLambdaExpressions;
23+
24+
public $targetVersion= 80500;
25+
26+
/** Sets up type => literal mappings */
27+
public function __construct() {
28+
$this->literals= [
29+
IsArray::class => function($t) { return 'array'; },
30+
IsMap::class => function($t) { return 'array'; },
31+
IsFunction::class => function($t) { return 'callable'; },
32+
IsValue::class => function($t) { return $t->literal(); },
33+
IsNullable::class => function($t) {
34+
if (null === ($l= $this->literal($t->element))) return null;
35+
return $t->element instanceof IsUnion ? $l.'|null' : '?'.$l;
36+
},
37+
IsIntersection::class => function($t) {
38+
$i= '';
39+
foreach ($t->components as $component) {
40+
if (null === ($l= $this->literal($component))) return null;
41+
$i.= '&'.$l;
42+
}
43+
return substr($i, 1);
44+
},
45+
IsUnion::class => function($t) {
46+
$u= '';
47+
foreach ($t->components as $component) {
48+
if (null === ($l= $this->literal($component))) return null;
49+
$u.= '|'.$l;
50+
}
51+
return substr($u, 1);
52+
},
53+
IsLiteral::class => function($t) { return $t->literal(); },
54+
IsGeneric::class => function($t) { return null; }
55+
];
56+
}
57+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php namespace lang\ast\unittest\emit;
2+
3+
use lang\ast\emit\Type;
4+
use test\{Assert, Test};
5+
6+
class PHP85Test extends EmittingTest {
7+
8+
/** @return string */
9+
protected function runtime() { return 'php:8.5.0'; }
10+
11+
#[Test]
12+
public function pipe_operator() {
13+
Assert::equals(
14+
'"test"|>strtoupper(...);',
15+
$this->emit('"test" |> strtoupper(...);')
16+
);
17+
}
18+
19+
#[Test]
20+
public function nullsafepipe_operator() {
21+
Assert::equals(
22+
'null===($_0="test")?null:$_0|>strtoupper(...);',
23+
$this->emit('"test" ?|> strtoupper(...);')
24+
);
25+
}
26+
}

0 commit comments

Comments
 (0)