From 4df7c22b99349dcf2175d69679eafa175d49aa9f Mon Sep 17 00:00:00 2001 From: _ov4 Date: Sun, 26 Jul 2026 12:02:32 +0000 Subject: refactor: batch 1 - correctness and error contract - MID/RIGHT/LEFT integer args now coerced at call sites (RIGHT(s, n/2) no longer emits invalid IR); drop emitLeft's private conversion - FOR loop direction decided at run time via select on STEP sign; descending FOR works, STEP evaluated once per iteration - ArrayHandler: extract emitCheckedIndices/loadElement; index count is validated before emission, fixing a compiler-crash (vector OOB UB) on OUTPUT with too many indices - Error contract: Lexer/Parser/CodeGen track errors; all silent failure paths now print Error: diagnostics with line numbers; unterminated char literal no longer truncates the rest of the program; module is verified with verifyModule; driver exits non-zero on any error Co-Authored-By: Claude Fable 5 --- include/cps/ArrayHandler.h | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'include/cps/ArrayHandler.h') diff --git a/include/cps/ArrayHandler.h b/include/cps/ArrayHandler.h index f15004f..6f563b7 100644 --- a/include/cps/ArrayHandler.h +++ b/include/cps/ArrayHandler.h @@ -42,6 +42,13 @@ class ArrayHandler { llvm::Value *getArrayBasePointer(const std::string &Name); llvm::Value *getElementPointer(const std::string &Name, llvm::Value *Offset); const ArrayMetadata *getMetadata(const std::string &Name) const; + bool emitCheckedIndices(const std::string &Name, + const std::vector> &IndexExprs, + int Line, + bool RequireExact, + CodeGen &CG, + std::vector &Out); + llvm::Value *loadElement(const std::string &Name, llvm::Value *Offset, CodeGen &CG); void emitPrintLoop(const std::string &Name, int CurrentDim, std::vector CurrentIndices, -- cgit v1.3.1-4-g156e