[rlox] Add trace to repl
This commit is contained in:
@@ -11,12 +11,15 @@ use vm::VM;
|
|||||||
fn repl() {
|
fn repl() {
|
||||||
let mut buffer = String::new();
|
let mut buffer = String::new();
|
||||||
|
|
||||||
|
let do_trace = env::var("LOX_TRACE").is_ok();
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
match io::stdin().read_line(&mut buffer) {
|
match io::stdin().read_line(&mut buffer) {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
let mut chunk = Chunk::new();
|
let mut chunk = Chunk::new();
|
||||||
lc::compile(buffer.as_str(), &mut chunk);
|
lc::compile(buffer.as_str(), &mut chunk);
|
||||||
let mut vm = VM::new();
|
let mut vm = VM::new();
|
||||||
|
vm.set_trace(do_trace);
|
||||||
let result = vm.run(&chunk);
|
let result = vm.run(&chunk);
|
||||||
println!("{:?}", result);
|
println!("{:?}", result);
|
||||||
buffer.clear();
|
buffer.clear();
|
||||||
|
|||||||
@@ -23,6 +23,10 @@ impl VM {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn set_trace(&mut self, trace: bool) {
|
||||||
|
self.trace = trace;
|
||||||
|
}
|
||||||
|
|
||||||
fn runtime_err(&self, msg: &'static str) -> VMError {
|
fn runtime_err(&self, msg: &'static str) -> VMError {
|
||||||
VMError::Runtime(msg.into(), self.pc)
|
VMError::Runtime(msg.into(), self.pc)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user