MCPcopy Index your code
hub / github.com/RustPython/RustPython / compile

Function compile

crates/vm/src/stdlib/_ast.rs:749–780  ·  view source on GitHub ↗
(
    vm: &VirtualMachine,
    object: PyObjectRef,
    filename: &str,
    mode: crate::compiler::Mode,
    optimize: Option<u8>,
)

Source from the content-addressed store, hash-verified

747
748#[cfg(feature = "codegen")]
749pub(crate) fn compile(
750 vm: &VirtualMachine,
751 object: PyObjectRef,
752 filename: &str,
753 mode: crate::compiler::Mode,
754 optimize: Option<u8>,
755) -> PyResult {
756 let mut opts = vm.compile_opts();
757 if let Some(optimize) = optimize {
758 opts.optimize = optimize;
759 }
760
761 let source_file = SourceFileBuilder::new(filename.to_owned(), "".to_owned()).finish();
762 let ast: Mod = Node::ast_from_object(vm, &source_file, object)?;
763 validate::validate_mod(vm, &ast)?;
764 let ast = match ast {
765 Mod::Module(m) => ast::Mod::Module(m),
766 Mod::Interactive(ModInteractive { range, body }) => ast::Mod::Module(ast::ModModule {
767 node_index: Default::default(),
768 range,
769 body,
770 }),
771 Mod::Expression(e) => ast::Mod::Expression(e),
772 Mod::FunctionType(_) => todo!(),
773 };
774 // TODO: create a textual representation of the ast
775 let text = "";
776 let source_file = SourceFileBuilder::new(filename, text).finish();
777 let code = codegen::compile::compile_top(ast, source_file, mode, opts)
778 .map_err(|err| vm.new_syntax_error(&err.into(), None))?; // FIXME source
779 Ok(vm.ctx.new_code(code).into())
780}
781
782#[cfg(feature = "codegen")]
783pub(crate) fn validate_ast_object(vm: &VirtualMachine, object: PyObjectRef) -> PyResult<()> {

Callers 3

get_codeMethod · 0.50
__jit__Method · 0.50
compile_with_optsMethod · 0.50

Calls 10

newFunction · 0.85
ast_from_objectFunction · 0.85
validate_modFunction · 0.85
compile_topFunction · 0.85
compile_optsMethod · 0.80
new_syntax_errorMethod · 0.80
ModuleClass · 0.50
finishMethod · 0.45
to_ownedMethod · 0.45
new_codeMethod · 0.45

Tested by

no test coverage detected