From b7a73fdc0ce772f2de9d92266ea8a5aa53b579ea Mon Sep 17 00:00:00 2001 From: Noah <33094578+coolreader18@users.noreply.github.com> Date: Fri, 30 Oct 2020 14:05:53 -0500 Subject: [PATCH] Capitalize boolean constants for dis --- bytecode/src/bytecode.rs | 25 +++---------------- ...hon_compiler__compile__tests__if_ands.snap | 6 ++--- ...on_compiler__compile__tests__if_mixed.snap | 8 +++--- ...thon_compiler__compile__tests__if_ors.snap | 6 ++--- 4 files changed, 14 insertions(+), 31 deletions(-) diff --git a/bytecode/src/bytecode.rs b/bytecode/src/bytecode.rs index 7fe640c1c..371165739 100644 --- a/bytecode/src/bytecode.rs +++ b/bytecode/src/bytecode.rs @@ -405,7 +405,9 @@ impl BorrowedConstant<'_, C> { BorrowedConstant::Integer { value } => write!(f, "{}", value), BorrowedConstant::Float { value } => write!(f, "{}", value), BorrowedConstant::Complex { value } => write!(f, "{}", value), - BorrowedConstant::Boolean { value } => write!(f, "{}", value), + BorrowedConstant::Boolean { value } => { + write!(f, "{}", if value { "True" } else { "False" }) + } BorrowedConstant::Str { value } => write!(f, "{:?}", value), BorrowedConstant::Bytes { value } => write!(f, "b{:?}", value.as_bstr()), BorrowedConstant::Code { code } => write!(f, "{:?}", code), @@ -800,26 +802,7 @@ impl Instruction { impl fmt::Display for ConstantData { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - match self { - ConstantData::Integer { value } => write!(f, "{}", value), - ConstantData::Float { value } => write!(f, "{}", value), - ConstantData::Complex { value } => write!(f, "{}", value), - ConstantData::Boolean { value } => write!(f, "{}", value), - ConstantData::Str { value } => write!(f, "{:?}", value), - ConstantData::Bytes { value } => write!(f, "{:?}", value), - ConstantData::Code { code } => write!(f, "{:?}", code), - ConstantData::Tuple { elements } => write!( - f, - "({})", - elements - .iter() - .map(|e| format!("{}", e)) - .collect::>() - .join(", ") - ), - ConstantData::None => write!(f, "None"), - ConstantData::Ellipsis => write!(f, "Ellipsis"), - } + self.borrow_constant().fmt_display(f) } } diff --git a/compiler/src/snapshots/rustpython_compiler__compile__tests__if_ands.snap b/compiler/src/snapshots/rustpython_compiler__compile__tests__if_ands.snap index 0d5953c28..d3344e3d7 100644 --- a/compiler/src/snapshots/rustpython_compiler__compile__tests__if_ands.snap +++ b/compiler/src/snapshots/rustpython_compiler__compile__tests__if_ands.snap @@ -2,11 +2,11 @@ source: compiler/src/compile.rs expression: "compile_exec(\"\\\nif True and False and False:\n pass\n\")" --- - 0 LoadConst (true) + 0 LoadConst (True) 1 JumpIfFalse (6) - 2 LoadConst (false) + 2 LoadConst (False) 3 JumpIfFalse (6) - 4 LoadConst (false) + 4 LoadConst (False) 5 JumpIfFalse (6) >> 6 LoadConst (None) 7 ReturnValue diff --git a/compiler/src/snapshots/rustpython_compiler__compile__tests__if_mixed.snap b/compiler/src/snapshots/rustpython_compiler__compile__tests__if_mixed.snap index 5476053b1..356067af4 100644 --- a/compiler/src/snapshots/rustpython_compiler__compile__tests__if_mixed.snap +++ b/compiler/src/snapshots/rustpython_compiler__compile__tests__if_mixed.snap @@ -2,13 +2,13 @@ source: compiler/src/compile.rs expression: "compile_exec(\"\\\nif (True and False) or (False and True):\n pass\n\")" --- - 0 LoadConst (true) + 0 LoadConst (True) 1 JumpIfFalse (4) - 2 LoadConst (false) + 2 LoadConst (False) 3 JumpIfTrue (8) - >> 4 LoadConst (false) + >> 4 LoadConst (False) 5 JumpIfFalse (8) - 6 LoadConst (true) + 6 LoadConst (True) 7 JumpIfFalse (8) >> 8 LoadConst (None) 9 ReturnValue diff --git a/compiler/src/snapshots/rustpython_compiler__compile__tests__if_ors.snap b/compiler/src/snapshots/rustpython_compiler__compile__tests__if_ors.snap index d2bc38502..4463c3bd0 100644 --- a/compiler/src/snapshots/rustpython_compiler__compile__tests__if_ors.snap +++ b/compiler/src/snapshots/rustpython_compiler__compile__tests__if_ors.snap @@ -2,11 +2,11 @@ source: compiler/src/compile.rs expression: "compile_exec(\"\\\nif True or False or False:\n pass\n\")" --- - 0 LoadConst (true) + 0 LoadConst (True) 1 JumpIfTrue (6) - 2 LoadConst (false) + 2 LoadConst (False) 3 JumpIfTrue (6) - 4 LoadConst (false) + 4 LoadConst (False) 5 JumpIfFalse (6) >> 6 LoadConst (None) 7 ReturnValue