cleanup, optimize. use Arc for reference sharing

pull/21/head
Ondřej Hruška 4 years ago
parent d5de189af6
commit 3599cb46c4
Signed by: MightyPork
GPG Key ID: 2C5FD5035250423D
  1. 108
      Cargo.lock
  2. 6
      crsn/src/asm/data/mod.rs
  3. 5
      crsn/src/asm/data/rd.rs
  4. 4
      crsn/src/asm/data/wr.rs
  5. 2
      crsn/src/asm/instr/op.rs
  6. 4
      crsn/src/asm/mod.rs
  7. 2
      crsn/src/asm/parse/arg_parser.rs
  8. 2
      crsn/src/asm/parse/parse_data.rs
  9. 2
      crsn/src/builtin/defs.rs
  10. 6
      crsn/src/builtin/exec.rs
  11. 1
      crsn/src/builtin/parse.rs
  12. 14
      crsn/src/module/mod.rs
  13. 6
      crsn/src/runtime/program.rs
  14. 26
      crsn/src/runtime/run_thread.rs
  15. 9
      crsn/src/runtime/run_thread/info.rs
  16. 2
      crsn/src/runtime/run_thread/state.rs
  17. 2
      crsn_stacks/src/defs.rs
  18. 7
      crsn_stacks/src/exec.rs
  19. 8
      crsn_stacks/src/parse.rs
  20. 14
      launcher/src/main.rs

108
Cargo.lock generated

