refactors
This commit is contained in:
@@ -28,7 +28,7 @@ impl CrsnExtension for BuiltinOps {
|
||||
"builtin"
|
||||
}
|
||||
|
||||
fn parse_op(&self, keyword: &str, mut args: ArgParser) -> Result<ParseOpRes, Error> {
|
||||
fn parse_op(&self, keyword: &str, mut args: ArgParser) -> Result<ParseOpRes<Op>, Error> {
|
||||
Ok(ParseOpRes::Parsed(Op::BuiltIn(match keyword {
|
||||
"nop" => {
|
||||
BuiltinOp::Nop
|
||||
|
||||
+10
-3
@@ -14,13 +14,20 @@ use crate::runtime::run_thread::ThreadInfo;
|
||||
mod eval_res;
|
||||
|
||||
/// Result type returned from the op parser. This is the Ok variant of a Result.
|
||||
pub enum ParseOpRes {
|
||||
pub enum ParseOpRes<T> {
|
||||
/// Parsing successful.
|
||||
Parsed(Op),
|
||||
Parsed(T),
|
||||
/// Instruction not recognized, but there was no error.
|
||||
Unknown(ArgParser),
|
||||
}
|
||||
|
||||
impl ParseOpRes<Op> {
|
||||
/// Helper to construct an extension op
|
||||
pub fn parsed(op : impl OpTrait) -> Self {
|
||||
Self::Parsed(Op::Ext(Box::new(op)))
|
||||
}
|
||||
}
|
||||
|
||||
pub trait OpTrait: Debug + Send + Sync + 'static {
|
||||
fn execute(&self, ti: &ThreadInfo, state: &mut RunState) -> Result<EvalRes, Fault>;
|
||||
}
|
||||
@@ -34,7 +41,7 @@ pub trait CrsnExtension: Debug + Send + Sync + 'static {
|
||||
/// the argument list and either return Ok or Err.
|
||||
///
|
||||
/// If the instruction keyword is not recognized, return Unknown with the unchanged argument list.
|
||||
fn parse_op(&self, keyword: &str, arg_tokens: ArgParser) -> Result<ParseOpRes, Error>;
|
||||
fn parse_op(&self, keyword: &str, arg_tokens: ArgParser) -> Result<ParseOpRes<Op>, Error>;
|
||||
|
||||
/// Drop an object referenced by a handle
|
||||
fn drop_obj(&self,
|
||||
|
||||
@@ -24,8 +24,8 @@ impl CrsnExtension for ArithOps {
|
||||
"arith"
|
||||
}
|
||||
|
||||
fn parse_op(&self, keyword: &str, mut args: ArgParser) -> Result<ParseOpRes, Error> {
|
||||
Ok(ParseOpRes::Parsed(Op::Ext(Box::new(match keyword {
|
||||
fn parse_op(&self, keyword: &str, mut args: ArgParser) -> Result<ParseOpRes<Op>, Error> {
|
||||
Ok(ParseOpRes::parsed(match keyword {
|
||||
"cmp" => {
|
||||
ArithOp::Compare {
|
||||
a: args.next_rd()?,
|
||||
@@ -450,6 +450,6 @@ impl CrsnExtension for ArithOps {
|
||||
_other => {
|
||||
return Ok(ParseOpRes::Unknown(args));
|
||||
}
|
||||
}))))
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,8 +26,8 @@ impl CrsnExtension for StackOps {
|
||||
"stacks"
|
||||
}
|
||||
|
||||
fn parse_op(&self, keyword: &str, mut args: ArgParser) -> Result<ParseOpRes, Error> {
|
||||
Ok(ParseOpRes::Parsed(Op::Ext(Box::new(match keyword {
|
||||
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()?,
|
||||
@@ -51,7 +51,7 @@ impl CrsnExtension for StackOps {
|
||||
_other => {
|
||||
return Ok(ParseOpRes::Unknown(args));
|
||||
}
|
||||
}))))
|
||||
}))
|
||||
}
|
||||
|
||||
fn drop_obj(&self, _ti: &ThreadInfo, state: &mut RunState, handle: Value) -> Result<Option<()>, Fault>
|
||||
|
||||
Reference in New Issue
Block a user