Ast list nodes

This commit is contained in:
Michael Schimmel
2025-11-29 18:59:16 +01:00
parent 250f950a68
commit 851f56c63f
24 changed files with 1819 additions and 863 deletions
+16 -15
View File
@@ -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 }