@ -12,9 +12,9 @@ version = "0.2.14"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
dependencies = [ dependencies = [
"hermit-abi", "hermit-abi",
"libc", "libc",
"winapi", "winapi",
] ]
[[package]] [[package]]
@ -35,9 +35,9 @@ version = "0.4.15"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "942f72db697d8767c22d46a598e01f2d3b475501ea43d0db4f16d90259182d0b" checksum = "942f72db697d8767c22d46a598e01f2d3b475501ea43d0db4f16d90259182d0b"
dependencies = [ dependencies = [
"num-integer", "num-integer",
"num-traits", "num-traits",
"time", "time",
] ]
[[package]] [[package]]
@ -46,36 +46,36 @@ version = "1.9.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f4ffc801dacf156c5854b9df4f425a626539c3a6ef7893cc0c5084a23f0b6c59" checksum = "f4ffc801dacf156c5854b9df4f425a626539c3a6ef7893cc0c5084a23f0b6c59"
dependencies = [ dependencies = [
"atty", "atty",
"lazy_static", "lazy_static",
"winapi", "winapi",
] ]
[[package]] [[package]]
name = "crsn" name = "crsn"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"dyn-clonable", "dyn-clonable",
"log", "log",
"num-traits", "num-traits",
"sexp", "sexp",
"thiserror", "thiserror",
] ]
[[package]] [[package]]
name = "crsn_arith" name = "crsn_arith"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"crsn", "crsn",
"num-traits", "num-traits",
] ]
[[package]] [[package]]
name = "crsn_stacks" name = "crsn_stacks"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"crsn", "crsn",
] ]
[[package]] [[package]]
@ -84,8 +84,8 @@ version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4e9232f0e607a262ceb9bd5141a3dfb3e4db6994b31989bbfd845878cba59fd4" checksum = "4e9232f0e607a262ceb9bd5141a3dfb3e4db6994b31989bbfd845878cba59fd4"
dependencies = [ dependencies = [
"dyn-clonable-impl", "dyn-clonable-impl",
"dyn-clone", "dyn-clone",
] ]
[[package]] [[package]]
@ -94,9 +94,9 @@ version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "558e40ea573c374cf53507fd240b7ee2f5477df7cfebdb97323ec61c719399c5" checksum = "558e40ea573c374cf53507fd240b7ee2f5477df7cfebdb97323ec61c719399c5"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn",
] ]
[[package]] [[package]]
@ -111,20 +111,20 @@ version = "0.1.16"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4c30f6d0bc6b00693347368a67d41b58f2fb851215ff1da49e90fe2c5c667151" checksum = "4c30f6d0bc6b00693347368a67d41b58f2fb851215ff1da49e90fe2c5c667151"
dependencies = [ dependencies = [
"libc", "libc",
] ]
[[package]] [[package]]
name = "launcher" name = "launcher"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"crsn", "crsn",
"crsn_arith", "crsn_arith",
"crsn_stacks", "crsn_stacks",
"log", "log",
"simple_logger", "simple_logger",
"thiserror", "thiserror",
] ]
[[package]] [[package]]
@ -145,7 +145,7 @@ version = "0.4.11"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4fabed175da42fed1fa0746b0ea71f412aa9d35e76e95e59b192c64b9dc2bf8b" checksum = "4fabed175da42fed1fa0746b0ea71f412aa9d35e76e95e59b192c64b9dc2bf8b"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
] ]
[[package]] [[package]]
@ -154,8 +154,8 @@ version = "0.1.43"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8d59457e662d541ba17869cf51cf177c0b5f0cbf476c66bdc90bf1edac4f875b" checksum = "8d59457e662d541ba17869cf51cf177c0b5f0cbf476c66bdc90bf1edac4f875b"
dependencies = [ dependencies = [
"autocfg", "autocfg",
"num-traits", "num-traits",
] ]
[[package]] [[package]]
@ -164,7 +164,7 @@ version = "0.2.12"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac267bcc07f48ee5f8935ab0d24f316fb722d7a1292e2913f0cc196b29ffd611" checksum = "ac267bcc07f48ee5f8935ab0d24f316fb722d7a1292e2913f0cc196b29ffd611"
dependencies = [ dependencies = [
"autocfg", "autocfg",
] ]
[[package]] [[package]]
@ -173,7 +173,7 @@ version = "1.0.21"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "36e28516df94f3dd551a587da5357459d9b36d945a7c37c3557928c1c2ff2a2c" checksum = "36e28516df94f3dd551a587da5357459d9b36d945a7c37c3557928c1c2ff2a2c"
dependencies = [ dependencies = [
"unicode-xid", "unicode-xid",
] ]
[[package]] [[package]]
@ -182,7 +182,7 @@ version = "1.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aa563d17ecb180e500da1cfd2b028310ac758de548efdd203e18f283af693f37" checksum = "aa563d17ecb180e500da1cfd2b028310ac758de548efdd203e18f283af693f37"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
] ]
[[package]] [[package]]
@ -197,11 +197,11 @@ version = "1.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "13a53ed2efd04911c8280f2da7bf9abd350c931b86bc7f9f2386fbafbf525ff9" checksum = "13a53ed2efd04911c8280f2da7bf9abd350c931b86bc7f9f2386fbafbf525ff9"
dependencies = [ dependencies = [
"atty", "atty",
"chrono", "chrono",
"colored", "colored",
"log", "log",
"winapi", "winapi",
] ]
[[package]] [[package]]
@ -210,9 +210,9 @@ version = "1.0.41"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6690e3e9f692504b941dc6c3b188fd28df054f7fb8469ab40680df52fdcc842b" checksum = "6690e3e9f692504b941dc6c3b188fd28df054f7fb8469ab40680df52fdcc842b"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"unicode-xid", "unicode-xid",
] ]
[[package]] [[package]]
@ -221,7 +221,7 @@ version = "1.0.20"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7dfdd070ccd8ccb78f4ad66bf1982dc37f620ef696c6b5028fe2ed83dd3d0d08" checksum = "7dfdd070ccd8ccb78f4ad66bf1982dc37f620ef696c6b5028fe2ed83dd3d0d08"
dependencies = [ dependencies = [
"thiserror-impl", "thiserror-impl",
] ]
[[package]] [[package]]
@ -230,9 +230,9 @@ version = "1.0.20"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bd80fc12f73063ac132ac92aceea36734f04a1d93c1240c6944e23a3b8841793" checksum = "bd80fc12f73063ac132ac92aceea36734f04a1d93c1240c6944e23a3b8841793"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn",
] ]
[[package]] [[package]]
@ -241,9 +241,9 @@ version = "0.1.44"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255" checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255"
dependencies = [ dependencies = [
"libc", "libc",
"wasi", "wasi",
"winapi", "winapi",
] ]
[[package]] [[package]]
@ -264,8 +264,8 @@ version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
dependencies = [ dependencies = [
"winapi-i686-pc-windows-gnu", "winapi-i686-pc-windows-gnu",
"winapi-x86_64-pc-windows-gnu", "winapi-x86_64-pc-windows-gnu",
] ]
[[package]] [[package]]

