forked from MightyPork/crsn
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
1.1 KiB
49 lines
1.1 KiB
4 years ago
|
|
||
|
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<dyn AsmModule> {
|
||
|
Box::new(Self {
|
||
|
_internal: ()
|
||
|
})
|
||
|
}
|
||
|
}
|
||
|
|
||
|
impl AsmModule for StackOps {
|
||
|
fn name(&self) -> &'static str {
|
||
|
"stacks"
|
||
|
}
|
||
|
|
||
|
fn parse_op(&self, keyword: &str, mut args: ArgParser) -> Result<ParseOpResult, Error> {
|
||
|
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));
|
||
|
}
|
||
|
}))))
|
||
|
}
|
||
|
}
|