Fix dis.dis to prints inner constant codes like CPython

This commit is contained in:
Jeong YunWon committed 2020-09-21 06:09:55 +09:00
1 parent 04e7b5ada4
commit 9e78ec9ef9
4 files changed
+14 -3

No files matched your search

+11 -1
View File
@@ -488,7 +488,17 @@ impl CodeObject {
impl fmt::Display for CodeObject {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
self.display_inner(f, false, 1)
self.display_inner(f, false, 1)?;
for constant in self.get_constants() {
match constant {
Constant::Code { code } => {
write!(f, "\nDisassembly of {}\n", constant)?;
code.fmt(f)?;
}
_ => continue,
}
}
Ok(())
}
}
+1
View File
@@ -1188,6 +1188,7 @@ impl<O: OutputStream> Compiler<O> {
}
fn store_docstring(&mut self, doc_str: Option<String>) {
// TODO: __doc__ must be default None and no bytecodes unless it is Some
// Duplicate top of stack (the function or class object)
self.emit(Instruction::Duplicate);
+1 -1
View File
@@ -831,7 +831,7 @@ mod decl {
} else if !objtype::issubclass(&metaclass, &base_class) {
return Err(vm.new_type_error(
"metaclass conflict: the metaclass of a derived class must be a (non-strict) \
subclass of the metaclasses of all its bases"
subclass of the metaclasses of all its bases"
.to_owned(),
));
}
+1 -1
View File
@@ -20,7 +20,7 @@ mod decl {
vm.compile(
co_str.borrow_value(),
compile::Mode::Exec,
"<string>".to_owned(),
"<dis>".to_owned(),
)
.map_err(|err| vm.new_syntax_error(&err))?
.into_object()