From 061d54702fc9c9b9107ec8bd05eedeb8d291e049 Mon Sep 17 00:00:00 2001 From: greg Date: Tue, 1 May 2018 02:58:29 -0700 Subject: [PATCH] Implement debug stages as a HashSet of strings Change to custom enum type later --- schala-repl/src/language.rs | 5 +++-- schala-repl/src/lib.rs | 21 +++++++++++++++------ 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/schala-repl/src/language.rs b/schala-repl/src/language.rs index 4bb57a0..4187160 100644 --- a/schala-repl/src/language.rs +++ b/schala-repl/src/language.rs @@ -1,4 +1,4 @@ -use std::collections::HashMap; +use std::collections::{HashSet, HashMap}; use colored::*; use std::fmt::Write; @@ -7,7 +7,8 @@ pub struct LLVMCodeString(pub String); #[derive(Debug, Default, Serialize, Deserialize)] pub struct EvalOptions { pub debug: DebugOptions, - pub execution_method: ExecutionMethod + pub execution_method: ExecutionMethod, + pub debug_stages: HashSet, } #[derive(Debug, Serialize, Deserialize)] pub enum ExecutionMethod { diff --git a/schala-repl/src/lib.rs b/schala-repl/src/lib.rs index 52dcd4d..7cfb8b4 100644 --- a/schala-repl/src/lib.rs +++ b/schala-repl/src/lib.rs @@ -294,14 +294,23 @@ impl Repl { Some(&"stages") => Some(stages.into_iter().intersperse(format!(" -> ")).collect()), b @ Some(&"show") | b @ Some(&"hide") => { let show = b == Some(&"show"); - let debug_stage = match commands.get(2) { - Some(s) => s, + let debug_stage: String = match commands.get(2) { + Some(s) => s.to_string(), None => return Some(format!("Must specify a stage to debug")), }; - let maybe_debug = stages.iter().find(|stage_name| stage_name == debug_stage); - match maybe_debug { - Some(s) => Some(format!("Will debug {}", s)), - None => Some(format!("couldn't find it")) + let maybe_debug = stages.iter().find(|stage_name| **stage_name == debug_stage); + match (show, maybe_debug) { + (true, Some(s)) => { + 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"))