This commit is contained in:
Michael Schimmel
2025-10-30 18:00:58 +01:00
parent dfe1f04333
commit 798aa08f02
12 changed files with 710 additions and 27 deletions
+38 -1
View File
@@ -6,7 +6,8 @@ uses
System.SysUtils,
System.Generics.Collections,
Myc.Data.Scalar,
Myc.Data.Value;
Myc.Data.Value,
Myc.Data.Keyword;
type
// --- Forward Declarations to break cycles ---
@@ -14,6 +15,7 @@ type
IAstNode = interface;
IIdentifierNode = interface;
IConstantNode = interface;
IKeywordNode = interface;
IBinaryExpressionNode = interface;
IUnaryExpressionNode = interface;
IIfExpressionNode = interface;
@@ -30,6 +32,7 @@ type
IUnquoteSplicingNode = interface;
IIndexerNode = interface;
IMemberAccessNode = interface;
IRecordLiteralNode = interface;
ICreateSeriesNode = interface;
IAddSeriesItemNode = interface;
ISeriesLengthNode = interface;
@@ -50,9 +53,17 @@ type
class operator Equal(const A: TResolvedAddress; B: TResolvedAddress): Boolean;
end;
// A single field in a record literal
TRecordFieldLiteral = record
Name: string; // The field name (from keyword :name)
Value: IAstNode;
constructor Create(const AName: string; const AValue: IAstNode);
end;
IAstVisitor = interface
function VisitConstant(const Node: IConstantNode): TDataValue;
function VisitIdentifier(const Node: IIdentifierNode): TDataValue;
function VisitKeyword(const Node: IKeywordNode): TDataValue;
function VisitBinaryExpression(const Node: IBinaryExpressionNode): TDataValue;
function VisitUnaryExpression(const Node: IUnaryExpressionNode): TDataValue;
function VisitIfExpression(const Node: IIfExpressionNode): TDataValue;
@@ -69,6 +80,7 @@ type
function VisitUnquoteSplicing(const Node: IUnquoteSplicingNode): TDataValue;
function VisitIndexer(const Node: IIndexerNode): TDataValue;
function VisitMemberAccess(const Node: IMemberAccessNode): TDataValue;
function VisitRecordLiteral(const Node: IRecordLiteralNode): TDataValue;
function VisitCreateSeries(const Node: ICreateSeriesNode): TDataValue;
function VisitAddSeriesItem(const Node: IAddSeriesItemNode): TDataValue;
function VisitSeriesLength(const Node: ISeriesLengthNode): TDataValue;
@@ -94,6 +106,15 @@ type
property Name: string read GetName;
end;
// Represents a keyword literal in the AST (e.g., :foo)
IKeywordNode = interface(IAstNode)
{$region 'private'}
function GetValue: IKeyword;
{$endregion}
// The interned keyword object
property Value: IKeyword read GetValue;
end;
IBinaryExpressionNode = interface(IAstNode)
{$region 'private'}
function GetLeft: IAstNode;
@@ -249,6 +270,14 @@ type
property Member: IIdentifierNode read GetMember;
end;
// Represents a record literal, e.g., {:a 1 :b 2}
IRecordLiteralNode = interface(IAstNode)
{$region 'private'}
function GetFields: TArray<TRecordFieldLiteral>;
{$endregion}
property Fields: TArray<TRecordFieldLiteral> read GetFields;
end;
ICreateSeriesNode = interface(IAstNode)
{$region 'private'}
function GetDefinition: String;
@@ -304,4 +333,12 @@ begin
Dest.SlotIndex := -1;
end;
{ TRecordFieldLiteral }
constructor TRecordFieldLiteral.Create(const AName: string; const AValue: IAstNode);
begin
Name := AName;
Value := AValue;
end;
end.