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

38 lines
809 B

4 years ago
use crsn::asm::error::CrsnError;
use crsn::asm::instr::Op;
use crsn::asm::parse::arg_parser::ArgParser;
4 years ago
use crsn::module::{ParseOpRes};
4 years ago
use crate::defs::StackOp;
4 years ago
pub(crate) fn parse(keyword: &str, mut args: ArgParser) -> Result<ParseOpRes<Op>, CrsnError> {
Ok(ParseOpRes::ext(match keyword {
"stack" => {
StackOp::NewStack {
dst: args.next_wr()?,
}
4 years ago
}
4 years ago
"push" => {
StackOp::Push {
obj: args.next_rdobj()?,
src: args.next_rd()?,
}
4 years ago
}
4 years ago
"pop" => {
StackOp::Pop {
dst: args.next_wr()?,
obj: args.next_rdobj()?,
}
4 years ago
}
4 years ago
_other => {
return Ok(ParseOpRes::Unknown(args));
}
}))
}