@ -3,7 +3,10 @@ use std::fmt::{Debug, Display, Formatter};
use std::fmt; use std::fmt;
pub use mask::Mask; pub use mask::Mask;
pub use rd::Rd;
pub use rd::RdObj;
pub use reg::Register; pub use reg::Register;
pub use wr::Wr;
use crate::asm::data::literal::{as_signed, Value}; use crate::asm::data::literal::{as_signed, Value};
@ -14,11 +17,8 @@ pub mod reg;
pub mod mask; pub mod mask;
mod rd; mod rd;
pub use rd::Rd;
pub use rd::RdObj;
mod wr; mod wr;
pub use wr::Wr;
/// Data source disposition /// Data source disposition
#[derive(Debug, Clone, Copy, Eq, PartialEq)] #[derive(Debug, Clone, Copy, Eq, PartialEq)]

@ -1,8 +1,9 @@
use crate::asm::data::{RdData, Mask, DataDisp, Register};
use crate::asm::data::literal::Value;
use std::fmt::{Debug, Formatter}; use std::fmt::{Debug, Formatter};
use std::fmt; use std::fmt;
use crate::asm::data::{DataDisp, Mask, RdData, Register};
use crate::asm::data::literal::Value;
/// Data source argument (read-only) /// Data source argument (read-only)
#[derive(Clone, Copy, Eq, PartialEq)] #[derive(Clone, Copy, Eq, PartialEq)]
pub struct Rd(pub RdData, pub Mask); pub struct Rd(pub RdData, pub Mask);

@ -1,8 +1,8 @@
use crate::asm::data::{RdData, Mask, DataDisp, WrData, Rd};
use crate::asm::data::literal::Value;
use std::fmt::{Debug, Formatter}; use std::fmt::{Debug, Formatter};
use std::fmt; use std::fmt;
use crate::asm::data::{DataDisp, Mask, Rd, WrData};
/// Data destination argument (read-write) /// Data destination argument (read-write)
#[derive(Clone, Copy, Eq, PartialEq)] #[derive(Clone, Copy, Eq, PartialEq)]
pub struct Wr(WrData, Mask); pub struct Wr(WrData, Mask);

@ -3,7 +3,7 @@ use std::fmt::Debug;
use crate::builtin::defs::BuiltinOp; use crate::builtin::defs::BuiltinOp;
use crate::module::{EvalRes, OpTrait}; use crate::module::{EvalRes, OpTrait};
use crate::runtime::fault::Fault; use crate::runtime::fault::Fault;
use crate::runtime::run_thread::{state::RunState, info::ThreadInfo}; use crate::runtime::run_thread::{info::ThreadInfo, state::RunState};
/// A higher level simple opration /// A higher level simple opration
#[derive(Debug)] #[derive(Debug)]

