forked from MightyPork/crsn
parent
8222efe6da
commit
79d5aa3cd5
@ -0,0 +1,18 @@ |
||||
/// Cycles spent executing an instruction
|
||||
pub type CyclesSpent = usize; |
||||
|
||||
/// Result of execution evaluation (when Fault is not generated)
|
||||
#[derive(Debug)] |
||||
pub struct EvalRes { |
||||
pub cycles: CyclesSpent, |
||||
pub advance: i64, |
||||
} |
||||
|
||||
impl Default for EvalRes { |
||||
fn default() -> Self { |
||||
Self { |
||||
cycles: 1, |
||||
advance: 1, |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,36 @@ |
||||
use std::fmt::Debug; |
||||
|
||||
pub use eval_res::EvalRes; |
||||
|
||||
use crate::asm::error::Error; |
||||
use crate::asm::instr::Op; |
||||
use crate::asm::parse::arg_parser::ArgParser; |
||||
use crate::runtime::fault::Fault; |
||||
use crate::runtime::run_thread::state::RunState; |
||||
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 { |
||||
/// Parsing successful.
|
||||
Parsed(Op), |
||||
/// Instruction not recognized, but there was no error.
|
||||
Unknown(ArgParser), |
||||
} |
||||
|
||||
pub trait OpTrait: Debug + Send + Sync + 'static { |
||||
fn execute(&self, ti: &ThreadInfo, state: &mut RunState) -> Result<EvalRes, Fault>; |
||||
} |
||||
|
||||
pub trait AsmModule: Debug + Send + 'static { |
||||
/// Get name of the module
|
||||
fn name(&self) -> &'static str; |
||||
|
||||
/// Parse an op.
|
||||
/// If the keyword matches and the function decides to parse the instruction, it must consume
|
||||
/// 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>; |
||||
} |
Loading…
Reference in new issue