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
+26 -7
View File
@@ -5,7 +5,8 @@ interface
uses
System.SysUtils,
System.Generics.Collections,
Myc.Data.Scalar;
Myc.Data.Scalar,
Myc.Data.Keyword;
type
IStaticType = interface;
@@ -17,6 +18,7 @@ type
stOrdinal, // Int64
stFloat, // Double
stText,
stKeyword,
stMethod,
stSeries,
stRecord,
@@ -77,6 +79,8 @@ type
FFloat: IStaticType;
class var
FText: IStaticType;
class var
FKeyword: IStaticType;
class constructor Create;
public
// Flyweight accessors for simple types
@@ -85,6 +89,7 @@ type
class property Ordinal: IStaticType read FOrdinal;
class property Float: IStaticType read FFloat;
class property Text: IStaticType read FText;
class property Keyword: IStaticType read FKeyword;
// Factory functions for complex types
class function CreateSeries(const AElementType: IStaticType): IStaticType; static;
@@ -124,6 +129,7 @@ begin
stOrdinal: Result := 'Ordinal';
stFloat: Result := 'Float';
stText: Result := 'Text';
stKeyword: Result := 'Keyword';
stMethod: Result := 'Method';
stSeries: Result := 'Series';
stRecord: Result := 'Record';
@@ -411,6 +417,7 @@ begin
FOrdinal := TSimpleStaticType.Create(stOrdinal);
FFloat := TSimpleStaticType.Create(stFloat);
FText := TSimpleStaticType.Create(stText);
FKeyword := TSimpleStaticType.Create(stKeyword);
end;
class function TTypes.CreateMethod(const AParamTypes: TArray<IStaticType>; const AReturnType: IStaticType): IStaticType;
@@ -541,12 +548,24 @@ begin
Result := TTypes.Float;
end;
TScalar.TBinaryOp.Equal,
TScalar.TBinaryOp.NotEqual,
TScalar.TBinaryOp.Less,
TScalar.TBinaryOp.Greater,
TScalar.TBinaryOp.LessOrEqual,
TScalar.TBinaryOp.GreaterOrEqual:
TScalar.TBinaryOp.Equal, TScalar.TBinaryOp.NotEqual:
begin
// Allow equality checks for Keywords
if (promotedKind = stKeyword) then
begin
Result := TTypes.Ordinal;
exit;
end;
// Comparison requires Ordinal or Float, but *always* results in Ordinal (boolean)
if not (promotedKind in [stOrdinal, stFloat]) then
raise ETypeException.CreateFmt(
'Comparison operator %s requires Ordinal, Float, or Keyword, but got %s after promotion',
[Op.ToString, promotedType.ToString]);
Result := TTypes.Ordinal;
end;
TScalar.TBinaryOp.Less, TScalar.TBinaryOp.Greater, TScalar.TBinaryOp.LessOrEqual, TScalar.TBinaryOp.GreaterOrEqual:
begin
// Comparison requires Ordinal or Float, but *always* results in Ordinal (boolean)
if not (promotedKind in [stOrdinal, stFloat]) then