Fixed closure upvalue scoping

This commit is contained in:
Michael Schimmel
2025-09-30 17:41:21 +02:00
parent 1c1bd4cdca
commit 1fd7fb9da9
2 changed files with 3 additions and 6 deletions
-5
View File
@@ -13,11 +13,6 @@ uses
Myc.Ast.Analyzer,
Myc.Ast;
//TODO Es gibt hier einen fundamentalen Fehler. Der Binder ist ist in einem Durchlauf nicht in der Lage, Upvalues zu erkennen.
// Wenn in TransformVariableDeclaration eine Variable definiert wird, ist sie grundsätzlich lokal, obwohl sie in einer nested lambda als upvalue benutzt werden könnte.
// Deshalb muss eigentlich zunächst ermittelt werden, wleche variablen später zur upvalue werden.
// Dafür ist Myc.Ast.Analyzer möglicherweise nützlich.
type
// The binder is a transformer that enriches the AST with semantic information
// like resolved addresses, scopes, and tail-call annotations.
+3 -1
View File
@@ -35,6 +35,8 @@ type
procedure Clear;
function Capture(const Address: TResolvedAddress): IValueCell;
function GetNameID(const Name: String): Integer;
function CreateDescriptor: IScopeDescriptor;
property Values[const Address: TResolvedAddress]: TDataValue read GetValues write SetValues; default;
@@ -101,7 +103,6 @@ type
procedure DumpScope(const ABuilder: TStringBuilder; AIndent: Integer);
procedure NeedNameToIndex;
function GetNameID(const Name: String): Integer;
function GetParent: IExecutionScope;
function GetNameToIndex: TDictionary<Integer, Integer>;
function GetValues(const Address: TResolvedAddress): TDataValue;
@@ -110,6 +111,7 @@ type
constructor Create(AParent: IExecutionScope; const ADescriptor: IScopeDescriptor; const ACapturedUpvalues: TArray<IValueCell>);
destructor Destroy; override;
procedure Clear;
function GetNameID(const Name: String): Integer;
function Dump: string;
procedure Define(const Name: string; const Value: TDataValue);
procedure DefineBoxed(const Address: TResolvedAddress; const Value: TDataValue);