From 3599cb46c48f07d29a54a5cc515979336f0a9fcc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Hru=C5=A1ka?= Date: Mon, 28 Sep 2020 20:12:31 +0200 Subject: [PATCH] cleanup, optimize. use Arc for reference sharing --- Cargo.lock | 108 +++++++++++++-------------- crsn/src/asm/data/mod.rs | 6 +- crsn/src/asm/data/rd.rs | 5 +- crsn/src/asm/data/wr.rs | 4 +- crsn/src/asm/instr/op.rs | 2 +- crsn/src/asm/mod.rs | 4 +- crsn/src/asm/parse/arg_parser.rs | 2 +- crsn/src/asm/parse/parse_data.rs | 2 +- crsn/src/builtin/defs.rs | 2 +- crsn/src/builtin/exec.rs | 6 +- crsn/src/builtin/parse.rs | 1 - crsn/src/module/mod.rs | 14 ++-- crsn/src/runtime/program.rs | 6 +- crsn/src/runtime/run_thread.rs | 26 +++---- crsn/src/runtime/run_thread/info.rs | 9 ++- crsn/src/runtime/run_thread/state.rs | 2 +- crsn_stacks/src/defs.rs | 2 +- crsn_stacks/src/exec.rs | 7 +- crsn_stacks/src/parse.rs | 8 +- launcher/src/main.rs | 14 ++-- 20 files changed, 111 insertions(+), 119 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f7f6015..380662f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -12,9 +12,9 @@ version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" dependencies = [ - "hermit-abi", - "libc", - "winapi", + "hermit-abi", + "libc", + "winapi", ] [[package]] @@ -35,9 +35,9 @@ version = "0.4.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "942f72db697d8767c22d46a598e01f2d3b475501ea43d0db4f16d90259182d0b" dependencies = [ - "num-integer", - "num-traits", - "time", + "num-integer", + "num-traits", + "time", ] [[package]] @@ -46,36 +46,36 @@ version = "1.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f4ffc801dacf156c5854b9df4f425a626539c3a6ef7893cc0c5084a23f0b6c59" dependencies = [ - "atty", - "lazy_static", - "winapi", + "atty", + "lazy_static", + "winapi", ] [[package]] name = "crsn" version = "0.1.0" dependencies = [ - "anyhow", - "dyn-clonable", - "log", - "num-traits", - "sexp", - "thiserror", + "anyhow", + "dyn-clonable", + "log", + "num-traits", + "sexp", + "thiserror", ] [[package]] name = "crsn_arith" version = "0.1.0" dependencies = [ - "crsn", - "num-traits", + "crsn", + "num-traits", ] [[package]] name = "crsn_stacks" version = "0.1.0" dependencies = [ - "crsn", + "crsn", ] [[package]] @@ -84,8 +84,8 @@ version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4e9232f0e607a262ceb9bd5141a3dfb3e4db6994b31989bbfd845878cba59fd4" dependencies = [ - "dyn-clonable-impl", - "dyn-clone", + "dyn-clonable-impl", + "dyn-clone", ] [[package]] @@ -94,9 +94,9 @@ version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "558e40ea573c374cf53507fd240b7ee2f5477df7cfebdb97323ec61c719399c5" dependencies = [ - "proc-macro2", - "quote", - "syn", + "proc-macro2", + "quote", + "syn", ] [[package]] @@ -111,20 +111,20 @@ version = "0.1.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4c30f6d0bc6b00693347368a67d41b58f2fb851215ff1da49e90fe2c5c667151" dependencies = [ - "libc", + "libc", ] [[package]] name = "launcher" version = "0.1.0" dependencies = [ - "anyhow", - "crsn", - "crsn_arith", - "crsn_stacks", - "log", - "simple_logger", - "thiserror", + "anyhow", + "crsn", + "crsn_arith", + "crsn_stacks", + "log", + "simple_logger", + "thiserror", ] [[package]] @@ -145,7 +145,7 @@ version = "0.4.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4fabed175da42fed1fa0746b0ea71f412aa9d35e76e95e59b192c64b9dc2bf8b" dependencies = [ - "cfg-if", + "cfg-if", ] [[package]] @@ -154,8 +154,8 @@ version = "0.1.43" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8d59457e662d541ba17869cf51cf177c0b5f0cbf476c66bdc90bf1edac4f875b" dependencies = [ - "autocfg", - "num-traits", + "autocfg", + "num-traits", ] [[package]] @@ -164,7 +164,7 @@ version = "0.2.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac267bcc07f48ee5f8935ab0d24f316fb722d7a1292e2913f0cc196b29ffd611" dependencies = [ - "autocfg", + "autocfg", ] [[package]] @@ -173,7 +173,7 @@ version = "1.0.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "36e28516df94f3dd551a587da5357459d9b36d945a7c37c3557928c1c2ff2a2c" dependencies = [ - "unicode-xid", + "unicode-xid", ] [[package]] @@ -182,7 +182,7 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "aa563d17ecb180e500da1cfd2b028310ac758de548efdd203e18f283af693f37" dependencies = [ - "proc-macro2", + "proc-macro2", ] [[package]] @@ -197,11 +197,11 @@ version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "13a53ed2efd04911c8280f2da7bf9abd350c931b86bc7f9f2386fbafbf525ff9" dependencies = [ - "atty", - "chrono", - "colored", - "log", - "winapi", + "atty", + "chrono", + "colored", + "log", + "winapi", ] [[package]] @@ -210,9 +210,9 @@ version = "1.0.41" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6690e3e9f692504b941dc6c3b188fd28df054f7fb8469ab40680df52fdcc842b" dependencies = [ - "proc-macro2", - "quote", - "unicode-xid", + "proc-macro2", + "quote", + "unicode-xid", ] [[package]] @@ -221,7 +221,7 @@ version = "1.0.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7dfdd070ccd8ccb78f4ad66bf1982dc37f620ef696c6b5028fe2ed83dd3d0d08" dependencies = [ - "thiserror-impl", + "thiserror-impl", ] [[package]] @@ -230,9 +230,9 @@ version = "1.0.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bd80fc12f73063ac132ac92aceea36734f04a1d93c1240c6944e23a3b8841793" dependencies = [ - "proc-macro2", - "quote", - "syn", + "proc-macro2", + "quote", + "syn", ] [[package]] @@ -241,9 +241,9 @@ version = "0.1.44" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255" dependencies = [ - "libc", - "wasi", - "winapi", + "libc", + "wasi", + "winapi", ] [[package]] @@ -264,8 +264,8 @@ version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", ] [[package]] diff --git a/crsn/src/asm/data/mod.rs b/crsn/src/asm/data/mod.rs index 1865e02..079c218 100644 --- a/crsn/src/asm/data/mod.rs +++ b/crsn/src/asm/data/mod.rs @@ -3,7 +3,10 @@ use std::fmt::{Debug, Display, Formatter}; use std::fmt; pub use mask::Mask; +pub use rd::Rd; +pub use rd::RdObj; pub use reg::Register; +pub use wr::Wr; use crate::asm::data::literal::{as_signed, Value}; @@ -14,11 +17,8 @@ pub mod reg; pub mod mask; mod rd; -pub use rd::Rd; -pub use rd::RdObj; mod wr; -pub use wr::Wr; /// Data source disposition #[derive(Debug, Clone, Copy, Eq, PartialEq)] diff --git a/crsn/src/asm/data/rd.rs b/crsn/src/asm/data/rd.rs index 525cfd2..8cd1568 100644 --- a/crsn/src/asm/data/rd.rs +++ b/crsn/src/asm/data/rd.rs @@ -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; +use crate::asm::data::{DataDisp, Mask, RdData, Register}; +use crate::asm::data::literal::Value; + /// Data source argument (read-only) #[derive(Clone, Copy, Eq, PartialEq)] pub struct Rd(pub RdData, pub Mask); diff --git a/crsn/src/asm/data/wr.rs b/crsn/src/asm/data/wr.rs index 9bac944..2b92530 100644 --- a/crsn/src/asm/data/wr.rs +++ b/crsn/src/asm/data/wr.rs @@ -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; +use crate::asm::data::{DataDisp, Mask, Rd, WrData}; + /// Data destination argument (read-write) #[derive(Clone, Copy, Eq, PartialEq)] pub struct Wr(WrData, Mask); diff --git a/crsn/src/asm/instr/op.rs b/crsn/src/asm/instr/op.rs index 4261280..a065720 100644 --- a/crsn/src/asm/instr/op.rs +++ b/crsn/src/asm/instr/op.rs @@ -3,7 +3,7 @@ use std::fmt::Debug; use crate::builtin::defs::BuiltinOp; use crate::module::{EvalRes, OpTrait}; 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 #[derive(Debug)] diff --git a/crsn/src/asm/mod.rs b/crsn/src/asm/mod.rs index 6229eca..f41c510 100644 --- a/crsn/src/asm/mod.rs +++ b/crsn/src/asm/mod.rs @@ -10,8 +10,8 @@ pub mod parse; pub mod patches; /// Parse a program from string and assemble a low level instruction sequence from it. -pub fn assemble(source: &str, parsers: &'static [Box]) -> Result, error::Error> { - let ops = parse::parse(source, parsers)?; +pub fn assemble(source: &str, parsers: Arc>>) -> Result, error::Error> { + let ops = parse::parse(source, &parsers)?; trace!("--- Compiled program ---"); for (n, op) in ops.iter().enumerate() { diff --git a/crsn/src/asm/parse/arg_parser.rs b/crsn/src/asm/parse/arg_parser.rs index c82f0e5..6baf957 100644 --- a/crsn/src/asm/parse/arg_parser.rs +++ b/crsn/src/asm/parse/arg_parser.rs @@ -1,6 +1,6 @@ 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::sexp_expect::expect_string_atom; diff --git a/crsn/src/asm/parse/parse_data.rs b/crsn/src/asm/parse/parse_data.rs index 414300a..0569f51 100644 --- a/crsn/src/asm/parse/parse_data.rs +++ b/crsn/src/asm/parse/parse_data.rs @@ -2,7 +2,7 @@ use std::convert::TryFrom; 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::error::Error; use crate::asm::parse::sexp_expect::expect_string_atom; diff --git a/crsn/src/builtin/defs.rs b/crsn/src/builtin/defs.rs index 289d29a..b74a6f9 100644 --- a/crsn/src/builtin/defs.rs +++ b/crsn/src/builtin/defs.rs @@ -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::instr::{Cond, Op}; diff --git a/crsn/src/builtin/exec.rs b/crsn/src/builtin/exec.rs index 63cf057..ba0fb6b 100644 --- a/crsn/src/builtin/exec.rs +++ b/crsn/src/builtin/exec.rs @@ -1,11 +1,11 @@ +use crate::asm::data::{Rd, RdData}; use crate::asm::data::literal::Addr; +use crate::asm::instr::Cond; use crate::builtin::defs::BuiltinOp; use crate::module::{EvalRes, OpTrait}; use crate::runtime::fault::Fault; use crate::runtime::frame::StackFrame; use crate::runtime::run_thread::{state::RunState, ThreadInfo}; -use crate::asm::data::{Rd, RdData}; -use crate::asm::instr::Cond; impl OpTrait for BuiltinOp { fn execute(&self, info: &ThreadInfo, state: &mut RunState) -> Result { @@ -142,7 +142,7 @@ impl OpTrait for BuiltinOp { trace!("Drop object: {:#x}", x); 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() { dropped = true; } diff --git a/crsn/src/builtin/parse.rs b/crsn/src/builtin/parse.rs index 7c098fb..e28f911 100644 --- a/crsn/src/builtin/parse.rs +++ b/crsn/src/builtin/parse.rs @@ -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::builtin::defs::BuiltinOp; use crate::module::{CrsnExtension, ParseOpRes}; -use crate::asm::data::RdObj; #[derive(Debug, Clone)] pub struct BuiltinOps { diff --git a/crsn/src/module/mod.rs b/crsn/src/module/mod.rs index c0f3599..a7abd66 100644 --- a/crsn/src/module/mod.rs +++ b/crsn/src/module/mod.rs @@ -2,14 +2,14 @@ use std::fmt::Debug; pub use eval_res::EvalRes; +use crate::asm::data::literal::Value; +use crate::asm::data::Mask; use crate::asm::error::Error; use crate::asm::instr::Op; use crate::asm::parse::arg_parser::ArgParser; use crate::runtime::fault::Fault; use crate::runtime::run_thread::state::RunState; use crate::runtime::run_thread::ThreadInfo; -use crate::asm::data::literal::Value; -use crate::asm::data::Mask; mod eval_res; @@ -40,7 +40,7 @@ pub trait CrsnExtension: Debug + Send + Sync + 'static { fn drop_obj(&self, #[allow(unused)] ti: &ThreadInfo, #[allow(unused)] state: &mut RunState, - #[allow(unused)] handle : Value) -> Result, Fault> + #[allow(unused)] handle: Value) -> Result, Fault> { // Default impl - we do not support dropping this object Ok(None) @@ -50,8 +50,8 @@ pub trait CrsnExtension: Debug + Send + Sync + 'static { fn read_obj(&self, #[allow(unused)] ti: &ThreadInfo, #[allow(unused)] state: &mut RunState, - #[allow(unused)] handle : Value, - #[allow(unused)] mask : Mask + #[allow(unused)] handle: Value, + #[allow(unused)] mask: Mask, ) -> Result, Fault> { // Default impl - we do not support reading this object Ok(None) @@ -61,8 +61,8 @@ pub trait CrsnExtension: Debug + Send + Sync + 'static { fn write_obj(&self, #[allow(unused)] ti: &ThreadInfo, #[allow(unused)] state: &mut RunState, - #[allow(unused)] handle : Value, - #[allow(unused)] mask : Mask + #[allow(unused)] handle: Value, + #[allow(unused)] mask: Mask, ) -> Result, Fault> { // Default impl - we do not support writing this object Ok(None) diff --git a/crsn/src/runtime/program.rs b/crsn/src/runtime/program.rs index f0424a8..af74057 100644 --- a/crsn/src/runtime/program.rs +++ b/crsn/src/runtime/program.rs @@ -4,20 +4,20 @@ use std::sync::Arc; use crate::asm::data::literal::{Addr, Label, RoutineName}; use crate::asm::instr::Op; use crate::builtin::defs::BuiltinOp; -use crate::runtime::fault::Fault; use crate::module::CrsnExtension; +use crate::runtime::fault::Fault; #[derive(Debug)] pub struct Program { pub ops: Vec, - pub extensions: &'static [Box], + pub extensions: Arc>>, routines: HashMap, far_labels: HashMap, barriers: Vec, } impl Program { - pub fn new(ops: Vec, extensions: &'static [Box]) -> Arc { + pub fn new(ops: Vec, extensions: Arc>>) -> Arc { let mut p = Self { ops, extensions, diff --git a/crsn/src/runtime/run_thread.rs b/crsn/src/runtime/run_thread.rs index 0f55f09..f26758a 100644 --- a/crsn/src/runtime/run_thread.rs +++ b/crsn/src/runtime/run_thread.rs @@ -1,14 +1,16 @@ use std::sync::Arc; -use std::sync::atomic::{AtomicU64, Ordering}; +use std::sync::atomic::AtomicU64; use std::thread::JoinHandle; 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::runtime::fault::Fault; use crate::runtime::frame::StackFrame; use crate::runtime::program::Program; -use crate::runtime::run_thread::info::{UNIQ_BASE}; #[derive(Clone, Copy, Eq, PartialEq, Debug, Ord, PartialOrd)] pub struct ThreadToken(pub u32); @@ -20,27 +22,17 @@ pub struct RunThread { pub mod info; pub mod state; -pub use info::ThreadInfo; -pub use state::RunState; -pub fn new_uniq() -> &'static AtomicU64 { - let uniq = AtomicU64::new(info::UNIQ_BASE); - Box::leak(Box::new(uniq)) +pub fn new_uniq() -> Arc { + Arc::new(AtomicU64::new(info::UNIQ_BASE)) } impl RunThread { - pub fn new(id: ThreadToken, uniq: Option<&'static AtomicU64>, program: Arc, 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 - }; - + pub fn new(id: ThreadToken, uniq: Option>, program: Arc, pc: Addr, args: &[u64]) -> Self { Self { info: ThreadInfo { id, - uniq, + uniq: uniq.unwrap_or_else(new_uniq), program, cycle_time: Duration::default(), }, diff --git a/crsn/src/runtime/run_thread/info.rs b/crsn/src/runtime/run_thread/info.rs index da5d9c4..c76cabe 100644 --- a/crsn/src/runtime/run_thread/info.rs +++ b/crsn/src/runtime/run_thread/info.rs @@ -1,15 +1,16 @@ -use crate::runtime::run_thread::ThreadToken; -use std::sync::atomic::{AtomicU64, Ordering}; use std::sync::Arc; -use crate::runtime::program::Program; +use std::sync::atomic::{AtomicU64, Ordering}; use std::time::Duration; + use crate::asm::data::literal::Value; +use crate::runtime::program::Program; +use crate::runtime::run_thread::ThreadToken; pub struct ThreadInfo { /// Thread ID pub id: ThreadToken, /// Thread ID - pub(crate) uniq: &'static AtomicU64, + pub(crate) uniq: Arc, /// Program to run pub program: Arc, /// Program to run diff --git a/crsn/src/runtime/run_thread/state.rs b/crsn/src/runtime/run_thread/state.rs index ccaed87..6369a91 100644 --- a/crsn/src/runtime/run_thread/state.rs +++ b/crsn/src/runtime/run_thread/state.rs @@ -1,7 +1,7 @@ use std::any::{Any, TypeId}; 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::instr::Cond; use crate::runtime::fault::Fault; diff --git a/crsn_stacks/src/defs.rs b/crsn_stacks/src/defs.rs index c78ba1d..c85ad4f 100644 --- a/crsn_stacks/src/defs.rs +++ b/crsn_stacks/src/defs.rs @@ -1,4 +1,4 @@ -use crsn::asm::data::{Rd, Wr, RdObj}; +use crsn::asm::data::{Rd, RdObj, Wr}; #[derive(Clone, Debug, Eq, PartialEq)] pub enum StackOp { diff --git a/crsn_stacks/src/exec.rs b/crsn_stacks/src/exec.rs index c6f14f2..bd4f8c9 100644 --- a/crsn_stacks/src/exec.rs +++ b/crsn_stacks/src/exec.rs @@ -1,13 +1,12 @@ -use std::collections::{VecDeque, HashMap}; +use std::collections::{HashMap, VecDeque}; use crsn::asm::data::literal::Value; 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::run_thread::{state::RunState, ThreadInfo}; use crate::defs::StackOp; -use crate::StackOps; #[derive(Debug, Default)] struct Stacks { @@ -68,7 +67,7 @@ impl OpTrait for StackOp { // } -pub(crate) fn drop_stack(state: &mut RunState, handle : Value) -> Result, Fault> { +pub(crate) fn drop_stack(state: &mut RunState, handle: Value) -> Result, Fault> { let stacks: &mut Stacks = state.ext_mut(); Ok(stacks.store.remove(&handle).map(|_| ())) } diff --git a/crsn_stacks/src/parse.rs b/crsn_stacks/src/parse.rs index dfedad0..3f028df 100644 --- a/crsn_stacks/src/parse.rs +++ b/crsn_stacks/src/parse.rs @@ -1,12 +1,12 @@ +use crsn::asm::data::literal::Value; use crsn::asm::error::Error; use crsn::asm::instr::Op; use crsn::asm::parse::arg_parser::ArgParser; use crsn::module::{CrsnExtension, ParseOpRes}; +use crsn::runtime::fault::Fault; +use crsn::runtime::run_thread::{RunState, ThreadInfo}; 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)] pub struct StackOps { @@ -54,7 +54,7 @@ impl CrsnExtension for StackOps { })))) } - fn drop_obj(&self, _ti: &ThreadInfo, state: &mut RunState, handle : Value) -> Result, Fault> + fn drop_obj(&self, _ti: &ThreadInfo, state: &mut RunState, handle: Value) -> Result, Fault> { crate::exec::drop_stack(state, handle) } diff --git a/launcher/src/main.rs b/launcher/src/main.rs index 883b055..30aa6f9 100644 --- a/launcher/src/main.rs +++ b/launcher/src/main.rs @@ -1,16 +1,16 @@ #[macro_use] extern crate log; -use std::time::Duration; + +use std::sync::Arc; use simple_logger::SimpleLogger; use crsn::asm::data::literal::Addr; use crsn::runtime::run_thread::{RunThread, ThreadToken}; +use crsn::runtime::run_thread; use crsn_arith::ArithOps; use crsn_stacks::StackOps; -use std::sync::atomic::AtomicU64; -use crsn::runtime::run_thread; fn main() { SimpleLogger::new().init().unwrap(); @@ -91,16 +91,16 @@ fn main() { ) "; - let parsers = Box::leak(Box::new(vec![ + let parsers = Arc::new(vec![ ArithOps::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 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)); let _thread2 = RunThread::new(ThreadToken(1), Some(uniq), parsed.clone(), Addr(0), &[]);