Pipes refactoring, Fixes in type checker
This commit is contained in:
@@ -629,16 +629,36 @@ begin
|
||||
if Length(sig.ParamTypes) <> Length(argTypes) then
|
||||
continue;
|
||||
match := True;
|
||||
|
||||
var sigIsStatic := sig.ReturnType.Kind <> stUnknown;
|
||||
for j := 0 to High(argTypes) do
|
||||
begin
|
||||
if not TTypeRules.CanAssign(sig.ParamTypes[j], argTypes[j]) then
|
||||
begin
|
||||
match := False;
|
||||
break;
|
||||
end;
|
||||
if sig.ParamTypes[j].Kind = stUnknown then
|
||||
sigIsStatic := false;
|
||||
end;
|
||||
|
||||
if match then
|
||||
begin
|
||||
bestSig := sig;
|
||||
break;
|
||||
if not sigIsStatic then
|
||||
begin
|
||||
if bestSig <> nil then
|
||||
if Assigned(FLog) then
|
||||
FLog.AddError(
|
||||
Format('RTL contains ambiguous signatures for method call on %s', [calleeType.ToString]),
|
||||
Node
|
||||
);
|
||||
bestSig := sig;
|
||||
end
|
||||
else
|
||||
begin
|
||||
bestSig := sig;
|
||||
break;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
@@ -763,19 +783,21 @@ begin
|
||||
baseType := PrepareBaseType(newBase, isOpt);
|
||||
resType := TTypes.Unknown;
|
||||
|
||||
if (baseType.Kind = stRecord) or (baseType.Kind = stRecordSeries) then
|
||||
begin
|
||||
idx := baseType.AsRecord.Definition.IndexOf(M.Member.Value);
|
||||
if idx >= 0 then
|
||||
case baseType.Kind of
|
||||
stRecord, stRecordSeries:
|
||||
begin
|
||||
var fieldType := TTypes.FromScalarKind(baseType.AsRecord.Definition[idx]);
|
||||
if baseType.Kind = stRecordSeries then
|
||||
resType := TTypes.CreateSeries(fieldType)
|
||||
else
|
||||
resType := fieldType;
|
||||
end
|
||||
else if Assigned(FLog) then
|
||||
FLog.AddError('Member not found', Node);
|
||||
idx := baseType.AsRecord.Definition.IndexOf(M.Member.Value);
|
||||
if idx >= 0 then
|
||||
begin
|
||||
var fieldType := TTypes.FromScalarKind(baseType.AsRecord.Definition[idx]);
|
||||
if baseType.Kind = stRecordSeries then
|
||||
resType := TTypes.CreateSeries(fieldType)
|
||||
else
|
||||
resType := fieldType;
|
||||
end
|
||||
else if Assigned(FLog) then
|
||||
FLog.AddError('Member not found', Node);
|
||||
end;
|
||||
end;
|
||||
|
||||
resType := ApplyOptionality(resType, isOpt);
|
||||
@@ -1081,7 +1103,8 @@ begin
|
||||
else
|
||||
inferredType := TTypes.Ordinal;
|
||||
end;
|
||||
paramTypes.Add(inferredType);
|
||||
|
||||
paramTypes.Add(TTypes.CreateSeries(inferredType));
|
||||
end;
|
||||
|
||||
// Reconstruct the typed Input Tuple [StreamIdent, [Selectors]]
|
||||
@@ -1150,7 +1173,7 @@ begin
|
||||
end
|
||||
else
|
||||
begin
|
||||
if (lambdaRetType.Kind <> stUnknown) and (lambdaRetType.Kind <> stVoid) then
|
||||
if lambdaRetType.Kind <> stVoid then
|
||||
begin
|
||||
if Assigned(FLog) then
|
||||
FLog.AddError(
|
||||
@@ -1158,7 +1181,7 @@ begin
|
||||
lambda
|
||||
);
|
||||
end;
|
||||
pipeType := TTypes.Unknown;
|
||||
pipeType := TTypes.Void;
|
||||
end;
|
||||
|
||||
// Reconstruct the Pipe Node with typed Inputs tuple and typed Lambda
|
||||
|
||||
@@ -411,7 +411,7 @@ begin
|
||||
vkRecordSeries: Result := base.AsRecordSeries.Fields[N.Member.Value];
|
||||
vkScalarRecord: Result := base.AsScalarRecord.Fields[N.Member.Value];
|
||||
vkRecord: Result := base.AsRecord.Fields[N.Member.Value];
|
||||
vkStream: Result := base.AsStream.Series.Fields[N.Member.Value];
|
||||
// vkStream: Result := base.AsStream.Def.Fields[N.Member.Value];
|
||||
else
|
||||
raise EEvaluatorException.Create('Member error');
|
||||
end;
|
||||
@@ -549,7 +549,6 @@ var
|
||||
sources: TArray<IStream>;
|
||||
config: TPipeConfig;
|
||||
inputVal: TDataValue;
|
||||
sourceSeries: IScalarRecordSeries;
|
||||
lambdaFunc: TDataValue.TFunc;
|
||||
|
||||
inputsElements: TArray<IAstNode>;
|
||||
@@ -581,8 +580,7 @@ begin
|
||||
raise EEvaluatorException.Create(Format('Variable "%s" is not a Stream.', [sourceId.Name]));
|
||||
|
||||
sources[i] := inputVal.AsStream;
|
||||
sourceSeries := sources[i].Series;
|
||||
var srcDef := sourceSeries.Def;
|
||||
var srcDef := sources[i].Def;
|
||||
|
||||
// Build Selectors Config
|
||||
SetLength(config[i], Length(selectorsElements));
|
||||
@@ -601,11 +599,18 @@ begin
|
||||
// Compile the transformation function
|
||||
lambdaFunc := Visit(N.Transformation).AsMethod();
|
||||
|
||||
// Allow both stRecord and stRecordSeries (as TypeChecker correctly assigns stRecordSeries for Pipe nodes)
|
||||
if (N.StaticType.Kind <> stRecordSeries) and (N.StaticType.Kind <> stRecord) then
|
||||
raise EEvaluatorException.Create('Pipe requires Type Checking to determine output structure (RecordDefinition).');
|
||||
var outputDef: IScalarRecordDefinition;
|
||||
|
||||
var outputDef := N.StaticType.AsRecord.Definition;
|
||||
case N.StaticType.Kind of
|
||||
stVoid:
|
||||
// This is an endpoint. The lambda returns nothing. So we produce "nothing".
|
||||
outputDef := TScalarRecord.TRegistry.Empty;
|
||||
stRecord, stRecordSeries:
|
||||
// Allow both stRecord and stRecordSeries (as TypeChecker correctly assigns stRecordSeries for Pipe nodes)
|
||||
outputDef := N.StaticType.AsRecord.Definition;
|
||||
else
|
||||
raise EEvaluatorException.Create('Pipe requires Type Checking to determine output structure (RecordDefinition).');
|
||||
end;
|
||||
|
||||
var pipeAdapter: TPipeStream.TPipeLambda :=
|
||||
function(const S: array of ISeries; out R: array of TScalar.TValue): Boolean
|
||||
@@ -630,7 +635,8 @@ begin
|
||||
Result := True;
|
||||
end;
|
||||
|
||||
Result := TPipeStream.Create(config, outputDef, sources, pipeAdapter);
|
||||
//TODO Lookback not evaluated in script!
|
||||
Result := TPipeStream.Create(config, outputDef, sources, pipeAdapter, 1000);
|
||||
end;
|
||||
|
||||
end.
|
||||
|
||||
Reference in New Issue
Block a user