Refactoring Binder

This commit is contained in:
Michael Schimmel
2025-09-17 13:34:48 +02:00
parent b972b05a07
commit ea5879520a
10 changed files with 713 additions and 507 deletions
+32 -8
View File
@@ -15,12 +15,22 @@ type
TValueCell = class(TInterfacedObject, IValueCell)
private
FValue: TDataValue;
function GetValue: TDataValue; inline;
procedure SetValue(const AValue: TDataValue); inline;
function GetValue: TDataValue;
procedure SetValue(const AValue: TDataValue);
public
constructor Create(const AValue: TDataValue);
end;
TValueRef = class(TInterfacedObject, IValueCell)
private
FValues: TArray<TDataValue>;
FIdx: Integer;
function GetValue: TDataValue;
procedure SetValue(const AValue: TDataValue);
public
constructor Create(const AValues: TArray<TDataValue>; AIdx: Integer);
end;
private
FParent: IExecutionScope;
FDescriptor: IScopeDescriptor;
@@ -34,11 +44,7 @@ type
function GetValues(const Address: TResolvedAddress): TDataValue;
procedure SetValues(const Address: TResolvedAddress; const Value: TDataValue);
public
constructor Create(
AParent: IExecutionScope = nil;
const ADescriptor: IScopeDescriptor = nil;
const ACapturedUpvalues: TArray<IValueCell> = nil
);
constructor Create(AParent: IExecutionScope; const ADescriptor: IScopeDescriptor; const ACapturedUpvalues: TArray<IValueCell>);
destructor Destroy; override;
procedure Clear;
function Dump: string;
@@ -111,6 +117,7 @@ begin
case Address.Kind of
akUpvalue:
begin
// TODO Dieser Pfad wir 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)),
@@ -130,7 +137,7 @@ begin
(Address.SlotIndex >= 0) and (Address.SlotIndex < Length(targetScope.FValues)),
'Invalid scope index during value retrieval.'
);
Result := TValueCell.Create(targetScope.FValues[Address.SlotIndex]);
Result := TValueRef.Create(targetScope.FValues, Address.SlotIndex);
end;
else
raise EInvalidOpException.Create('Cannot get value for an unresolved address.');
@@ -281,4 +288,21 @@ begin
end;
end;
constructor TExecutionScope.TValueRef.Create(const AValues: TArray<TDataValue>; AIdx: Integer);
begin
inherited Create;
FValues := AValues;
FIdx := AIdx;
end;
function TExecutionScope.TValueRef.GetValue: TDataValue;
begin
Result := FValues[FIdx];
end;
procedure TExecutionScope.TValueRef.SetValue(const AValue: TDataValue);
begin
FValues[FIdx] := AValue;
end;
end.