Ast list nodes
This commit is contained in:
@@ -122,7 +122,7 @@ end;
|
||||
function TStaticSpecializer.VisitFunctionCall(const Node: IFunctionCallNode): IAstNode;
|
||||
var
|
||||
newCallee: IAstNode;
|
||||
newArgs: TArray<IAstNode>;
|
||||
newArgsList: IArgumentList;
|
||||
i: Integer;
|
||||
calleeIdent: IIdentifierNode;
|
||||
argTypes: TArray<IStaticType>;
|
||||
@@ -134,15 +134,16 @@ var
|
||||
begin
|
||||
// 1. Specialize children first (bottom-up)
|
||||
newCallee := Accept(Node.Callee);
|
||||
newArgs := AcceptNodes(Node.Arguments);
|
||||
// Arguments are now visited as a List, returning an IArgumentList
|
||||
newArgsList := Accept(Node.Arguments).AsArgumentList;
|
||||
|
||||
// 2. Check if this call is a candidate for specialization
|
||||
if newCallee.Kind <> akIdentifier then
|
||||
begin
|
||||
if (newCallee = Node.Callee) and (newArgs = Node.Arguments) then
|
||||
if (newCallee = Node.Callee) and (newArgsList = Node.Arguments) then
|
||||
Result := Node
|
||||
else
|
||||
Result := TAst.FunctionCall(Node.Identity, newCallee, newArgs, Node.StaticType, Node.IsTailCall, nil);
|
||||
Result := TAst.FunctionCall(Node.Identity, newCallee, newArgsList, Node.StaticType, Node.IsTailCall, nil);
|
||||
exit;
|
||||
end;
|
||||
|
||||
@@ -151,10 +152,10 @@ begin
|
||||
|
||||
// 3. Check if all argument types are statically known
|
||||
allTypesKnown := True;
|
||||
SetLength(argTypes, Length(newArgs));
|
||||
for i := 0 to High(newArgs) do
|
||||
SetLength(argTypes, newArgsList.Count);
|
||||
for i := 0 to newArgsList.Count - 1 do
|
||||
begin
|
||||
argTypes[i] := newArgs[i].AsTypedNode.StaticType;
|
||||
argTypes[i] := newArgsList[i].AsTypedNode.StaticType;
|
||||
if argTypes[i].Kind = stUnknown then
|
||||
begin
|
||||
allTypesKnown := False;
|
||||
@@ -164,10 +165,10 @@ begin
|
||||
|
||||
if not allTypesKnown then
|
||||
begin
|
||||
if (newCallee = Node.Callee) and (newArgs = Node.Arguments) then
|
||||
if (newCallee = Node.Callee) and (newArgsList = Node.Arguments) then
|
||||
Result := Node
|
||||
else
|
||||
Result := TAst.FunctionCall(Node.Identity, newCallee, newArgs, Node.StaticType, Node.IsTailCall, nil);
|
||||
Result := TAst.FunctionCall(Node.Identity, newCallee, newArgsList, Node.StaticType, Node.IsTailCall, nil);
|
||||
exit;
|
||||
end;
|
||||
|
||||
@@ -183,7 +184,7 @@ begin
|
||||
TAst.FunctionCall(
|
||||
Node.Identity,
|
||||
newCallee,
|
||||
newArgs,
|
||||
newArgsList,
|
||||
specializedMethod.ReturnType,
|
||||
Node.IsTailCall,
|
||||
specializedMethod.Target,
|
||||
@@ -203,7 +204,7 @@ begin
|
||||
TAst.FunctionCall(
|
||||
Node.Identity,
|
||||
newCallee,
|
||||
newArgs,
|
||||
newArgsList,
|
||||
specializedMethod.ReturnType,
|
||||
Node.IsTailCall,
|
||||
specializedMethod.Target,
|
||||
@@ -223,7 +224,7 @@ begin
|
||||
var lambdaDef := funcDef.AsLambdaExpression;
|
||||
if (Length(lambdaDef.Upvalues) > 0) or (lambdaDef.HasNestedLambdas) then
|
||||
begin
|
||||
Result := TAst.FunctionCall(Node.Identity, newCallee, newArgs, Node.StaticType, Node.IsTailCall, nil);
|
||||
Result := TAst.FunctionCall(Node.Identity, newCallee, newArgsList, Node.StaticType, Node.IsTailCall, nil);
|
||||
exit;
|
||||
end;
|
||||
end;
|
||||
@@ -244,15 +245,15 @@ begin
|
||||
FMonomorphCache.Add(key, specializedMethod);
|
||||
|
||||
// 6c. Return the new node
|
||||
Result := TAst.FunctionCall(Node.Identity, newCallee, newArgs, returnType, Node.IsTailCall, compiled.Func, compiled.IsPure);
|
||||
Result := TAst.FunctionCall(Node.Identity, newCallee, newArgsList, returnType, Node.IsTailCall, compiled.Func, compiled.IsPure);
|
||||
exit;
|
||||
end;
|
||||
|
||||
// 7. Fallback: Not RTL, Not User-Code -> Dynamic
|
||||
if (newCallee = Node.Callee) and (newArgs = Node.Arguments) then
|
||||
if (newCallee = Node.Callee) and (newArgsList = Node.Arguments) then
|
||||
Result := Node
|
||||
else
|
||||
Result := TAst.FunctionCall(Node.Identity, newCallee, newArgs, Node.StaticType, Node.IsTailCall, nil);
|
||||
Result := TAst.FunctionCall(Node.Identity, newCallee, newArgsList, Node.StaticType, Node.IsTailCall, nil);
|
||||
end;
|
||||
|
||||
{ TMonoCacheKey }
|
||||
|
||||
Reference in New Issue
Block a user