mirror of
https://github.com/RustPython/Parser.git
synced 2025-07-22 04:25:25 +00:00
remove with_compiler
This commit is contained in:
parent
5e94f56ae4
commit
f97d1ed5d9
1 changed files with 7 additions and 16 deletions
|
@ -100,19 +100,6 @@ impl CompileContext {
|
|||
}
|
||||
}
|
||||
|
||||
/// A helper function for the shared code of the different compile functions
|
||||
fn with_compiler(
|
||||
source_path: String,
|
||||
opts: CompileOpts,
|
||||
f: impl FnOnce(&mut Compiler) -> CompileResult<()>,
|
||||
) -> CompileResult<CodeObject> {
|
||||
let mut compiler = Compiler::new(opts, source_path, "<module>".to_owned());
|
||||
f(&mut compiler)?;
|
||||
let code = compiler.pop_code_object();
|
||||
trace!("Compilation completed: {:?}", code);
|
||||
Ok(code)
|
||||
}
|
||||
|
||||
/// Compile an ast::Mod produced from rustpython_parser::parser::parse()
|
||||
pub fn compile_top(
|
||||
ast: &ast::Mod,
|
||||
|
@ -127,6 +114,7 @@ pub fn compile_top(
|
|||
}
|
||||
}
|
||||
|
||||
/// A helper function for the shared code of the different compile functions
|
||||
fn compile_impl<Ast: ?Sized>(
|
||||
ast: &Ast,
|
||||
source_path: String,
|
||||
|
@ -138,9 +126,12 @@ fn compile_impl<Ast: ?Sized>(
|
|||
Ok(x) => x,
|
||||
Err(e) => return Err(e.into_compile_error(source_path)),
|
||||
};
|
||||
with_compiler(source_path, opts, |compiler| {
|
||||
compile(compiler, ast, symbol_table)
|
||||
})
|
||||
|
||||
let mut compiler = Compiler::new(opts, source_path, "<module>".to_owned());
|
||||
compile(&mut compiler, ast, symbol_table)?;
|
||||
let code = compiler.pop_code_object();
|
||||
trace!("Compilation completed: {:?}", code);
|
||||
Ok(code)
|
||||
}
|
||||
|
||||
/// Compile a standard Python program to bytecode
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue