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