Skip to content

Commit 2b28390

Browse files
committed
resume debug code object print at startup
Impl more detail debug message for pyobject kind
1 parent 000f889 commit 2b28390

2 files changed

Lines changed: 17 additions & 4 deletions

File tree

src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ fn run_script(script_file: &String) {
4747
match parser::read_file(filepath) {
4848
Ok(source) => {
4949
let code_obj = compile::compile(&mut vm, &source, compile::Mode::Exec).unwrap();
50-
debug!("Code object: {:?}", code_obj);
50+
debug!("Code object: {:?}", code_obj.borrow());
5151
let vars = vm.new_dict(); // Keep track of local variables
5252
vm.run_code_obj(code_obj, vars);
5353
}

vm/src/pyobject.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,6 @@ impl fmt::Debug for PyObject {
182182

183183
type RustPyFunc = fn(rt: &mut Executor, Vec<PyObjectRef>) -> PyResult;
184184

185-
// #[derive(Debug)]
186185
pub enum PyObjectKind {
187186
String {
188187
value: String,
@@ -241,8 +240,22 @@ pub enum PyObjectKind {
241240
impl fmt::Debug for PyObjectKind {
242241
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
243242
match self {
244-
&PyObjectKind::String { ref value } => write!(f, "str[{}]", value),
245-
_ => write!(f, "Some kind of python obj"),
243+
&PyObjectKind::String { ref value } => write!(f, "str \"{}\"", value),
244+
&PyObjectKind::Integer { ref value } => write!(f, "int {}", value),
245+
&PyObjectKind::Float { ref value } => write!(f, "float {}", value),
246+
&PyObjectKind::Boolean { ref value } => write!(f, "boolean {}", value),
247+
&PyObjectKind::List { ref elements } => write!(f, "list"),
248+
&PyObjectKind::Tuple { ref elements } => write!(f, "tuple"),
249+
&PyObjectKind::Dict { ref elements } => write!(f, "dict"),
250+
&PyObjectKind::Iterator { ref position, ref iterated_obj } => write!(f, "iterator"),
251+
&PyObjectKind::Slice { ref start, ref stop, ref step } => write!(f, "slice"),
252+
&PyObjectKind::NameError { ref name } => write!(f, "NameError"),
253+
&PyObjectKind::Code { ref code } => write!(f, "code: {:?}", code),
254+
&PyObjectKind::Function { ref code } => write!(f, "function"),
255+
&PyObjectKind::Module { ref name, ref dict } => write!(f, "module"),
256+
&PyObjectKind::None => write!(f, "None"),
257+
&PyObjectKind::Class { ref name } => write!(f, "class"),
258+
&PyObjectKind::RustFunction { ref function } => write!(f, "rust function"),
246259
}
247260
}
248261
}

0 commit comments

Comments
 (0)