Immutable infered types

This commit is contained in:
Michael Schimmel
2025-11-04 22:10:11 +01:00
parent f73c0c67b8
commit 980919525b
6 changed files with 395 additions and 271 deletions
+9 -5
View File
@@ -65,7 +65,7 @@ type
{$endregion}
function CreateScope(const AParent: IExecutionScope): IExecutionScope;
// Defines a symbol, returns its slot index.
function Define(const Name: string; const AType: IStaticType): Integer;
function Define(const Name: string; const AType: IStaticType = nil): Integer;
// Updates the type of an already defined symbol (e.g., for lambda self-reference).
procedure UpdateType(SlotIndex: Integer; const AType: IStaticType);
procedure DefineMacro(const Name: string; const Node: IMacroDefinitionNode);
@@ -161,7 +161,7 @@ type
destructor Destroy; override;
class function CreateDescriptor(const Scope: IExecutionScope): IScopeDescriptor; static;
function Define(const Name: string; const AType: IStaticType): Integer;
procedure UpdateType(SlotIndex: Integer; const AType: IStaticType);
procedure UpdateType(SlotIndex: Integer; const AType: IStaticType = nil);
procedure DefineMacro(const Name: string; const Node: IMacroDefinitionNode);
function FindSymbol(const Name: string): TResolvedSymbol;
function FindMacro(const Name: string): IMacroDefinitionNode;
@@ -525,14 +525,18 @@ begin
Result := FSymbols.Count;
FSymbols.Add(Name, Result);
SetLength(FSlotTypes, Result + 1);
FSlotTypes[Result] := AType;
FSlotTypes[Result] :=
if AType <> nil then AType
else TTypes.Unknown;
end;
procedure TScopeDescriptor.UpdateType(SlotIndex: Integer; const AType: IStaticType);
procedure TScopeDescriptor.UpdateType(SlotIndex: Integer; const AType: IStaticType = nil);
begin
if (SlotIndex < 0) or (SlotIndex >= Length(FSlotTypes)) then
raise EArgumentOutOfRangeException.Create('Invalid SlotIndex in UpdateType.');
FSlotTypes[SlotIndex] := AType;
FSlotTypes[SlotIndex] :=
If AType <> nil then AType
else TTypes.Unknown;
end;
procedure TScopeDescriptor.DefineMacro(const Name: string; const Node: IMacroDefinitionNode);