Implement debug stages as a HashSet of strings

Change to custom enum type later
This commit is contained in:
greg 2018-05-01 02:58:29 -07:00
parent 27885500fd
commit 061d54702f
2 changed files with 18 additions and 8 deletions

View File

@ -1,4 +1,4 @@
use std::collections::HashMap; use std::collections::{HashSet, HashMap};
use colored::*; use colored::*;
use std::fmt::Write; use std::fmt::Write;
@ -7,7 +7,8 @@ pub struct LLVMCodeString(pub String);
#[derive(Debug, Default, Serialize, Deserialize)] #[derive(Debug, Default, Serialize, Deserialize)]
pub struct EvalOptions { pub struct EvalOptions {
pub debug: DebugOptions, pub debug: DebugOptions,
pub execution_method: ExecutionMethod pub execution_method: ExecutionMethod,
pub debug_stages: HashSet<String>,
} }
#[derive(Debug, Serialize, Deserialize)] #[derive(Debug, Serialize, Deserialize)]
pub enum ExecutionMethod { pub enum ExecutionMethod {

View File

@ -294,14 +294,23 @@ impl Repl {
Some(&"stages") => Some(stages.into_iter().intersperse(format!(" -> ")).collect()), Some(&"stages") => Some(stages.into_iter().intersperse(format!(" -> ")).collect()),
b @ Some(&"show") | b @ Some(&"hide") => { b @ Some(&"show") | b @ Some(&"hide") => {
let show = b == Some(&"show"); let show = b == Some(&"show");
let debug_stage = match commands.get(2) { let debug_stage: String = match commands.get(2) {
Some(s) => s, Some(s) => s.to_string(),
None => return Some(format!("Must specify a stage to debug")), None => return Some(format!("Must specify a stage to debug")),
}; };
let maybe_debug = stages.iter().find(|stage_name| stage_name == debug_stage); let maybe_debug = stages.iter().find(|stage_name| **stage_name == debug_stage);
match maybe_debug { match (show, maybe_debug) {
Some(s) => Some(format!("Will debug {}", s)), (true, Some(s)) => {
None => Some(format!("couldn't find it")) let msg = format!("Enabling debug for stage {}", debug_stage);
self.options.debug_stages.insert(debug_stage);
Some(msg)
},
(false, Some(s)) => {
let msg = format!("Disabling debug for stage {}", debug_stage);
self.options.debug_stages.remove(&debug_stage);
Some(msg)
},
(_, None) => Some(format!("couldn't find it"))
} }
}, },
_ => Some(format!("Unknown debug command")) _ => Some(format!("Unknown debug command"))