pull/21/head
Ondřej Hruška 4 years ago
parent 3599cb46c4
commit 2269d759c6
Signed by: MightyPork
GPG Key ID: 2C5FD5035250423D
  1. 2
      crsn/src/builtin/parse.rs
  2. 13
      crsn/src/module/mod.rs
  3. 6
      crsn_arith/src/parse.rs
  4. 6
      crsn_stacks/src/parse.rs

@ -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

@ -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>

Loading…
Cancel
Save