diff options
| author | Miquel Sabaté Solà <mssola@mssola.com> | 2026-04-24 16:26:08 +0200 |
|---|---|---|
| committer | Miquel Sabaté Solà <mssola@mssola.com> | 2026-04-24 16:26:08 +0200 |
| commit | c8138a0fc5353dc9017fc32fb5ef12a6fe780415 (patch) | |
| tree | f8c88e98bfad1afa0456cc81ea23af678d9876a5 /lib | |
| parent | cf767fc97329b83aa4091e745c204552514f3983 (diff) | |
| download | tools.nes-c8138a0fc5353dc9017fc32fb5ef12a6fe780415.tar.gz tools.nes-c8138a0fc5353dc9017fc32fb5ef12a6fe780415.zip | |
Add the .version pseudo-variable
Signed-off-by: Miquel Sabaté Solà <mssola@mssola.com>
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/xixanta/src/assembler.rs | 33 | ||||
| -rw-r--r-- | lib/xixanta/src/node.rs | 2 | ||||
| -rw-r--r-- | lib/xixanta/src/opcodes.rs | 10 |
3 files changed, 45 insertions, 0 deletions
diff --git a/lib/xixanta/src/assembler.rs b/lib/xixanta/src/assembler.rs index cf11de1..646b072 100644 --- a/lib/xixanta/src/assembler.rs +++ b/lib/xixanta/src/assembler.rs @@ -2385,6 +2385,7 @@ impl<'a> Assembler<'a> { NodeType::Control(ControlType::Hibyte) => self.evaluate_byte(node, true), NodeType::Control(ControlType::Lobyte) => self.evaluate_byte(node, false), NodeType::Control(ControlType::Defined) => self.evaluate_defined(node), + NodeType::Control(ControlType::Version) => self.evaluate_version(node), _ => Err(Error { line: node.value.line, message: format!( @@ -2421,6 +2422,38 @@ impl<'a> Assembler<'a> { Ok(bundle) } + // Returns a bundle which is just the version from this library. + fn evaluate_version(&mut self, node: &PNode) -> Result<Bundle, Error> { + let Ok(major) = env!("CARGO_PKG_VERSION_MAJOR").parse::<u8>() else { + return Err(Error { + line: node.value.line, + message: "bad version number".to_string(), + source: self.source_for(node), + expanded_from: self.macro_context.clone(), + global: false, + }); + }; + let Ok(minor) = env!("CARGO_PKG_VERSION_MINOR").parse::<u8>() else { + return Err(Error { + line: node.value.line, + message: "bad version number".to_string(), + source: self.source_for(node), + expanded_from: self.macro_context.clone(), + global: false, + }); + }; + + Ok(Bundle { + bytes: [minor, major, 0x00], + size: 2, + address: 0, + cycles: 0, + affected_on_page: false, + resolved: true, + negative: false, + }) + } + // Returns a bundle containing a boolean value on whether the symbol // referenced in the given `node` is actually defined on this context or // not. diff --git a/lib/xixanta/src/node.rs b/lib/xixanta/src/node.rs index 3803840..af76edd 100644 --- a/lib/xixanta/src/node.rs +++ b/lib/xixanta/src/node.rs @@ -170,6 +170,7 @@ pub enum ControlType { EndIf, Defined, Echo(EchoKind), + Version, } impl fmt::Display for ControlType { @@ -200,6 +201,7 @@ impl fmt::Display for ControlType { ControlType::Else => write!(f, ".else"), ControlType::EndIf => write!(f, ".endif"), ControlType::Defined => write!(f, ".defined"), + ControlType::Version => write!(f, ".version"), ControlType::Echo(t) => match t { EchoKind::Info => write!(f, ".info"), EchoKind::Warning => write!(f, ".warning"), diff --git a/lib/xixanta/src/opcodes.rs b/lib/xixanta/src/opcodes.rs index 48e4fca..150813e 100644 --- a/lib/xixanta/src/opcodes.rs +++ b/lib/xixanta/src/opcodes.rs @@ -1670,6 +1670,16 @@ pub static CONTROL_FUNCTIONS: LazyLock<HashMap<String, Control>> = LazyLock::new let mut functions = HashMap::new(); functions.insert( + String::from(".version"), + Control { + control_type: ControlType::Version, + has_identifier: None, + required_args: Some((0, 0)), + touches_context: false, + only_string: false, + }, + ); + functions.insert( String::from(".hibyte"), Control { control_type: ControlType::Hibyte, |
