forked from Rust-related/RustPython
clean up new_code_object
This commit is contained in:
@@ -89,7 +89,7 @@ impl ConstantBag for PyObjBag<'_> {
|
||||
bytecode::ConstantData::Str { value } => vm.ctx.new_utf8_str(value),
|
||||
bytecode::ConstantData::Bytes { value } => ctx.new_bytes(value.to_vec()),
|
||||
bytecode::ConstantData::Boolean { value } => ctx.new_bool(value).into(),
|
||||
bytecode::ConstantData::Code { code } => ctx.new_code_object(code.map_bag(self)).into(),
|
||||
bytecode::ConstantData::Code { code } => vm.new_code_object(code.map_bag(self)).into(),
|
||||
bytecode::ConstantData::Tuple { elements } => {
|
||||
let elements = elements
|
||||
.into_iter()
|
||||
@@ -116,7 +116,7 @@ impl ConstantBag for PyObjBag<'_> {
|
||||
bytecode::BorrowedConstant::Bytes { value } => ctx.new_bytes(value.to_vec()),
|
||||
bytecode::BorrowedConstant::Boolean { value } => ctx.new_bool(value).into(),
|
||||
bytecode::BorrowedConstant::Code { code } => {
|
||||
ctx.new_code_object(code.map_clone_bag(self)).into()
|
||||
vm.new_code_object(code.map_clone_bag(self)).into()
|
||||
}
|
||||
bytecode::BorrowedConstant::Tuple { elements } => {
|
||||
let elements = elements
|
||||
@@ -171,6 +171,13 @@ impl PyCode {
|
||||
pub fn new(code: CodeObject) -> PyCode {
|
||||
PyCode { code }
|
||||
}
|
||||
|
||||
/// Create a new `PyRef<PyCode>` from a `code::CodeObject`. If you have a non-mapped codeobject or
|
||||
/// this is giving you a type error even though you've passed a `CodeObject`, try
|
||||
/// [`vm.new_code_object()`](VirtualMachine::new_code_object) instead.
|
||||
pub fn new_ref(code: CodeObject, ctx: &PyContext) -> PyRef<Self> {
|
||||
PyRef::new_ref(PyCode { code }, ctx.types.code_type.clone(), None)
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for PyCode {
|
||||
|
||||
@@ -8,7 +8,6 @@ use crate::{
|
||||
builtins::{
|
||||
builtinfunc::{PyBuiltinFunction, PyBuiltinMethod, PyNativeFuncDef},
|
||||
bytearray, bytes,
|
||||
code::{self, PyCode},
|
||||
getset::{IntoPyGetterFunc, IntoPySetterFunc, PyGetSet},
|
||||
object, pystr, PyBaseExceptionRef, PyBoundMethod, PyDict, PyDictRef, PyEllipsis, PyFloat,
|
||||
PyFrozenSet, PyInt, PyIntRef, PyList, PyNone, PyNotImplemented, PyStr, PyTuple, PyTupleRef,
|
||||
@@ -306,13 +305,6 @@ impl PyContext {
|
||||
)
|
||||
}
|
||||
|
||||
/// Create a new `PyRef<PyCode>` from a `code::CodeObject`. If you have a non-mapped codeobject or
|
||||
/// this is giving you a type error even though you've passed a `CodeObject`, try
|
||||
/// [`vm.new_code_object()`](VirtualMachine::new_code_object) instead.
|
||||
pub fn new_code_object(&self, code: code::CodeObject) -> PyRef<PyCode> {
|
||||
PyRef::new_ref(PyCode::new(code), self.types.code_type.clone(), None)
|
||||
}
|
||||
|
||||
pub fn new_base_object(&self, class: PyTypeRef, dict: Option<PyDictRef>) -> PyObjectRef {
|
||||
debug_assert_eq!(
|
||||
class.slots.flags.contains(PyTypeFlags::HAS_DICT),
|
||||
|
||||
@@ -579,7 +579,7 @@ impl VirtualMachine {
|
||||
}
|
||||
|
||||
pub fn new_code_object(&self, code: impl code::IntoCodeObject) -> PyRef<PyCode> {
|
||||
self.ctx.new_code_object(code.into_codeobj(self))
|
||||
PyCode::new_ref(code.into_codeobj(self), &self.ctx)
|
||||
}
|
||||
|
||||
pub fn new_module(&self, name: &str, dict: PyDictRef, doc: Option<&str>) -> PyObjectRef {
|
||||
|
||||
Reference in New Issue
Block a user