use crate::ir::IR; use crate::stable::StringIdx; use crate::ty::TyIdx; use std::slice::IterMut; #[derive(Debug, Default, PartialEq, Clone)] pub struct Block { arguments: Vec<(StringIdx, TyIdx)>, ir: Vec, } impl Block { /// Consumes the block and returns the IR data. pub fn ir(self) -> Vec { self.ir } pub fn is_empty(&self) -> bool { self.ir.is_empty() } pub fn iter_mut(&mut self) -> IterMut { self.ir.iter_mut() } pub fn new(arguments: Vec<(StringIdx, TyIdx)>) -> Block { Block { arguments, ir: Vec::default(), } } pub fn pop(&mut self) -> Option { self.ir.pop() } pub fn push(&mut self, ir: IR) { self.ir.push(ir); } pub fn set_arguments(&mut self, arguments: Vec<(StringIdx, TyIdx)>) { self.arguments = arguments; } } #[derive(Debug, Clone, PartialEq)] pub struct BlockIdx(usize); impl From for BlockIdx { fn from(i: usize) -> BlockIdx { BlockIdx(i) } } impl From for usize { fn from(i: BlockIdx) -> usize { i.0 } } impl From<&BlockIdx> for usize { fn from(i: &BlockIdx) -> usize { i.0 } }