use crsn::asm::data::literal::Value; use crsn::asm::error::Error; use crsn::asm::instr::Op; use crsn::asm::parse::arg_parser::ArgParser; use crsn::module::{CrsnExtension, ParseOpRes}; use crsn::runtime::fault::Fault; use crsn::runtime::run_thread::{RunState, ThreadInfo}; use crate::defs::StackOp; #[derive(Debug, Clone)] pub struct StackOps { _internal: () } impl StackOps { pub fn new() -> Box { Box::new(Self { _internal: () }) } } impl CrsnExtension for StackOps { fn name(&self) -> &'static str { "stacks" } fn parse_op(&self, keyword: &str, mut args: ArgParser) -> Result, Error> { Ok(ParseOpRes::parsed(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, Fault> { crate::exec::drop_stack(state, handle) } }