use super::{fmt, hasher, Box, CodeBlock, Digest};
#[derive(Clone, Debug)]
pub struct Loop {
body: Box<CodeBlock>,
hash: Digest,
}
impl Loop {
pub fn new(body: CodeBlock) -> Self {
let hash = hasher::merge(&[body.hash(), Digest::default()]);
Self {
body: Box::new(body),
hash,
}
}
pub fn hash(&self) -> Digest {
self.hash
}
pub fn body(&self) -> &CodeBlock {
&self.body
}
}
impl fmt::Display for Loop {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "while.true {} end", self.body)
}
}