From 30df9409f14fccd818371a623103d2a1260a87a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carl-Henrik=20Sk=C3=A5rstedt?= Date: Fri, 2 Oct 2015 21:52:55 -0700 Subject: [PATCH] Fixed error obscured by cleanup code --- README.md | 1 + asm6502.cpp | 36 +++++++++++++++++++----------------- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 883f5c1..6e1dfef 100644 --- a/README.md +++ b/README.md @@ -374,6 +374,7 @@ Currently the assembler is in the first public revision and while features are t * TEXT directive converts ascii to petscii (respect uppercase or lowercase petscii) (simplistic) Revisions: +* 2015-10-02 Cleanup hid an error (#else without #if), exit with nonzero if error was encountered * 2015-10-02 General cleanup, wrapping conditional assembly in functions * 2015-10-01 Added Label Pools and conditional assembly * 2015-09-29 Moved Asm6502 out of Struse Samples. diff --git a/asm6502.cpp b/asm6502.cpp index ed3c2e2..0301b86 100644 --- a/asm6502.cpp +++ b/asm6502.cpp @@ -520,6 +520,7 @@ public: bool conditional_consumed[MAX_CONDITIONAL_DEPTH]; bool set_load_address; bool symbol_export, last_label_local; + bool errorEncountered; // Convert source to binary void Assemble(strref source, strref filename); @@ -579,7 +580,7 @@ public: bool ConditionalConsumed(); // Has a block of this conditional already been assembled? void SetConditional(); // This conditional block is not going to be assembled so mark that it is nesting bool ConditionalAvail(); // Returns true if this conditional can be consumed - StatusCode ConditionalElse(); // Conditional else that does not enable block + void ConditionalElse(); // Conditional else that does not enable block void EnableConditional(bool enable); // This conditional block is enabled and the prior wasn't // Conditional statement evaluation (A==B? A?) @@ -620,6 +621,7 @@ void Asm::Cleanup() { output_capacity = false; symbol_export = false; last_label_local = false; + errorEncountered = false; } // Make sure there is room to assemble in @@ -1366,12 +1368,9 @@ void Asm::EnableConditional(bool enable) { } // Conditional else that does not enable block -StatusCode Asm::ConditionalElse() { - if (conditional_consumed[conditional_depth]) { +void Asm::ConditionalElse() { + if (conditional_consumed[conditional_depth]) conditional_nesting[conditional_depth]++; - return STATUS_OK; - } - return ERROR_ELSE_WITHOUT_IF; } // Conditional statement evaluation (true/false) @@ -1790,15 +1789,20 @@ StatusCode Asm::ApplyDirective(AssemblerDirective dir, strref line, strref sourc case AD_ELSE: if (ConditionalAsm()) { if (ConditionalConsumed()) - error = ConditionalElse(); + ConditionalElse(); + else + error = ERROR_ELSE_WITHOUT_IF; } else if (ConditionalAvail()) EnableConditional(true); break; case AD_ELIF: if (ConditionalAsm()) { if (ConditionalConsumed()) - error = ConditionalElse(); - } else if (ConditionalAvail()) { + ConditionalElse(); + else + error = ERROR_ELSE_WITHOUT_IF; + } + else if (ConditionalAvail()) { bool conditional_result; error = EvalStatement(line, conditional_result); EnableConditional(conditional_result); @@ -2196,6 +2200,7 @@ StatusCode Asm::BuildSegment(OP_ID *pInstr, int numInstructions) errorText.append("\"\n"); errorText.c_str(); fwrite(errorText.get(), errorText.get_len(), 1, stderr); + errorEncountered = true; } if (error > ERROR_STOP_PROCESSING_ON_HIGHER) break; @@ -2249,17 +2254,13 @@ void Asm::Assemble(strref source, strref filename) fwrite(errorText.get(), errorText.get_len(), 1, stderr); } } - -// for (unsigned int i = 0; i