This commit is contained in:
Michael Schimmel
2025-10-31 18:12:53 +01:00
parent 0526ec8a24
commit 8abec8e98f
8 changed files with 199 additions and 106 deletions
+7 -7
View File
@@ -155,10 +155,10 @@ type
TBoundRecordLiteralNode = class(TRecordLiteralNode)
private
FDefinition: TScalarRecordDefinition;
FDefinition: IScalarRecordDefinition;
public
constructor Create(const AFields: TArray<TRecordFieldLiteral>; const ADef: TScalarRecordDefinition);
property Definition: TScalarRecordDefinition read FDefinition;
constructor Create(const AFields: TArray<TRecordFieldLiteral>; const ADef: IScalarRecordDefinition);
property Definition: IScalarRecordDefinition read FDefinition;
end;
implementation
@@ -345,7 +345,7 @@ begin
end;
{ TBoundRecordLiteralNode }
constructor TBoundRecordLiteralNode.Create(const AFields: TArray<TRecordFieldLiteral>; const ADef: TScalarRecordDefinition);
constructor TBoundRecordLiteralNode.Create(const AFields: TArray<TRecordFieldLiteral>; const ADef: IScalarRecordDefinition);
begin
inherited Create(AFields);
FDefinition := ADef;
@@ -960,8 +960,8 @@ function TAstBinder.VisitRecordLiteral(const Node: IRecordLiteralNode): TDataVal
var
i: Integer;
boundFields: TArray<TRecordFieldLiteral>;
defFields: TArray<TScalarRecordDefinition.TField>;
def: TScalarRecordDefinition;
defFields: TArray<TScalarRecordField>;
def: IScalarRecordDefinition;
staticType: IStaticType;
boundNode: IRecordLiteralNode;
valNode: IAstNode;
@@ -997,7 +997,7 @@ begin
defFields[i] := TScalarRecordField.Create(Node.Fields[i].Key.Value, scalarKind);
end;
def := TScalarRecordDefinition.Create(defFields);
def := TScalarRecordRegistry.Intern(defFields);
staticType := TTypes.CreateRecord(def);
boundNode := TBoundRecordLiteralNode.Create(boundFields, def);
+2 -10
View File
@@ -91,7 +91,7 @@ end;
function NativeCreateRecordSeries(const Args: TArray<TDataValue>): TDataValue;
var
jsonDef: string;
recordDef: TScalarRecordDefinition;
recordDef: IScalarRecordDefinition;
series: IRecordSeries;
begin
if (Length(Args) <> 1) or (Args[0].Kind <> vkText) then
@@ -421,14 +421,6 @@ begin
Result := Items[Integer(index)];
end;
end;
vkRecordSeries:
begin
var series := baseValue.AsRecordSeries;
if (index < 0) or (index >= series.TotalCount) then
raise EArgumentException.CreateFmt('Index %d is out of bounds for series with %d elements.', [index, series.TotalCount]);
var recordValue := series.Items[Integer(index)];
Result := TDataValue.FromRecord(recordValue);
end;
else
raise EArgumentException.Create('Indexer `[]` is not supported for this value type.');
end;
@@ -441,7 +433,7 @@ begin
baseValue := Node.Base.Accept(Self);
case baseValue.Kind of
vkRecordSeries: Result := TDataValue.FromSeries(baseValue.AsRecordSeries.CreateMemberSeries(Node.Member.Value));
vkRecordSeries: Result := TDataValue.FromSeries(baseValue.AsRecordSeries[Node.Member.Value]);
vkRecord: Result := baseValue.AsRecord[Node.Member.Value];
else
raise EArgumentException.Create('Member access operator `.` is not supported for this value type.');
+14 -14
View File
@@ -46,7 +46,7 @@ type
function GetKind: TStaticTypeKind;
function GetElementType: IStaticType;
function GetSignature: IMethodSignature;
function GetDefinition: TScalarRecordDefinition;
function GetDefinition: IScalarRecordDefinition;
{$endregion}
// The kind of type (e.g., Ordinal, Series, etc.)
@@ -56,7 +56,7 @@ type
// The signature (if Kind = stMethod)
property Signature: IMethodSignature read GetSignature;
// The definition (if Kind = stRecord or stRecordSeries)
property Definition: TScalarRecordDefinition read GetDefinition;
property Definition: IScalarRecordDefinition read GetDefinition;
// Checks for type equality
function IsEqual(const Other: IStaticType): Boolean;
@@ -94,8 +94,8 @@ type
// Factory functions for complex types
class function CreateSeries(const AElementType: IStaticType): IStaticType; static;
class function CreateMethod(const AParamTypes: TArray<IStaticType>; const AReturnType: IStaticType): IStaticType; static;
class function CreateRecord(const ADef: TScalarRecordDefinition): IStaticType; static;
class function CreateRecordSeries(const ADef: TScalarRecordDefinition): IStaticType; static;
class function CreateRecord(const ADef: IScalarRecordDefinition): IStaticType; static;
class function CreateRecordSeries(const ADef: IScalarRecordDefinition): IStaticType; static;
class function FromScalarKind(AKind: TScalar.TKind): IStaticType; static;
end;
@@ -148,7 +148,7 @@ type
function GetKind: TStaticTypeKind; virtual; abstract;
function GetElementType: IStaticType; virtual;
function GetSignature: IMethodSignature; virtual;
function GetDefinition: TScalarRecordDefinition; virtual;
function GetDefinition: IScalarRecordDefinition; virtual;
function IsEqual(const Other: IStaticType): Boolean; virtual;
function ToString: string; override;
end;
@@ -163,10 +163,10 @@ begin
Result := nil;
end;
function TAbstractStaticType.GetDefinition: TScalarRecordDefinition;
function TAbstractStaticType.GetDefinition: IScalarRecordDefinition;
begin
// Return an empty/invalid definition
Result := Default(TScalarRecordDefinition);
Result := Default(IScalarRecordDefinition);
end;
function TAbstractStaticType.IsEqual(const Other: IStaticType): Boolean;
@@ -346,16 +346,16 @@ type
TRecordType = class(TAbstractStaticType)
private
FKind: TStaticTypeKind;
FDefinition: TScalarRecordDefinition;
FDefinition: IScalarRecordDefinition;
public
constructor Create(AKind: TStaticTypeKind; ADef: TScalarRecordDefinition);
constructor Create(AKind: TStaticTypeKind; ADef: IScalarRecordDefinition);
function GetKind: TStaticTypeKind; override;
function GetDefinition: TScalarRecordDefinition; override;
function GetDefinition: IScalarRecordDefinition; override;
function IsEqual(const Other: IStaticType): Boolean; override;
function ToString: string; override;
end;
constructor TRecordType.Create(AKind: TStaticTypeKind; ADef: TScalarRecordDefinition);
constructor TRecordType.Create(AKind: TStaticTypeKind; ADef: IScalarRecordDefinition);
begin
inherited Create;
Assert(AKind in [stRecord, stRecordSeries]);
@@ -368,7 +368,7 @@ begin
Result := FKind;
end;
function TRecordType.GetDefinition: TScalarRecordDefinition;
function TRecordType.GetDefinition: IScalarRecordDefinition;
begin
Result := FDefinition;
end;
@@ -426,12 +426,12 @@ begin
Result := TMethodType.Create(AParamTypes, AReturnType);
end;
class function TTypes.CreateRecord(const ADef: TScalarRecordDefinition): IStaticType;
class function TTypes.CreateRecord(const ADef: IScalarRecordDefinition): IStaticType;
begin
Result := TRecordType.Create(stRecord, ADef);
end;
class function TTypes.CreateRecordSeries(const ADef: TScalarRecordDefinition): IStaticType;
class function TTypes.CreateRecordSeries(const ADef: IScalarRecordDefinition): IStaticType;
begin
Result := TRecordType.Create(stRecordSeries, ADef);
end;