refactors

This commit is contained in:
2020-09-28 20:58:30 +02:00
parent 2269d759c6
commit b7345144e0
19 changed files with 546 additions and 546 deletions
+1 -1
View File
@@ -67,7 +67,7 @@ impl OpTrait for StackOp {
//
}
pub(crate) fn drop_stack(state: &mut RunState, handle: Value) -> Result<Option<()>, Fault> {
pub(crate) fn drop_obj(state: &mut RunState, handle: Value) -> Result<Option<()>, Fault> {
let stacks: &mut Stacks = state.ext_mut();
Ok(stacks.store.remove(&handle).map(|_| ()))
}
+22 -1
View File
@@ -1,6 +1,27 @@
pub use parse::StackOps;
use crsn::module::{CrsnExtension, ParseOpRes};
use crsn::asm::parse::arg_parser::ArgParser;
use crsn::asm::instr::Op;
use crsn::asm::error::CrsnError;
mod defs;
mod parse;
mod exec;
#[derive(Debug, Clone)]
pub struct StackOps;
impl StackOps {
pub fn new() -> Box<dyn CrsnExtension> {
Box::new(Self)
}
}
impl CrsnExtension for StackOps {
fn name(&self) -> &'static str {
"stacks"
}
fn parse_op(&self, keyword: &str, args: ArgParser) -> Result<ParseOpRes<Op>, CrsnError> {
parse::parse(keyword, args)
}
}
+25 -49
View File
@@ -1,61 +1,37 @@
use crsn::asm::data::literal::Value;
use crsn::asm::error::Error;
use crsn::asm::error::CrsnError;
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 crsn::module::{ParseOpRes};
use crate::defs::StackOp;
#[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<Op>, Error> {
Ok(ParseOpRes::parsed(match keyword {
"stack" => {
StackOp::NewStack {
dst: args.next_wr()?,
}
}
"push" => {
StackOp::Push {
obj: args.next_rdobj()?,
src: args.next_rd()?,
}
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()?,
}
}
"pop" => {
StackOp::Pop {
dst: args.next_wr()?,
obj: args.next_rdobj()?,
}
"push" => {
StackOp::Push {
obj: args.next_rdobj()?,
src: args.next_rd()?,
}
}
_other => {
return Ok(ParseOpRes::Unknown(args));
"pop" => {
StackOp::Pop {
dst: args.next_wr()?,
obj: args.next_rdobj()?,
}
}))
}
}
fn drop_obj(&self, _ti: &ThreadInfo, state: &mut RunState, handle: Value) -> Result<Option<()>, Fault>
{
crate::exec::drop_stack(state, handle)
}
_other => {
return Ok(ParseOpRes::Unknown(args));
}
}))
}