Refactoring Keyword mapping, introducing tuples
This commit is contained in:
@@ -344,7 +344,7 @@ begin
|
|||||||
var i64 := idx.AsScalar.Value.AsInt64;
|
var i64 := idx.AsScalar.Value.AsInt64;
|
||||||
for var k := 0 to rs.Def.Count - 1 do
|
for var k := 0 to rs.Def.Count - 1 do
|
||||||
vals[k] := rs.Fields[rs.Def.Keywords[k]].Items[Integer(i64)].Value;
|
vals[k] := rs.Fields[rs.Def.Keywords[k]].Items[Integer(i64)].Value;
|
||||||
Result := TDataValue.FromScalarRecord(TScalarRecord.Create(rs.Def, vals));
|
Result := TScalarRecord.Create(rs.Def, vals);
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
raise EEvaluatorException.Create('Indexer error');
|
raise EEvaluatorException.Create('Indexer error');
|
||||||
@@ -358,10 +358,10 @@ begin
|
|||||||
if base.IsVoid then
|
if base.IsVoid then
|
||||||
exit(TDataValue.Void);
|
exit(TDataValue.Void);
|
||||||
case base.Kind of
|
case base.Kind of
|
||||||
vkRecordSeries: Result := TDataValue.FromSeries(base.AsRecordSeries.Fields[N.Member.Value]);
|
vkRecordSeries: Result := base.AsRecordSeries.Fields[N.Member.Value];
|
||||||
vkScalarRecord: Result := TDataValue(base.AsScalarRecord.Fields[N.Member.Value]);
|
vkScalarRecord: Result := base.AsScalarRecord.Fields[N.Member.Value];
|
||||||
vkRecord: Result := TDataValue(base.AsRecord.Fields[N.Member.Value]);
|
vkRecord: Result := base.AsRecord.Fields[N.Member.Value];
|
||||||
vkStream: Result := TDataValue.FromSeries(base.AsStream.Series.Fields[N.Member.Value]);
|
vkStream: Result := base.AsStream.Series.Fields[N.Member.Value];
|
||||||
else
|
else
|
||||||
raise EEvaluatorException.Create('Member error');
|
raise EEvaluatorException.Create('Member error');
|
||||||
end;
|
end;
|
||||||
@@ -377,7 +377,7 @@ begin
|
|||||||
SetLength(vals, N.Fields.Count);
|
SetLength(vals, N.Fields.Count);
|
||||||
for i := 0 to N.Fields.Count - 1 do
|
for i := 0 to N.Fields.Count - 1 do
|
||||||
vals[i] := Visit(N.Fields[i].Value).AsScalar.Value;
|
vals[i] := Visit(N.Fields[i].Value).AsScalar.Value;
|
||||||
Result := TDataValue.FromScalarRecord(TScalarRecord.Create(N.ScalarDefinition, vals));
|
Result := TScalarRecord.Create(N.ScalarDefinition, vals);
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
begin
|
begin
|
||||||
@@ -385,16 +385,16 @@ begin
|
|||||||
SetLength(fields, N.Fields.Count);
|
SetLength(fields, N.Fields.Count);
|
||||||
for i := 0 to N.Fields.Count - 1 do
|
for i := 0 to N.Fields.Count - 1 do
|
||||||
fields[i] := TPair<IKeyword, TDataValue>.Create(N.Fields[i].Key.Value, Visit(N.Fields[i].Value));
|
fields[i] := TPair<IKeyword, TDataValue>.Create(N.Fields[i].Key.Value, Visit(N.Fields[i].Value));
|
||||||
Result := TDataValue.FromGenericRecord(TGenericRecord<TDataValue>.Create(fields));
|
Result := TGenericRecord<TDataValue>.Create(fields);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TEvaluatorVisitor.VisitCreateSeries(const N: ICreateSeriesNode): TDataValue;
|
function TEvaluatorVisitor.VisitCreateSeries(const N: ICreateSeriesNode): TDataValue;
|
||||||
begin
|
begin
|
||||||
if N.Definition.Trim.StartsWith('[') then
|
if N.Definition.Trim.StartsWith('[') then
|
||||||
Result := TDataValue.FromRecordSeries(TScalarRecordSeries.Create(TRttiAstHelper.JsonToRecordDefinition(N.Definition)))
|
Result := TScalarRecordSeries.Create(TRttiAstHelper.JsonToRecordDefinition(N.Definition))
|
||||||
else
|
else
|
||||||
Result := TDataValue.FromSeries(TScalarSeries.Create(TScalar.StringToKind(N.Definition)));
|
Result := TScalarSeries.Create(TScalar.StringToKind(N.Definition));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TEvaluatorVisitor.VisitAddSeriesItem(const N: IAddSeriesItemNode): TDataValue;
|
function TEvaluatorVisitor.VisitAddSeriesItem(const N: IAddSeriesItemNode): TDataValue;
|
||||||
@@ -465,7 +465,7 @@ begin
|
|||||||
R[k] := rec.Items[k].Value;
|
R[k] := rec.Items[k].Value;
|
||||||
Result := True;
|
Result := True;
|
||||||
end;
|
end;
|
||||||
Result := TDataValue.FromStream(TPipeStream.Create(config, outputDef, sources, pipeAdapter));
|
Result := TPipeStream.Create(config, outputDef, sources, pipeAdapter);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
|||||||
@@ -540,7 +540,7 @@ begin
|
|||||||
if Args[1].Kind <> vkMethod then
|
if Args[1].Kind <> vkMethod then
|
||||||
raise EArgumentException.Create('The second argument to Map must be a function.');
|
raise EArgumentException.Create('The second argument to Map must be a function.');
|
||||||
|
|
||||||
Result := TDataValue.FromSeries(TDataValue.Map(sourceArg.AsSeries, Args[1].AsMethod()));
|
Result := TDataValue.Map(sourceArg.AsSeries, Args[1].AsMethod());
|
||||||
end;
|
end;
|
||||||
|
|
||||||
class function TRtlFunctions.Reduce(const Args: TArray<TDataValue>): TDataValue;
|
class function TRtlFunctions.Reduce(const Args: TArray<TDataValue>): TDataValue;
|
||||||
@@ -629,8 +629,7 @@ begin
|
|||||||
Result := TDataValue(sourceSeries.Items[idx]);
|
Result := TDataValue(sourceSeries.Items[idx]);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
finalSeries := TDataValue.Map(indexSeries, mapperFunc);
|
Result := TDataValue.Map(indexSeries, mapperFunc);
|
||||||
Result := TDataValue.FromSeries(finalSeries);
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
class function TRtlFunctions.Any(const Args: TArray<TDataValue>): TDataValue;
|
class function TRtlFunctions.Any(const Args: TArray<TDataValue>): TDataValue;
|
||||||
|
|||||||
@@ -482,7 +482,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
Result := TDataValue.FromGenericRecord(TGenericRecord<TDataValue>.Create(recFields.ToArray));
|
Result := TGenericRecord<TDataValue>.Create(recFields.ToArray);
|
||||||
finally
|
finally
|
||||||
recFields.Free;
|
recFields.Free;
|
||||||
end;
|
end;
|
||||||
|
|||||||
+38
-37
@@ -10,6 +10,7 @@ uses
|
|||||||
Myc.Data.Scalar,
|
Myc.Data.Scalar,
|
||||||
Myc.Data.Series,
|
Myc.Data.Series,
|
||||||
Myc.Data.Stream,
|
Myc.Data.Stream,
|
||||||
|
Myc.Data.Tuple,
|
||||||
Myc.Data.Keyword;
|
Myc.Data.Keyword;
|
||||||
|
|
||||||
type
|
type
|
||||||
@@ -38,7 +39,6 @@ type
|
|||||||
|
|
||||||
TDataValue = record
|
TDataValue = record
|
||||||
type
|
type
|
||||||
TTuple = TArray<TDataValue>;
|
|
||||||
TFunc = reference to function(const ArgNodes: TArray<TDataValue>): TDataValue;
|
TFunc = reference to function(const ArgNodes: TArray<TDataValue>): TDataValue;
|
||||||
|
|
||||||
private
|
private
|
||||||
@@ -76,6 +76,13 @@ type
|
|||||||
class operator Implicit(const AValue: String): TDataValue; overload; inline;
|
class operator Implicit(const AValue: String): TDataValue; overload; inline;
|
||||||
class operator Implicit(const AValue: TDataValue.TFunc): TDataValue; overload; inline;
|
class operator Implicit(const AValue: TDataValue.TFunc): TDataValue; overload; inline;
|
||||||
|
|
||||||
|
class operator Implicit(const AValue: IKeywordMapping<TScalar>): TDataValue; overload; inline;
|
||||||
|
class operator Implicit(const AValue: IKeywordMapping<TDataValue>): TDataValue; overload; inline;
|
||||||
|
|
||||||
|
class operator Implicit(const AValue: IWriteableScalarRecordSeries): TDataValue; overload; inline;
|
||||||
|
class operator Implicit(const AValue: ISeries): TDataValue; overload; inline;
|
||||||
|
class operator Implicit(const AValue: IStream): TDataValue; overload; inline;
|
||||||
|
|
||||||
// --- Existing Factories ---
|
// --- Existing Factories ---
|
||||||
class function FromIntf<T: IInterface>(const AValue: T): TDataValue; static;
|
class function FromIntf<T: IInterface>(const AValue: T): TDataValue; static;
|
||||||
function AsIntf<T: IInterface>: T; inline;
|
function AsIntf<T: IInterface>: T; inline;
|
||||||
@@ -91,12 +98,6 @@ type
|
|||||||
|
|
||||||
class function Map(const SourceSeries: ISeries; const MapperFunc: TFunc): ISeries; static;
|
class function Map(const SourceSeries: ISeries; const MapperFunc: TFunc): ISeries; static;
|
||||||
|
|
||||||
class function FromRecordSeries(const AValue: IWriteableScalarRecordSeries): TDataValue; static; inline;
|
|
||||||
class function FromScalarRecord(const AValue: IKeywordMapping<TScalar>): TDataValue; static; inline;
|
|
||||||
class function FromGenericRecord(const AValue: IKeywordMapping<TDataValue>): TDataValue; static; inline;
|
|
||||||
class function FromSeries(const AValue: ISeries): TDataValue; static; inline;
|
|
||||||
class function FromStream(const AStream: IStream): TDataValue; static; inline;
|
|
||||||
|
|
||||||
// --- Existing Accessors ---
|
// --- Existing Accessors ---
|
||||||
function AsScalar: TScalar; inline;
|
function AsScalar: TScalar; inline;
|
||||||
function AsMethod: TFunc; inline;
|
function AsMethod: TFunc; inline;
|
||||||
@@ -264,36 +265,6 @@ begin
|
|||||||
FInterface := TObjVal.Create(AValue);
|
FInterface := TObjVal.Create(AValue);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
class function TDataValue.FromSeries(const AValue: ISeries): TDataValue;
|
|
||||||
begin
|
|
||||||
Result.FKind := vkSeries;
|
|
||||||
Result.FInterface := AValue;
|
|
||||||
end;
|
|
||||||
|
|
||||||
class function TDataValue.FromRecordSeries(const AValue: IWriteableScalarRecordSeries): TDataValue;
|
|
||||||
begin
|
|
||||||
Result.FKind := vkRecordSeries;
|
|
||||||
Result.FInterface := AValue;
|
|
||||||
end;
|
|
||||||
|
|
||||||
class function TDataValue.FromScalarRecord(const AValue: IKeywordMapping<TScalar>): TDataValue;
|
|
||||||
begin
|
|
||||||
Result.FKind := vkScalarRecord;
|
|
||||||
Result.FInterface := AValue;
|
|
||||||
end;
|
|
||||||
|
|
||||||
class function TDataValue.FromGenericRecord(const AValue: IKeywordMapping<TDataValue>): TDataValue;
|
|
||||||
begin
|
|
||||||
Result.FKind := vkRecord;
|
|
||||||
Result.FInterface := AValue;
|
|
||||||
end;
|
|
||||||
|
|
||||||
class function TDataValue.FromStream(const AStream: IStream): TDataValue;
|
|
||||||
begin
|
|
||||||
Result.FKind := vkStream;
|
|
||||||
Result.FInterface := AStream;
|
|
||||||
end;
|
|
||||||
|
|
||||||
class function TDataValue.Map(const SourceSeries: ISeries; const MapperFunc: TFunc): ISeries;
|
class function TDataValue.Map(const SourceSeries: ISeries; const MapperFunc: TFunc): ISeries;
|
||||||
begin
|
begin
|
||||||
Result := TMapSeries.Create(SourceSeries, MapperFunc);
|
Result := TMapSeries.Create(SourceSeries, MapperFunc);
|
||||||
@@ -478,6 +449,36 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
class operator TDataValue.Implicit(const AValue: IKeywordMapping<TScalar>): TDataValue;
|
||||||
|
begin
|
||||||
|
Result.FKind := vkScalarRecord;
|
||||||
|
Result.FInterface := AValue;
|
||||||
|
end;
|
||||||
|
|
||||||
|
class operator TDataValue.Implicit(const AValue: IKeywordMapping<TDataValue>): TDataValue;
|
||||||
|
begin
|
||||||
|
Result.FKind := vkRecord;
|
||||||
|
Result.FInterface := AValue;
|
||||||
|
end;
|
||||||
|
|
||||||
|
class operator TDataValue.Implicit(const AValue: IWriteableScalarRecordSeries): TDataValue;
|
||||||
|
begin
|
||||||
|
Result.FKind := vkRecordSeries;
|
||||||
|
Result.FInterface := AValue;
|
||||||
|
end;
|
||||||
|
|
||||||
|
class operator TDataValue.Implicit(const AValue: ISeries): TDataValue;
|
||||||
|
begin
|
||||||
|
Result.FKind := vkSeries;
|
||||||
|
Result.FInterface := AValue;
|
||||||
|
end;
|
||||||
|
|
||||||
|
class operator TDataValue.Implicit(const AValue: IStream): TDataValue;
|
||||||
|
begin
|
||||||
|
Result.FKind := vkStream;
|
||||||
|
Result.FInterface := AValue;
|
||||||
|
end;
|
||||||
|
|
||||||
{ TMapSeries }
|
{ TMapSeries }
|
||||||
|
|
||||||
constructor TMapSeries.Create(const ASourceSeries: ISeries; const AMapperFunc: TDataValue.TFunc);
|
constructor TMapSeries.Create(const ASourceSeries: ISeries; const AMapperFunc: TDataValue.TFunc);
|
||||||
|
|||||||
@@ -192,7 +192,7 @@ begin
|
|||||||
source := CreateSourceSeries('val', TScalar.TKind.Ordinal, [10, 20, 30]);
|
source := CreateSourceSeries('val', TScalar.TKind.Ordinal, [10, 20, 30]);
|
||||||
mockStream := TTestStream.Create(source);
|
mockStream := TTestStream.Create(source);
|
||||||
|
|
||||||
FEnv.RootScope.Define('src', TDataValue.FromStream(mockStream), TTypes.CreateRecordSeries(source.Def));
|
FEnv.RootScope.Define('src', mockStream, TTypes.CreateRecordSeries(source.Def));
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
script := '(pipe [src [:val]] (fn [x] {:res (* x 2)}))';
|
script := '(pipe [src [:val]] (fn [x] {:res (* x 2)}))';
|
||||||
@@ -225,7 +225,7 @@ begin
|
|||||||
source := CreateSourceSeries('val', TScalar.TKind.Ordinal, [1]);
|
source := CreateSourceSeries('val', TScalar.TKind.Ordinal, [1]);
|
||||||
mockStream := TTestStream.Create(source);
|
mockStream := TTestStream.Create(source);
|
||||||
|
|
||||||
FEnv.RootScope.Define('src', TDataValue.FromStream(mockStream), TTypes.CreateRecordSeries(source.Def));
|
FEnv.RootScope.Define('src', mockStream, TTypes.CreateRecordSeries(source.Def));
|
||||||
|
|
||||||
script := '(pipe [src [:non_existent]] (fn [x] {:res x}))';
|
script := '(pipe [src [:non_existent]] (fn [x] {:res x}))';
|
||||||
|
|
||||||
@@ -249,8 +249,8 @@ begin
|
|||||||
m1 := TTestStream.Create(s1);
|
m1 := TTestStream.Create(s1);
|
||||||
m2 := TTestStream.Create(s2);
|
m2 := TTestStream.Create(s2);
|
||||||
|
|
||||||
FEnv.RootScope.Define('in1', TDataValue.FromStream(m1), TTypes.CreateRecordSeries(s1.Def));
|
FEnv.RootScope.Define('in1', m1, TTypes.CreateRecordSeries(s1.Def));
|
||||||
FEnv.RootScope.Define('in2', TDataValue.FromStream(m2), TTypes.CreateRecordSeries(s2.Def));
|
FEnv.RootScope.Define('in2', m2, TTypes.CreateRecordSeries(s2.Def));
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
script := '(pipe [in1 [:a] in2 [:b]] (fn [valA valB] {:sum (+ valA valB)}))';
|
script := '(pipe [in1 [:a] in2 [:b]] (fn [valA valB] {:sum (+ valA valB)}))';
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ begin
|
|||||||
// Für den Compiler ist es eine RecordSeries (Typ), zur Laufzeit ein Stream (Wert)
|
// Für den Compiler ist es eine RecordSeries (Typ), zur Laufzeit ein Stream (Wert)
|
||||||
StaticType := TTypes.CreateRecordSeries(Def);
|
StaticType := TTypes.CreateRecordSeries(Def);
|
||||||
|
|
||||||
Scope.Define(VarName, TDataValue.FromStream(Stream), StaticType);
|
Scope.Define(VarName, Stream, StaticType);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TFinanceSimulator.AddRandomCandle(const Scope: IExecutionScope; const VarName: string);
|
procedure TFinanceSimulator.AddRandomCandle(const Scope: IExecutionScope; const VarName: string);
|
||||||
|
|||||||
Reference in New Issue
Block a user