Ast list nodes
This commit is contained in:
@@ -12,7 +12,7 @@ uses
|
||||
Myc.Ast.Visitor,
|
||||
Myc.Ast.Scope,
|
||||
Myc.Ast.Types,
|
||||
Myc.Ast.Identities, // Wichtig für Casts (AsNamed etc.)
|
||||
Myc.Ast.Identities,
|
||||
Myc.Ast;
|
||||
|
||||
type
|
||||
@@ -200,17 +200,15 @@ var
|
||||
identity: INamedIdentity;
|
||||
begin
|
||||
adr := Node.Address;
|
||||
identity := Node.Identity.AsNamed; // Extract specific identity
|
||||
identity := Node.Identity.AsNamed;
|
||||
|
||||
if adr.Kind = akUnresolved then
|
||||
begin
|
||||
// Propagate identity, set type to Unknown
|
||||
Result := TAst.Identifier(identity, adr, TTypes.Unknown);
|
||||
Exit;
|
||||
end;
|
||||
|
||||
typ := FCurrentContext.LookupType(adr);
|
||||
// CoW: Reuse Identity
|
||||
Result := TAst.Identifier(identity, adr, typ);
|
||||
end;
|
||||
|
||||
@@ -219,12 +217,13 @@ var
|
||||
newArgs: TArray<IAstNode>;
|
||||
i: Integer;
|
||||
begin
|
||||
SetLength(newArgs, Length(Node.Arguments));
|
||||
for i := 0 to High(Node.Arguments) do
|
||||
SetLength(newArgs, Node.Arguments.Count);
|
||||
for i := 0 to Node.Arguments.Count - 1 do
|
||||
newArgs[i] := Accept(Node.Arguments[i]);
|
||||
|
||||
// CoW: Reuse Identity
|
||||
Result := TAst.Recur(Node.Identity, newArgs, TTypes.Void);
|
||||
// FIX: Wrap in List
|
||||
var argList := TArgumentList.Create(newArgs, Node.Arguments.Identity);
|
||||
Result := TAst.Recur(Node.Identity, argList, TTypes.Void);
|
||||
end;
|
||||
|
||||
function TTypeChecker.VisitVariableDeclaration(const Node: IVariableDeclarationNode): IAstNode;
|
||||
@@ -256,7 +255,7 @@ begin
|
||||
begin
|
||||
lambdaNode := Node.Initializer.AsLambdaExpression;
|
||||
var paramTypes: TArray<IStaticType>;
|
||||
SetLength(paramTypes, Length(lambdaNode.Parameters));
|
||||
SetLength(paramTypes, lambdaNode.Parameters.Count);
|
||||
for i := 0 to High(paramTypes) do
|
||||
paramTypes[i] := TTypes.Unknown;
|
||||
|
||||
@@ -278,10 +277,8 @@ begin
|
||||
if initType.Kind <> stUnknown then
|
||||
FCurrentContext.SetType(adr.SlotIndex, initType);
|
||||
|
||||
// Reuse Identity for Identifier
|
||||
newIdent := TAst.Identifier(identIdentity, adr, initType);
|
||||
|
||||
// Reuse Identity for VarDecl
|
||||
Result := TAst.VarDecl(Node.Identity, newIdent, newInitializer, initType, Node.IsBoxed);
|
||||
end;
|
||||
|
||||
@@ -296,11 +293,10 @@ var
|
||||
identNode: IIdentifierNode;
|
||||
identIdentity: INamedIdentity;
|
||||
begin
|
||||
// Rebuild Identifier with potential type info updates
|
||||
identNode := Node.Target.AsIdentifier;
|
||||
identIdentity := identNode.Identity.AsNamed;
|
||||
|
||||
newIdent := Accept(Node.Target); // This visits identifier and might update type from context
|
||||
newIdent := Accept(Node.Target);
|
||||
targetType := newIdent.AsTypedNode.StaticType;
|
||||
adr := identNode.Address;
|
||||
|
||||
@@ -318,7 +314,7 @@ begin
|
||||
if (targetType.Kind <> stMethod) then
|
||||
begin
|
||||
var paramTypes: TArray<IStaticType>;
|
||||
SetLength(paramTypes, Length(lambdaNode.Parameters));
|
||||
SetLength(paramTypes, lambdaNode.Parameters.Count);
|
||||
for i := 0 to High(paramTypes) do
|
||||
paramTypes[i] := TTypes.Unknown;
|
||||
|
||||
@@ -343,12 +339,10 @@ begin
|
||||
if ((targetType.Kind = stUnknown) or Assigned(placeholderType)) and (sourceType.Kind <> stUnknown) then
|
||||
begin
|
||||
FCurrentContext.SetType(adr.SlotIndex, sourceType);
|
||||
// Recreate Identifier with new type and original identity
|
||||
newIdent := TAst.Identifier(identIdentity, adr, sourceType);
|
||||
targetType := sourceType;
|
||||
end;
|
||||
|
||||
// CoW: Reuse Assignment Identity
|
||||
Result := TAst.Assign(Node.Identity, newIdent, newValue, targetType);
|
||||
end;
|
||||
|
||||
@@ -372,10 +366,10 @@ begin
|
||||
|
||||
FCurrentContext := TTypeContext.Create(FCurrentContext, Node.Layout, upvalueTypes);
|
||||
try
|
||||
SetLength(newParams, Length(Node.Parameters));
|
||||
SetLength(paramTypes, Length(Node.Parameters));
|
||||
SetLength(newParams, Node.Parameters.Count);
|
||||
SetLength(paramTypes, Node.Parameters.Count);
|
||||
|
||||
for i := 0 to High(Node.Parameters) do
|
||||
for i := 0 to Node.Parameters.Count - 1 do
|
||||
begin
|
||||
paramIdent := Node.Parameters[i];
|
||||
paramIdentity := paramIdent.Identity.AsNamed;
|
||||
@@ -386,7 +380,6 @@ begin
|
||||
if paramAdr.Kind <> akUnresolved then
|
||||
FCurrentContext.SetType(paramAdr.SlotIndex, paramTypes[i]);
|
||||
|
||||
// CoW: Reuse Parameter Identity
|
||||
newParams[i] := TAst.Identifier(paramIdentity, paramAdr, paramTypes[i]);
|
||||
end;
|
||||
|
||||
@@ -402,11 +395,13 @@ begin
|
||||
temp.Free;
|
||||
end;
|
||||
|
||||
// CoW: Reuse Lambda Identity
|
||||
// FIX: Wrap in List
|
||||
var paramList := TParameterList.Create(newParams, Node.Parameters.Identity);
|
||||
|
||||
Result :=
|
||||
TAst.LambdaExpr(
|
||||
Node.Identity,
|
||||
newParams,
|
||||
paramList,
|
||||
newBody,
|
||||
Node.Layout,
|
||||
finalDescriptor,
|
||||
@@ -431,11 +426,11 @@ var
|
||||
argsStr: string;
|
||||
begin
|
||||
newCallee := Accept(Node.Callee);
|
||||
SetLength(newArgs, Length(Node.Arguments));
|
||||
SetLength(argTypes, Length(Node.Arguments));
|
||||
SetLength(newArgs, Node.Arguments.Count);
|
||||
SetLength(argTypes, Node.Arguments.Count);
|
||||
|
||||
hasUnknownArgs := False;
|
||||
for i := 0 to High(Node.Arguments) do
|
||||
for i := 0 to Node.Arguments.Count - 1 do
|
||||
begin
|
||||
newArgs[i] := Accept(Node.Arguments[i]);
|
||||
argTypes[i] := newArgs[i].AsTypedNode.StaticType;
|
||||
@@ -498,17 +493,10 @@ begin
|
||||
retType := TTypes.Unknown;
|
||||
end;
|
||||
|
||||
// CoW: Reuse Call Identity
|
||||
Result :=
|
||||
TAst.FunctionCall(
|
||||
Node.Identity,
|
||||
newCallee,
|
||||
newArgs,
|
||||
retType,
|
||||
Node.IsTailCall,
|
||||
nil, // StaticTarget set by Specializer
|
||||
False // IsTargetPure set by Specializer
|
||||
);
|
||||
// FIX: Wrap in List
|
||||
var argList := TArgumentList.Create(newArgs, Node.Arguments.Identity);
|
||||
|
||||
Result := TAst.FunctionCall(Node.Identity, newCallee, argList, retType, Node.IsTailCall, nil, False);
|
||||
end;
|
||||
|
||||
function TTypeChecker.VisitBlockExpression(const Node: IBlockExpressionNode): IAstNode;
|
||||
@@ -517,8 +505,8 @@ var
|
||||
newExprs: TArray<IAstNode>;
|
||||
i: Integer;
|
||||
begin
|
||||
SetLength(newExprs, Length(Node.Expressions));
|
||||
for i := 0 to High(Node.Expressions) do
|
||||
SetLength(newExprs, Node.Expressions.Count);
|
||||
for i := 0 to Node.Expressions.Count - 1 do
|
||||
newExprs[i] := Accept(Node.Expressions[i]);
|
||||
|
||||
if Length(newExprs) > 0 then
|
||||
@@ -526,8 +514,9 @@ begin
|
||||
else
|
||||
blockType := TTypes.Void;
|
||||
|
||||
// CoW: Reuse Block Identity
|
||||
Result := TAst.Block(Node.Identity, newExprs, blockType);
|
||||
// FIX: Wrap in List
|
||||
var exprList := TExpressionList.Create(newExprs, Node.Expressions.Identity);
|
||||
Result := TAst.Block(Node.Identity, exprList, blockType);
|
||||
end;
|
||||
|
||||
function TTypeChecker.VisitIfExpression(const Node: IIfExpressionNode): IAstNode;
|
||||
@@ -561,7 +550,6 @@ begin
|
||||
resultType := TTypes.Unknown;
|
||||
end;
|
||||
|
||||
// CoW: Reuse If Identity
|
||||
Result := TAst.IfExpr(Node.Identity, newCond, newThen, newElse, resultType);
|
||||
end;
|
||||
|
||||
@@ -594,7 +582,6 @@ begin
|
||||
resultType := TTypes.Unknown;
|
||||
end;
|
||||
|
||||
// CoW: Reuse Ternary Identity
|
||||
Result := TAst.TernaryExpr(Node.Identity, newCond, newThen, newElse, resultType);
|
||||
end;
|
||||
|
||||
@@ -648,7 +635,6 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
// CoW: Reuse MemberAccess Identity
|
||||
Result := TAst.MemberAccess(Node.Identity, newBase, newMember.AsKeyword, elemType);
|
||||
end;
|
||||
|
||||
@@ -686,7 +672,6 @@ begin
|
||||
FLog.AddError(Format('Indexer `[]` requires an Ordinal index, but got %s', [indexType.ToString]), Node);
|
||||
end;
|
||||
|
||||
// CoW: Reuse Indexer Identity
|
||||
Result := TAst.Indexer(Node.Identity, newBase, newIndex, elemType);
|
||||
end;
|
||||
|
||||
@@ -699,13 +684,19 @@ var
|
||||
valType: IStaticType;
|
||||
scalarKind: TScalar.TKind;
|
||||
allScalar: Boolean;
|
||||
newFields: TArray<TRecordFieldLiteral>;
|
||||
newFields: TArray<IRecordFieldNode>;
|
||||
begin
|
||||
SetLength(newFields, Length(Node.Fields));
|
||||
for i := 0 to High(Node.Fields) do
|
||||
SetLength(newFields, Node.Fields.Count);
|
||||
for i := 0 to Node.Fields.Count - 1 do
|
||||
begin
|
||||
newFields[i].Key := Accept(Node.Fields[i].Key).AsKeyword;
|
||||
newFields[i].Value := Accept(Node.Fields[i].Value);
|
||||
var field := Node.Fields[i];
|
||||
var newKey := Accept(field.Key).AsKeyword;
|
||||
var newValue := Accept(field.Value);
|
||||
|
||||
if (newKey = field.Key) and (newValue = field.Value) then
|
||||
newFields[i] := field
|
||||
else
|
||||
newFields[i] := TAst.RecordField(field.Identity, newKey, newValue);
|
||||
end;
|
||||
|
||||
SetLength(scalarDefFields, Length(newFields));
|
||||
@@ -735,11 +726,14 @@ begin
|
||||
scalarDefFields[i] := TScalarRecordField.Create(newFields[i].Key.Value, scalarKind);
|
||||
end;
|
||||
|
||||
// FIX: Wrap in List
|
||||
var fieldList := TRecordFieldList.Create(newFields, Node.Fields.Identity);
|
||||
|
||||
if allScalar then
|
||||
begin
|
||||
def := TScalarRecordRegistry.Intern(scalarDefFields);
|
||||
staticType := TTypes.CreateRecord(def);
|
||||
Result := TAst.RecordLiteral(Node.Identity, newFields, def, nil, staticType);
|
||||
Result := TAst.RecordLiteral(Node.Identity, fieldList, def, nil, staticType);
|
||||
end
|
||||
else
|
||||
begin
|
||||
@@ -750,7 +744,7 @@ begin
|
||||
|
||||
var genDef := TGenericRecordRegistry.Intern(genDefFields);
|
||||
staticType := TTypes.CreateGenericRecord(genDef);
|
||||
Result := TAst.RecordLiteral(Node.Identity, newFields, nil, genDef, staticType);
|
||||
Result := TAst.RecordLiteral(Node.Identity, fieldList, nil, genDef, staticType);
|
||||
end;
|
||||
end;
|
||||
|
||||
@@ -760,7 +754,6 @@ var
|
||||
defIdentity: IDefinitionIdentity;
|
||||
begin
|
||||
try
|
||||
// Use definition from Identity to ensure SSOT
|
||||
defIdentity := Node.Identity.AsDefinition;
|
||||
elemType := TTypes.FromScalarKind(TScalar.StringToKind(defIdentity.Definition));
|
||||
except
|
||||
@@ -772,7 +765,6 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
// CoW: Reuse Definition Identity
|
||||
Result := TAst.CreateSeries(defIdentity, TTypes.CreateSeries(elemType));
|
||||
end;
|
||||
|
||||
@@ -818,7 +810,6 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
// CoW: Reuse Add Identity
|
||||
Result := TAst.AddSeriesItem(Node.Identity, newSeries.AsIdentifier, newValue, newLookback, TTypes.Void);
|
||||
end;
|
||||
|
||||
@@ -843,7 +834,6 @@ begin
|
||||
FLog.AddError(Format('"length" requires a series, but got %s', [seriesType.ToString]), Node);
|
||||
end;
|
||||
|
||||
// CoW: Reuse SeriesLength Identity
|
||||
Result := TAst.SeriesLength(Node.Identity, newSeries.AsIdentifier, TTypes.Ordinal);
|
||||
end;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user