Debug immediate working for symbol table
This commit is contained in:
parent
938c0401d1
commit
6c369b072f
@ -21,7 +21,10 @@ use std::cell::RefCell;
|
|||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use schala_repl::{ProgrammingLanguageInterface, ComputationRequest, ComputationResponse, LangMetaRequest, LangMetaResponse, GlobalOutputStats, DebugRequest, DebugResponse};
|
use schala_repl::{ProgrammingLanguageInterface,
|
||||||
|
ComputationRequest, ComputationResponse,
|
||||||
|
LangMetaRequest, LangMetaResponse, GlobalOutputStats,
|
||||||
|
DebugRequest, DebugResponse, DebugAsk};
|
||||||
|
|
||||||
macro_rules! bx {
|
macro_rules! bx {
|
||||||
($e:expr) => { Box::new($e) }
|
($e:expr) => { Box::new($e) }
|
||||||
@ -84,14 +87,25 @@ impl Schala {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn handle_debug_immediate(&self, request: DebugRequest) -> DebugResponse {
|
fn handle_debug_immediate(&self, request: DebugRequest) -> DebugResponse {
|
||||||
if request.kind == "symbol-table" {
|
use DebugAsk::*;
|
||||||
let debug = self.symbol_table.borrow().debug_symbol_table();
|
let ask = request.ask;
|
||||||
return DebugResponse { kind: format!("symbol-table"), value: debug };
|
match ask {
|
||||||
}
|
Timing => DebugResponse { ask: Timing, value: format!("Invalid") },
|
||||||
|
ByStage { stage_name } => match &stage_name[..] {
|
||||||
DebugResponse {
|
"symbol-table" => {
|
||||||
kind: format!("unknown"),
|
let value = self.symbol_table.borrow().debug_symbol_table();
|
||||||
value: format!(""),
|
DebugResponse {
|
||||||
|
ask: ByStage { stage_name: format!("symbol-table") },
|
||||||
|
value
|
||||||
|
}
|
||||||
|
},
|
||||||
|
s => {
|
||||||
|
DebugResponse {
|
||||||
|
ask: ByStage { stage_name: s.to_string() },
|
||||||
|
value: format!("Not-implemented")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -259,8 +273,8 @@ impl ProgrammingLanguageInterface for Schala {
|
|||||||
fn request_meta(&mut self, request: LangMetaRequest) -> LangMetaResponse {
|
fn request_meta(&mut self, request: LangMetaRequest) -> LangMetaResponse {
|
||||||
match request {
|
match request {
|
||||||
LangMetaRequest::StageNames => LangMetaResponse::StageNames(
|
LangMetaRequest::StageNames => LangMetaResponse::StageNames(
|
||||||
vec!["tokenizing".into(), "parsing".into(), "typechecking".into(),
|
vec!["tokenizing".into(), "parsing".into(), "typechecking".into(), "symbol-table".into(),
|
||||||
"ast reduction".into(), "ast-walking-evaluation".into()]
|
"ast-reduction".into(), "ast-walking-evaluation".into()]
|
||||||
),
|
),
|
||||||
LangMetaRequest::Docs { source } => self.handle_docs(source),
|
LangMetaRequest::Docs { source } => self.handle_docs(source),
|
||||||
LangMetaRequest::ImmediateDebug(debug_request) =>
|
LangMetaRequest::ImmediateDebug(debug_request) =>
|
||||||
|
@ -29,12 +29,17 @@ pub struct ComputationResponse {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub struct DebugRequest {
|
pub struct DebugRequest {
|
||||||
pub kind: String,
|
pub ask: DebugAsk,
|
||||||
pub value: String
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Hash, Eq, PartialEq)]
|
||||||
|
pub enum DebugAsk {
|
||||||
|
Timing,
|
||||||
|
ByStage { stage_name: String },
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct DebugResponse {
|
pub struct DebugResponse {
|
||||||
pub kind: String,
|
pub ask: DebugAsk,
|
||||||
pub value: String
|
pub value: String
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,7 +24,10 @@ mod repl;
|
|||||||
mod language;
|
mod language;
|
||||||
mod webapp;
|
mod webapp;
|
||||||
|
|
||||||
pub use language::{ProgrammingLanguageInterface, ComputationRequest, ComputationResponse, LangMetaRequest, LangMetaResponse, DebugRequest, DebugResponse, GlobalOutputStats};
|
pub use language::{ProgrammingLanguageInterface,
|
||||||
|
ComputationRequest, ComputationResponse,
|
||||||
|
LangMetaRequest, LangMetaResponse,
|
||||||
|
DebugRequest, DebugResponse, DebugAsk, GlobalOutputStats};
|
||||||
|
|
||||||
include!(concat!(env!("OUT_DIR"), "/static.rs"));
|
include!(concat!(env!("OUT_DIR"), "/static.rs"));
|
||||||
const VERSION_STRING: &'static str = "0.1.0";
|
const VERSION_STRING: &'static str = "0.1.0";
|
||||||
|
@ -2,10 +2,15 @@ use std::fmt::Write as FmtWrite;
|
|||||||
use std::io::{Read, Write};
|
use std::io::{Read, Write};
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
use std::collections::HashSet;
|
||||||
|
|
||||||
use colored::*;
|
use colored::*;
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use crate::language::{ProgrammingLanguageInterface, ComputationRequest, ComputationResponse, LangMetaRequest, LangMetaResponse, DebugRequest, DebugResponse};
|
use crate::language::{ProgrammingLanguageInterface,
|
||||||
|
ComputationRequest, ComputationResponse,
|
||||||
|
LangMetaRequest, LangMetaResponse,
|
||||||
|
DebugRequest, DebugAsk, DebugResponse};
|
||||||
|
|
||||||
mod command_tree;
|
mod command_tree;
|
||||||
use self::command_tree::{CommandTree, BoxedCommandFunction};
|
use self::command_tree::{CommandTree, BoxedCommandFunction};
|
||||||
|
|
||||||
@ -16,7 +21,7 @@ pub struct Repl {
|
|||||||
interpreter_directive_sigil: char,
|
interpreter_directive_sigil: char,
|
||||||
line_reader: ::linefeed::interface::Interface<::linefeed::terminal::DefaultTerminal>,
|
line_reader: ::linefeed::interface::Interface<::linefeed::terminal::DefaultTerminal>,
|
||||||
language_states: Vec<Box<ProgrammingLanguageInterface>>,
|
language_states: Vec<Box<ProgrammingLanguageInterface>>,
|
||||||
debug_asks: Vec<String>,
|
debug_asks: HashSet<DebugAsk>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Repl {
|
impl Repl {
|
||||||
@ -24,7 +29,7 @@ impl Repl {
|
|||||||
use linefeed::Interface;
|
use linefeed::Interface;
|
||||||
let line_reader = Interface::new("schala-repl").unwrap();
|
let line_reader = Interface::new("schala-repl").unwrap();
|
||||||
let interpreter_directive_sigil = ':';
|
let interpreter_directive_sigil = ':';
|
||||||
let debug_asks = vec![];
|
let debug_asks = HashSet::new();
|
||||||
|
|
||||||
Repl {
|
Repl {
|
||||||
interpreter_directive_sigil, line_reader, language_states: initial_states, debug_asks
|
interpreter_directive_sigil, line_reader, language_states: initial_states, debug_asks
|
||||||
@ -175,13 +180,18 @@ impl Repl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn handle_input(&mut self, input: &str) -> String {
|
fn handle_input(&mut self, input: &str) -> String {
|
||||||
let ref mut language_state = self.get_cur_language_state();
|
let mut debug_requests = vec![];
|
||||||
|
for ask in self.debug_asks.iter() {
|
||||||
|
debug_requests.push(DebugRequest { ask: ask.clone() });
|
||||||
|
}
|
||||||
|
|
||||||
let request = ComputationRequest {
|
let request = ComputationRequest {
|
||||||
source: input,
|
source: input,
|
||||||
debug_requests: vec![],
|
debug_requests,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let ref mut language_state = self.get_cur_language_state();
|
||||||
|
|
||||||
let ComputationResponse { main_output, global_output_stats, debug_responses }
|
let ComputationResponse { main_output, global_output_stats, debug_responses }
|
||||||
= language_state.run_computation(request);
|
= language_state.run_computation(request);
|
||||||
|
|
||||||
@ -245,20 +255,45 @@ impl Repl {
|
|||||||
let mut cur_state = repl.get_cur_language_state();
|
let mut cur_state = repl.get_cur_language_state();
|
||||||
match cmds.get(0) {
|
match cmds.get(0) {
|
||||||
Some(&"show-immediate") => {
|
Some(&"show-immediate") => {
|
||||||
let debug_stage = 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")),
|
||||||
};
|
};
|
||||||
let meta = LangMetaRequest::ImmediateDebug(DebugRequest {
|
let meta = LangMetaRequest::ImmediateDebug(
|
||||||
kind: debug_stage,
|
DebugRequest { ask: DebugAsk::ByStage { stage_name: stage_name.clone() } }
|
||||||
value: format!(""),
|
);
|
||||||
});
|
let response = match cur_state.request_meta(meta) {
|
||||||
let response = cur_state.request_meta(meta);
|
LangMetaResponse::ImmediateDebug(DebugResponse { ask, value }) => {
|
||||||
|
if (ask != DebugAsk::ByStage { stage_name: stage_name }) {
|
||||||
|
return Some(format!("Didn't get debug stage requested"));
|
||||||
|
}
|
||||||
|
value
|
||||||
|
},
|
||||||
|
_ => return Some(format!("Invalid language meta response")),
|
||||||
|
};
|
||||||
|
Some(response)
|
||||||
|
},
|
||||||
|
cmd @ Some(&"show") | cmd @ Some(&"hide") => {
|
||||||
|
let stage_name = match cmds.get(1) {
|
||||||
|
Some(s) => s.to_string(),
|
||||||
|
None => return Some(format!("Must specify a stage to show or hide")),
|
||||||
|
};
|
||||||
|
let ask = DebugAsk::ByStage { stage_name };
|
||||||
|
if cmd == Some(&"show") {
|
||||||
|
repl.debug_asks.insert(ask);
|
||||||
|
} else {
|
||||||
|
repl.debug_asks.remove(&ask);
|
||||||
|
}
|
||||||
|
None
|
||||||
|
},
|
||||||
|
Some(&"timing") => {
|
||||||
|
match cmds.get(1) {
|
||||||
|
Some(&"on") => repl.debug_asks.insert(DebugAsk::Timing),
|
||||||
|
Some(&"off") => repl.debug_asks.remove(&DebugAsk::Timing),
|
||||||
|
_ => return Some(format!("Must specify 'on' or 'off'")),
|
||||||
|
};
|
||||||
None
|
None
|
||||||
},
|
},
|
||||||
Some(&"show") => panic!(),
|
|
||||||
Some(&"hide") => panic!(),
|
|
||||||
Some(&"timing") => panic!(),
|
|
||||||
e => Some(format!("Unsupported command: {:?}", e)),
|
e => Some(format!("Unsupported command: {:?}", e)),
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user