diff --git a/Src/AST/Myc.Ast.Evaluator.pas b/Src/AST/Myc.Ast.Evaluator.pas index 3918af0..e55d3cd 100644 --- a/Src/AST/Myc.Ast.Evaluator.pas +++ b/Src/AST/Myc.Ast.Evaluator.pas @@ -126,7 +126,8 @@ var i: Integer; sourceAddresses: TArray; closureScope: IExecutionScope; - closureValue: TDataValue; + [weak] + closure: TDataValue.TFunc; visitorFactory: TVisitorFactory; begin sourceAddresses := Node.Upvalues; @@ -145,7 +146,8 @@ begin var scopeDescriptor := Node.ScopeDescriptor; var params := Node.Parameters; - closureValue := + // weak reference to break cyclic referencing + closure := TDataValue.TFunc( function(const ArgValues: TArray): TDataValue var @@ -164,7 +166,7 @@ begin // Capture 'Self' (slot 0) for recursion using the captured variable. adr.SlotIndex := 0; - lambdaScope[adr] := closureValue; + lambdaScope[adr] := TDataValue(closure); // Populate the actual parameters. for i := 0 to High(ArgValues) do @@ -180,7 +182,7 @@ begin end ); - Result := closureValue; + Result := TDataValue(closure); end; function TEvaluatorVisitor.VisitFunctionCall(const Node: IFunctionCallNode): TDataValue; diff --git a/Src/AST/Myc.Ast.Scope.pas b/Src/AST/Myc.Ast.Scope.pas index 6f88862..d6020ff 100644 --- a/Src/AST/Myc.Ast.Scope.pas +++ b/Src/AST/Myc.Ast.Scope.pas @@ -140,7 +140,6 @@ begin case Address.Kind of akUpvalue: begin - // TODO Dieser Pfad wird nie erreicht! Assert(Assigned(FCapturedUpvalues), 'Attempt to access an upvalue in a scope with no closure context.'); Assert( (Address.SlotIndex >= 0) and (Address.SlotIndex < Length(FCapturedUpvalues)),