From be1ee6697074ad38b26152aadf007e1997879ea6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Hru=C5=A1ka?= Date: Sat, 26 Sep 2020 23:08:04 +0200 Subject: [PATCH] make exec speed configurable --- crsn/src/runtime/exec.rs | 7 +------ crsn/src/runtime/run_thread.rs | 4 ++++ crsn_stacks/src/exec.rs | 4 ++++ launcher/src/main.rs | 16 +++++++++++++--- 4 files changed, 22 insertions(+), 9 deletions(-) diff --git a/crsn/src/runtime/exec.rs b/crsn/src/runtime/exec.rs index 5bb0e9b..07b681b 100644 --- a/crsn/src/runtime/exec.rs +++ b/crsn/src/runtime/exec.rs @@ -16,11 +16,6 @@ impl RunThread { trace!("### {:04} : {:?}", state.frame.pc.0, op); - /* Operations can be given different execution times when run in slow mode. */ - /* Presently, all that do anything use 1 cycle. */ - - let rv = op.execute(info, state); - trace!("-> {:?}", rv); - rv + op.execute(info, state) } } diff --git a/crsn/src/runtime/run_thread.rs b/crsn/src/runtime/run_thread.rs index be1e214..69b4758 100644 --- a/crsn/src/runtime/run_thread.rs +++ b/crsn/src/runtime/run_thread.rs @@ -63,6 +63,10 @@ impl RunThread { } } + pub fn set_speed(&mut self, cycle_time : Duration) { + self.info.cycle_time = cycle_time; + } + pub fn start(self) -> JoinHandle<()> { std::thread::spawn(move || { self.run(); diff --git a/crsn_stacks/src/exec.rs b/crsn_stacks/src/exec.rs index ee22509..88da5f7 100644 --- a/crsn_stacks/src/exec.rs +++ b/crsn_stacks/src/exec.rs @@ -48,6 +48,10 @@ impl OpTrait for StackOp { let obj: &mut Stacks = state.ext_mut(); let val = obj.stacks[stack_num as usize].pop_back(); + if obj.stacks[stack_num as usize].is_empty() { + state.frame.status.zero = true; + } + let val = match val { None => { state.frame.status.overflow = true; diff --git a/launcher/src/main.rs b/launcher/src/main.rs index c90dc72..805019f 100644 --- a/launcher/src/main.rs +++ b/launcher/src/main.rs @@ -8,6 +8,7 @@ use crsn::asm::data::literal::Addr; use crsn::runtime::run_thread::{RunThread, ThreadToken}; use crsn_arith::ArithOps; use crsn_stacks::StackOps; +use std::time::Duration; fn main() { SimpleLogger::new().init().unwrap(); @@ -71,12 +72,19 @@ fn main() { (main (push 0 10) (push 0 20) + (call emptystack 0) (push 0 30) (pop r0 0) (pop r0 0) (pop r0 0) (halt) ) + (emptystack + (:again) + (pop _ arg0 (z? (ret))) + (j :again) + (ret) + ) ) "; @@ -87,12 +95,14 @@ fn main() { let parsed = crsn::asm::assemble(program, parsers.as_slice()).unwrap(); - let thread1 = RunThread::new(ThreadToken(0), parsed.clone(), Addr(0), &[]); + let mut thread1 = RunThread::new(ThreadToken(0), parsed.clone(), Addr(0), &[]); + thread1.set_speed(Duration::from_millis(1000)); + let thread2 = RunThread::new(ThreadToken(1), parsed.clone(), Addr(0), &[]); let a = thread1.start(); - let b = thread2.start(); + //let b = thread2.start(); a.join().unwrap(); - b.join().unwrap(); + //b.join().unwrap(); }