Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
remove unsed slots
  • Loading branch information
youknowone committed Dec 28, 2025
commit 112aff686eba11bc22712ad5e7ebbd617e6de81e
14 changes: 5 additions & 9 deletions crates/vm/src/builtins/bool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,10 @@ impl PyBool {
.and_then(|format_spec| format_spec.format_bool(new_bool))
.map_err(|err| err.into_pyexception(vm))
}
}

#[pymethod(name = "__ror__")]
#[pymethod]
fn __or__(lhs: PyObjectRef, rhs: PyObjectRef, vm: &VirtualMachine) -> PyObjectRef {
impl PyBool {
pub(crate) fn __or__(lhs: PyObjectRef, rhs: PyObjectRef, vm: &VirtualMachine) -> PyObjectRef {
if lhs.fast_isinstance(vm.ctx.types.bool_type)
&& rhs.fast_isinstance(vm.ctx.types.bool_type)
{
Expand All @@ -143,9 +143,7 @@ impl PyBool {
}
}

#[pymethod(name = "__rand__")]
#[pymethod]
fn __and__(lhs: PyObjectRef, rhs: PyObjectRef, vm: &VirtualMachine) -> PyObjectRef {
pub(crate) fn __and__(lhs: PyObjectRef, rhs: PyObjectRef, vm: &VirtualMachine) -> PyObjectRef {
if lhs.fast_isinstance(vm.ctx.types.bool_type)
&& rhs.fast_isinstance(vm.ctx.types.bool_type)
{
Expand All @@ -159,9 +157,7 @@ impl PyBool {
}
}

#[pymethod(name = "__rxor__")]
#[pymethod]
fn __xor__(lhs: PyObjectRef, rhs: PyObjectRef, vm: &VirtualMachine) -> PyObjectRef {
pub(crate) fn __xor__(lhs: PyObjectRef, rhs: PyObjectRef, vm: &VirtualMachine) -> PyObjectRef {
if lhs.fast_isinstance(vm.ctx.types.bool_type)
&& rhs.fast_isinstance(vm.ctx.types.bool_type)
{
Expand Down
122 changes: 0 additions & 122 deletions crates/vm/src/builtins/complex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,133 +264,11 @@ impl PyComplex {
self.value.im
}

#[pymethod]
fn __abs__(&self, vm: &VirtualMachine) -> PyResult<f64> {
let Complex64 { im, re } = self.value;
let is_finite = im.is_finite() && re.is_finite();
let abs_result = re.hypot(im);
if is_finite && abs_result.is_infinite() {
Err(vm.new_overflow_error("absolute value too large"))
} else {
Ok(abs_result)
}
}

#[inline]
fn op<F>(
&self,
other: PyObjectRef,
op: F,
vm: &VirtualMachine,
) -> PyResult<PyArithmeticValue<Complex64>>
where
F: Fn(Complex64, Complex64) -> PyResult<Complex64>,
{
to_op_complex(&other, vm)?.map_or_else(
|| Ok(NotImplemented),
|other| Ok(Implemented(op(self.value, other)?)),
)
}

#[pymethod(name = "__radd__")]
#[pymethod]
fn __add__(
&self,
other: PyObjectRef,
vm: &VirtualMachine,
) -> PyResult<PyArithmeticValue<Complex64>> {
self.op(other, |a, b| Ok(a + b), vm)
}

#[pymethod]
fn __sub__(
&self,
other: PyObjectRef,
vm: &VirtualMachine,
) -> PyResult<PyArithmeticValue<Complex64>> {
self.op(other, |a, b| Ok(a - b), vm)
}

#[pymethod]
fn __rsub__(
&self,
other: PyObjectRef,
vm: &VirtualMachine,
) -> PyResult<PyArithmeticValue<Complex64>> {
self.op(other, |a, b| Ok(b - a), vm)
}

#[pymethod]
fn conjugate(&self) -> Complex64 {
self.value.conj()
}

#[pymethod(name = "__rmul__")]
#[pymethod]
fn __mul__(
&self,
other: PyObjectRef,
vm: &VirtualMachine,
) -> PyResult<PyArithmeticValue<Complex64>> {
self.op(other, |a, b| Ok(a * b), vm)
}

#[pymethod]
fn __truediv__(
&self,
other: PyObjectRef,
vm: &VirtualMachine,
) -> PyResult<PyArithmeticValue<Complex64>> {
self.op(other, |a, b| inner_div(a, b, vm), vm)
}

#[pymethod]
fn __rtruediv__(
&self,
other: PyObjectRef,
vm: &VirtualMachine,
) -> PyResult<PyArithmeticValue<Complex64>> {
self.op(other, |a, b| inner_div(b, a, vm), vm)
}

#[pymethod]
const fn __pos__(&self) -> Complex64 {
self.value
}

#[pymethod]
fn __neg__(&self) -> Complex64 {
-self.value
}

#[pymethod]
fn __pow__(
&self,
other: PyObjectRef,
mod_val: OptionalOption<PyObjectRef>,
vm: &VirtualMachine,
) -> PyResult<PyArithmeticValue<Complex64>> {
if mod_val.flatten().is_some() {
Err(vm.new_value_error("complex modulo not allowed"))
} else {
self.op(other, |a, b| inner_pow(a, b, vm), vm)
}
}

#[pymethod]
fn __rpow__(
&self,
other: PyObjectRef,
vm: &VirtualMachine,
) -> PyResult<PyArithmeticValue<Complex64>> {
self.op(other, |a, b| inner_pow(b, a, vm), vm)
}

#[pymethod]
fn __bool__(&self) -> bool {
!Complex64::is_zero(&self.value)
}

#[pymethod]
const fn __getnewargs__(&self) -> (f64, f64) {
let Complex64 { re, im } = self.value;
Expand Down
186 changes: 0 additions & 186 deletions crates/vm/src/builtins/float.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,182 +238,6 @@ impl PyFloat {
.to_owned())
}

#[pymethod]
const fn __abs__(&self) -> f64 {
self.value.abs()
}

#[inline]
fn simple_op<F>(
&self,
other: PyObjectRef,
op: F,
vm: &VirtualMachine,
) -> PyResult<PyArithmeticValue<f64>>
where
F: Fn(f64, f64) -> PyResult<f64>,
{
to_op_float(&other, vm)?.map_or_else(
|| Ok(NotImplemented),
|other| Ok(Implemented(op(self.value, other)?)),
)
}

#[inline]
fn complex_op<F>(&self, other: PyObjectRef, op: F, vm: &VirtualMachine) -> PyResult
where
F: Fn(f64, f64) -> PyResult,
{
to_op_float(&other, vm)?.map_or_else(
|| Ok(vm.ctx.not_implemented()),
|other| op(self.value, other),
)
}

#[inline]
fn tuple_op<F>(
&self,
other: PyObjectRef,
op: F,
vm: &VirtualMachine,
) -> PyResult<PyArithmeticValue<(f64, f64)>>
where
F: Fn(f64, f64) -> PyResult<(f64, f64)>,
{
to_op_float(&other, vm)?.map_or_else(
|| Ok(NotImplemented),
|other| Ok(Implemented(op(self.value, other)?)),
)
}

#[pymethod(name = "__radd__")]
#[pymethod]
fn __add__(&self, other: PyObjectRef, vm: &VirtualMachine) -> PyResult<PyArithmeticValue<f64>> {
self.simple_op(other, |a, b| Ok(a + b), vm)
}

#[pymethod]
const fn __bool__(&self) -> bool {
self.value != 0.0
}

#[pymethod]
fn __divmod__(
&self,
other: PyObjectRef,
vm: &VirtualMachine,
) -> PyResult<PyArithmeticValue<(f64, f64)>> {
self.tuple_op(other, |a, b| inner_divmod(a, b, vm), vm)
}

#[pymethod]
fn __rdivmod__(
&self,
other: PyObjectRef,
vm: &VirtualMachine,
) -> PyResult<PyArithmeticValue<(f64, f64)>> {
self.tuple_op(other, |a, b| inner_divmod(b, a, vm), vm)
}

#[pymethod]
fn __floordiv__(
&self,
other: PyObjectRef,
vm: &VirtualMachine,
) -> PyResult<PyArithmeticValue<f64>> {
self.simple_op(other, |a, b| inner_floordiv(a, b, vm), vm)
}

#[pymethod]
fn __rfloordiv__(
&self,
other: PyObjectRef,
vm: &VirtualMachine,
) -> PyResult<PyArithmeticValue<f64>> {
self.simple_op(other, |a, b| inner_floordiv(b, a, vm), vm)
}

#[pymethod(name = "__mod__")]
fn mod_(&self, other: PyObjectRef, vm: &VirtualMachine) -> PyResult<PyArithmeticValue<f64>> {
self.simple_op(other, |a, b| inner_mod(a, b, vm), vm)
}

#[pymethod]
fn __rmod__(
&self,
other: PyObjectRef,
vm: &VirtualMachine,
) -> PyResult<PyArithmeticValue<f64>> {
self.simple_op(other, |a, b| inner_mod(b, a, vm), vm)
}

#[pymethod]
const fn __pos__(&self) -> f64 {
self.value
}

#[pymethod]
const fn __neg__(&self) -> f64 {
-self.value
}

#[pymethod]
fn __pow__(
&self,
other: PyObjectRef,
mod_val: OptionalOption<PyObjectRef>,
vm: &VirtualMachine,
) -> PyResult {
if mod_val.flatten().is_some() {
Err(vm.new_type_error("floating point pow() does not accept a 3rd argument"))
} else {
self.complex_op(other, |a, b| float_pow(a, b, vm), vm)
}
}

#[pymethod]
fn __rpow__(&self, other: PyObjectRef, vm: &VirtualMachine) -> PyResult {
self.complex_op(other, |a, b| float_pow(b, a, vm), vm)
}

#[pymethod]
fn __sub__(&self, other: PyObjectRef, vm: &VirtualMachine) -> PyResult<PyArithmeticValue<f64>> {
self.simple_op(other, |a, b| Ok(a - b), vm)
}

#[pymethod]
fn __rsub__(
&self,
other: PyObjectRef,
vm: &VirtualMachine,
) -> PyResult<PyArithmeticValue<f64>> {
self.simple_op(other, |a, b| Ok(b - a), vm)
}

#[pymethod]
fn __truediv__(
&self,
other: PyObjectRef,
vm: &VirtualMachine,
) -> PyResult<PyArithmeticValue<f64>> {
self.simple_op(other, |a, b| inner_div(a, b, vm), vm)
}

#[pymethod]
fn __rtruediv__(
&self,
other: PyObjectRef,
vm: &VirtualMachine,
) -> PyResult<PyArithmeticValue<f64>> {
self.simple_op(other, |a, b| inner_div(b, a, vm), vm)
}

#[pymethod(name = "__rmul__")]
#[pymethod]
fn __mul__(&self, other: PyObjectRef, vm: &VirtualMachine) -> PyResult<PyArithmeticValue<f64>> {
self.simple_op(other, |a, b| Ok(a * b), vm)
}

#[pymethod]
fn __trunc__(&self, vm: &VirtualMachine) -> PyResult<BigInt> {
try_to_bigint(self.value, vm)
Expand Down Expand Up @@ -459,16 +283,6 @@ impl PyFloat {
Ok(value)
}

#[pymethod]
fn __int__(&self, vm: &VirtualMachine) -> PyResult<BigInt> {
self.__trunc__(vm)
}

#[pymethod]
const fn __float__(zelf: PyRef<Self>) -> PyRef<Self> {
zelf
}

#[pygetset]
const fn real(zelf: PyRef<Self>) -> PyRef<Self> {
zelf
Expand Down
Loading
Loading