mindustry logic execution, map- and schematic- parsing and rendering
Diffstat (limited to 'lemu/src/instructions/io.rs')
-rw-r--r--lemu/src/instructions/io.rs28
1 files changed, 26 insertions, 2 deletions
diff --git a/lemu/src/instructions/io.rs b/lemu/src/instructions/io.rs
index 8b1eed5..6e8e325 100644
--- a/lemu/src/instructions/io.rs
+++ b/lemu/src/instructions/io.rs
@@ -3,7 +3,10 @@ use crate::{
executor::{ExecutorContext, Memory},
memory::{LAddress, LVar},
};
-use std::io::Write as Wr;
+use std::{
+ fmt::{self, Display, Formatter},
+ io::Write as Wr,
+};
#[derive(Debug)]
pub struct Read<'v> {
@@ -24,6 +27,12 @@ impl<'v> LInstruction<'v> for Read<'v> {
}
}
+impl Display for Read<'_> {
+ fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
+ write!(f, "read {} {} {}", self.output, self.container, self.index)
+ }
+}
+
#[derive(Debug)]
pub struct Write<'v> {
pub(crate) index: LAddress<'v>,
@@ -43,6 +52,12 @@ impl<'v> LInstruction<'v> for Write<'v> {
}
}
+impl Display for Write<'_> {
+ fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
+ write!(f, "write {} {} {}", self.set, self.container, self.index)
+ }
+}
+
#[derive(Debug)]
pub struct Print<'v> {
pub(crate) val: LAddress<'v>,
@@ -51,8 +66,17 @@ impl LInstruction<'_> for Print<'_> {
fn run<W: Wr>(&self, exec: &mut ExecutorContext<'_, W>) -> Flow {
let v = exec.get(&self.val).clone();
if let Some(o) = &mut exec.output {
- write!(o, "{v}").unwrap();
+ match v {
+ LVar::Num(n) => write!(o, "{n}"),
+ LVar::String(s) => write!(o, r#"{s}"#),
+ }
+ .unwrap();
}
Flow::Continue
}
}
+impl Display for Print<'_> {
+ fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
+ write!(f, "print {}", self.val)
+ }
+}