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 --- lib/CodeGen/ArithmeticHandler.cc | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'lib/CodeGen/ArithmeticHandler.cc') diff --git a/lib/CodeGen/ArithmeticHandler.cc b/lib/CodeGen/ArithmeticHandler.cc index 585104d..b909abc 100644 --- a/lib/CodeGen/ArithmeticHandler.cc +++ b/lib/CodeGen/ArithmeticHandler.cc @@ -49,7 +49,8 @@ Value *ArithmeticHandler::emitBinaryOp(int Op, Value *LHS, Value *RHS, int Line) if (Op == tok_div || Op == tok_mod) { if (!LIsInt || !RIsInt) { - fprintf(stderr, "Error: DIV and MOD operators require INTEGER operands.\n"); + fprintf(stderr, "Error: DIV and MOD operators require INTEGER operands (line %d).\n", Line); + HadError = true; return nullptr; } if (Op == tok_div) return Builder.CreateSDiv(LHS, RHS, "div_int_tmp"); @@ -106,6 +107,8 @@ Value *ArithmeticHandler::emitBinaryOp(int Op, Value *LHS, Value *RHS, int Line) case tok_ge: return Builder.CreateICmpSGE(LHS, RHS, "sgetmp"); } } - + + fprintf(stderr, "Error: Unsupported operand types for binary operator (line %d).\n", Line); + HadError = true; return nullptr; } -- cgit v1.3.1-4-g156e