Compiler exceptions

This commit is contained in:
Michael Schimmel
2025-11-25 15:27:57 +01:00
parent d84509c034
commit 4e508d90a5
8 changed files with 62 additions and 28 deletions
+5 -3
View File
@@ -14,6 +14,9 @@ uses
Myc.Ast;
type
// Exception specific to optimization/TCO errors
EOptimizerException = class(EAstException);
IAstTCO = interface(IAstVisitor)
function Execute(const RootNode: IAstNode): IAstNode;
end;
@@ -180,7 +183,6 @@ begin
begin
// Rebuild using factory.
// IMPORTANT: Pass Layout AND Descriptor (TCO runs after TypeChecker).
// (* FIX: Pass Node.IsPure to preserve it *)
Result :=
TAst.LambdaExpr(
newParams,
@@ -200,7 +202,7 @@ var
newArgs: TArray<IAstNode>;
begin
if not FIsTailStack.Peek then
raise Exception.Create('''recur'' can only be used in a tail position.');
raise EOptimizerException.Create('''recur'' can only be used in a tail position.');
// Arguments are not in tail position
FNextIsTail := False;
@@ -254,7 +256,7 @@ begin
Node.StaticType,
isTailCall,
Node.StaticTarget, // Preserve the static target from Specializer
Node.IsTargetPure // (* FIX: Preserve the purity flag from Specializer! *)
Node.IsTargetPure // Preserve purity flag
);
end;