3 <<file
:__EnableUnstableFeatures('expression_trees')>>
9 // Inferred type needs to be compatible
10 $z = Code`$
{$y} + $
{$x}`
;
14 // Placeholder definition so we don't get naming/typing errors.
16 const type TAst
= mixed;
18 public static function intLiteral(
20 ): ExprTree
<Code
, Code
::TAst
, ExampleInt
> {
21 throw new Exception();
23 public static function floatLiteral(
25 ): ExprTree
<Code
, Code
::TAst
, ExampleFloat
> {
26 throw new Exception();
28 public static function boolLiteral(bool $_):
29 ExprTree
<Code
, Code
::TAst
, ExampleBool
>
31 throw new Exception();
33 public static function stringLiteral(string $_):
34 ExprTree
<Code
, Code
::TAst
, ExampleString
>
36 throw new Exception();
38 public static function nullLiteral(): ExprTree
<Code
, Code
::TAst
, null> {
39 throw new Exception();
43 public static function symbol
<T
>(
45 (function(ExampleContext
): ExprTree
<Code
, Code
::TAst
, T
>) $_,
46 ): ExprTree
<Code
, Code
::TAst
, T
> {
47 throw new Exception();
51 public function localVar(?ExprPos
$_, string $_): Code
::TAst
{
52 throw new Exception();
54 public function lambdaLiteral(
57 vec
<Code
::TAst
> $_body,
59 throw new Exception();
63 public function methCall(
69 throw new Exception();
72 // Old style operators
73 public function call
<T
>(
76 vec
<Code
::TAst
> $_args,
78 throw new Exception();
81 public function assign(
86 throw new Exception();
89 public function ternary(
91 Code
::TAst
$_condition,
95 throw new Exception();
99 public function ifStatement(
102 vec
<Code
::TAst
> $_then_body,
103 vec
<Code
::TAst
> $_else_body,
105 throw new Exception();
107 public function whileStatement(
110 vec
<Code
::TAst
> $_body,
112 throw new Exception();
114 public function returnStatement(
118 throw new Exception();
120 public function forStatement(
127 throw new Exception();
129 public function breakStatement(?ExprPos
$_): Code
::TAst
{
130 throw new Exception();
132 public function continueStatement(?ExprPos
$_,): Code
::TAst
{
133 throw new Exception();
137 public function splice
<T
>(
140 ExprTree
<Code
, Code
::TAst
, T
> $_,
142 throw new Exception();
145 // TODO: Discard unsupported syntax nodes while lowering
146 public function unsupportedSyntax(string $msg): Code
::TAst
{
147 throw new Exception($msg);
151 final class ExprTree
<TVisitor
, TResult
, +TInfer
>{
152 public function __construct(
153 private ?ExprPos
$pos,
154 private string $filepath,
155 private dict
<string, mixed> $spliced_values,
156 private (function(TVisitor
): TResult
) $x,
157 private (function(): TInfer
) $err,
161 final class ExprPos
{
162 public function __construct(
163 private int $begin_line,
164 private int $begin_col,
165 private int $end_line,
166 private int $end_col,
170 final class ExampleInt
{
171 public function __plus(ExampleInt
$_): ExampleInt
{
172 throw new Exception();
174 public function __minus(ExampleInt
$_): ExampleInt
{
175 throw new Exception();
177 public function __star(ExampleInt
$_): ExampleInt
{
178 throw new Exception();
180 public function __slash(ExampleInt
$_): ExampleInt
{
181 throw new Exception();
184 public function __lessThan(ExampleInt
$_): ExampleBool
{
185 throw new Exception();
188 public function __lessThanEqual(ExampleInt
$_): ExampleBool
{
189 throw new Exception();
192 public function __greaterThan(ExampleInt
$_): ExampleBool
{
193 throw new Exception();
196 public function __greaterThanEqual(ExampleInt
$_): ExampleBool
{
197 throw new Exception();
200 public function __tripleEquals(ExampleInt
$_): ExampleBool
{
201 throw new Exception();
204 public function __notTripleEquals(ExampleInt
$_): ExampleBool
{
205 throw new Exception();
209 final class ExampleBool
{
210 public function __ampamp(ExampleBool
$_): ExampleBool
{
211 throw new Exception();
214 public function __barbar(ExampleBool
$_): ExampleBool
{
215 throw new Exception();
218 public function __bool(): bool {
219 throw new Exception();
222 public function __exclamationMark(): ExampleBool
{
223 throw new Exception();
227 final class ExampleString
{}
229 final class ExampleContext
{}
231 final class ExampleFloat
{}