Handle Nop properly
This commit is contained in:
@@ -46,12 +46,8 @@ type
|
||||
|
||||
// --- Standard Traversal (Use inherited) ---
|
||||
function VisitKeyword(const Node: IKeywordNode): IAstNode; override;
|
||||
function VisitRecurNode(const Node: IRecurNode): IAstNode; override;
|
||||
function VisitConstant(const Node: IConstantNode): IAstNode; override;
|
||||
function VisitCreateSeries(const Node: ICreateSeriesNode): IAstNode; override;
|
||||
function VisitAddSeriesItem(const Node: IAddSeriesItemNode): IAstNode; override;
|
||||
function VisitSeriesLength(const Node: ISeriesLengthNode): IAstNode; override;
|
||||
|
||||
public
|
||||
constructor Create(const AInitialDescriptor: IScopeDescriptor);
|
||||
destructor Destroy; override;
|
||||
@@ -222,20 +218,6 @@ begin
|
||||
Result := Node;
|
||||
end;
|
||||
|
||||
function TAstBinder.VisitAddSeriesItem(const Node: IAddSeriesItemNode): IAstNode;
|
||||
begin
|
||||
// Visit children
|
||||
Result := inherited VisitAddSeriesItem(Node);
|
||||
// Binding pass does not assign types.
|
||||
end;
|
||||
|
||||
function TAstBinder.VisitSeriesLength(const Node: ISeriesLengthNode): IAstNode;
|
||||
begin
|
||||
// Visit children
|
||||
Result := inherited VisitSeriesLength(Node);
|
||||
// Binding pass does not assign types.
|
||||
end;
|
||||
|
||||
function TAstBinder.VisitLambdaExpression(const Node: ILambdaExpressionNode): IAstNode;
|
||||
var
|
||||
i: integer;
|
||||
@@ -304,13 +286,6 @@ begin
|
||||
Result := TAst.LambdaExpr(newParams, newBody, scopeDescriptor, upvalues, hasNestedLambdas);
|
||||
end;
|
||||
|
||||
function TAstBinder.VisitRecurNode(const Node: IRecurNode): IAstNode;
|
||||
begin
|
||||
// Visit children
|
||||
Result := inherited VisitRecurNode(Node);
|
||||
// Binding pass does not assign types.
|
||||
end;
|
||||
|
||||
function TAstBinder.VisitIdentifier(const Node: IIdentifierNode): IAstNode;
|
||||
var
|
||||
symbol: TResolvedSymbol;
|
||||
|
||||
@@ -45,6 +45,7 @@ type
|
||||
function VisitAddSeriesItem(const Node: IAddSeriesItemNode): IAstNode; override;
|
||||
function VisitSeriesLength(const Node: ISeriesLengthNode): IAstNode; override;
|
||||
function VisitRecurNode(const Node: IRecurNode): IAstNode; override;
|
||||
function VisitNop(const Node: INopNode): IAstNode; override;
|
||||
|
||||
// Base cases (types are now set here)
|
||||
function VisitConstant(const Node: IConstantNode): IAstNode; override;
|
||||
@@ -609,6 +610,12 @@ begin
|
||||
Result := TAst.AddSeriesItem(newSeries.AsIdentifier, newValue, newLookback, TTypes.Void);
|
||||
end;
|
||||
|
||||
function TTypeChecker.VisitNop(const Node: INopNode): IAstNode;
|
||||
begin
|
||||
// This is a leaf node. Assign its final type as Void.
|
||||
Result := TAst.Nop(TTypes.Void);
|
||||
end;
|
||||
|
||||
function TTypeChecker.VisitSeriesLength(const Node: ISeriesLengthNode): IAstNode;
|
||||
var
|
||||
seriesType: IStaticType;
|
||||
|
||||
@@ -160,9 +160,8 @@ type
|
||||
property StaticType: IStaticType read GetStaticType;
|
||||
end;
|
||||
|
||||
INopNode = interface(IAstNode)
|
||||
INopNode = interface(IAstTypedNode)
|
||||
// A placeholder node for the UI (e.g., drag target).
|
||||
// This node is illegal during compilation.
|
||||
end;
|
||||
|
||||
IConstantNode = interface(IAstTypedNode)
|
||||
|
||||
+7
-8
@@ -29,8 +29,7 @@ type
|
||||
class function CreateScope(Parent: IExecutionScope; const Descriptor: IScopeDescriptor = nil): IExecutionScope; static;
|
||||
|
||||
// A No-Operation node, used as a placeholder/stub (e.g., for UI drop targets).
|
||||
// This node is illegal in the compiler (Binder/TypeChecker will reject it).
|
||||
class function Nop: IAstNode; static;
|
||||
class function Nop(const AStaticType: IStaticType = nil): IAstNode; static;
|
||||
|
||||
// --- Factory functions ---
|
||||
class function Constant(const AValue: TDataValue; const AStaticType: IStaticType = nil): IConstantNode; overload; static;
|
||||
@@ -583,11 +582,11 @@ type
|
||||
property GenericDefinition: IGenericRecordDefinition read GetGenericDefinition;
|
||||
end;
|
||||
|
||||
TNopNode = class(TAstNode, INopNode)
|
||||
TNopNode = class(TAstTypedNode, INopNode)
|
||||
private
|
||||
function GetKind: TAstNodeKind; override;
|
||||
public
|
||||
constructor Create;
|
||||
constructor Create(const AStaticType: IStaticType);
|
||||
function Accept(const Visitor: IAstVisitor): TDataValue; override;
|
||||
function AsNop: INopNode; override;
|
||||
end;
|
||||
@@ -858,10 +857,10 @@ begin
|
||||
);
|
||||
end;
|
||||
|
||||
class function TAst.Nop: IAstNode;
|
||||
class function TAst.Nop(const AStaticType: IStaticType = nil): IAstNode;
|
||||
begin
|
||||
// Factory function for the new Nop node
|
||||
Result := TNopNode.Create;
|
||||
Result := TNopNode.Create(TTypes.Unknown);
|
||||
end;
|
||||
|
||||
class function TAst.Quasiquote(const AExpression: IAstNode): IQuasiquoteNode;
|
||||
@@ -963,9 +962,9 @@ end;
|
||||
|
||||
{ TNopNode }
|
||||
|
||||
constructor TNopNode.Create;
|
||||
constructor TNopNode.Create(const AStaticType: IStaticType);
|
||||
begin
|
||||
inherited Create;
|
||||
inherited Create(AStaticType);
|
||||
end;
|
||||
|
||||
function TNopNode.Accept(const Visitor: IAstVisitor): TDataValue;
|
||||
|
||||
Reference in New Issue
Block a user