Some various work

This commit is contained in:
greg 2019-03-27 02:20:43 -07:00
parent a829fb6cd8
commit 938c0401d1
5 changed files with 52 additions and 14 deletions

View File

@ -21,7 +21,7 @@ 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}; use schala_repl::{ProgrammingLanguageInterface, ComputationRequest, ComputationResponse, LangMetaRequest, LangMetaResponse, GlobalOutputStats, DebugRequest, DebugResponse};
macro_rules! bx { macro_rules! bx {
($e:expr) => { Box::new($e) } ($e:expr) => { Box::new($e) }
@ -82,6 +82,18 @@ impl Schala {
s.run_computation(request); s.run_computation(request);
s s
} }
fn handle_debug_immediate(&self, request: DebugRequest) -> DebugResponse {
if request.kind == "symbol-table" {
let debug = self.symbol_table.borrow().debug_symbol_table();
return DebugResponse { kind: format!("symbol-table"), value: debug };
}
DebugResponse {
kind: format!("unknown"),
value: format!(""),
}
}
} }
fn tokenizing(input: &str, _handle: &mut Schala, comp: Option<&mut PassDebugArtifact>) -> Result<Vec<tokenizing::Token>, String> { fn tokenizing(input: &str, _handle: &mut Schala, comp: Option<&mut PassDebugArtifact>) -> Result<Vec<tokenizing::Token>, String> {
@ -251,6 +263,8 @@ impl ProgrammingLanguageInterface for Schala {
"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) =>
LangMetaResponse::ImmediateDebug(self.handle_debug_immediate(debug_request)),
LangMetaRequest::Custom { .. } => LangMetaResponse::Custom { kind: format!("not-implemented"), value: format!("") } LangMetaRequest::Custom { .. } => LangMetaResponse::Custom { kind: format!("not-implemented"), value: format!("") }
} }
} }

View File

@ -29,13 +29,13 @@ pub struct ComputationResponse {
} }
pub struct DebugRequest { pub struct DebugRequest {
kind: String, pub kind: String,
value: String pub value: String
} }
pub struct DebugResponse { pub struct DebugResponse {
kind: String, pub kind: String,
value: String pub value: String
} }
pub enum LangMetaRequest { pub enum LangMetaRequest {
@ -46,7 +46,8 @@ pub enum LangMetaRequest {
Custom { Custom {
kind: String, kind: String,
value: String value: String
} },
ImmediateDebug(DebugRequest),
} }
pub enum LangMetaResponse { pub enum LangMetaResponse {
@ -57,7 +58,8 @@ pub enum LangMetaResponse {
Custom { Custom {
kind: String, kind: String,
value: String value: String
} },
ImmediateDebug(DebugResponse),
} }
#[derive(Default, Debug)] #[derive(Default, Debug)]

View File

@ -24,7 +24,7 @@ mod repl;
mod language; mod language;
mod webapp; mod webapp;
pub use language::{ProgrammingLanguageInterface, ComputationRequest, ComputationResponse, LangMetaRequest, LangMetaResponse, GlobalOutputStats}; pub use language::{ProgrammingLanguageInterface, ComputationRequest, ComputationResponse, LangMetaRequest, LangMetaResponse, DebugRequest, DebugResponse, 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";

View File

@ -61,10 +61,11 @@ impl CommandTree {
} }
} }
pub fn get_children(&self) -> Vec<&str> { pub fn get_children(&self) -> Vec<&str> {
use CommandTree::*;
match self { match self {
CommandTree::Terminal { .. } => vec![], Terminal { children, .. } |
CommandTree::NonTerminal { children, .. } => children.iter().map(|x| x.get_cmd()).collect(), NonTerminal { children, .. } |
CommandTree::Top(children) => children.iter().map(|x| x.get_cmd()).collect(), Top(children) => children.iter().map(|x| x.get_cmd()).collect()
} }
} }
} }

View File

@ -5,7 +5,7 @@ use std::sync::Arc;
use colored::*; use colored::*;
use itertools::Itertools; use itertools::Itertools;
use crate::language::{ProgrammingLanguageInterface, ComputationRequest, ComputationResponse, LangMetaRequest, LangMetaResponse}; use crate::language::{ProgrammingLanguageInterface, ComputationRequest, ComputationResponse, LangMetaRequest, LangMetaResponse, DebugRequest, DebugResponse};
mod command_tree; mod command_tree;
use self::command_tree::{CommandTree, BoxedCommandFunction}; use self::command_tree::{CommandTree, BoxedCommandFunction};
@ -16,6 +16,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>,
} }
impl Repl { impl Repl {
@ -23,9 +24,10 @@ 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![];
Repl { Repl {
interpreter_directive_sigil, line_reader, language_states: initial_states, interpreter_directive_sigil, line_reader, language_states: initial_states, debug_asks
} }
} }
@ -231,6 +233,7 @@ impl Repl {
} }
Some(buf) Some(buf)
})), })),
CommandTree::nonterm("show-immediate", None, passes_directives.clone()),
CommandTree::nonterm("show", None, passes_directives.clone()), CommandTree::nonterm("show", None, passes_directives.clone()),
CommandTree::nonterm("hide", None, passes_directives.clone()), CommandTree::nonterm("hide", None, passes_directives.clone()),
CommandTree::nonterm("timing", None, vec![ CommandTree::nonterm("timing", None, vec![
@ -239,7 +242,25 @@ impl Repl {
]) ])
], ],
Box::new(|repl: &mut Repl, cmds: &[&str]| { Box::new(|repl: &mut Repl, cmds: &[&str]| {
Some(format!("Commands: {:?}", cmds)) let mut cur_state = repl.get_cur_language_state();
match cmds.get(0) {
Some(&"show-immediate") => {
let debug_stage = match cmds.get(1) {
Some(s) => s.to_string(),
None => return Some(format!("Must specify a thing to debug")),
};
let meta = LangMetaRequest::ImmediateDebug(DebugRequest {
kind: debug_stage,
value: format!(""),
});
let response = cur_state.request_meta(meta);
None
},
Some(&"show") => panic!(),
Some(&"hide") => panic!(),
Some(&"timing") => panic!(),
e => Some(format!("Unsupported command: {:?}", e)),
}
}) })
), ),
CommandTree::nonterm("lang", CommandTree::nonterm("lang",