Momory hole fixed

This commit is contained in:
Michael Schimmel
2025-09-18 20:37:15 +02:00
parent d12c6c966c
commit 565742275c
2 changed files with 6 additions and 5 deletions
+6 -4
View File
@@ -126,7 +126,8 @@ var
i: Integer; i: Integer;
sourceAddresses: TArray<TResolvedAddress>; sourceAddresses: TArray<TResolvedAddress>;
closureScope: IExecutionScope; closureScope: IExecutionScope;
closureValue: TDataValue; [weak]
closure: TDataValue.TFunc;
visitorFactory: TVisitorFactory; visitorFactory: TVisitorFactory;
begin begin
sourceAddresses := Node.Upvalues; sourceAddresses := Node.Upvalues;
@@ -145,7 +146,8 @@ begin
var scopeDescriptor := Node.ScopeDescriptor; var scopeDescriptor := Node.ScopeDescriptor;
var params := Node.Parameters; var params := Node.Parameters;
closureValue := // weak reference to break cyclic referencing
closure :=
TDataValue.TFunc( TDataValue.TFunc(
function(const ArgValues: TArray<TDataValue>): TDataValue function(const ArgValues: TArray<TDataValue>): TDataValue
var var
@@ -164,7 +166,7 @@ begin
// Capture 'Self' (slot 0) for recursion using the captured variable. // Capture 'Self' (slot 0) for recursion using the captured variable.
adr.SlotIndex := 0; adr.SlotIndex := 0;
lambdaScope[adr] := closureValue; lambdaScope[adr] := TDataValue(closure);
// Populate the actual parameters. // Populate the actual parameters.
for i := 0 to High(ArgValues) do for i := 0 to High(ArgValues) do
@@ -180,7 +182,7 @@ begin
end end
); );
Result := closureValue; Result := TDataValue(closure);
end; end;
function TEvaluatorVisitor.VisitFunctionCall(const Node: IFunctionCallNode): TDataValue; function TEvaluatorVisitor.VisitFunctionCall(const Node: IFunctionCallNode): TDataValue;
-1
View File
@@ -140,7 +140,6 @@ begin
case Address.Kind of case Address.Kind of
akUpvalue: akUpvalue:
begin begin
// TODO Dieser Pfad wird nie erreicht!
Assert(Assigned(FCapturedUpvalues), 'Attempt to access an upvalue in a scope with no closure context.'); Assert(Assigned(FCapturedUpvalues), 'Attempt to access an upvalue in a scope with no closure context.');
Assert( Assert(
(Address.SlotIndex >= 0) and (Address.SlotIndex < Length(FCapturedUpvalues)), (Address.SlotIndex >= 0) and (Address.SlotIndex < Length(FCapturedUpvalues)),