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/FileHandler.h | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'include/cps/FileHandler.h') diff --git a/include/cps/FileHandler.h b/include/cps/FileHandler.h index 3898a57..8b8ddf4 100644 --- a/include/cps/FileHandler.h +++ b/include/cps/FileHandler.h @@ -7,6 +7,7 @@ namespace cps { class RuntimeCheck; +class ExceptionHandler; // Emits the text-file runtime: a fixed-size open-file table plus internal // __cps_file_* helper functions, synthesized once on first use so programs @@ -20,6 +21,7 @@ class FileHandler { llvm::IRBuilder<> &Builder; llvm::Module &Module; RuntimeCheck &Checker; + ExceptionHandler &Exceptions; static constexpr uint64_t TableSize = 16; bool RuntimeEmitted = false; @@ -35,9 +37,6 @@ class FileHandler { llvm::GlobalVariable *FileModes = nullptr; // [TableSize x i8] 0 = free slot, else FileMode llvm::Value *ModeReadStr = nullptr, *ModeWriteStr = nullptr, *ModeAppendStr = nullptr; - llvm::Value *ErrOpenFail = nullptr, *ErrAlreadyOpen = nullptr, *ErrTableFull = nullptr, - *ErrNotOpen = nullptr, *ErrNotRead = nullptr, *ErrNotWrite = nullptr, - *ErrPastEof = nullptr; // synthesized helpers (internal linkage; pseudocode identifiers cannot // start with '_', so these names are un-collidable) @@ -60,7 +59,7 @@ class FileHandler { public: FileHandler(llvm::LLVMContext &Ctx, llvm::IRBuilder<> &B, llvm::Module &M, - RuntimeCheck &RC); + RuntimeCheck &RC, ExceptionHandler &EH); // NameStr/DataStr are already-coerced STRING ptrs; Line is the statement's // source line for runtime diagnostics. All methods null-check and bail; -- cgit v1.3.1-4-g156e