use std::fmt;
use som_core::ast;
use crate::class::Class;
use crate::frame::Frame;
use crate::universe::Universe;
use crate::SOMRef;
#[derive(Clone)]
pub struct Block {
pub frame: SOMRef<Frame>,
pub block: ast::Block,
}
impl Block {
pub fn class(&self, universe: &Universe) -> SOMRef<Class> {
match self.nb_parameters() {
0 => universe.block1_class(),
1 => universe.block2_class(),
2 => universe.block3_class(),
_ => panic!("no support for blocks with more than 2 parameters"),
}
}
pub fn nb_parameters(&self) -> usize {
self.block.parameters.len()
}
}
impl fmt::Debug for Block {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct(&format!("Block{}", self.nb_parameters() + 1))
.finish()
}
}