diff options
| author | Miquel Sabaté Solà <mikisabate@gmail.com> | 2025-01-09 22:03:46 +0100 |
|---|---|---|
| committer | Miquel Sabaté Solà <mikisabate@gmail.com> | 2025-01-09 22:03:46 +0100 |
| commit | e7c5e63d04f6b22f87dae9385bb06ffaa9a6a275 (patch) | |
| tree | 7fe5dda398225dd4048ed42d11786753440c2f8e /lib | |
| parent | 119111c42223893c6071af91da47cb12aab103c6 (diff) | |
| download | tools.nes-e7c5e63d04f6.tar.gz tools.nes-e7c5e63d04f6.zip | |
Evaluate bare numbers as decimal values
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à <mikisabate@gmail.com>
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/xixanta/src/assembler.rs | 17 |
1 files changed, 11 insertions, 6 deletions
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] |