@ -10,8 +10,8 @@ pub mod parse;
pub mod patches; pub mod patches;
/// Parse a program from string and assemble a low level instruction sequence from it. /// Parse a program from string and assemble a low level instruction sequence from it.
pub fn assemble(source: &str, parsers: &'static [Box<dyn CrsnExtension>]) -> Result<Arc<Program>, error::Error> { pub fn assemble(source: &str, parsers: Arc<Vec<Box<dyn CrsnExtension>>>) -> Result<Arc<Program>, error::Error> {
let ops = parse::parse(source, parsers)?; let ops = parse::parse(source, &parsers)?;
trace!("--- Compiled program ---"); trace!("--- Compiled program ---");
for (n, op) in ops.iter().enumerate() { for (n, op) in ops.iter().enumerate() {

@ -1,6 +1,6 @@
use sexp::Sexp; use sexp::Sexp;
use crate::asm::data::{Rd, Wr, RdObj, RdData, Mask}; use crate::asm::data::{Mask, Rd, RdData, RdObj, Wr};
use crate::asm::parse::parse_data::{parse_rd, parse_wr}; use crate::asm::parse::parse_data::{parse_rd, parse_wr};
use crate::asm::parse::sexp_expect::expect_string_atom; use crate::asm::parse::sexp_expect::expect_string_atom;

@ -2,7 +2,7 @@ use std::convert::TryFrom;
use sexp::{Atom, Sexp}; use sexp::{Atom, Sexp};
use crate::asm::data::{DataDisp, WrData, Rd, reg, RdData, Wr}; use crate::asm::data::{DataDisp, Rd, RdData, reg, Wr, WrData};
use crate::asm::data::literal::Label; use crate::asm::data::literal::Label;
use crate::asm::error::Error; use crate::asm::error::Error;
use crate::asm::parse::sexp_expect::expect_string_atom; use crate::asm::parse::sexp_expect::expect_string_atom;

@ -1,4 +1,4 @@
use crate::asm::data::{Rd, Wr, RdObj}; use crate::asm::data::{Rd, RdObj, Wr};
use crate::asm::data::literal::{DebugMsg, Label, RoutineName}; use crate::asm::data::literal::{DebugMsg, Label, RoutineName};
use crate::asm::instr::{Cond, Op}; use crate::asm::instr::{Cond, Op};

@ -1,11 +1,11 @@
use crate::asm::data::{Rd, RdData};
use crate::asm::data::literal::Addr; use crate::asm::data::literal::Addr;
use crate::asm::instr::Cond;
use crate::builtin::defs::BuiltinOp; use crate::builtin::defs::BuiltinOp;
use crate::module::{EvalRes, OpTrait}; use crate::module::{EvalRes, OpTrait};
use crate::runtime::fault::Fault; 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 crate::asm::data::{Rd, RdData};
use crate::asm::instr::Cond;
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> {
@ -142,7 +142,7 @@ impl OpTrait for BuiltinOp {
trace!("Drop object: {:#x}", x); trace!("Drop object: {:#x}", x);
let mut dropped = false; let mut dropped = false;
for ex in info.program.extensions { for ex in info.program.extensions.iter() {
if ex.drop_obj(info, state, x)?.is_some() { if ex.drop_obj(info, state, x)?.is_some() {
dropped = true; dropped = true;
} }

@ -9,7 +9,6 @@ use crate::asm::parse::parse_data::{parse_label, parse_rd};
use crate::asm::parse::sexp_expect::expect_string_atom; use crate::asm::parse::sexp_expect::expect_string_atom;
use crate::builtin::defs::BuiltinOp; use crate::builtin::defs::BuiltinOp;
use crate::module::{CrsnExtension, ParseOpRes}; use crate::module::{CrsnExtension, ParseOpRes};
use crate::asm::data::RdObj;
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct BuiltinOps { pub struct BuiltinOps {

@ -2,14 +2,14 @@ use std::fmt::Debug;
pub use eval_res::EvalRes; pub use eval_res::EvalRes;
use crate::asm::data::literal::Value;
use crate::asm::data::Mask;
use crate::asm::error::Error; use crate::asm::error::Error;
use crate::asm::instr::Op; use crate::asm::instr::Op;
use crate::asm::parse::arg_parser::ArgParser; use crate::asm::parse::arg_parser::ArgParser;
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;
use crate::asm::data::literal::Value;
use crate::asm::data::Mask;
mod eval_res; mod eval_res;
@ -40,7 +40,7 @@ pub trait CrsnExtension: Debug + Send + Sync + 'static {
fn drop_obj(&self, fn drop_obj(&self,
#[allow(unused)] ti: &ThreadInfo, #[allow(unused)] ti: &ThreadInfo,
#[allow(unused)] state: &mut RunState, #[allow(unused)] state: &mut RunState,
#[allow(unused)] handle : Value) -> Result<Option<()>, Fault> #[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)
@ -50,8 +50,8 @@ pub trait CrsnExtension: Debug + Send + Sync + 'static {
fn read_obj(&self, fn read_obj(&self,
#[allow(unused)] ti: &ThreadInfo, #[allow(unused)] ti: &ThreadInfo,
#[allow(unused)] state: &mut RunState, #[allow(unused)] state: &mut RunState,
#[allow(unused)] handle : Value, #[allow(unused)] handle: Value,
#[allow(unused)] mask : Mask #[allow(unused)] mask: Mask,
) -> Result<Option<Value>, Fault> { ) -> 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)
@ -61,8 +61,8 @@ pub trait CrsnExtension: Debug + Send + Sync + 'static {
fn write_obj(&self, fn write_obj(&self,
#[allow(unused)] ti: &ThreadInfo, #[allow(unused)] ti: &ThreadInfo,
#[allow(unused)] state: &mut RunState, #[allow(unused)] state: &mut RunState,
#[allow(unused)] handle : Value, #[allow(unused)] handle: Value,
#[allow(unused)] mask : Mask #[allow(unused)] mask: Mask,
) -> Result<Option<()>, Fault> { ) -> 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)

@ -4,20 +4,20 @@ use std::sync::Arc;
use crate::asm::data::literal::{Addr, Label, RoutineName}; use crate::asm::data::literal::{Addr, Label, RoutineName};
use crate::asm::instr::Op; use crate::asm::instr::Op;
use crate::builtin::defs::BuiltinOp; use crate::builtin::defs::BuiltinOp;
use crate::runtime::fault::Fault;
use crate::module::CrsnExtension; use crate::module::CrsnExtension;
use crate::runtime::fault::Fault;
#[derive(Debug)] #[derive(Debug)]
pub struct Program { pub struct Program {
pub ops: Vec<Op>, pub ops: Vec<Op>,
pub extensions: &'static [Box<dyn CrsnExtension>], pub extensions: Arc<Vec<Box<dyn CrsnExtension>>>,
routines: HashMap<RoutineName, Addr>, routines: HashMap<RoutineName, Addr>,
far_labels: HashMap<Label, Addr>, far_labels: HashMap<Label, Addr>,
barriers: Vec<Addr>, barriers: Vec<Addr>,
} }
impl Program { impl Program {
pub fn new(ops: Vec<Op>, extensions: &'static [Box<dyn CrsnExtension>]) -> Arc<Self> { pub fn new(ops: Vec<Op>, extensions: Arc<Vec<Box<dyn CrsnExtension>>>) -> Arc<Self> {
let mut p = Self { let mut p = Self {
ops, ops,
extensions, extensions,

@ -1,14 +1,16 @@
use std::sync::Arc; use std::sync::Arc;
use std::sync::atomic::{AtomicU64, Ordering}; use std::sync::atomic::AtomicU64;
use std::thread::JoinHandle; use std::thread::JoinHandle;
use std::time::Duration; use std::time::Duration;
use crate::asm::data::literal::{Addr, Value}; pub use info::ThreadInfo;
pub use state::RunState;
use crate::asm::data::literal::Addr;
use crate::module::EvalRes; use crate::module::EvalRes;
use crate::runtime::fault::Fault; use crate::runtime::fault::Fault;
use crate::runtime::frame::StackFrame; use crate::runtime::frame::StackFrame;
use crate::runtime::program::Program; use crate::runtime::program::Program;
use crate::runtime::run_thread::info::{UNIQ_BASE};
#[derive(Clone, Copy, Eq, PartialEq, Debug, Ord, PartialOrd)] #[derive(Clone, Copy, Eq, PartialEq, Debug, Ord, PartialOrd)]
pub struct ThreadToken(pub u32); pub struct ThreadToken(pub u32);
@ -20,27 +22,17 @@ pub struct RunThread {
pub mod info; pub mod info;
pub mod state; pub mod state;
pub use info::ThreadInfo;
pub use state::RunState;
pub fn new_uniq() -> &'static AtomicU64 { pub fn new_uniq() -> Arc<AtomicU64> {
let uniq = AtomicU64::new(info::UNIQ_BASE); Arc::new(AtomicU64::new(info::UNIQ_BASE))
Box::leak(Box::new(uniq))
} }
impl RunThread { impl RunThread {
pub fn new(id: ThreadToken, uniq: Option<&'static AtomicU64>, program: Arc<Program>, pc: Addr, args: &[u64]) -> Self { pub fn new(id: ThreadToken, uniq: Option<Arc<AtomicU64>>, program: Arc<Program>, pc: Addr, args: &[u64]) -> Self {
let uniq = if let Some(u) = uniq {
u
} else {
let u = AtomicU64::new(UNIQ_BASE);
Box::leak(Box::new(u)) as &AtomicU64
};
Self { Self {
info: ThreadInfo { info: ThreadInfo {
id, id,
uniq, uniq: uniq.unwrap_or_else(new_uniq),
program, program,
cycle_time: Duration::default(), cycle_time: Duration::default(),
}, },

@ -1,15 +1,16 @@
use crate::runtime::run_thread::ThreadToken;
use std::sync::atomic::{AtomicU64, Ordering};
use std::sync::Arc; use std::sync::Arc;
use crate::runtime::program::Program; use std::sync::atomic::{AtomicU64, Ordering};
use std::time::Duration; use std::time::Duration;
use crate::asm::data::literal::Value; use crate::asm::data::literal::Value;
use crate::runtime::program::Program;
use crate::runtime::run_thread::ThreadToken;
pub struct ThreadInfo { pub struct ThreadInfo {
/// Thread ID /// Thread ID
pub id: ThreadToken, pub id: ThreadToken,
/// Thread ID /// Thread ID
pub(crate) uniq: &'static AtomicU64, pub(crate) uniq: Arc<AtomicU64>,
/// Program to run /// Program to run
pub program: Arc<Program>, pub program: Arc<Program>,
/// Program to run /// Program to run

@ -1,7 +1,7 @@
use std::any::{Any, TypeId}; use std::any::{Any, TypeId};
use std::collections::HashMap; use std::collections::HashMap;
use crate::asm::data::{WrData, Rd, Register, RdData, Wr, RdObj}; use crate::asm::data::{Rd, RdData, RdObj, Register, Wr, WrData};
use crate::asm::data::literal::{Addr, Value}; use crate::asm::data::literal::{Addr, Value};
use crate::asm::instr::Cond; use crate::asm::instr::Cond;
use crate::runtime::fault::Fault; use crate::runtime::fault::Fault;

@ -1,4 +1,4 @@
use crsn::asm::data::{Rd, Wr, RdObj}; use crsn::asm::data::{Rd, RdObj, Wr};
#[derive(Clone, Debug, Eq, PartialEq)] #[derive(Clone, Debug, Eq, PartialEq)]
pub enum StackOp { pub enum StackOp {

@ -1,13 +1,12 @@
use std::collections::{VecDeque, HashMap}; use std::collections::{HashMap, VecDeque};
use crsn::asm::data::literal::Value; use crsn::asm::data::literal::Value;
use crsn::asm::instr::Cond; use crsn::asm::instr::Cond;
use crsn::module::{EvalRes, OpTrait, CrsnExtension}; use crsn::module::{CrsnExtension, EvalRes, OpTrait};
use crsn::runtime::fault::Fault; use crsn::runtime::fault::Fault;
use crsn::runtime::run_thread::{state::RunState, ThreadInfo}; use crsn::runtime::run_thread::{state::RunState, ThreadInfo};
use crate::defs::StackOp; use crate::defs::StackOp;
use crate::StackOps;
#[derive(Debug, Default)] #[derive(Debug, Default)]
struct Stacks { struct Stacks {
@ -68,7 +67,7 @@ impl OpTrait for StackOp {
// //
} }
pub(crate) fn drop_stack(state: &mut RunState, handle : Value) -> Result<Option<()>, Fault> { pub(crate) fn drop_stack(state: &mut RunState, handle: Value) -> Result<Option<()>, Fault> {
let stacks: &mut Stacks = state.ext_mut(); let stacks: &mut Stacks = state.ext_mut();
Ok(stacks.store.remove(&handle).map(|_| ())) Ok(stacks.store.remove(&handle).map(|_| ()))
} }

@ -1,12 +1,12 @@
use crsn::asm::data::literal::Value;
use crsn::asm::error::Error; use crsn::asm::error::Error;
use crsn::asm::instr::Op; use crsn::asm::instr::Op;
use crsn::asm::parse::arg_parser::ArgParser; use crsn::asm::parse::arg_parser::ArgParser;
use crsn::module::{CrsnExtension, ParseOpRes}; use crsn::module::{CrsnExtension, ParseOpRes};
use crsn::runtime::fault::Fault;
use crsn::runtime::run_thread::{RunState, ThreadInfo};
use crate::defs::StackOp; use crate::defs::StackOp;
use crsn::runtime::run_thread::{ThreadInfo, RunState};
use crsn::asm::data::literal::Value;
use crsn::runtime::fault::Fault;
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct StackOps { pub struct StackOps {
@ -54,7 +54,7 @@ impl CrsnExtension for StackOps {
})))) }))))
} }
fn drop_obj(&self, _ti: &ThreadInfo, state: &mut RunState, handle : Value) -> Result<Option<()>, Fault> fn drop_obj(&self, _ti: &ThreadInfo, state: &mut RunState, handle: Value) -> Result<Option<()>, Fault>
{ {
crate::exec::drop_stack(state, handle) crate::exec::drop_stack(state, handle)
} }

@ -1,16 +1,16 @@
#[macro_use] #[macro_use]
extern crate log; extern crate log;
use std::time::Duration;
use std::sync::Arc;
use simple_logger::SimpleLogger; use simple_logger::SimpleLogger;
use crsn::asm::data::literal::Addr; use crsn::asm::data::literal::Addr;
use crsn::runtime::run_thread::{RunThread, ThreadToken}; use crsn::runtime::run_thread::{RunThread, ThreadToken};
use crsn::runtime::run_thread;
use crsn_arith::ArithOps; use crsn_arith::ArithOps;
use crsn_stacks::StackOps; use crsn_stacks::StackOps;
use std::sync::atomic::AtomicU64;
use crsn::runtime::run_thread;
fn main() { fn main() {
SimpleLogger::new().init().unwrap(); SimpleLogger::new().init().unwrap();
@ -91,16 +91,16 @@ fn main() {
) )
"; ";
let parsers = Box::leak(Box::new(vec![ let parsers = Arc::new(vec![
ArithOps::new(), ArithOps::new(),
StackOps::new(), StackOps::new(),
])); ]);
let parsed = crsn::asm::assemble(program, parsers.as_slice()).unwrap(); let parsed = crsn::asm::assemble(program, parsers).unwrap();
let uniq = run_thread::new_uniq(); let uniq = run_thread::new_uniq();
let mut thread1 = RunThread::new(ThreadToken(0), Some(uniq), parsed.clone(), Addr(0), &[]); let thread1 = RunThread::new(ThreadToken(0), Some(uniq.clone()), parsed.clone(), Addr(0), &[]);
//thread1.set_speed(Duration::from_millis(250)); //thread1.set_speed(Duration::from_millis(250));
let _thread2 = RunThread::new(ThreadToken(1), Some(uniq), parsed.clone(), Addr(0), &[]); let _thread2 = RunThread::new(ThreadToken(1), Some(uniq), parsed.clone(), Addr(0), &[]);

Loading…
Cancel
Save