use crsn::asm::error::Error; use crsn::asm::instr::op::{AsmModule, ParseOpResult}; use crsn::asm::instr::Op; use crsn::asm::parse::arg_parser::ArgParser; use crate::defs::StackOp; #[derive(Debug, Clone)] pub struct StackOps { _internal: () } impl StackOps { pub fn new() -> Box { Box::new(Self { _internal: () }) } } impl AsmModule for StackOps { fn name(&self) -> &'static str { "stacks" } fn parse_op(&self, keyword: &str, mut args: ArgParser) -> Result { Ok(ParseOpResult::Parsed(Op::Ext(Box::new(match keyword { "push" => { StackOp::Push { num: args.next_rd()?, src: args.next_rd()?, } } "pop" => { StackOp::Pop { dst: args.next_wr()?, num: args.next_rd()?, } } _other => { return Ok(ParseOpResult::Unknown(args)); } })))) } }