aboutsummaryrefslogtreecommitdiff
path: root/lib/xixanta
diff options
context:
space:
mode:
Diffstat (limited to 'lib/xixanta')
-rw-r--r--lib/xixanta/src/assembler.rs33
-rw-r--r--lib/xixanta/src/node.rs2
-rw-r--r--lib/xixanta/src/opcodes.rs10
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,