From a484f314b719aec5ed7bdc6f08403342b2125561 Mon Sep 17 00:00:00 2001 From: _ov4 Date: Tue, 13 Oct 2026 14:52:57 +0000 Subject: feat(compiler)!: add try-catch with C++ stack unwinding Add TRY/CATCH/ENDTRY and anonymous THROW statements. Use LLVM exception handling and the C++ ABI to propagate exceptions across function calls, clean up catch state, and handle uncaught exceptions at the program boundary. Register exception runtime symbols for the statically linked embedded runner. Verify runtime checks, nested catches, returns, loops, and invalid syntax with smoke programs; exercise unwinding with MCJIT, lli, and native binaries. BREAKING CHANGE: Runtime check failures now throw anonymous exceptions and print only a generic message when uncaught. Native binaries require linking the C++ runtime. Co-Authored-By: Claude Fable 5.1 --- include/cps/CodeGen.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'include/cps/CodeGen.h') diff --git a/include/cps/CodeGen.h b/include/cps/CodeGen.h index 2c837fd..acd6cb2 100644 --- a/include/cps/CodeGen.h +++ b/include/cps/CodeGen.h @@ -19,6 +19,7 @@ namespace cps { class ArrayHandler; class FileHandler; +class ExceptionHandler; class CodeGen { std::unique_ptr TheContext; @@ -28,6 +29,7 @@ class CodeGen { std::unique_ptr Types; std::unique_ptr Arrays; + std::unique_ptr Exceptions; std::unique_ptr RuntimeChecker; std::unique_ptr FuncGen; @@ -87,6 +89,7 @@ class CodeGen { void emitOutputValue(llvm::Value *Val, const TypeInfo *TypeInfo, bool AppendNewline = true); void emitIfStmt(IfStmtAST *Stmt); + void emitTryStmt(TryStmtAST *Stmt); void emitWhileStmt(WhileStmtAST *Stmt); void emitRepeatStmt(RepeatStmtAST *Stmt); void emitForStmt(ForStmtAST *Stmt); -- cgit v1.3.1-4-g156e