diff --git a/src/main.rs b/src/main.rs index b2e276b..d344c7f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -87,6 +87,10 @@ fn main () { match input.as_str ().trim_end () { "c" => in_break = false, "q" => return, + "registers" => { + dbg! (&vm.registers); + continue; + } "s" => { match vm.step () { None => (), diff --git a/src/state.rs b/src/state.rs index a125725..a334f4a 100644 --- a/src/state.rs +++ b/src/state.rs @@ -48,7 +48,7 @@ pub struct Breakpoint { #[derive (Debug)] pub struct State <'a> { - registers: Vec , + pub registers: Vec , // Currently only used for native function calls top: usize, pub stack: Vec , diff --git a/src/value.rs b/src/value.rs index 60eb2ef..b8257f2 100644 --- a/src/value.rs +++ b/src/value.rs @@ -15,7 +15,7 @@ pub struct BogusClosure { pub upvalues: Vec , } -#[derive (Clone, Debug, PartialEq)] +#[derive (Clone, PartialEq)] pub enum Value { Nil, Boolean (bool), @@ -35,6 +35,23 @@ pub enum Value { BogusClosure (Rc >), } +impl fmt::Debug for Value { + fn fmt (&self, f: &mut fmt::Formatter) -> fmt::Result { + match self { + Value::Nil => write! (f, "nil"), + Value::Boolean (false) => write! (f, "false"), + Value::Boolean (true) => write! (f, "true"), + Value::Float (x) => write! (f, "{:?}", x), + Value::Integer (x) => write! (f, "{}", x), + Value::RsFunc (x) => write! (f, "function: {:?}", x), + Value::String (s) => write! (f, "{}", s), + Value::Table (t) => write! (f, "{:?}", t.borrow ()), + + Value::BogusClosure (x) => write! (f, "{:?}", x.borrow ()), + } + } +} + impl Default for Value { fn default () -> Self { Self::Nil @@ -213,12 +230,20 @@ impl Value { } } -#[derive (Debug, Default, Eq, PartialEq)] +#[derive (Default, Eq, PartialEq)] pub struct Table { array: Vec , hash: HashMap , } +impl fmt::Debug for Table { + fn fmt (&self, f: &mut fmt::Formatter) -> fmt::Result { + write! (f, "Table {:#?}", self.hash)?; + + Ok (()) + } +} + impl Table { fn get_inner (&self, key: &Value) -> Value { self.hash.get (key).cloned ().unwrap_or_default ()