From 5d06ba11c981430aca68f2ea31771fca7f18529b Mon Sep 17 00:00:00 2001 From: Miquel Sabaté Solà Date: Wed, 22 Jan 2025 22:22:46 +0100 Subject: Implement echo control statements MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Miquel Sabaté Solà --- lib/xixanta/src/assembler.rs | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to 'lib/xixanta/src/assembler.rs') 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> { + 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> { // 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!( -- cgit v1.2.3