diff --git a/Src/AST/Myc.Ast.Compiler.Binder.pas b/Src/AST/Myc.Ast.Compiler.Binder.pas index 7fa76d3..054640b 100644 --- a/Src/AST/Myc.Ast.Compiler.Binder.pas +++ b/Src/AST/Myc.Ast.Compiler.Binder.pas @@ -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; diff --git a/Src/AST/Myc.Ast.Compiler.TypeChecker.pas b/Src/AST/Myc.Ast.Compiler.TypeChecker.pas index ee73570..9c46100 100644 --- a/Src/AST/Myc.Ast.Compiler.TypeChecker.pas +++ b/Src/AST/Myc.Ast.Compiler.TypeChecker.pas @@ -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; diff --git a/Src/AST/Myc.Ast.Nodes.pas b/Src/AST/Myc.Ast.Nodes.pas index c8ae1f5..d4f6a95 100644 --- a/Src/AST/Myc.Ast.Nodes.pas +++ b/Src/AST/Myc.Ast.Nodes.pas @@ -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) diff --git a/Src/AST/Myc.Ast.pas b/Src/AST/Myc.Ast.pas index 10d8fb4..5387a38 100644 --- a/Src/AST/Myc.Ast.pas +++ b/Src/AST/Myc.Ast.pas @@ -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;