ITupleNode signature change

This commit is contained in:
Michael Schimmel
2026-01-06 11:37:18 +01:00
parent 264314cd93
commit 40ed51aef8
23 changed files with 340 additions and 270 deletions
+18 -21
View File
@@ -198,12 +198,13 @@ var
i: Integer;
begin
T := N.AsTuple;
var elements := T.Elements;
Append('[');
for i := 0 to T.Count - 1 do
for i := 0 to High(elements) do
begin
if i > 0 then
Append(' ');
Visit(T.Items[i]);
Visit(elements[i]);
end;
Append(']');
end;
@@ -315,26 +316,25 @@ function TPrettyPrintVisitor.VisitFunctionCall(const N: IAstNode): TVoid;
var
C: IFunctionCallNode;
i: Integer;
args: ITupleNode;
begin
C := N.AsFunctionCall;
args := C.Arguments;
var args := C.Arguments.Elements;
// Special case for 'quote'
if (C.Callee.Kind = akIdentifier) and (C.Callee.AsIdentifier.Name = 'quote') and (args.Count = 1) then
if (C.Callee.Kind = akIdentifier) and (C.Callee.AsIdentifier.Name = 'quote') and (Length(args) = 1) then
begin
Append('''');
Visit(args.Items[0]);
Visit(args[0]);
exit;
end;
Append('(');
Visit(C.Callee);
// Manually iterate arguments tuple to avoid printing [...] inside ()
for i := 0 to args.Count - 1 do
for i := 0 to High(args) do
begin
Append(' ');
Visit(args.Items[i]);
Visit(args[i]);
end;
Append(')');
end;
@@ -348,16 +348,15 @@ function TPrettyPrintVisitor.VisitRecurNode(const N: IAstNode): TVoid;
var
R: IRecurNode;
i: Integer;
args: ITupleNode;
begin
R := N.AsRecur;
args := R.Arguments;
var args := R.Arguments.Elements;
Append('(recur');
// Manually iterate arguments
for i := 0 to args.Count - 1 do
for i := 0 to High(args) do
begin
Append(' ');
Visit(args.Items[i]);
Visit(args[i]);
end;
Append(')');
end;
@@ -365,18 +364,17 @@ end;
function TPrettyPrintVisitor.VisitBlockExpression(const N: IAstNode): TVoid;
var
B: IBlockExpressionNode;
exprs: ITupleNode;
i: Integer;
begin
B := N.AsBlockExpression;
exprs := B.Expressions;
var exprs := B.Expressions.Elements;
Append('(do');
Indent;
// Manually iterate expressions tuple for newlines
for i := 0 to exprs.Count - 1 do
for i := 0 to High(exprs) do
begin
NewLine;
Visit(exprs.Items[i]);
Visit(exprs[i]);
end;
Unindent;
NewLine;
@@ -437,22 +435,21 @@ end;
function TPrettyPrintVisitor.VisitRecordLiteral(const N: IAstNode): TVoid;
var
R: IRecordLiteralNode;
fields: ITupleNode;
i: Integer;
begin
R := N.AsRecordLiteral;
fields := R.Fields;
if fields.Count = 0 then
var fields := R.Fields.Elements;
if Length(fields) = 0 then
begin
Append('{}');
exit;
end;
Append('{');
Indent;
for i := 0 to fields.Count - 1 do
for i := 0 to High(fields) do
begin
NewLine;
Visit(fields.Items[i]);
Visit(fields[i]);
end;
Unindent;
NewLine;