(
vm: &VirtualMachine,
object: PyObjectRef,
filename: &str,
mode: crate::compiler::Mode,
optimize: Option<u8>,
)
| 747 | |
| 748 | #[cfg(feature = "codegen")] |
| 749 | pub(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")] |
| 783 | pub(crate) fn validate_ast_object(vm: &VirtualMachine, object: PyObjectRef) -> PyResult<()> { |
no test coverage detected