|
|
|
use crsn::asm::error::CrsnError;
|
|
|
|
use crsn::asm::instr::op::OpKind;
|
|
|
|
use crsn::asm::parse::arg_parser::TokenParser;
|
|
|
|
use crsn::module::ParseRes;
|
|
|
|
|
|
|
|
use crate::defs::StackOp;
|
|
|
|
use crsn::sexp::SourcePosition;
|
|
|
|
|
|
|
|
pub(crate) fn parse<'a>(pos: SourcePosition, keyword: &str, mut args: TokenParser<'a>) -> Result<ParseRes<'a, OpKind>, CrsnError> {
|
|
|
|
Ok(ParseRes::ext(match keyword {
|
|
|
|
"stack" => {
|
|
|
|
StackOp::NewStack {
|
|
|
|
dst: args.next_wr()?,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
"push" => {
|
|
|
|
StackOp::Push {
|
|
|
|
obj: args.next_rdobj()?,
|
|
|
|
src: args.next_rd()?,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
"pop" => {
|
|
|
|
StackOp::Pop {
|
|
|
|
dst: args.next_wr()?,
|
|
|
|
obj: args.next_rdobj()?,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
"rpush" => {
|
|
|
|
StackOp::ReversePush {
|
|
|
|
obj: args.next_rdobj()?,
|
|
|
|
src: args.next_rd()?,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
"rpop" => {
|
|
|
|
StackOp::ReversePop {
|
|
|
|
dst: args.next_wr()?,
|
|
|
|
obj: args.next_rdobj()?,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_other => {
|
|
|
|
return Ok(ParseRes::Unknown(args));
|
|
|
|
}
|
|
|
|
}))
|
|
|
|
}
|