|
|
|
#[macro_use]
|
|
|
|
extern crate log;
|
|
|
|
|
|
|
|
use crsn::asm::error::CrsnError;
|
|
|
|
use crsn::asm::instr::op::OpKind;
|
|
|
|
use crsn::asm::parse::arg_parser::TokenParser;
|
|
|
|
use crsn::module::{CrsnExtension, ParseRes};
|
|
|
|
use crsn::sexp::SourcePosition;
|
|
|
|
use crsn::asm::data::literal::Value;
|
|
|
|
use crate::exec::f2u;
|
|
|
|
|
|
|
|
mod defs;
|
|
|
|
mod parse;
|
|
|
|
mod exec;
|
|
|
|
|
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
pub struct ArithOps;
|
|
|
|
|
|
|
|
impl ArithOps {
|
|
|
|
pub fn new() -> Box<dyn CrsnExtension> {
|
|
|
|
Box::new(Self)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl CrsnExtension for ArithOps {
|
|
|
|
fn name(&self) -> &'static str {
|
|
|
|
"arith"
|
|
|
|
}
|
|
|
|
|
|
|
|
fn parse_op<'a>(&self, pos: &SourcePosition, keyword: &str, args: TokenParser<'a>) -> Result<ParseRes<'a, OpKind>, CrsnError> {
|
|
|
|
parse::parse(pos, keyword, args)
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Get value of an extension-provided constant.
|
|
|
|
/// This constant may be an object handle, or a constant value used as argument in some other instruction.
|
|
|
|
fn get_constant_value<'a>(&self, name: &str) -> Option<Value>
|
|
|
|
{
|
|
|
|
use std::f64::consts;
|
|
|
|
match name {
|
|
|
|
"PI" => Some(f2u(consts::PI)),
|
|
|
|
"PI_2" => Some(f2u(consts::FRAC_PI_2)),
|
|
|
|
"TAU" => Some(f2u(consts::TAU)),
|
|
|
|
"E" => Some(f2u(consts::E)),
|
|
|
|
// TODO more?...
|
|
|
|
_ => None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|