Optimizing captures in Scope
This commit is contained in:
@@ -133,7 +133,7 @@ begin
|
||||
sourceAddresses := Node.Upvalues;
|
||||
SetLength(capturedCells, Length(sourceAddresses));
|
||||
for i := 0 to High(sourceAddresses) do
|
||||
capturedCells[i] := FScope.GetCell(sourceAddresses[i]);
|
||||
capturedCells[i] := FScope.Capture(sourceAddresses[i]);
|
||||
|
||||
if Node.HasNestedLambdas then
|
||||
closureScope := FScope
|
||||
@@ -163,15 +163,15 @@ begin
|
||||
adr.Kind := akLocalOrParent;
|
||||
adr.ScopeDepth := 0;
|
||||
|
||||
// Set 'Self' (slot 0) to the captured closureValue for recursion.
|
||||
// Capture 'Self' (slot 0) for recursion.
|
||||
adr.SlotIndex := 0;
|
||||
lambdaScope.Cell[adr].Value := closureValue;
|
||||
lambdaScope[adr] := closureValue;
|
||||
|
||||
// Populate the actual parameters.
|
||||
for i := 0 to High(ArgValues) do
|
||||
begin
|
||||
adr.SlotIndex := params[i].Address.SlotIndex;
|
||||
lambdaScope.Cell[adr].Value := ArgValues[i];
|
||||
lambdaScope[adr] := ArgValues[i];
|
||||
end;
|
||||
|
||||
// Use the injected factory to create the visitor for the lambda's body.
|
||||
@@ -218,7 +218,7 @@ var
|
||||
itemValue, lookbackValue, seriesVar: TDataValue;
|
||||
lookback: Int64;
|
||||
begin
|
||||
seriesVar := FScope[Node.Series.Address].Value;
|
||||
seriesVar := FScope[Node.Series.Address];
|
||||
itemValue := Node.Value.Accept(Self);
|
||||
lookback := -1;
|
||||
|
||||
@@ -267,7 +267,7 @@ end;
|
||||
function TEvaluatorVisitor.VisitAssignment(const Node: IAssignmentNode): TDataValue;
|
||||
begin
|
||||
Result := Node.Value.Accept(Self);
|
||||
FScope[Node.Identifier.Address].Value := Result;
|
||||
FScope[Node.Identifier.Address] := Result;
|
||||
end;
|
||||
|
||||
function TEvaluatorVisitor.VisitConstant(const Node: IConstantNode): TDataValue;
|
||||
@@ -300,7 +300,7 @@ end;
|
||||
|
||||
function TEvaluatorVisitor.VisitIdentifier(const Node: IIdentifierNode): TDataValue;
|
||||
begin
|
||||
Result := FScope[Node.Address].Value;
|
||||
Result := FScope[Node.Address];
|
||||
end;
|
||||
|
||||
function TEvaluatorVisitor.VisitIndexer(const Node: IIndexerNode): TDataValue;
|
||||
@@ -389,11 +389,9 @@ var
|
||||
value: TDataValue;
|
||||
begin
|
||||
if Assigned(Node.Initializer) then
|
||||
value := Node.Initializer.Accept(Self)
|
||||
else
|
||||
value := TDataValue.Void;
|
||||
value := Node.Initializer.Accept(Self);
|
||||
|
||||
FScope[Node.Identifier.Address].Value := value;
|
||||
FScope[Node.Identifier.Address] := value;
|
||||
|
||||
Result := value;
|
||||
end;
|
||||
@@ -539,7 +537,7 @@ var
|
||||
seriesValue: TDataValue;
|
||||
len: Int64;
|
||||
begin
|
||||
seriesValue := FScope[Node.Series.Address].Value;
|
||||
seriesValue := FScope[Node.Series.Address];
|
||||
|
||||
case seriesValue.Kind of
|
||||
vkSeries: len := seriesValue.AsSeries.Value.Items.Count;
|
||||
|
||||
Reference in New Issue
Block a user