floats
Ondřej Hruška 4 years ago
parent fe8bf87e6d
commit 6eef2b7ae3
Signed by untrusted user: MightyPork
GPG Key ID: 2C5FD5035250423D
  1. 2
      crsn/src/asm/instr/flatten.rs
  2. 2
      crsn/src/asm/parse/parse_op.rs
  3. 8
      crsn/src/builtin/exec.rs
  4. 24
      crsn/src/builtin/mod.rs
  5. 39
      crsn/src/builtin/parse.rs
  6. 4
      crsn/src/module/mod.rs

@ -1,5 +1,5 @@
use std::collections::HashMap; use std::collections::HashMap;
use std::sync::atomic::{AtomicU32, Ordering}; use std::sync::atomic::{AtomicU32};
use crate::asm::data::{Rd, RdData}; use crate::asm::data::{Rd, RdData};
use crate::asm::data::literal::{Label, Value}; use crate::asm::data::literal::{Label, Value};

@ -2,8 +2,8 @@ use crate::asm::error::CrsnError;
use crate::asm::instr::cond::parse_cond; use crate::asm::instr::cond::parse_cond;
use crate::asm::instr::Op; use crate::asm::instr::Op;
use crate::asm::parse::arg_parser::TokenParser; use crate::asm::parse::arg_parser::TokenParser;
use crate::builtin::parse::BuiltinOps;
use crate::module::ParseRes; use crate::module::ParseRes;
use crate::builtin::BuiltinOps;
pub fn parse_op<'a>(mut keyword: &str, mut arg_tokens: TokenParser<'a>) -> Result<Option<Op>, CrsnError> { pub fn parse_op<'a>(mut keyword: &str, mut arg_tokens: TokenParser<'a>) -> Result<Option<Op>, CrsnError> {
// Include built-in instructions // Include built-in instructions

@ -9,10 +9,10 @@ use crate::runtime::fault::Fault;
use crate::runtime::frame::StackFrame; use crate::runtime::frame::StackFrame;
use crate::runtime::run_thread::{state::RunState, ThreadInfo}; use crate::runtime::run_thread::{state::RunState, ThreadInfo};
use sexp::Sexp; use sexp::Sexp;
use sexp::Atom;
use std::str::FromStr;
use std::fmt::Display;
use crate::utils::A;
impl OpTrait for BuiltinOp { impl OpTrait for BuiltinOp {
fn execute(&self, info: &ThreadInfo, state: &mut RunState) -> Result<EvalRes, Fault> { fn execute(&self, info: &ThreadInfo, state: &mut RunState) -> Result<EvalRes, Fault> {

@ -1,3 +1,27 @@
use crate::module::{CrsnExtension, ParseRes};
use crate::asm::parse::arg_parser::TokenParser;
use crate::asm::instr::op::OpKind;
use crate::asm::error::CrsnError;
pub mod defs; pub mod defs;
pub mod exec; pub mod exec;
pub mod parse; pub mod parse;
#[derive(Debug, Clone)]
pub struct BuiltinOps;
impl BuiltinOps {
pub fn new() -> Box<dyn CrsnExtension> {
Box::new(Self)
}
}
impl CrsnExtension for BuiltinOps {
fn name(&self) -> &'static str {
"builtin"
}
fn parse_op<'a>(&self, keyword: &str, args: TokenParser<'a>) -> Result<ParseRes<'a, OpKind>, CrsnError> {
parse::parse_op(keyword, args)
}
}

@ -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 {
@ -222,7 +204,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> {
@ -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);

@ -1,6 +1,6 @@
#![allow(unused_variables)] #![allow(unused_variables)]
use std::fmt::{Debug, Display, Formatter}; use std::fmt::{Debug};
pub use eval_res::EvalRes; pub use eval_res::EvalRes;
@ -14,7 +14,7 @@ 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;
use sexp::Sexp; use sexp::Sexp;
use std::fmt;
mod eval_res; mod eval_res;

Loading…
Cancel
Save