cleanup. remove conditional jumps, replaced by condition embedded in the enum

This commit is contained in:
2020-10-04 23:30:11 +02:00
parent 810ed2dddc
commit 986f3be6a2
28 changed files with 172 additions and 181 deletions
+25 -2
View File
@@ -3,6 +3,7 @@ extern crate log;
use std::collections::HashMap;
use std::sync::Arc;
use std::time::Duration;
use clappconfig::{AppConfig, clap};
use clappconfig::clap::ArgMatches;
@@ -13,7 +14,6 @@ use crsn::runtime::run_thread::{RunThread, ThreadToken};
use crsn_arith::ArithOps;
use crsn_screen::ScreenOps;
use crsn_stacks::StackOps;
use std::time::Duration;
mod read_file;
mod serde_duration_millis;
@@ -30,7 +30,9 @@ struct Config {
log: LogConfig,
#[serde(skip)]
program_file: String,
#[serde(with="serde_duration_millis")]
#[serde(skip)]
asm_only: bool,
#[serde(with = "serde_duration_millis")]
cycle_time: Duration,
}
@@ -42,6 +44,7 @@ impl Default for Config {
modules: Default::default(),
},
program_file: "".to_string(),
asm_only: false,
cycle_time: Duration::default(),
}
}
@@ -69,6 +72,12 @@ impl AppConfig for Config {
.required_unless("default-config")
.takes_value(true),
)
.arg(
clap::Arg::with_name("asm-only")
.short("P")
.long("asm")
.help("Only assemble, do not run."),
)
.arg(
clap::Arg::with_name("cycle")
.long("cycle")
@@ -95,6 +104,7 @@ impl AppConfig for Config {
fn configure(mut self, clap: &ArgMatches) -> anyhow::Result<Self> {
self.program_file = clap.value_of("input").unwrap().to_string();
self.asm_only = clap.is_present("asm-only");
if let Some(c) = clap.value_of("cycle") {
self.cycle_time = Duration::from_millis(c.parse().unwrap());
}
@@ -118,6 +128,19 @@ fn main() -> anyhow::Result<()> {
let parsed = crsn::asm::assemble(&source, parsers)?;
if config.asm_only {
for (n, op) in parsed.ops.iter().enumerate() {
println!("{:04} : {:?}", n, op);
}
return Ok(());
} else {
trace!("--- Compiled program ---");
for (n, op) in parsed.ops.iter().enumerate() {
trace!("{:04} : {:?}", n, op);
}
trace!("------------------------");
}
info!("Start runtime");
let args = &[];
+2 -1
View File
@@ -1,6 +1,7 @@
use serde::{self, Deserialize, Deserializer, Serializer};
use std::time::Duration;
use serde::{self, Deserialize, Deserializer, Serializer};
pub fn serialize<S>(value: &Duration, se: S) -> Result<S::Ok, S::Error>
where
S: Serializer,