From c9216cbef4f133bc6f85f29423c1618296bcdf60 Mon Sep 17 00:00:00 2001 From: Jeong YunWon Date: Sun, 10 Oct 2021 22:21:00 +0900 Subject: [PATCH] new_bigint returns PyIntRef --- vm/src/builtins/code.rs | 2 +- vm/src/builtins/float.rs | 4 ++-- vm/src/builtins/int.rs | 6 +++--- vm/src/pyobject.rs | 6 +++--- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/vm/src/builtins/code.rs b/vm/src/builtins/code.rs index bbceba209..eda2bd1da 100644 --- a/vm/src/builtins/code.rs +++ b/vm/src/builtins/code.rs @@ -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 => { diff --git a/vm/src/builtins/float.rs b/vm/src/builtins/float.rs index 1adfde5a1..8c0eec325 100644 --- a/vm/src/builtins/float.rs +++ b/vm/src/builtins/float.rs @@ -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])) } diff --git a/vm/src/builtins/int.rs b/vm/src/builtins/int.rs index 14a789ddd..7d7459106 100644 --- a/vm/src/builtins/int.rs +++ b/vm/src/builtins/int.rs @@ -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, 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 { // subclasses must return int here vm.ctx.new_bigint(&self.value) } diff --git a/vm/src/pyobject.rs b/vm/src/pyobject.rs index 712dd46e8..7e9685d3a 100644 --- a/vm/src/pyobject.rs +++ b/vm/src/pyobject.rs @@ -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 {