forked from Rust-related/RustPython
vm.ctx.new_complex -> PyComplex::new_ref
This commit is contained in:
@@ -82,7 +82,7 @@ impl ConstantBag for PyObjBag<'_> {
|
||||
let obj = match constant {
|
||||
bytecode::ConstantData::Integer { value } => ctx.new_int(value).into(),
|
||||
bytecode::ConstantData::Float { value } => ctx.new_float(value).into(),
|
||||
bytecode::ConstantData::Complex { value } => ctx.new_complex(value),
|
||||
bytecode::ConstantData::Complex { value } => vm.new_pyobj(value),
|
||||
bytecode::ConstantData::Str { value } if value.len() <= 20 => {
|
||||
vm.intern_string(value).into()
|
||||
}
|
||||
@@ -108,7 +108,7 @@ impl ConstantBag for PyObjBag<'_> {
|
||||
let obj = match constant {
|
||||
bytecode::BorrowedConstant::Integer { value } => ctx.new_bigint(value).into(),
|
||||
bytecode::BorrowedConstant::Float { value } => ctx.new_float(value).into(),
|
||||
bytecode::BorrowedConstant::Complex { value } => ctx.new_complex(value),
|
||||
bytecode::BorrowedConstant::Complex { value } => vm.new_pyobj(value),
|
||||
bytecode::BorrowedConstant::Str { value } if value.len() <= 20 => {
|
||||
vm.intern_string(value).into()
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ impl PyValue for PyComplex {
|
||||
|
||||
impl IntoPyObject for Complex64 {
|
||||
fn into_pyobject(self, vm: &VirtualMachine) -> PyObjectRef {
|
||||
vm.ctx.new_complex(self)
|
||||
PyComplex::new_ref(self, &vm.ctx).into()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -186,12 +186,18 @@ impl SlotConstructor for PyComplex {
|
||||
}
|
||||
}
|
||||
|
||||
#[pyimpl(flags(BASETYPE), with(Comparable, Hashable, SlotConstructor))]
|
||||
impl PyComplex {
|
||||
pub fn new_ref(value: Complex64, ctx: &PyContext) -> PyRef<Self> {
|
||||
PyRef::new_ref(Self::from(value), ctx.types.complex_type.clone(), None)
|
||||
}
|
||||
|
||||
pub fn to_complex(&self) -> Complex64 {
|
||||
self.value
|
||||
}
|
||||
}
|
||||
|
||||
#[pyimpl(flags(BASETYPE), with(Comparable, Hashable, SlotConstructor))]
|
||||
impl PyComplex {
|
||||
#[pymethod(magic)]
|
||||
fn complex(zelf: PyRef<Self>, vm: &VirtualMachine) -> PyRef<PyComplex> {
|
||||
if zelf.is(&vm.ctx.types.complex_type) {
|
||||
|
||||
@@ -13,9 +13,8 @@ use crate::{
|
||||
namespace::PyNamespace,
|
||||
object, pystr,
|
||||
set::{self, PyFrozenSet},
|
||||
PyBaseExceptionRef, PyBoundMethod, PyComplex, PyDict, PyDictRef, PyEllipsis, PyFloat,
|
||||
PyInt, PyIntRef, PyList, PyNone, PyNotImplemented, PyStaticMethod, PyTuple, PyTupleRef,
|
||||
PyType, PyTypeRef,
|
||||
PyBaseExceptionRef, PyBoundMethod, PyDict, PyDictRef, PyEllipsis, PyFloat, PyInt, PyIntRef,
|
||||
PyList, PyNone, PyNotImplemented, PyStaticMethod, PyTuple, PyTupleRef, PyType, PyTypeRef,
|
||||
},
|
||||
dictdatatype::Dict,
|
||||
exceptions,
|
||||
@@ -26,7 +25,6 @@ use crate::{
|
||||
VirtualMachine,
|
||||
};
|
||||
use num_bigint::BigInt;
|
||||
use num_complex::Complex64;
|
||||
use num_traits::ToPrimitive;
|
||||
use std::any::Any;
|
||||
use std::collections::HashMap;
|
||||
@@ -186,14 +184,6 @@ impl PyContext {
|
||||
PyRef::new_ref(PyFloat::from(value), self.types.float_type.clone(), None)
|
||||
}
|
||||
|
||||
pub fn new_complex(&self, value: Complex64) -> PyObjectRef {
|
||||
PyObject::new(
|
||||
PyComplex::from(value),
|
||||
self.types.complex_type.clone(),
|
||||
None,
|
||||
)
|
||||
}
|
||||
|
||||
pub fn new_utf8_str<S>(&self, s: S) -> PyObjectRef
|
||||
where
|
||||
S: Into<pystr::PyStr>,
|
||||
|
||||
@@ -197,7 +197,7 @@ impl Node for ast::Constant {
|
||||
.new_tuple(t.into_iter().map(|c| c.ast_to_object(vm)).collect())
|
||||
.into(),
|
||||
ast::Constant::Float(f) => vm.ctx.new_float(f).into(),
|
||||
ast::Constant::Complex { real, imag } => vm.ctx.new_complex(Complex64::new(real, imag)),
|
||||
ast::Constant::Complex { real, imag } => vm.new_pyobj(Complex64::new(real, imag)),
|
||||
ast::Constant::Ellipsis => vm.ctx.ellipsis(),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user