Croissant Runtime
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.
 
 
crsn/crsn_stacks/src/parse.rs

47 lines
1.0 KiB

use crsn::asm::error::Error;
use crsn::asm::instr::Op;
use crsn::asm::parse::arg_parser::ArgParser;
use crsn::module::{AsmModule, ParseOpRes};
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<ParseOpRes, Error> {
Ok(ParseOpRes::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(ParseOpRes::Unknown(args));
}
}))))
}
}