diff options
| author | Miquel Sabaté Solà <mikisabate@gmail.com> | 2025-01-22 22:22:46 +0100 |
|---|---|---|
| committer | Miquel Sabaté Solà <mikisabate@gmail.com> | 2025-01-22 22:22:46 +0100 |
| commit | 5d06ba11c981430aca68f2ea31771fca7f18529b (patch) | |
| tree | 8ef437976a615ed942ea1a339000fb274419e0b6 /lib/xixanta/src/assembler.rs | |
| parent | 4a7e8db884fdaa80f6a026ec4c0c8409ea975d81 (diff) | |
| download | tools.nes-5d06ba11c981430aca68f2ea31771fca7f18529b.tar.gz tools.nes-5d06ba11c981430aca68f2ea31771fca7f18529b.zip | |
Implement echo control statements
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
Diffstat (limited to 'lib/xixanta/src/assembler.rs')
| -rw-r--r-- | lib/xixanta/src/assembler.rs | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/lib/xixanta/src/assembler.rs b/lib/xixanta/src/assembler.rs index 4ee769b..66fe418 100644 --- a/lib/xixanta/src/assembler.rs +++ b/lib/xixanta/src/assembler.rs @@ -1,5 +1,5 @@ use crate::mapping::{get_mapping_configuration, Mapping}; -use crate::node::{ControlType, NodeType, OperationType, PNode, PString}; +use crate::node::{ControlType, EchoKind, NodeType, OperationType, PNode, PString}; use crate::object::{Bundle, Context, Object, ObjectType}; use crate::opcodes::{AddressingMode, INSTRUCTIONS}; use crate::parser::Parser; @@ -569,6 +569,7 @@ impl<'a> Assembler<'a> { // On control statements which modify the context, there are // some further evaluating to do. match control_type { + ControlType::Echo(t) => self.evaluate_echo(node, t)?, ControlType::StartRepeat => { self.evaluate_repeat_statement(node)?; } @@ -708,6 +709,33 @@ impl<'a> Assembler<'a> { } } + // Consume an .info/.warning/.error call. + fn evaluate_echo(&mut self, node: &PNode, t: &EchoKind) -> Result<(), Vec<Error>> { + let arg = node.args.as_ref().unwrap().first().unwrap(); + let val = &arg.value.value[1..arg.value.value.len() - 1]; + + match t { + EchoKind::Info => println!("info: {}", val), + EchoKind::Warning => self.warnings.push(Error { + global: false, + line: node.value.line, + source: self.source_for(node), + message: val.to_string(), + }), + EchoKind::Error => { + return Err(Error { + global: false, + line: node.value.line, + source: self.source_for(node), + message: val.to_string(), + } + .into()); + } + } + + Ok(()) + } + // Consume a node which contains a macro call by pushing its bundles now. fn bundle_call(&mut self, node: &PNode) -> Result<(), Vec<Error>> { // Get the macro we are trying to reproduce. @@ -1372,6 +1400,7 @@ impl<'a> Assembler<'a> { } NodeType::Control(ControlType::EndIf) => Ok(()), NodeType::Control(ControlType::IncludeSource) => Ok(()), + NodeType::Control(ControlType::Echo(_)) => Ok(()), _ => Err(Error { line: node.value.line, message: format!( |
