|
|
|
use crsn::asm::error::Error;
|
|
|
|
use crsn::asm::instr::Op;
|
|
|
|
use crsn::asm::parse::arg_parser::ArgParser;
|
|
|
|
use crsn::module::{CrsnExtension, ParseOpRes};
|
|
|
|
|
|
|
|
use crate::defs::StackOp;
|
|
|
|
use crsn::runtime::run_thread::{ThreadInfo, RunState};
|
|
|
|
use crsn::asm::data::literal::Value;
|
|
|
|
use crsn::runtime::fault::Fault;
|
|
|
|
|
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
pub struct StackOps {
|
|
|
|
_internal: ()
|
|
|
|
}
|
|
|
|
|
|
|
|
impl StackOps {
|
|
|
|
pub fn new() -> Box<dyn CrsnExtension> {
|
|
|
|
Box::new(Self {
|
|
|
|
_internal: ()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl CrsnExtension 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 {
|
|
|
|
"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()?,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_other => {
|
|
|
|
return Ok(ParseOpRes::Unknown(args));
|
|
|
|
}
|
|
|
|
}))))
|
|
|
|
}
|
|
|
|
|
|
|
|
fn drop_obj(&self, _ti: &ThreadInfo, state: &mut RunState, handle : Value) -> Result<Option<()>, Fault>
|
|
|
|
{
|
|
|
|
crate::exec::drop_stack(state, handle)
|
|
|
|
}
|
|
|
|
}
|