Refactoring for immutable nodes

This commit is contained in:
Michael Schimmel
2025-11-05 13:21:17 +01:00
parent 9bd2d6f7ab
commit c0a689d2bc
13 changed files with 217 additions and 190 deletions
+17 -5
View File
@@ -112,6 +112,7 @@ type
TScopeItem = record
Value: TDataValue;
IsBoxed: Boolean;
function GetContent: TDataValue;
end;
private
@@ -606,7 +607,6 @@ end;
procedure TScopeDescriptor.PopulateFromScope(Scope: TExecutionScope);
var
val: TDataValue;
i: Integer;
begin
// Recreate descriptor by iterating all defined symbols in the runtime scope.
@@ -627,11 +627,16 @@ begin
// FSlotTypes[slotIndex] remains TTypes.Unknown.
// Check if the symbol is also a macro and add it to the macro table.
val := Scope.ValuesArray[slotIndex].Value;
if (val.Kind = vkInterface) and (val.AsIntf<IAstNode> is TMacroDefinitionNode) then
var val := Scope.ValuesArray[slotIndex].GetContent;
if val.Kind = vkInterface then
begin
if not FMacros.ContainsKey(name) then
FMacros.Add(name, val.AsIntf<IMacroDefinitionNode>);
var node := val.AsIntf<IAstNode>;
if (node <> nil) and (node.Kind = akMacroDefinition) then
begin
if not FMacros.ContainsKey(name) then
FMacros.Add(name, node.AsMacroDefinition);
end;
end;
end;
end;
@@ -652,4 +657,11 @@ begin
Result := TExecutionScope.Create(Parent, Descriptor, CapturedUpvalues);
end;
function TExecutionScope.TScopeItem.GetContent: TDataValue;
begin
Result := Value;
if IsBoxed then
Result := Result.AsIntf<IValueCell>.Value;
end;
end.