RECUR keyword added
This commit is contained in:
@@ -36,6 +36,7 @@ type
|
||||
class function TernaryExpr(const ACondition: IAstNode; const AThenBranch, AElseBranch: IAstNode): ITernaryExpressionNode; static;
|
||||
class function LambdaExpr(const AParameters: TArray<IIdentifierNode>; const ABody: IAstNode): ILambdaExpressionNode; static;
|
||||
class function FunctionCall(const ACallee: IAstNode; const AArguments: TArray<IAstNode>): IFunctionCallNode; static;
|
||||
class function Recur(const AArguments: array of IAstNode): IRecurNode; static;
|
||||
class function Block(const AExpressions: array of IAstNode): IBlockExpressionNode; static;
|
||||
class function VarDecl(const AIdentifier: IIdentifierNode; AInitializer: IAstNode = nil): IVariableDeclarationNode; static;
|
||||
class function Assign(const AIdentifier: IIdentifierNode; const AValue: IAstNode): IAssignmentNode; static;
|
||||
@@ -164,6 +165,18 @@ type
|
||||
property IsTailCall: Boolean read FIsTailCall write FIsTailCall;
|
||||
end;
|
||||
|
||||
TRecurNode = class(TAstNode, IRecurNode)
|
||||
private
|
||||
FArguments: TArray<IAstNode>;
|
||||
FIsTailCall: Boolean;
|
||||
function GetArguments: TArray<IAstNode>;
|
||||
function GetIsTailCall: Boolean;
|
||||
public
|
||||
constructor Create(const AArguments: TArray<IAstNode>);
|
||||
function Accept(const Visitor: IAstVisitor): TDataValue; override;
|
||||
property IsTailCall: Boolean read FIsTailCall write FIsTailCall;
|
||||
end;
|
||||
|
||||
TBlockExpressionNode = class(TAstNode, IBlockExpressionNode)
|
||||
private
|
||||
FExpressions: TList<IAstNode>;
|
||||
@@ -479,6 +492,30 @@ begin
|
||||
Result := FIsTailCall;
|
||||
end;
|
||||
|
||||
{ TRecurNode }
|
||||
|
||||
constructor TRecurNode.Create(const AArguments: TArray<IAstNode>);
|
||||
begin
|
||||
inherited Create;
|
||||
FArguments := AArguments;
|
||||
FIsTailCall := True;
|
||||
end;
|
||||
|
||||
function TRecurNode.Accept(const Visitor: IAstVisitor): TDataValue;
|
||||
begin
|
||||
Result := Visitor.VisitRecurNode(Self);
|
||||
end;
|
||||
|
||||
function TRecurNode.GetArguments: TArray<IAstNode>;
|
||||
begin
|
||||
Result := FArguments;
|
||||
end;
|
||||
|
||||
function TRecurNode.GetIsTailCall: Boolean;
|
||||
begin
|
||||
Result := FIsTailCall;
|
||||
end;
|
||||
|
||||
{ TBlockExpressionNode }
|
||||
|
||||
constructor TBlockExpressionNode.Create(const AExpressions: array of IAstNode);
|
||||
@@ -760,6 +797,17 @@ begin
|
||||
Result := TMemberAccessNode.Create(ABase, AMember);
|
||||
end;
|
||||
|
||||
class function TAst.Recur(const AArguments: array of IAstNode): IRecurNode;
|
||||
var
|
||||
args: TArray<IAstNode>;
|
||||
i: Integer;
|
||||
begin
|
||||
SetLength(args, Length(AArguments));
|
||||
for i := 0 to High(AArguments) do
|
||||
args[i] := AArguments[i];
|
||||
Result := TRecurNode.Create(args);
|
||||
end;
|
||||
|
||||
class function TAst.SeriesLength(const ASeries: IIdentifierNode): ISeriesLengthNode;
|
||||
begin
|
||||
Result := TSeriesLengthNode.Create(ASeries);
|
||||
|
||||
Reference in New Issue
Block a user