From 8f28149f671cfeca329892089456f4e89687375a Mon Sep 17 00:00:00 2001 From: coolreader18 <33094578+coolreader18@users.noreply.github.com> Date: Wed, 7 Aug 2019 14:40:16 -0500 Subject: [PATCH] Address comments --- compiler/src/compile.rs | 11 +- compiler/src/lib.rs | 2 +- compiler/src/peephole.rs | 224 ++++++++++++++++++++++----------------- 3 files changed, 136 insertions(+), 101 deletions(-) diff --git a/compiler/src/compile.rs b/compiler/src/compile.rs index ef481df02..f89772ecf 100644 --- a/compiler/src/compile.rs +++ b/compiler/src/compile.rs @@ -1832,10 +1832,13 @@ impl Compiler { fn emit(&mut self, instruction: Instruction) { let location = compile_location(&self.current_source_location); // TODO: insert source filename + self.current_output().emit(instruction, location); + } + + fn current_output(&mut self) -> &mut O { self.output_stack .last_mut() - .unwrap() - .emit(instruction, location); + .expect("No OutputStream on stack") } // Generate a new label @@ -1847,7 +1850,7 @@ impl Compiler { // Assign current position the given label fn set_label(&mut self, label: Label) { - self.output_stack.last_mut().unwrap().set_label(label) + self.current_output().set_label(label) } fn set_source_location(&mut self, location: &ast::Location) { @@ -1867,7 +1870,7 @@ impl Compiler { } fn mark_generator(&mut self) { - self.output_stack.last_mut().unwrap().mark_generator(); + self.current_output().mark_generator(); } } diff --git a/compiler/src/lib.rs b/compiler/src/lib.rs index c2a0e54dc..9e18f1c26 100644 --- a/compiler/src/lib.rs +++ b/compiler/src/lib.rs @@ -8,6 +8,6 @@ extern crate log; pub mod compile; pub mod error; -pub mod output_stream; +pub(crate) mod output_stream; pub mod peephole; pub mod symboltable; diff --git a/compiler/src/peephole.rs b/compiler/src/peephole.rs index c0bc5a0b4..64c06b81b 100644 --- a/compiler/src/peephole.rs +++ b/compiler/src/peephole.rs @@ -5,7 +5,7 @@ use rustpython_bytecode::bytecode::{self, CodeObject, Instruction, Location}; const PEEPHOLE_BUFFER_SIZE: usize = 20; -struct InstructionMetadata { +pub struct InstructionMetadata { loc: Location, labels: Vec