|
|
@ -1,3 +1,5 @@ |
|
|
|
|
|
|
|
#![allow(unused_variables)] |
|
|
|
|
|
|
|
|
|
|
|
use std::fmt::Debug; |
|
|
|
use std::fmt::Debug; |
|
|
|
|
|
|
|
|
|
|
|
pub use eval_res::EvalRes; |
|
|
|
pub use eval_res::EvalRes; |
|
|
@ -5,8 +7,8 @@ pub use eval_res::EvalRes; |
|
|
|
use crate::asm::data::literal::Value; |
|
|
|
use crate::asm::data::literal::Value; |
|
|
|
use crate::asm::data::Mask; |
|
|
|
use crate::asm::data::Mask; |
|
|
|
use crate::asm::error::CrsnError; |
|
|
|
use crate::asm::error::CrsnError; |
|
|
|
use crate::asm::instr::Op; |
|
|
|
use crate::asm::instr::{Op, Flatten}; |
|
|
|
use crate::asm::parse::arg_parser::ArgParser; |
|
|
|
use crate::asm::parse::arg_parser::TokenParser; |
|
|
|
use crate::runtime::fault::Fault; |
|
|
|
use crate::runtime::fault::Fault; |
|
|
|
use crate::runtime::run_thread::state::RunState; |
|
|
|
use crate::runtime::run_thread::state::RunState; |
|
|
|
use crate::runtime::run_thread::ThreadInfo; |
|
|
|
use crate::runtime::run_thread::ThreadInfo; |
|
|
@ -14,14 +16,14 @@ use crate::runtime::run_thread::ThreadInfo; |
|
|
|
mod eval_res; |
|
|
|
mod eval_res; |
|
|
|
|
|
|
|
|
|
|
|
/// Result type returned from the op parser. This is the Ok variant of a Result.
|
|
|
|
/// Result type returned from the op parser. This is the Ok variant of a Result.
|
|
|
|
pub enum ParseOpRes<T> { |
|
|
|
pub enum ParseRes<T> { |
|
|
|
/// Parsing successful.
|
|
|
|
/// Parsing successful.
|
|
|
|
Parsed(T), |
|
|
|
Parsed(T), |
|
|
|
/// Instruction not recognized, but there was no error.
|
|
|
|
/// Instruction not recognized, but there was no error.
|
|
|
|
Unknown(ArgParser), |
|
|
|
Unknown(TokenParser), |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
impl ParseOpRes<Op> { |
|
|
|
impl ParseRes<Op> { |
|
|
|
/// Helper to construct an extension op
|
|
|
|
/// Helper to construct an extension op
|
|
|
|
pub fn ext(op: impl OpTrait) -> Self { |
|
|
|
pub fn ext(op: impl OpTrait) -> Self { |
|
|
|
Self::Parsed(Op::Ext(Box::new(op))) |
|
|
|
Self::Parsed(Op::Ext(Box::new(op))) |
|
|
@ -41,36 +43,35 @@ pub trait CrsnExtension: Debug + Send + Sync + 'static { |
|
|
|
/// the argument list and either return Ok or Err.
|
|
|
|
/// the argument list and either return Ok or Err.
|
|
|
|
///
|
|
|
|
///
|
|
|
|
/// If the instruction keyword is not recognized, return Unknown with the unchanged argument list.
|
|
|
|
/// 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<Op>, CrsnError>; |
|
|
|
fn parse_op(&self, keyword: &str, arg_tokens: TokenParser) -> Result<ParseRes<Op>, CrsnError>; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Parse a generic S-expression (non-op)
|
|
|
|
|
|
|
|
fn parse_syntax(&self, keyword: &str, tokens: TokenParser, parsers: &[Box<dyn CrsnExtension>]) |
|
|
|
|
|
|
|
-> Result<ParseRes<Box<dyn Flatten>>, CrsnError> |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Ok(ParseRes::Unknown(tokens)) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// Drop an object referenced by a handle
|
|
|
|
/// Drop an object referenced by a handle
|
|
|
|
fn drop_obj(&self, |
|
|
|
fn drop_obj(&self, ti: &ThreadInfo, state: &mut RunState, handle: Value) |
|
|
|
#[allow(unused)] ti: &ThreadInfo, |
|
|
|
-> Result<Option<()>, Fault> |
|
|
|
#[allow(unused)] state: &mut RunState, |
|
|
|
|
|
|
|
#[allow(unused)] handle: Value) -> Result<Option<()>, Fault> |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
// Default impl - we do not support dropping this object
|
|
|
|
// Default impl - we do not support dropping this object
|
|
|
|
Ok(None) |
|
|
|
Ok(None) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// Run-time method called to read an object (using the object handle syntax)
|
|
|
|
/// Run-time method called to read an object (using the object handle syntax)
|
|
|
|
fn read_obj(&self, |
|
|
|
fn read_obj(&self, ti: &ThreadInfo, state: &mut RunState, handle: Value, _mask: Mask) |
|
|
|
#[allow(unused)] ti: &ThreadInfo, |
|
|
|
-> Result<Option<Value>, Fault> |
|
|
|
#[allow(unused)] state: &mut RunState, |
|
|
|
{ |
|
|
|
#[allow(unused)] handle: Value, |
|
|
|
|
|
|
|
#[allow(unused)] mask: Mask, |
|
|
|
|
|
|
|
) -> Result<Option<Value>, Fault> { |
|
|
|
|
|
|
|
// Default impl - we do not support reading this object
|
|
|
|
// Default impl - we do not support reading this object
|
|
|
|
Ok(None) |
|
|
|
Ok(None) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// Run-time method called to write an object (using the object handle syntax)
|
|
|
|
/// Run-time method called to write an object (using the object handle syntax)
|
|
|
|
fn write_obj(&self, |
|
|
|
fn write_obj(&self, ti: &ThreadInfo, state: &mut RunState, handle: Value, mask: Mask) |
|
|
|
#[allow(unused)] ti: &ThreadInfo, |
|
|
|
-> Result<Option<()>, Fault> |
|
|
|
#[allow(unused)] state: &mut RunState, |
|
|
|
{ |
|
|
|
#[allow(unused)] handle: Value, |
|
|
|
|
|
|
|
#[allow(unused)] mask: Mask, |
|
|
|
|
|
|
|
) -> Result<Option<()>, Fault> { |
|
|
|
|
|
|
|
// Default impl - we do not support writing this object
|
|
|
|
// Default impl - we do not support writing this object
|
|
|
|
Ok(None) |
|
|
|
Ok(None) |
|
|
|
} |
|
|
|
} |
|
|
|