From 17cec530b0a4d792bde2d37583b6c26e89f9b1bd Mon Sep 17 00:00:00 2001 From: _ov4 Date: Tue, 13 Oct 2026 12:32:03 +0000 Subject: fix: distinguish compiler errors and report compilation termination Co-Authored-By: Claude Fable 5.1 --- AGENTS/ARCH.md | 9 +++++++-- AGENTS/CONVENTIONS.md | 7 +++++-- 2 files changed, 12 insertions(+), 4 deletions(-) (limited to 'AGENTS') diff --git a/AGENTS/ARCH.md b/AGENTS/ARCH.md index 181c207..8245027 100644 --- a/AGENTS/ARCH.md +++ b/AGENTS/ARCH.md @@ -57,12 +57,17 @@ release because MSYS2 has no Pandoc package. Only the Linux build is verified. Driver behavior (`tools/driver/main.cc`): - One source file, with optional `-o path` and `-r`; options may precede or follow the source. - No stdin source input. No arguments exits silently with status 0 (help TODO). + No stdin source input. Missing input, including no arguments, prints + `cpsc: fatal error: no input files` and `compilation terminated.`, then returns 1. - IR is written only after successful parsing, code generation and module verification. Diagnostics stay on stderr; failures do not overwrite existing IR. - Lexer, Parser and CodeGen track error flags (`hadError()`); any error, including invalid IR from `verifyModule`, makes the driver return 1. File/argument errors - also return 1. Check the exit code rather than grepping stderr. + also return 1. Ordinary compiler errors use `error:`; failures that prevent + compilation, such as file I/O errors, use `fatal error:`. The driver prints + `compilation terminated.` once on compilation failure, including argument errors. + Execution-stage failures do not print that line. Check the exit code rather + than grepping stderr. - Successful compilation overwrites the output, but paths aliasing the source (including symlinks/hard links) are rejected. - In PATH mode, `-r` executes PATH's `lli` using LLVM Support process APIs, with diff --git a/AGENTS/CONVENTIONS.md b/AGENTS/CONVENTIONS.md index a49b381..638013a 100644 --- a/AGENTS/CONVENTIONS.md +++ b/AGENTS/CONVENTIONS.md @@ -92,12 +92,15 @@ scope stack. `FunctionGen` saves/clears/restores the table around a function bod `emitExpr` walk a linear if-chain of casts. **A statement type missing from the chain is silently ignored** — no error. Adding an AST node always means touching these chains. -**Error style everywhere: print an `Error:` line, set the component's error flag, and +**Compiler error style: print an `error:` line, set the component's error flag, and keep compiling.** No exceptions, no exit mid-compile. `Lexer`/`Parser`/`CodeGen` each expose `hadError()`; `CodeGen::reportError(fmt, ...)` is the helper for codegen-side diagnostics (`ArrayHandler` reaches it through its `CodeGen &` parameter, `FunctionGen`/`ArithmeticHandler` hold a `bool &HadError` reference). The driver exits -non-zero when any flag is set. The parser drops a failed statement and resyncs at the +non-zero when any flag is set, printing `compilation terminated.` once. Errors that +prevent compilation (missing input, file I/O or invalid IR) use `fatal error:`. +Execution-stage errors do not print the compilation termination line. +The parser drops a failed statement and resyncs at the next token that can start a statement or end a block (`syncToStatementStart`), then continues; the failure is always diagnosed and reflected in the exit code. -- cgit v1.3.1-4-g156e