Fix commandtree debug processing
This commit is contained in:
parent
5cdc2f3d07
commit
bdee4fe7c6
@ -2,6 +2,8 @@ use super::Repl;
|
|||||||
|
|
||||||
pub type BoxedCommandFunction = Box<(fn(&mut Repl, &[&str]) -> Option<String>)>;
|
pub type BoxedCommandFunction = Box<(fn(&mut Repl, &[&str]) -> Option<String>)>;
|
||||||
|
|
||||||
|
/// A CommandTree is either a `Terminal` or a `NonTerminal`. When command parsing reaches the first
|
||||||
|
/// Terminal, it will execute the `BoxedCommandFunction` found there with any remaining arguments
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub enum CommandTree {
|
pub enum CommandTree {
|
||||||
Terminal {
|
Terminal {
|
||||||
@ -23,7 +25,7 @@ impl CommandTree {
|
|||||||
CommandTree::NonTerminal {name: s.to_string(), help_msg: help.map(|x| x.to_string()), children: vec![] }
|
CommandTree::NonTerminal {name: s.to_string(), help_msg: help.map(|x| x.to_string()), children: vec![] }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn term_with_function(s: &str, help: Option<&str>, children: Vec<CommandTree>, function: BoxedCommandFunction) -> CommandTree {
|
pub fn terminal(s: &str, help: Option<&str>, children: Vec<CommandTree>, function: BoxedCommandFunction) -> CommandTree {
|
||||||
CommandTree::Terminal {name: s.to_string(), help_msg: help.map(|x| x.to_string()), function, children }
|
CommandTree::Terminal {name: s.to_string(), help_msg: help.map(|x| x.to_string()), function, children }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -217,21 +217,21 @@ impl Repl {
|
|||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
CommandTree::Top(vec![
|
CommandTree::Top(vec![
|
||||||
CommandTree::term_with_function("exit", Some("exit the REPL"), vec![], Box::new(|repl: &mut Repl, _cmds: &[&str]| {
|
CommandTree::terminal("exit", Some("exit the REPL"), vec![], Box::new(|repl: &mut Repl, _cmds: &[&str]| {
|
||||||
repl.save_before_exit();
|
repl.save_before_exit();
|
||||||
::std::process::exit(0)
|
::std::process::exit(0)
|
||||||
})),
|
})),
|
||||||
CommandTree::term_with_function("quit", Some("exit the REPL"), vec![], Box::new(|repl: &mut Repl, _cmds: &[&str]| {
|
CommandTree::terminal("quit", Some("exit the REPL"), vec![], Box::new(|repl: &mut Repl, _cmds: &[&str]| {
|
||||||
repl.save_before_exit();
|
repl.save_before_exit();
|
||||||
::std::process::exit(0)
|
::std::process::exit(0)
|
||||||
})),
|
})),
|
||||||
CommandTree::term_with_function("help", Some("Print this help message"), vec![], Box::new(|repl: &mut Repl, cmds: &[&str]| {
|
CommandTree::terminal("help", Some("Print this help message"), vec![], Box::new(|repl: &mut Repl, cmds: &[&str]| {
|
||||||
Some(repl.print_help_message(cmds))
|
Some(repl.print_help_message(cmds))
|
||||||
})),
|
})),
|
||||||
CommandTree::term_with_function("debug",
|
CommandTree::nonterm("debug",
|
||||||
Some("Configure debug information"),
|
Some("Configure debug information"),
|
||||||
vec![
|
vec![
|
||||||
CommandTree::term_with_function("list-passes", Some("List all registered compiler passes"), vec![], Box::new(|repl: &mut Repl, _cmds: &[&str]| {
|
CommandTree::terminal("list-passes", Some("List all registered compiler passes"), vec![], Box::new(|repl: &mut Repl, _cmds: &[&str]| {
|
||||||
let language_state = repl.get_cur_language_state();
|
let language_state = repl.get_cur_language_state();
|
||||||
let pass_names = match language_state.request_meta(LangMetaRequest::StageNames) {
|
let pass_names = match language_state.request_meta(LangMetaRequest::StageNames) {
|
||||||
LangMetaResponse::StageNames(names) => names,
|
LangMetaResponse::StageNames(names) => names,
|
||||||
@ -247,24 +247,9 @@ impl Repl {
|
|||||||
}
|
}
|
||||||
Some(buf)
|
Some(buf)
|
||||||
})),
|
})),
|
||||||
CommandTree::nonterm("show-immediate", None, passes_directives.clone()),
|
CommandTree::terminal("show-immediate", None, passes_directives.clone(),
|
||||||
CommandTree::nonterm("show", None, passes_directives.clone()),
|
|
||||||
CommandTree::nonterm("hide", None, passes_directives.clone()),
|
|
||||||
CommandTree::nonterm("total-time", None, vec![
|
|
||||||
CommandTree::term_with_function("on", None, vec![], Box::new(|repl: &mut Repl, _: &[&str]| {
|
|
||||||
repl.options.show_total_time = true;
|
|
||||||
None
|
|
||||||
})),
|
|
||||||
CommandTree::term_with_function("off", None, vec![], Box::new(|repl: &mut Repl, _: &[&str]| {
|
|
||||||
repl.options.show_total_time = false;
|
|
||||||
None
|
|
||||||
})),
|
|
||||||
])
|
|
||||||
],
|
|
||||||
Box::new(|repl: &mut Repl, cmds: &[&str]| {
|
Box::new(|repl: &mut Repl, cmds: &[&str]| {
|
||||||
let cur_state = repl.get_cur_language_state();
|
let cur_state = repl.get_cur_language_state();
|
||||||
match cmds.get(0) {
|
|
||||||
Some(&"show-immediate") => {
|
|
||||||
let stage_name = match cmds.get(1) {
|
let stage_name = match cmds.get(1) {
|
||||||
Some(s) => s.to_string(),
|
Some(s) => s.to_string(),
|
||||||
None => return Some(format!("Must specify a thing to debug")),
|
None => return Some(format!("Must specify a thing to debug")),
|
||||||
@ -282,31 +267,36 @@ impl Repl {
|
|||||||
_ => return Some(format!("Invalid language meta response")),
|
_ => return Some(format!("Invalid language meta response")),
|
||||||
};
|
};
|
||||||
Some(response)
|
Some(response)
|
||||||
},
|
})),
|
||||||
cmd @ Some(&"show") | cmd @ Some(&"hide") => {
|
CommandTree::terminal("show", None, passes_directives.clone(), Box::new(|repl: &mut Repl, cmds: &[&str]| {
|
||||||
let stage_name = match cmds.get(1) {
|
let stage_name = match cmds.get(0) {
|
||||||
Some(s) => s.to_string(),
|
Some(s) => s.to_string(),
|
||||||
None => return Some(format!("Must specify a stage to show or hide")),
|
None => return Some(format!("Must specify a stage to show")),
|
||||||
};
|
};
|
||||||
let ask = DebugAsk::ByStage { stage_name };
|
let ask = DebugAsk::ByStage { stage_name };
|
||||||
if cmd == Some(&"show") {
|
|
||||||
repl.options.debug_asks.insert(ask);
|
repl.options.debug_asks.insert(ask);
|
||||||
} else {
|
|
||||||
repl.options.debug_asks.remove(&ask);
|
|
||||||
}
|
|
||||||
None
|
None
|
||||||
},
|
})),
|
||||||
Some(&"timing") => {
|
CommandTree::terminal("hide", None, passes_directives.clone(), Box::new(|repl: &mut Repl, cmds: &[&str]| {
|
||||||
match cmds.get(1) {
|
let stage_name = match cmds.get(0) {
|
||||||
Some(&"on") => repl.options.debug_asks.insert(DebugAsk::Timing),
|
Some(s) => s.to_string(),
|
||||||
Some(&"off") => repl.options.debug_asks.remove(&DebugAsk::Timing),
|
None => return Some(format!("Must specify a stage to hide")),
|
||||||
_ => return Some(format!("Must specify 'on' or 'off'")),
|
|
||||||
};
|
};
|
||||||
|
let ask = DebugAsk::ByStage { stage_name };
|
||||||
|
repl.options.debug_asks.remove(&ask);
|
||||||
None
|
None
|
||||||
},
|
})),
|
||||||
e => Some(format!("Unsupported command: {:?}", e)),
|
CommandTree::nonterm("total-time", None, vec![
|
||||||
}
|
CommandTree::terminal("on", None, vec![], Box::new(|repl: &mut Repl, _: &[&str]| {
|
||||||
})
|
repl.options.show_total_time = true;
|
||||||
|
None
|
||||||
|
})),
|
||||||
|
CommandTree::terminal("off", None, vec![], Box::new(|repl: &mut Repl, _: &[&str]| {
|
||||||
|
repl.options.show_total_time = false;
|
||||||
|
None
|
||||||
|
})),
|
||||||
|
])
|
||||||
|
]
|
||||||
),
|
),
|
||||||
CommandTree::nonterm("lang",
|
CommandTree::nonterm("lang",
|
||||||
Some("switch between languages, or go directly to a langauge by name"),
|
Some("switch between languages, or go directly to a langauge by name"),
|
||||||
@ -316,7 +306,7 @@ impl Repl {
|
|||||||
CommandTree::nonterm("go", None, vec![]),
|
CommandTree::nonterm("go", None, vec![]),
|
||||||
]
|
]
|
||||||
),
|
),
|
||||||
CommandTree::term_with_function("doc", Some("Get language-specific help for an item"), vec![], Box::new(|repl: &mut Repl, cmds: &[&str]| {
|
CommandTree::terminal("doc", Some("Get language-specific help for an item"), vec![], Box::new(|repl: &mut Repl, cmds: &[&str]| {
|
||||||
cmds.get(0).map(|cmd| {
|
cmds.get(0).map(|cmd| {
|
||||||
let source = cmd.to_string();
|
let source = cmd.to_string();
|
||||||
let meta = LangMetaRequest::Docs { source };
|
let meta = LangMetaRequest::Docs { source };
|
||||||
|
Loading…
Reference in New Issue
Block a user