|
|
@ -5,32 +5,14 @@ use crate::asm::data::reg::parse_reg; |
|
|
|
use crate::asm::error::CrsnError; |
|
|
|
use crate::asm::error::CrsnError; |
|
|
|
use crate::asm::instr::op::OpKind; |
|
|
|
use crate::asm::instr::op::OpKind; |
|
|
|
use crate::asm::parse::arg_parser::TokenParser; |
|
|
|
use crate::asm::parse::arg_parser::TokenParser; |
|
|
|
use crate::asm::parse::parse_data::{parse_constant_name, parse_label, parse_rd, parse_reg_alias, parse_value, parse_u64, parse_label_str}; |
|
|
|
use crate::asm::parse::parse_data::{parse_constant_name, parse_label, parse_rd, parse_reg_alias, parse_value, parse_label_str}; |
|
|
|
use crate::asm::parse::sexp_expect::expect_string_atom; |
|
|
|
use crate::asm::parse::sexp_expect::expect_string_atom; |
|
|
|
use crate::builtin::defs::{Barrier, BuiltinOp}; |
|
|
|
use crate::builtin::defs::{Barrier, BuiltinOp}; |
|
|
|
use crate::module::{CrsnExtension, ParseRes}; |
|
|
|
use crate::module::{CrsnExtension, ParseRes}; |
|
|
|
use crate::utils::A; |
|
|
|
use crate::utils::A; |
|
|
|
use std::convert::TryFrom; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Clone)] |
|
|
|
|
|
|
|
pub struct BuiltinOps { |
|
|
|
|
|
|
|
_internal: () |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
impl BuiltinOps { |
|
|
|
|
|
|
|
pub fn new() -> Box<dyn CrsnExtension> { |
|
|
|
|
|
|
|
Box::new(Self { |
|
|
|
|
|
|
|
_internal: () |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
impl CrsnExtension for BuiltinOps { |
|
|
|
pub(crate) fn parse_op<'a>(keyword: &str, mut args: TokenParser<'a>) -> Result<ParseRes<'a, OpKind>, CrsnError> { |
|
|
|
fn name(&self) -> &'static str { |
|
|
|
|
|
|
|
"builtin" |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn parse_op<'a>(&self, keyword: &str, mut args: TokenParser<'a>) -> Result<ParseRes<'a, OpKind>, CrsnError> { |
|
|
|
|
|
|
|
let pcx = args.pcx; |
|
|
|
let pcx = args.pcx; |
|
|
|
|
|
|
|
|
|
|
|
Ok(ParseRes::Parsed(OpKind::BuiltIn(match keyword { |
|
|
|
Ok(ParseRes::Parsed(OpKind::BuiltIn(match keyword { |
|
|
@ -223,7 +205,6 @@ impl CrsnExtension for BuiltinOps { |
|
|
|
} |
|
|
|
} |
|
|
|
}))) |
|
|
|
}))) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub(crate) fn parse_routine_name(name: String) -> Result<RoutineName, CrsnError> { |
|
|
|
pub(crate) fn parse_routine_name(name: String) -> Result<RoutineName, CrsnError> { |
|
|
|
let (name, arity) = if let Some(n) = name.find('/') { |
|
|
|
let (name, arity) = if let Some(n) = name.find('/') { |
|
|
@ -304,16 +285,16 @@ pub(crate) fn to_sexp(op: &BuiltinOp) -> Sexp { |
|
|
|
|
|
|
|
|
|
|
|
#[cfg(test)] |
|
|
|
#[cfg(test)] |
|
|
|
mod test { |
|
|
|
mod test { |
|
|
|
use std::any::Any; |
|
|
|
|
|
|
|
use std::cell::RefCell; |
|
|
|
|
|
|
|
use std::sync::atomic::AtomicU32; |
|
|
|
use std::sync::atomic::AtomicU32; |
|
|
|
|
|
|
|
|
|
|
|
use crate::asm::instr::{Flatten, InstrWithBranches}; |
|
|
|
use crate::asm::instr::{Flatten}; |
|
|
|
use crate::asm::parse::{parse_instructions, ParserContext}; |
|
|
|
use crate::asm::parse::{parse_instructions, ParserContext}; |
|
|
|
use crate::asm::parse::sexp_expect::expect_list; |
|
|
|
use crate::asm::parse::sexp_expect::expect_list; |
|
|
|
use crate::builtin::defs::BuiltinOp; |
|
|
|
|
|
|
|
use crate::builtin::parse::BuiltinOps; |
|
|
|
|
|
|
|
use crate::module::OpTrait; |
|
|
|
use crate::module::OpTrait; |
|
|
|
|
|
|
|
use crate::builtin::BuiltinOps; |
|
|
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
#[test] |
|
|
|
fn roundtrip() { |
|
|
|
fn roundtrip() { |
|
|
@ -374,7 +355,7 @@ mod test { |
|
|
|
let parsers = &[parser]; |
|
|
|
let parsers = &[parser]; |
|
|
|
|
|
|
|
|
|
|
|
for (sample, expected) in samples { |
|
|
|
for (sample, expected) in samples { |
|
|
|
let mut pcx = ParserContext { |
|
|
|
let pcx = ParserContext { |
|
|
|
parsers, |
|
|
|
parsers, |
|
|
|
state: Default::default(), |
|
|
|
state: Default::default(), |
|
|
|
}; |
|
|
|
}; |
|
|
@ -386,7 +367,7 @@ mod test { |
|
|
|
.expect("parse sexp"); |
|
|
|
.expect("parse sexp"); |
|
|
|
let list = expect_list(Some(s), false).unwrap(); |
|
|
|
let list = expect_list(Some(s), false).unwrap(); |
|
|
|
let num = AtomicU32::new(0); |
|
|
|
let num = AtomicU32::new(0); |
|
|
|
let mut parsed = parse_instructions(list.into_iter(), &pcx) |
|
|
|
let parsed = parse_instructions(list.into_iter(), &pcx) |
|
|
|
.expect("parse instr").flatten(&num) |
|
|
|
.expect("parse instr").flatten(&num) |
|
|
|
.expect("flatten").remove(0); |
|
|
|
.expect("flatten").remove(0); |
|
|
|
|
|
|
|
|
|
|
@ -402,7 +383,7 @@ mod test { |
|
|
|
.expect("parse sexp (2c)"); |
|
|
|
.expect("parse sexp (2c)"); |
|
|
|
let list = expect_list(Some(s), false).unwrap(); |
|
|
|
let list = expect_list(Some(s), false).unwrap(); |
|
|
|
let num = AtomicU32::new(0); |
|
|
|
let num = AtomicU32::new(0); |
|
|
|
let mut parsed = parse_instructions(list.into_iter(), &pcx) |
|
|
|
let parsed = parse_instructions(list.into_iter(), &pcx) |
|
|
|
.expect("parse instr (2c)").flatten(&num) |
|
|
|
.expect("parse instr (2c)").flatten(&num) |
|
|
|
.expect("flatten (2c)").remove(0); |
|
|
|
.expect("flatten (2c)").remove(0); |
|
|
|
|
|
|
|
|
|
|
|