diff --git a/vm/src/vm/compile.rs b/vm/src/vm/compile.rs new file mode 100644 index 000000000..61c8ab762 --- /dev/null +++ b/vm/src/vm/compile.rs @@ -0,0 +1,35 @@ +use crate::{ + builtins::PyCode, + compile::{self, CompileError, CompileOpts}, + PyPayload, PyRef, VirtualMachine, +}; + +impl VirtualMachine { + /// Returns a basic CompileOpts instance with options accurate to the vm. Used + /// as the CompileOpts for `vm.compile()`. + pub fn compile_opts(&self) -> CompileOpts { + CompileOpts { + optimize: self.state.settings.optimize, + } + } + + pub fn compile( + &self, + source: &str, + mode: compile::Mode, + source_path: String, + ) -> Result, CompileError> { + self.compile_with_opts(source, mode, source_path, self.compile_opts()) + } + + pub fn compile_with_opts( + &self, + source: &str, + mode: compile::Mode, + source_path: String, + opts: CompileOpts, + ) -> Result, CompileError> { + compile::compile(source, mode, source_path, opts) + .map(|code| PyCode::new(self.map_codeobj(code)).into_ref(self)) + } +} diff --git a/vm/src/vm/mod.rs b/vm/src/vm/mod.rs index 0c9680030..42a6b74c9 100644 --- a/vm/src/vm/mod.rs +++ b/vm/src/vm/mod.rs @@ -4,7 +4,14 @@ //! #[cfg(feature = "rustpython-compiler")] -use crate::compile::{self, CompileError, CompileOpts}; +mod compile; +mod interpreter; +mod setting; +pub mod thread; +mod vm_new; +mod vm_object; +mod vm_ops; + use crate::{ builtins::{ code::{self, PyCode}, @@ -32,16 +39,8 @@ use std::{ collections::{HashMap, HashSet}, }; -mod interpreter; -mod setting; -pub mod thread; -mod vm_new; -mod vm_object; -mod vm_ops; - pub use interpreter::Interpreter; pub use setting::PySettings; -pub use thread::ThreadedVirtualMachine; // Objects are live when they are on stack, or referenced by a name (for now) @@ -719,34 +718,3 @@ impl VirtualMachine { object::generic_setattr(module, attr_name.into_pystr_ref(self), Some(val), self) } } - -#[cfg(feature = "rustpython-compiler")] -impl VirtualMachine { - /// Returns a basic CompileOpts instance with options accurate to the vm. Used - /// as the CompileOpts for `vm.compile()`. - pub fn compile_opts(&self) -> CompileOpts { - CompileOpts { - optimize: self.state.settings.optimize, - } - } - - pub fn compile( - &self, - source: &str, - mode: compile::Mode, - source_path: String, - ) -> Result, CompileError> { - self.compile_with_opts(source, mode, source_path, self.compile_opts()) - } - - pub fn compile_with_opts( - &self, - source: &str, - mode: compile::Mode, - source_path: String, - opts: CompileOpts, - ) -> Result, CompileError> { - compile::compile(source, mode, source_path, opts) - .map(|code| PyCode::new(self.map_codeobj(code)).into_ref(self)) - } -}