diff --git a/porcelain/src/lib.rs b/porcelain/src/lib.rs index c14c0ba..fcbcfa8 100644 --- a/porcelain/src/lib.rs +++ b/porcelain/src/lib.rs @@ -1,7 +1,9 @@ use rustpython_bytecode::CodeObject; use rustpython_compiler_core::{compile, symboltable}; -use rustpython_parser::ast::{fold::Fold, ConstantOptimizer, Location}; -use rustpython_parser::parser; +use rustpython_parser::{ + ast::{fold::Fold, ConstantOptimizer, Location}, + parser, +}; use std::fmt; pub use compile::{CompileOpts, Mode}; diff --git a/src/compile.rs b/src/compile.rs index 6e5cbfc..895e869 100644 --- a/src/compile.rs +++ b/src/compile.rs @@ -5,13 +5,11 @@ //! //! -use crate::ir::{self, CodeInfo}; -pub use crate::mode::Mode; -use crate::symboltable::{make_symbol_table, make_symbol_table_expr, SymbolScope, SymbolTable}; -use crate::IndexSet; use crate::{ error::{CompileError, CompileErrorType}, - symboltable, + ir, + symboltable::{self, make_symbol_table, make_symbol_table_expr, SymbolScope, SymbolTable}, + IndexSet, }; use itertools::Itertools; use num_complex::Complex64; @@ -20,6 +18,8 @@ use rustpython_ast as ast; use rustpython_bytecode::{self as bytecode, CodeObject, ConstantData, Instruction}; use std::borrow::Cow; +pub use crate::mode::Mode; + type CompileResult = Result; #[derive(PartialEq, Eq, Clone, Copy)] @@ -61,7 +61,7 @@ fn is_forbidden_name(name: &str) -> bool { /// Main structure holding the state of compilation. struct Compiler { - code_stack: Vec, + code_stack: Vec, symbol_table_stack: Vec, source_path: String, current_source_location: ast::Location, @@ -199,7 +199,7 @@ pub fn compile_expression( impl Compiler { fn new(opts: CompileOpts, source_path: String, code_name: String) -> Self { - let module_code = CodeInfo { + let module_code = ir::CodeInfo { flags: bytecode::CodeFlags::NEW_LOCALS, posonlyarg_count: 0, arg_count: 0, @@ -278,7 +278,7 @@ impl Compiler { self.symbol_table_stack.push(table); - let info = CodeInfo { + let info = ir::CodeInfo { flags, posonlyarg_count, arg_count, @@ -318,7 +318,7 @@ impl Compiler { fn _name_inner( &mut self, name: &str, - cache: impl FnOnce(&mut CodeInfo) -> &mut IndexSet, + cache: impl FnOnce(&mut ir::CodeInfo) -> &mut IndexSet, ) -> bytecode::NameIdx { let name = self.mangle(name); let cache = cache(self.current_codeinfo()); @@ -2583,7 +2583,7 @@ impl Compiler { self.emit(Instruction::LoadConst { idx }) } - fn current_codeinfo(&mut self) -> &mut CodeInfo { + fn current_codeinfo(&mut self) -> &mut ir::CodeInfo { self.code_stack.last_mut().expect("no code on stack") }