3 <<file
:__EnableUnstableFeatures('expression_trees')>>
7 public function reset(): int {
12 function lift
<T
>(T
$_): ExprTree
<Code
, Code
::TAst
, T
> {
13 throw new Exception();
16 // This technically shouldn't throw an error.
17 // It currently is due to typechecking the current desugaring
18 // So, for the moment, allow this error to be thrown and fix the desugaring
19 function test(): void
{
24 // We know that $x->x is not null
25 __splice__(lift($x->x +
1));
32 // Placeholder definition so we don't get naming/typing errors.
34 const type TAst
= mixed;
36 public function intLiteral(?ExprPos
$_, int $_): this
::TAst
{
37 throw new Exception();
39 public function boolLiteral(?ExprPos
$_, bool $_): this
::TAst
{
40 throw new Exception();
42 public function stringLiteral(?ExprPos
$_, string $_): this
::TAst
{
43 throw new Exception();
45 public function nullLiteral(?ExprPos
$_): this
::TAst
{
46 throw new Exception();
48 public function localVar(?ExprPos
$_, string $_): this
::TAst
{
49 throw new Exception();
51 public function lambdaLiteral(
54 vec
<this
::TAst
> $_body,
56 throw new Exception();
65 throw new Exception();
67 public function ampamp(
72 throw new Exception();
74 public function barbar(
79 throw new Exception();
81 public function exclamationMark(
85 throw new Exception();
90 vec
<this
::TAst
> $_args,
92 throw new Exception();
95 public function assign(
100 throw new Exception();
104 public function ifStatement(
107 vec
<this
::TAst
> $_then_body,
108 vec
<this
::TAst
> $_else_body,
110 throw new Exception();
112 public function whileStatement(
115 vec
<this
::TAst
> $_body,
117 throw new Exception();
119 public function returnStatement(
123 throw new Exception();
125 public function forStatement(
132 throw new Exception();
134 public function breakStatement(?ExprPos
$_): this
::TAst
{
135 throw new Exception();
137 public function continueStatement(?ExprPos
$_,): this
::TAst
{
138 throw new Exception();
142 public function splice
<T
>(
144 ExprTree
<this
, this
::TAst
, T
> $_,
146 throw new Exception();
149 // TODO: Discard unsupported syntax nodes while lowering
150 public function unsupportedSyntax(string $msg): this
::TAst
{
151 throw new Exception($msg);
155 final class ExprTree
<TVisitor
, TResult
, TInfer
>{
156 public function __construct(
157 private ?ExprPos
$pos,
158 private (function(TVisitor
): TResult
) $x,
159 private (function(): TInfer
) $err,
163 final class ExprPos
{
164 public function __construct(
165 private int $begin_line,
166 private int $begin_col,
167 private int $end_line,
168 private int $end_col,