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

50 lines
1.2 KiB

4 years ago
use crsn::asm::error::CrsnError;
use crsn::asm::instr::op::OpKind;
use crsn::asm::parse::arg_parser::TokenParser;
use crsn::module::ParseRes;
use crsn::sexp::SourcePosition;
4 years ago
use crate::defs::StackOp;
pub(crate) fn parse<'a>(_pos: &SourcePosition, keyword: &str, mut args: TokenParser<'a>) -> Result<ParseRes<'a, OpKind>, CrsnError> {
Ok(ParseRes::ext(match keyword {
4 years ago
"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
}
"rpush" => {
StackOp::ReversePush {
obj: args.next_rdobj()?,
src: args.next_rd()?,
}
}
"rpop" => {
StackOp::ReversePop {
dst: args.next_wr()?,
obj: args.next_rdobj()?,
}
}
4 years ago
_other => {
return Ok(ParseRes::Unknown(args));
4 years ago
}
}))
}