From b3ca67428d329df16dc3c82acb41de62300c28f5 Mon Sep 17 00:00:00 2001 From: Michael Schimmel Date: Tue, 13 Jan 2026 23:51:41 +0100 Subject: [PATCH] Small refactorings --- Src/AST/Myc.Ast.Compiler.TypeChecker.pas | 37 +++++++++--------------- Src/AST/Myc.Ast.Debugger.pas | 2 -- Src/AST/Myc.Ast.Dumper.pas | 1 - 3 files changed, 14 insertions(+), 26 deletions(-) diff --git a/Src/AST/Myc.Ast.Compiler.TypeChecker.pas b/Src/AST/Myc.Ast.Compiler.TypeChecker.pas index 5475eaf..c45d5e8 100644 --- a/Src/AST/Myc.Ast.Compiler.TypeChecker.pas +++ b/Src/AST/Myc.Ast.Compiler.TypeChecker.pas @@ -44,9 +44,6 @@ type private FCurrentContext: TTypeContext; FLog: ICompilerLog; - FRootScope: IExecutionScope; - - function CreateContextChain(L: IScopeLayout): TTypeContext; // Helpers for Null Propagation function PrepareBaseType(const BaseNode: IAstNode; out IsOptional: Boolean): IStaticType; @@ -174,34 +171,28 @@ begin FSlotTypes[SlotIndex] := AType; end; -{ TTypeChecker } +constructor TTypeChecker.Create(const RootLayout: IScopeLayout; const RootScope: IExecutionScope; const ALog: ICompilerLog); -function TTypeChecker.CreateContextChain(L: IScopeLayout): TTypeContext; -var - p: TTypeContext; - desc: IScopeDescriptor; -begin - if L = nil then - exit(nil); - - p := CreateContextChain(L.Parent); - - desc := nil; - if (L.Parent = nil) and Assigned(FRootScope) then + function CreateChain(L: IScopeLayout): TTypeContext; begin - desc := FRootScope.Descriptor; + if L = nil then + exit(nil); + + Result := + TTypeContext.Create( + CreateChain(L.Parent), + L, + [], + if (L.Parent = nil) and Assigned(RootScope) then RootScope.Descriptor + else nil + ); end; - Result := TTypeContext.Create(p, L, [], desc); -end; - -constructor TTypeChecker.Create(const RootLayout: IScopeLayout; const RootScope: IExecutionScope; const ALog: ICompilerLog); begin inherited Create; FLog := ALog; - FRootScope := RootScope; - FCurrentContext := CreateContextChain(RootLayout); + FCurrentContext := CreateChain(RootLayout); if FCurrentContext = nil then FCurrentContext := TTypeContext.Create(nil, nil, [], nil); end; diff --git a/Src/AST/Myc.Ast.Debugger.pas b/Src/AST/Myc.Ast.Debugger.pas index f5b4273..37d86a9 100644 --- a/Src/AST/Myc.Ast.Debugger.pas +++ b/Src/AST/Myc.Ast.Debugger.pas @@ -151,8 +151,6 @@ begin akLambdaExpression: Result := 'FN'; akRecordLiteral: Result := 'RECORD'; akPipe: Result := 'PIPE'; - - // NEW: akIndexer: Result := 'INDEXER'; akMemberAccess: Result := 'MEMBER'; akTuple: Result := 'TUPLE'; diff --git a/Src/AST/Myc.Ast.Dumper.pas b/Src/AST/Myc.Ast.Dumper.pas index 5f3e3b3..f74c195 100644 --- a/Src/AST/Myc.Ast.Dumper.pas +++ b/Src/AST/Myc.Ast.Dumper.pas @@ -488,7 +488,6 @@ end; function TAstDumper.VisitCreateSeries(const Node: IAstNode): TVoid; begin - // REFACTORED: Log the structure of the definition Log('CreateSeries', Node); Indent; Log('Definition:');