AST Refactoring
This commit is contained in:
@@ -201,23 +201,32 @@ end;
|
||||
function TEvaluatorVisitor.VisitFunctionCall(const Node: IFunctionCallNode): TDataValue;
|
||||
var
|
||||
calleeValue: TDataValue;
|
||||
argValues: TArray<TDataValue>;
|
||||
i: Integer;
|
||||
begin
|
||||
calleeValue := Node.Callee.Accept(Self);
|
||||
|
||||
var argNodes := Node.Arguments;
|
||||
SetLength(argValues, Length(argNodes));
|
||||
for i := 0 to High(argNodes) do
|
||||
argValues[i] := argNodes[i].Accept(Self);
|
||||
|
||||
if (calleeValue.Kind = vkMethod) then
|
||||
Result := (calleeValue.AsMethod)(argValues)
|
||||
else
|
||||
if calleeValue.Kind <> vkMethod then
|
||||
raise EArgumentException.Create('Expression is not invokable in this context.');
|
||||
|
||||
var argNodes := Node.Arguments;
|
||||
case Length(argNodes) of
|
||||
0: Result := (calleeValue.AsMethod)([]);
|
||||
1: Result := (calleeValue.AsMethod)([argNodes[0].Accept(Self)]);
|
||||
2: Result := (calleeValue.AsMethod)([argNodes[0].Accept(Self), argNodes[1].Accept(Self)]);
|
||||
3: Result := (calleeValue.AsMethod)([argNodes[0].Accept(Self), argNodes[1].Accept(Self), argNodes[2].Accept(Self)]);
|
||||
4:
|
||||
Result :=
|
||||
(calleeValue.AsMethod)
|
||||
([argNodes[0].Accept(Self), argNodes[1].Accept(Self), argNodes[2].Accept(Self), argNodes[3].Accept(Self)]);
|
||||
else
|
||||
var argValues: TArray<TDataValue>;
|
||||
SetLength(argValues, Length(argNodes));
|
||||
for var i := 0 to High(argNodes) do
|
||||
argValues[i] := argNodes[i].Accept(Self);
|
||||
|
||||
Result := (calleeValue.AsMethod)(argValues);
|
||||
end;
|
||||
end;
|
||||
|
||||
// ... The rest of the Visit... methods are unchanged and remain as they were ...
|
||||
function TEvaluatorVisitor.VisitAddSeriesItem(const Node: IAddSeriesItemNode): TDataValue;
|
||||
var
|
||||
itemValue, lookbackValue, seriesVar: TDataValue;
|
||||
|
||||
Reference in New Issue
Block a user