new_bigint returns PyIntRef

This commit is contained in:
Jeong YunWon
2021-10-10 22:21:00 +09:00
parent 741cfea565
commit c9216cbef4
4 changed files with 9 additions and 9 deletions

View File

@@ -106,7 +106,7 @@ impl ConstantBag for PyObjBag<'_> {
let vm = self.0;
let ctx = &vm.ctx;
let obj = match constant {
bytecode::BorrowedConstant::Integer { value } => ctx.new_bigint(value),
bytecode::BorrowedConstant::Integer { value } => ctx.new_bigint(value).into(),
bytecode::BorrowedConstant::Float { value } => ctx.new_float(value),
bytecode::BorrowedConstant::Complex { value } => ctx.new_complex(value),
bytecode::BorrowedConstant::Str { value } if value.len() <= 20 => {

View File

@@ -468,8 +468,8 @@ impl PyFloat {
}
let ratio = Ratio::from_float(value).unwrap();
let numer = vm.ctx.new_bigint(ratio.numer());
let denom = vm.ctx.new_bigint(ratio.denom());
let numer = vm.ctx.new_bigint(ratio.numer()).into();
let denom = vm.ctx.new_bigint(ratio.denom()).into();
Ok(vm.ctx.new_tuple(vec![numer, denom]))
}

View File

@@ -595,8 +595,8 @@ impl PyInt {
}
#[pymethod]
fn as_integer_ratio(&self, vm: &VirtualMachine) -> (PyObjectRef, BigInt) {
(vm.ctx.new_bigint(&self.value), BigInt::one())
fn as_integer_ratio(&self, vm: &VirtualMachine) -> (PyRef<Self>, i32) {
(vm.ctx.new_bigint(&self.value), 1)
}
#[pymethod]
@@ -688,7 +688,7 @@ impl PyInt {
Ok(bytes.into())
}
#[pyproperty]
fn real(&self, vm: &VirtualMachine) -> PyObjectRef {
fn real(&self, vm: &VirtualMachine) -> PyRef<Self> {
// subclasses must return int here
vm.ctx.new_bigint(&self.value)
}

View File

@@ -172,14 +172,14 @@ impl PyContext {
}
#[inline]
pub fn new_bigint(&self, i: &BigInt) -> PyObjectRef {
pub fn new_bigint(&self, i: &BigInt) -> PyIntRef {
if let Some(i) = i.to_i32() {
if i >= Self::INT_CACHE_POOL_MIN && i <= Self::INT_CACHE_POOL_MAX {
let inner_idx = (i - Self::INT_CACHE_POOL_MIN) as usize;
return self.int_cache_pool[inner_idx].as_object().clone();
return self.int_cache_pool[inner_idx].clone();
}
}
PyObject::new(PyInt::from(i.clone()), self.types.int_type.clone(), None)
PyRef::new_ref(PyInt::from(i.clone()), self.types.int_type.clone(), None)
}
pub fn new_float(&self, value: f64) -> PyObjectRef {