3 <<file
:__EnableUnstableFeatures('expression_trees')>>
7 ): ExprTree
<Code
, Code
::TAst
, (function(): void
)> {
12 ): ExprTree
<Code
, Code
::TAst
, (function(ExampleInt
): void
)> {
13 throw new Exception();
16 function foo(): void
{
17 $loop = Code`
() ==> { while(true) { bar(); } }`
;
18 $for = Code`
() ==> { for($x = 0; true; $x = $x +
1) { baz($x); } }`
;
22 // Placeholder definition so we don't get naming/typing errors.
24 const type TAst
= mixed;
26 public static function intLiteral(
28 ): ExprTree
<Code
, Code
::TAst
, ExampleInt
> {
29 throw new Exception();
31 public static function floatLiteral(
33 ): ExprTree
<Code
, Code
::TAst
, ExampleFloat
> {
34 throw new Exception();
36 public static function boolLiteral(bool $_):
37 ExprTree
<Code
, Code
::TAst
, ExampleBool
>
39 throw new Exception();
41 public static function stringLiteral(string $_):
42 ExprTree
<Code
, Code
::TAst
, ExampleString
>
44 throw new Exception();
46 public static function nullLiteral(): ExprTree
<Code
, Code
::TAst
, null> {
47 throw new Exception();
51 public static function symbol
<T
>(
53 (function(ExampleContext
): ExprTree
<Code
, Code
::TAst
, T
>) $_,
54 ): ExprTree
<Code
, Code
::TAst
, T
> {
55 throw new Exception();
59 public function localVar(?ExprPos
$_, string $_): Code
::TAst
{
60 throw new Exception();
62 public function lambdaLiteral(
65 vec
<Code
::TAst
> $_body,
67 throw new Exception();
71 public function methCall(
77 throw new Exception();
80 // Old style operators
81 public function call
<T
>(
84 vec
<Code
::TAst
> $_args,
86 throw new Exception();
89 public function assign(
94 throw new Exception();
97 public function ternary(
99 Code
::TAst
$_condition,
100 ?Code
::TAst
$_truthy,
103 throw new Exception();
107 public function ifStatement(
110 vec
<Code
::TAst
> $_then_body,
111 vec
<Code
::TAst
> $_else_body,
113 throw new Exception();
115 public function whileStatement(
118 vec
<Code
::TAst
> $_body,
120 throw new Exception();
122 public function returnStatement(
126 throw new Exception();
128 public function forStatement(
135 throw new Exception();
137 public function breakStatement(?ExprPos
$_): Code
::TAst
{
138 throw new Exception();
140 public function continueStatement(?ExprPos
$_,): Code
::TAst
{
141 throw new Exception();
145 public function splice
<T
>(
148 ExprTree
<Code
, Code
::TAst
, T
> $_,
150 throw new Exception();
153 // TODO: Discard unsupported syntax nodes while lowering
154 public function unsupportedSyntax(string $msg): Code
::TAst
{
155 throw new Exception($msg);
159 final class ExprTree
<TVisitor
, TResult
, +TInfer
>{
160 public function __construct(
161 private ?ExprPos
$pos,
162 private string $filepath,
163 private dict
<string, mixed> $spliced_values,
164 private (function(TVisitor
): TResult
) $x,
165 private (function(): TInfer
) $err,
169 final class ExprPos
{
170 public function __construct(
171 private int $begin_line,
172 private int $begin_col,
173 private int $end_line,
174 private int $end_col,
178 final class ExampleInt
{
179 public function __plus(ExampleInt
$_): ExampleInt
{
180 throw new Exception();
182 public function __minus(ExampleInt
$_): ExampleInt
{
183 throw new Exception();
185 public function __star(ExampleInt
$_): ExampleInt
{
186 throw new Exception();
188 public function __slash(ExampleInt
$_): ExampleInt
{
189 throw new Exception();
192 public function __lessThan(ExampleInt
$_): ExampleBool
{
193 throw new Exception();
196 public function __lessThanEqual(ExampleInt
$_): ExampleBool
{
197 throw new Exception();
200 public function __greaterThan(ExampleInt
$_): ExampleBool
{
201 throw new Exception();
204 public function __greaterThanEqual(ExampleInt
$_): ExampleBool
{
205 throw new Exception();
208 public function __tripleEquals(ExampleInt
$_): ExampleBool
{
209 throw new Exception();
212 public function __notTripleEquals(ExampleInt
$_): ExampleBool
{
213 throw new Exception();
217 final class ExampleBool
{
218 public function __ampamp(ExampleBool
$_): ExampleBool
{
219 throw new Exception();
222 public function __barbar(ExampleBool
$_): ExampleBool
{
223 throw new Exception();
226 public function __bool(): bool {
227 throw new Exception();
230 public function __exclamationMark(): ExampleBool
{
231 throw new Exception();
235 final class ExampleString
{}
237 final class ExampleContext
{}
239 final class ExampleFloat
{}