From e7c5e63d04f6b22f87dae9385bb06ffaa9a6a275 Mon Sep 17 00:00:00 2001 From: Miquel Sabaté Solà Date: Thu, 9 Jan 2025 22:03:46 +0100 Subject: Evaluate bare numbers as decimal values MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In places like macro calls, the programmer might actually prefer to pass a numeric argument as is, without any prefixes. In these cases, just evaluate it as a decimal. In fact, this was already covered when evaluating the context because the same thing happens to assignments. Hence, I just needed to expand the scope of this. Signed-off-by: Miquel Sabaté Solà --- lib/xixanta/src/assembler.rs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'lib/xixanta/src/assembler.rs') diff --git a/lib/xixanta/src/assembler.rs b/lib/xixanta/src/assembler.rs index c52c36c..b147768 100644 --- a/lib/xixanta/src/assembler.rs +++ b/lib/xixanta/src/assembler.rs @@ -767,17 +767,16 @@ impl<'a> Assembler<'a> { Some(LiteralMode::Binary) => Ok(self.evaluate_binary(node)?), Some(LiteralMode::Plain) => Ok(self.evaluate_decimal(node)?), None => { - if self.stage == Stage::Context { - // If we are just evaluating the context (e.g. parsing a - // variable), we'll assume that non-prefixed literals are - // just decimal values. + if node.value.value.chars().nth(0).unwrap_or(' ').is_numeric() { + // If the first digit is a number, let's actually try to + // parse it as a decimal value. Ok(self.evaluate_decimal(node)?) } else if node.value.is_anonymous_relative_reference() { Ok(self.evaluate_anonymous_relative_reference(node)?) } else if node.value.is_valid_identifier(true).is_err() { // If this is not a valid identifier, just error out. Err(Error { - message: "no prefix was given to operand".to_string(), + message: "invalid identifier".to_string(), line: node.value.line, source: self.source_for(node), global: false, @@ -2427,7 +2426,13 @@ cpx #(4 * var2)"#, false, "cannot use indirect addressing mode for the instruction 'adc'", ); - assert_error("lda 12", 1, false, "no prefix was given to operand") + assert_error("lda //", 1, false, "invalid identifier"); + assert_error( + "lda 12", + 1, + false, + "left arm of instruction is neither an address nor an immediate", + ); } #[test] -- cgit v1.2.3