diff --git a/stdlib/Cargo.toml b/stdlib/Cargo.toml index e7b983f42..97a290711 100644 --- a/stdlib/Cargo.toml +++ b/stdlib/Cargo.toml @@ -19,7 +19,7 @@ ssl-vendor = ["ssl", "openssl/vendored", "openssl-probe"] [dependencies] # rustpython crates rustpython-derive = { workspace = true } -rustpython-vm = { workspace = true, features = ["compiler"] } +rustpython-vm = { workspace = true } rustpython-common = { workspace = true } ahash = { workspace = true } diff --git a/vm/src/compiler.rs b/vm/src/compiler.rs index 1e35d3b7a..c81475b6d 100644 --- a/vm/src/compiler.rs +++ b/vm/src/compiler.rs @@ -1,14 +1,14 @@ -use crate::{builtins::PyBaseExceptionRef, convert::ToPyException, VirtualMachine}; - #[cfg(feature = "rustpython-codegen")] pub use rustpython_codegen::CompileOpts; #[cfg(feature = "rustpython-compiler")] pub use rustpython_compiler::*; +#[cfg(not(feature = "rustpython-compiler"))] +pub use rustpython_compiler_core::Mode; #[cfg(not(feature = "rustpython-compiler"))] pub use rustpython_compiler_core as core; -#[cfg(all(not(feature = "rustpython-compiler"), feature = "rustpython-parser"))] +#[cfg(not(feature = "rustpython-compiler"))] pub use rustpython_parser_core as parser; #[cfg(not(feature = "rustpython-compiler"))] @@ -26,13 +26,14 @@ mod error { Parse(#[from] rustpython_parser::error::ParseErrorType), } - pub type CompileError = rustpython_compiler_core::CompileError; + pub type CompileError = rustpython_parser_core::source_code::LocatedError; } #[cfg(not(feature = "rustpython-compiler"))] pub use error::{CompileError, CompileErrorType}; -impl ToPyException for (CompileError, Option<&str>) { - fn to_pyexception(&self, vm: &VirtualMachine) -> PyBaseExceptionRef { +#[cfg(any(feature = "rustpython-parser", feature = "rustpython-codegen"))] +impl crate::convert::ToPyException for (CompileError, Option<&str>) { + fn to_pyexception(&self, vm: &crate::VirtualMachine) -> crate::builtins::PyBaseExceptionRef { vm.new_syntax_error(&self.0, self.1) } } diff --git a/vm/src/stdlib/builtins.rs b/vm/src/stdlib/builtins.rs index 4cc3a5363..fbe1170c0 100644 --- a/vm/src/stdlib/builtins.rs +++ b/vm/src/stdlib/builtins.rs @@ -17,7 +17,6 @@ mod builtins { PyByteArray, PyBytes, PyDictRef, PyStr, PyStrRef, PyTuple, PyTupleRef, PyType, }, common::{hash::PyHash, str::to_ascii}, - convert::ToPyException, function::{ ArgBytesLike, ArgCallable, ArgIndex, ArgIntoBool, ArgIterable, ArgMapping, ArgStrOrBytesLike, Either, FsPath, FuncArgs, KwArgs, OptionalArg, OptionalOption, @@ -147,7 +146,7 @@ mod builtins { } #[cfg(feature = "rustpython-parser")] { - use crate::builtins::PyBytesRef; + use crate::{builtins::PyBytesRef, convert::ToPyException}; use num_traits::Zero; use rustpython_parser as parser; diff --git a/vm/src/vm/vm_new.rs b/vm/src/vm/vm_new.rs index 9cf6931d9..922c137a0 100644 --- a/vm/src/vm/vm_new.rs +++ b/vm/src/vm/vm_new.rs @@ -8,8 +8,6 @@ use crate::{ convert::ToPyObject, function::{IntoPyNativeFn, PyMethodFlags}, scope::Scope, - source::AtLocation, - source_code::SourceLocation, vm::VirtualMachine, AsObject, Py, PyObject, PyObjectRef, PyRef, }; @@ -255,6 +253,9 @@ impl VirtualMachine { error: &crate::compiler::CompileError, source: Option<&str>, ) -> PyBaseExceptionRef { + use crate::source::AtLocation; + use crate::source_code::SourceLocation; + let syntax_error_type = match &error.error { #[cfg(feature = "rustpython-parser")] crate::compiler::CompileErrorType::Parse(p) if p.is_indentation_error() => {