use vcore::opcodes::Opcode; use std::collections::BTreeMap; use std::fmt::{Display, Formatter}; /// One of the five arithmetical operators #[derive(Debug, PartialEq, Copy, Clone)] pub enum Operator { Add, Sub, Mul, Div, Mod, } /// An AST node for an instruction argument. This can be a string, number, label reference, /// line offset, or an expr containing a sequence of other Nodes joined by same-precedence /// `Operator`s. #[derive(Debug, PartialEq, Clone)] pub enum Node { Number(i32), Label(String), RelativeLabel(String), AbsoluteOffset(i32), RelativeOffset(i32), Expr(Box, Vec<(Operator, Node)>), } impl Node { pub fn label(lbl: &str) -> Self { Self::Label(lbl.to_string()) } pub fn relative_label(lbl: &str) -> Self { Self::RelativeLabel(lbl.to_string()) } } #[derive(Debug, PartialEq, Clone)] pub struct Label(pub String); impl Display for Label { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { write!(f, "{}", self.0) } } impl From<&str> for Label { fn from(s: &str) -> Self { Self(s.to_string()) } } pub type Scope = BTreeMap; #[derive(Debug, PartialEq, Clone)] pub enum Macro { Include(String), If, Unless, Else, While, Until, Do, End, } #[derive(Debug, PartialEq, Clone)] pub enum VASMLine { Instruction(Option