From 9e78ec9ef9a3d24bba76237f712c0d05bf2c3210 Mon Sep 17 00:00:00 2001 From: Jeong YunWon Date: Mon, 21 Sep 2020 06:07:20 +0900 Subject: [PATCH] Fix dis.dis to prints inner constant codes like CPython --- bytecode/src/bytecode.rs | 12 +++++++++++- compiler/src/compile.rs | 1 + vm/src/builtins.rs | 2 +- vm/src/stdlib/dis.rs | 2 +- 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/bytecode/src/bytecode.rs b/bytecode/src/bytecode.rs index a931e888c..74c8a0356 100644 --- a/bytecode/src/bytecode.rs +++ b/bytecode/src/bytecode.rs @@ -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(()) } } diff --git a/compiler/src/compile.rs b/compiler/src/compile.rs index a3b758443..05d077273 100644 --- a/compiler/src/compile.rs +++ b/compiler/src/compile.rs @@ -1188,6 +1188,7 @@ impl Compiler { } fn store_docstring(&mut self, doc_str: Option) { + // 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); diff --git a/vm/src/builtins.rs b/vm/src/builtins.rs index ea9791bf8..83159eab4 100644 --- a/vm/src/builtins.rs +++ b/vm/src/builtins.rs @@ -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(), )); } diff --git a/vm/src/stdlib/dis.rs b/vm/src/stdlib/dis.rs index d53eba879..53c6129a6 100644 --- a/vm/src/stdlib/dis.rs +++ b/vm/src/stdlib/dis.rs @@ -20,7 +20,7 @@ mod decl { vm.compile( co_str.borrow_value(), compile::Mode::Exec, - "".to_owned(), + "".to_owned(), ) .map_err(|err| vm.new_syntax_error(&err))? .into_object()