diff --git a/vm/src/builtins.rs b/vm/src/builtins.rs index 72891812c..bfa1a01f4 100644 --- a/vm/src/builtins.rs +++ b/vm/src/builtins.rs @@ -87,7 +87,7 @@ pub fn to_ascii(value: &str) -> String { ascii } -fn builtin_bin(x: PyIntRef, _vm: &VirtualMachine) -> String { +fn builtin_bin(x: PyIntRef) -> String { let x = x.as_bigint(); if x.is_negative() { format!("-0b{:b}", x.abs()) @@ -343,7 +343,7 @@ fn builtin_hex(number: PyIntRef, vm: &VirtualMachine) -> PyResult { Ok(vm.new_str(s)) } -fn builtin_id(obj: PyObjectRef, _vm: &VirtualMachine) -> usize { +fn builtin_id(obj: PyObjectRef) -> usize { obj.get_id() } @@ -391,7 +391,7 @@ fn builtin_len(obj: PyObjectRef, vm: &VirtualMachine) -> PyResult { fn builtin_locals(vm: &VirtualMachine) -> PyDictRef { let locals = vm.get_locals(); - locals.copy(vm).into_ref(vm) + locals.copy().into_ref(vm) } fn builtin_max(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult { diff --git a/vm/src/exceptions.rs b/vm/src/exceptions.rs index 305483ec4..3d30a86e4 100644 --- a/vm/src/exceptions.rs +++ b/vm/src/exceptions.rs @@ -67,8 +67,8 @@ impl PyBaseException { Ok(()) } - #[pyproperty(name = "args")] - fn get_args(&self, _vm: &VirtualMachine) -> PyTupleRef { + #[pyproperty] + pub fn args(&self) -> PyTupleRef { self.args.borrow().clone() } @@ -80,7 +80,7 @@ impl PyBaseException { } #[pyproperty(name = "__traceback__")] - fn get_traceback(&self) -> Option { + pub fn traceback(&self) -> Option { self.traceback.borrow().clone() } @@ -90,51 +90,37 @@ impl PyBaseException { } #[pyproperty(name = "__cause__")] - fn get_cause(&self, _vm: &VirtualMachine) -> Option { + pub fn cause(&self) -> Option { self.cause.borrow().clone() } #[pyproperty(name = "__cause__", setter)] - fn setter_cause( - &self, - cause: Option, - _vm: &VirtualMachine, - ) -> PyResult<()> { + pub fn set_cause(&self, cause: Option) { self.cause.replace(cause); - Ok(()) } #[pyproperty(name = "__context__")] - fn get_context(&self, _vm: &VirtualMachine) -> Option { + pub fn context(&self) -> Option { self.context.borrow().clone() } #[pyproperty(name = "__context__", setter)] - fn setter_context( - &self, - context: Option, - _vm: &VirtualMachine, - ) -> PyResult<()> { + pub fn set_context(&self, context: Option) { self.context.replace(context); - Ok(()) } #[pyproperty(name = "__suppress_context__")] - fn get_suppress_context(&self, _vm: &VirtualMachine) -> bool { + fn get_suppress_context(&self) -> bool { self.suppress_context.get() } #[pyproperty(name = "__suppress_context__", setter)] - fn set_suppress_context(&self, suppress_context: bool, _vm: &VirtualMachine) { + fn set_suppress_context(&self, suppress_context: bool) { self.suppress_context.set(suppress_context); } #[pymethod] - fn with_traceback( - zelf: PyRef, - tb: Option, - _vm: &VirtualMachine, - ) -> PyResult { + fn with_traceback(zelf: PyRef, tb: Option) -> PyResult { zelf.traceback.replace(tb); Ok(zelf.as_object().clone()) } @@ -158,28 +144,6 @@ impl PyBaseException { Err(i) => format!("{}({})", cls.name, i.format(", ")), } } - - pub fn args(&self) -> PyTupleRef { - self.args.borrow().clone() - } - - pub fn traceback(&self) -> Option { - self.traceback.borrow().clone() - } - - pub fn cause(&self) -> Option { - self.cause.borrow().clone() - } - pub fn set_cause(&self, cause: Option) { - self.cause.replace(cause); - } - - pub fn context(&self) -> Option { - self.context.borrow().clone() - } - pub fn set_context(&self, context: Option) { - self.context.replace(context); - } } /// Print exception chain diff --git a/vm/src/frame.rs b/vm/src/frame.rs index 4466bc881..61b4abe12 100644 --- a/vm/src/frame.rs +++ b/vm/src/frame.rs @@ -337,7 +337,7 @@ impl Frame { bytecode::Instruction::ListAppend { i } => { let list_obj = self.nth_value(*i); let item = self.pop_value(); - objlist::PyListRef::try_from_object(vm, list_obj)?.append(item, vm); + objlist::PyListRef::try_from_object(vm, list_obj)?.append(item); Ok(None) } bytecode::Instruction::SetAdd { i } => { diff --git a/vm/src/obj/objbool.rs b/vm/src/obj/objbool.rs index 264d30599..1cd91e9b9 100644 --- a/vm/src/obj/objbool.rs +++ b/vm/src/obj/objbool.rs @@ -118,7 +118,7 @@ pub fn get_py_int(obj: &PyObjectRef) -> &PyInt { &obj.payload::().unwrap() } -fn bool_repr(obj: bool, _vm: &VirtualMachine) -> String { +fn bool_repr(obj: bool) -> String { if obj { "True".to_owned() } else { diff --git a/vm/src/obj/objbytearray.rs b/vm/src/obj/objbytearray.rs index 73e5d9d5d..440749730 100644 --- a/vm/src/obj/objbytearray.rs +++ b/vm/src/obj/objbytearray.rs @@ -99,17 +99,17 @@ impl PyByteArray { } #[pymethod(name = "__repr__")] - fn repr(&self, _vm: &VirtualMachine) -> PyResult { + fn repr(&self) -> PyResult { Ok(format!("bytearray(b'{}')", self.inner.borrow().repr()?)) } #[pymethod(name = "__len__")] - fn len(&self, _vm: &VirtualMachine) -> usize { + fn len(&self) -> usize { self.inner.borrow().len() } #[pymethod(name = "__sizeof__")] - fn sizeof(&self, _vm: &VirtualMachine) -> usize { + fn sizeof(&self) -> usize { size_of::() + self.inner.borrow().len() * size_of::() } @@ -144,7 +144,7 @@ impl PyByteArray { } #[pymethod(name = "__iter__")] - fn iter(zelf: PyRef, _vm: &VirtualMachine) -> PyByteArrayIterator { + fn iter(zelf: PyRef) -> PyByteArrayIterator { PyByteArrayIterator { position: Cell::new(0), bytearray: zelf, @@ -190,67 +190,67 @@ impl PyByteArray { } #[pymethod(name = "isalnum")] - fn isalnum(&self, _vm: &VirtualMachine) -> bool { + fn isalnum(&self) -> bool { self.inner.borrow().isalnum() } #[pymethod(name = "isalpha")] - fn isalpha(&self, _vm: &VirtualMachine) -> bool { + fn isalpha(&self) -> bool { self.inner.borrow().isalpha() } #[pymethod(name = "isascii")] - fn isascii(&self, _vm: &VirtualMachine) -> bool { + fn isascii(&self) -> bool { self.inner.borrow().isascii() } #[pymethod(name = "isdigit")] - fn isdigit(&self, _vm: &VirtualMachine) -> bool { + fn isdigit(&self) -> bool { self.inner.borrow().isdigit() } #[pymethod(name = "islower")] - fn islower(&self, _vm: &VirtualMachine) -> bool { + fn islower(&self) -> bool { self.inner.borrow().islower() } #[pymethod(name = "isspace")] - fn isspace(&self, _vm: &VirtualMachine) -> bool { + fn isspace(&self) -> bool { self.inner.borrow().isspace() } #[pymethod(name = "isupper")] - fn isupper(&self, _vm: &VirtualMachine) -> bool { + fn isupper(&self) -> bool { self.inner.borrow().isupper() } #[pymethod(name = "istitle")] - fn istitle(&self, _vm: &VirtualMachine) -> bool { + fn istitle(&self) -> bool { self.inner.borrow().istitle() } #[pymethod(name = "lower")] - fn lower(&self, _vm: &VirtualMachine) -> PyByteArray { + fn lower(&self) -> PyByteArray { self.inner.borrow().lower().into() } #[pymethod(name = "upper")] - fn upper(&self, _vm: &VirtualMachine) -> PyByteArray { + fn upper(&self) -> PyByteArray { self.inner.borrow().upper().into() } #[pymethod(name = "capitalize")] - fn capitalize(&self, _vm: &VirtualMachine) -> PyByteArray { + fn capitalize(&self) -> PyByteArray { self.inner.borrow().capitalize().into() } #[pymethod(name = "swapcase")] - fn swapcase(&self, _vm: &VirtualMachine) -> PyByteArray { + fn swapcase(&self) -> PyByteArray { self.inner.borrow().swapcase().into() } #[pymethod(name = "hex")] - fn hex(&self, _vm: &VirtualMachine) -> String { + fn hex(&self) -> String { self.inner.borrow().hex() } @@ -375,11 +375,7 @@ impl PyByteArray { } #[pymethod(name = "strip")] - fn strip( - &self, - chars: OptionalArg, - _vm: &VirtualMachine, - ) -> PyResult { + fn strip(&self, chars: OptionalArg) -> PyResult { Ok(self .inner .borrow() @@ -388,11 +384,7 @@ impl PyByteArray { } #[pymethod(name = "lstrip")] - fn lstrip( - &self, - chars: OptionalArg, - _vm: &VirtualMachine, - ) -> PyResult { + fn lstrip(&self, chars: OptionalArg) -> PyResult { Ok(self .inner .borrow() @@ -401,11 +393,7 @@ impl PyByteArray { } #[pymethod(name = "rstrip")] - fn rstrip( - &self, - chars: OptionalArg, - _vm: &VirtualMachine, - ) -> PyResult { + fn rstrip(&self, chars: OptionalArg) -> PyResult { Ok(self .inner .borrow() @@ -460,7 +448,7 @@ impl PyByteArray { } #[pymethod(name = "expandtabs")] - fn expandtabs(&self, options: ByteInnerExpandtabsOptions, _vm: &VirtualMachine) -> PyByteArray { + fn expandtabs(&self, options: ByteInnerExpandtabsOptions) -> PyByteArray { self.inner.borrow().expandtabs(options).into() } @@ -477,7 +465,7 @@ impl PyByteArray { } #[pymethod(name = "zfill")] - fn zfill(&self, width: PyIntRef, _vm: &VirtualMachine) -> PyByteArray { + fn zfill(&self, width: PyIntRef) -> PyByteArray { self.inner.borrow().zfill(width).into() } @@ -487,18 +475,17 @@ impl PyByteArray { old: PyByteInner, new: PyByteInner, count: OptionalArg, - _vm: &VirtualMachine, ) -> PyResult { Ok(self.inner.borrow().replace(old, new, count)?.into()) } #[pymethod(name = "clear")] - fn clear(&self, _vm: &VirtualMachine) { + fn clear(&self) { self.inner.borrow_mut().elements.clear(); } #[pymethod(name = "copy")] - fn copy(&self, _vm: &VirtualMachine) -> PyByteArray { + fn copy(&self) -> PyByteArray { self.inner.borrow().elements.clone().into() } @@ -560,22 +547,22 @@ impl PyByteArray { } #[pymethod(name = "title")] - fn title(&self, _vm: &VirtualMachine) -> PyByteArray { + fn title(&self) -> PyByteArray { self.inner.borrow().title().into() } #[pymethod(name = "__mul__")] - fn repeat(&self, n: isize, _vm: &VirtualMachine) -> PyByteArray { + fn repeat(&self, n: isize) -> PyByteArray { self.inner.borrow().repeat(n).into() } #[pymethod(name = "__rmul__")] - fn rmul(&self, n: isize, vm: &VirtualMachine) -> PyByteArray { - self.repeat(n, vm) + fn rmul(&self, n: isize) -> PyByteArray { + self.repeat(n) } #[pymethod(name = "__imul__")] - fn irepeat(&self, n: isize, _vm: &VirtualMachine) { + fn irepeat(&self, n: isize) { self.inner.borrow_mut().irepeat(n) } @@ -603,7 +590,7 @@ impl PyByteArray { } #[pymethod(name = "reverse")] - fn reverse(&self, _vm: &VirtualMachine) -> PyResult<()> { + fn reverse(&self) -> PyResult<()> { self.inner.borrow_mut().elements.reverse(); Ok(()) } @@ -640,7 +627,7 @@ impl PyByteArrayIterator { } #[pymethod(name = "__iter__")] - fn iter(zelf: PyRef, _vm: &VirtualMachine) -> PyRef { + fn iter(zelf: PyRef) -> PyRef { zelf } } diff --git a/vm/src/obj/objbytes.rs b/vm/src/obj/objbytes.rs index 99a9c6a26..07a333a93 100644 --- a/vm/src/obj/objbytes.rs +++ b/vm/src/obj/objbytes.rs @@ -109,7 +109,7 @@ impl PyBytes { } #[pymethod(name = "__len__")] - fn len(&self, _vm: &VirtualMachine) -> usize { + fn len(&self) -> usize { self.inner.len() } @@ -135,12 +135,12 @@ impl PyBytes { } #[pymethod(name = "__hash__")] - fn hash(&self, _vm: &VirtualMachine) -> pyhash::PyHash { + fn hash(&self) -> pyhash::PyHash { self.inner.hash() } #[pymethod(name = "__iter__")] - fn iter(zelf: PyRef, _vm: &VirtualMachine) -> PyBytesIterator { + fn iter(zelf: PyRef) -> PyBytesIterator { PyBytesIterator { position: Cell::new(0), bytes: zelf, @@ -148,7 +148,7 @@ impl PyBytes { } #[pymethod(name = "__sizeof__")] - fn sizeof(&self, _vm: &VirtualMachine) -> PyResult { + fn sizeof(&self) -> PyResult { Ok(size_of::() + self.inner.elements.len() * size_of::()) } @@ -176,67 +176,67 @@ impl PyBytes { } #[pymethod(name = "isalnum")] - fn isalnum(&self, _vm: &VirtualMachine) -> bool { + fn isalnum(&self) -> bool { self.inner.isalnum() } #[pymethod(name = "isalpha")] - fn isalpha(&self, _vm: &VirtualMachine) -> bool { + fn isalpha(&self) -> bool { self.inner.isalpha() } #[pymethod(name = "isascii")] - fn isascii(&self, _vm: &VirtualMachine) -> bool { + fn isascii(&self) -> bool { self.inner.isascii() } #[pymethod(name = "isdigit")] - fn isdigit(&self, _vm: &VirtualMachine) -> bool { + fn isdigit(&self) -> bool { self.inner.isdigit() } #[pymethod(name = "islower")] - fn islower(&self, _vm: &VirtualMachine) -> bool { + fn islower(&self) -> bool { self.inner.islower() } #[pymethod(name = "isspace")] - fn isspace(&self, _vm: &VirtualMachine) -> bool { + fn isspace(&self) -> bool { self.inner.isspace() } #[pymethod(name = "isupper")] - fn isupper(&self, _vm: &VirtualMachine) -> bool { + fn isupper(&self) -> bool { self.inner.isupper() } #[pymethod(name = "istitle")] - fn istitle(&self, _vm: &VirtualMachine) -> bool { + fn istitle(&self) -> bool { self.inner.istitle() } #[pymethod(name = "lower")] - fn lower(&self, _vm: &VirtualMachine) -> PyBytes { + fn lower(&self) -> PyBytes { self.inner.lower().into() } #[pymethod(name = "upper")] - fn upper(&self, _vm: &VirtualMachine) -> PyBytes { + fn upper(&self) -> PyBytes { self.inner.upper().into() } #[pymethod(name = "capitalize")] - fn capitalize(&self, _vm: &VirtualMachine) -> PyBytes { + fn capitalize(&self) -> PyBytes { self.inner.capitalize().into() } #[pymethod(name = "swapcase")] - fn swapcase(&self, _vm: &VirtualMachine) -> PyBytes { + fn swapcase(&self) -> PyBytes { self.inner.swapcase().into() } #[pymethod(name = "hex")] - fn hex(&self, _vm: &VirtualMachine) -> String { + fn hex(&self) -> String { self.inner.hex() } @@ -330,17 +330,17 @@ impl PyBytes { } #[pymethod(name = "strip")] - fn strip(&self, chars: OptionalArg, _vm: &VirtualMachine) -> PyResult { + fn strip(&self, chars: OptionalArg) -> PyResult { Ok(self.inner.strip(chars, ByteInnerPosition::All)?.into()) } #[pymethod(name = "lstrip")] - fn lstrip(&self, chars: OptionalArg, _vm: &VirtualMachine) -> PyResult { + fn lstrip(&self, chars: OptionalArg) -> PyResult { Ok(self.inner.strip(chars, ByteInnerPosition::Left)?.into()) } #[pymethod(name = "rstrip")] - fn rstrip(&self, chars: OptionalArg, _vm: &VirtualMachine) -> PyResult { + fn rstrip(&self, chars: OptionalArg) -> PyResult { Ok(self.inner.strip(chars, ByteInnerPosition::Right)?.into()) } @@ -386,7 +386,7 @@ impl PyBytes { } #[pymethod(name = "expandtabs")] - fn expandtabs(&self, options: ByteInnerExpandtabsOptions, _vm: &VirtualMachine) -> PyBytes { + fn expandtabs(&self, options: ByteInnerExpandtabsOptions) -> PyBytes { self.inner.expandtabs(options).into() } @@ -402,7 +402,7 @@ impl PyBytes { } #[pymethod(name = "zfill")] - fn zfill(&self, width: PyIntRef, _vm: &VirtualMachine) -> PyBytes { + fn zfill(&self, width: PyIntRef) -> PyBytes { self.inner.zfill(width).into() } @@ -412,24 +412,23 @@ impl PyBytes { old: PyByteInner, new: PyByteInner, count: OptionalArg, - _vm: &VirtualMachine, ) -> PyResult { Ok(self.inner.replace(old, new, count)?.into()) } #[pymethod(name = "title")] - fn title(&self, _vm: &VirtualMachine) -> PyBytes { + fn title(&self) -> PyBytes { self.inner.title().into() } #[pymethod(name = "__mul__")] - fn repeat(&self, n: isize, _vm: &VirtualMachine) -> PyBytes { + fn repeat(&self, n: isize) -> PyBytes { self.inner.repeat(n).into() } #[pymethod(name = "__rmul__")] - fn rmul(&self, n: isize, vm: &VirtualMachine) -> PyBytes { - self.repeat(n, vm) + fn rmul(&self, n: isize) -> PyBytes { + self.repeat(n) } fn do_cformat( @@ -512,7 +511,7 @@ impl PyBytesIterator { } #[pymethod(name = "__iter__")] - fn iter(zelf: PyRef, _vm: &VirtualMachine) -> PyRef { + fn iter(zelf: PyRef) -> PyRef { zelf } } diff --git a/vm/src/obj/objclassmethod.rs b/vm/src/obj/objclassmethod.rs index 8c3d5070d..edc579698 100644 --- a/vm/src/obj/objclassmethod.rs +++ b/vm/src/obj/objclassmethod.rs @@ -75,7 +75,7 @@ impl PyClassMethod { } #[pyproperty(name = "__func__")] - fn func(&self, _vm: &VirtualMachine) -> PyObjectRef { + fn func(&self) -> PyObjectRef { self.callable.clone() } } diff --git a/vm/src/obj/objcode.rs b/vm/src/obj/objcode.rs index b84e50c0e..8c1d9b8e8 100644 --- a/vm/src/obj/objcode.rs +++ b/vm/src/obj/objcode.rs @@ -47,7 +47,7 @@ impl PyCodeRef { Err(vm.new_type_error("Cannot directly create code object".to_owned())) } - fn repr(self, _vm: &VirtualMachine) -> String { + fn repr(self) -> String { let code = &self.code; format!( "", @@ -58,19 +58,19 @@ impl PyCodeRef { ) } - fn co_argcount(self, _vm: &VirtualMachine) -> usize { + fn co_argcount(self) -> usize { self.code.arg_names.len() } - fn co_filename(self, _vm: &VirtualMachine) -> String { + fn co_filename(self) -> String { self.code.source_path.clone() } - fn co_firstlineno(self, _vm: &VirtualMachine) -> usize { + fn co_firstlineno(self) -> usize { self.code.first_line_number } - fn co_kwonlyargcount(self, _vm: &VirtualMachine) -> usize { + fn co_kwonlyargcount(self) -> usize { self.code.kwonlyarg_names.len() } @@ -83,11 +83,11 @@ impl PyCodeRef { vm.ctx.new_tuple(consts) } - fn co_name(self, _vm: &VirtualMachine) -> String { + fn co_name(self) -> String { self.code.obj_name.clone() } - fn co_flags(self, _vm: &VirtualMachine) -> u8 { + fn co_flags(self) -> u8 { self.code.flags.bits() } } diff --git a/vm/src/obj/objcomplex.rs b/vm/src/obj/objcomplex.rs index 24085c141..fa39c1797 100644 --- a/vm/src/obj/objcomplex.rs +++ b/vm/src/obj/objcomplex.rs @@ -57,17 +57,17 @@ fn try_complex(value: &PyObjectRef, vm: &VirtualMachine) -> PyResult f64 { + fn real(&self) -> f64 { self.value.re } #[pyproperty(name = "imag")] - fn imag(&self, _vm: &VirtualMachine) -> f64 { + fn imag(&self) -> f64 { self.value.im } #[pymethod(name = "__abs__")] - fn abs(&self, _vm: &VirtualMachine) -> f64 { + fn abs(&self) -> f64 { let Complex64 { im, re } = self.value; re.hypot(im) } @@ -104,7 +104,7 @@ impl PyComplex { } #[pymethod(name = "conjugate")] - fn conjugate(&self, _vm: &VirtualMachine) -> Complex64 { + fn conjugate(&self) -> Complex64 { self.value.conj() } @@ -184,12 +184,12 @@ impl PyComplex { } #[pymethod(name = "__neg__")] - fn neg(&self, _vm: &VirtualMachine) -> Complex64 { + fn neg(&self) -> Complex64 { -self.value } #[pymethod(name = "__repr__")] - fn repr(&self, _vm: &VirtualMachine) -> String { + fn repr(&self) -> String { let Complex64 { re, im } = self.value; if re == 0.0 { format!("{}j", im) @@ -209,7 +209,7 @@ impl PyComplex { } #[pymethod(name = "__bool__")] - fn bool(&self, _vm: &VirtualMachine) -> bool { + fn bool(&self) -> bool { !Complex64::is_zero(&self.value) } @@ -235,7 +235,7 @@ impl PyComplex { } #[pymethod(name = "__hash__")] - fn hash(&self, _vm: &VirtualMachine) -> pyhash::PyHash { + fn hash(&self) -> pyhash::PyHash { let re_hash = pyhash::hash_float(self.value.re); let im_hash = pyhash::hash_float(self.value.im); let ret = Wrapping(re_hash) + Wrapping(im_hash) * Wrapping(pyhash::IMAG); diff --git a/vm/src/obj/objcoroutine.rs b/vm/src/obj/objcoroutine.rs index eb6f1faa2..86cf17a83 100644 --- a/vm/src/obj/objcoroutine.rs +++ b/vm/src/obj/objcoroutine.rs @@ -105,7 +105,7 @@ impl PyCoroutine { } #[pymethod(name = "__await__")] - fn r#await(zelf: PyRef, _vm: &VirtualMachine) -> PyCoroutineWrapper { + fn r#await(zelf: PyRef) -> PyCoroutineWrapper { PyCoroutineWrapper { coro: zelf } } } @@ -125,7 +125,7 @@ impl PyValue for PyCoroutineWrapper { #[pyimpl] impl PyCoroutineWrapper { #[pymethod(name = "__iter__")] - fn iter(zelf: PyRef, _vm: &VirtualMachine) -> PyRef { + fn iter(zelf: PyRef) -> PyRef { zelf } diff --git a/vm/src/obj/objdict.rs b/vm/src/obj/objdict.rs index 8eca81299..bcd66d87d 100644 --- a/vm/src/obj/objdict.rs +++ b/vm/src/obj/objdict.rs @@ -121,7 +121,7 @@ impl PyDictRef { } #[pymethod(magic)] - fn bool(self, _vm: &VirtualMachine) -> bool { + fn bool(self) -> bool { !self.entries.borrow().is_empty() } @@ -168,12 +168,12 @@ impl PyDictRef { } #[pymethod(magic)] - fn len(self, _vm: &VirtualMachine) -> usize { + fn len(self) -> usize { self.entries.borrow().len() } #[pymethod(magic)] - fn sizeof(self, _vm: &VirtualMachine) -> usize { + fn sizeof(self) -> usize { size_of::() + self.entries.borrow().sizeof() } @@ -205,27 +205,27 @@ impl PyDictRef { } #[pymethod] - fn clear(self, _vm: &VirtualMachine) { + fn clear(self) { self.entries.borrow_mut().clear() } #[pymethod(magic)] - fn iter(self, _vm: &VirtualMachine) -> PyDictKeyIterator { + fn iter(self) -> PyDictKeyIterator { PyDictKeyIterator::new(self) } #[pymethod] - fn keys(self, _vm: &VirtualMachine) -> PyDictKeys { + fn keys(self) -> PyDictKeys { PyDictKeys::new(self) } #[pymethod] - fn values(self, _vm: &VirtualMachine) -> PyDictValues { + fn values(self) -> PyDictValues { PyDictValues::new(self) } #[pymethod] - fn items(self, _vm: &VirtualMachine) -> PyDictItems { + fn items(self) -> PyDictItems { PyDictItems::new(self) } @@ -305,7 +305,7 @@ impl PyDictRef { } #[pymethod] - pub fn copy(self, _vm: &VirtualMachine) -> PyDict { + pub fn copy(self) -> PyDict { PyDict { entries: self.entries.clone(), } @@ -508,13 +508,13 @@ macro_rules! dict_iterator { } #[pymethod(name = "__iter__")] - fn iter(&self, _vm: &VirtualMachine) -> $iter_name { + fn iter(&self) -> $iter_name { $iter_name::new(self.dict.clone()) } #[pymethod(name = "__len__")] - fn len(&self, vm: &VirtualMachine) -> usize { - self.dict.clone().len(vm) + fn len(&self) -> usize { + self.dict.clone().len() } #[pymethod(name = "__repr__")] @@ -579,12 +579,12 @@ macro_rules! dict_iterator { } #[pymethod(name = "__iter__")] - fn iter(zelf: PyRef, _vm: &VirtualMachine) -> PyRef { + fn iter(zelf: PyRef) -> PyRef { zelf } #[pymethod(name = "__length_hint__")] - fn length_hint(&self, _vm: &VirtualMachine) -> usize { + fn length_hint(&self) -> usize { self.dict .entries .borrow() diff --git a/vm/src/obj/objellipsis.rs b/vm/src/obj/objellipsis.rs index a8a22a4da..407a9b266 100644 --- a/vm/src/obj/objellipsis.rs +++ b/vm/src/obj/objellipsis.rs @@ -21,10 +21,10 @@ fn ellipsis_new(cls: PyClassRef, vm: &VirtualMachine) -> PyResult { } } -fn ellipsis_repr(_self: PyEllipsisRef, _vm: &VirtualMachine) -> String { +fn ellipsis_repr(_self: PyEllipsisRef) -> String { "Ellipsis".to_owned() } -fn ellipsis_reduce(_self: PyEllipsisRef, _vm: &VirtualMachine) -> String { +fn ellipsis_reduce(_self: PyEllipsisRef) -> String { "Ellipsis".to_owned() } diff --git a/vm/src/obj/objenumerate.rs b/vm/src/obj/objenumerate.rs index 0eddb0c61..4bbe8cacc 100644 --- a/vm/src/obj/objenumerate.rs +++ b/vm/src/obj/objenumerate.rs @@ -62,7 +62,7 @@ impl PyEnumerate { } #[pymethod(name = "__iter__")] - fn iter(zelf: PyRef, _vm: &VirtualMachine) -> PyRef { + fn iter(zelf: PyRef) -> PyRef { zelf } } diff --git a/vm/src/obj/objfilter.rs b/vm/src/obj/objfilter.rs index 482c1ab61..1b3f2ae65 100644 --- a/vm/src/obj/objfilter.rs +++ b/vm/src/obj/objfilter.rs @@ -61,7 +61,7 @@ impl PyFilter { } #[pymethod(name = "__iter__")] - fn iter(zelf: PyRef, _vm: &VirtualMachine) -> PyRef { + fn iter(zelf: PyRef) -> PyRef { zelf } } diff --git a/vm/src/obj/objfloat.rs b/vm/src/obj/objfloat.rs index ffc8e946b..cbb5196d7 100644 --- a/vm/src/obj/objfloat.rs +++ b/vm/src/obj/objfloat.rs @@ -273,7 +273,7 @@ impl PyFloat { } #[pymethod(name = "__abs__")] - fn abs(&self, _vm: &VirtualMachine) -> f64 { + fn abs(&self) -> f64 { self.value.abs() } @@ -315,7 +315,7 @@ impl PyFloat { } #[pymethod(name = "__bool__")] - fn bool(&self, _vm: &VirtualMachine) -> bool { + fn bool(&self) -> bool { self.value != 0.0 } @@ -350,12 +350,12 @@ impl PyFloat { } #[pymethod(name = "__pos__")] - fn pos(&self, _vm: &VirtualMachine) -> f64 { + fn pos(&self) -> f64 { self.value } #[pymethod(name = "__neg__")] - fn neg(&self, _vm: &VirtualMachine) -> f64 { + fn neg(&self) -> f64 { -self.value } @@ -380,14 +380,14 @@ impl PyFloat { } #[pymethod(name = "__repr__")] - fn repr(&self, vm: &VirtualMachine) -> String { + fn repr(&self) -> String { let value = format!("{:e}", self.value); if let Some(position) = value.find('e') { let significand = &value[..position]; let exponent = &value[position + 1..]; let exponent = exponent.parse::().unwrap(); if exponent < 16 && exponent > -5 { - if self.is_integer(vm) { + if self.is_integer() { format!("{:.1?}", self.value) } else { self.value.to_string() @@ -489,32 +489,32 @@ impl PyFloat { } #[pymethod(name = "__float__")] - fn float(zelf: PyRef, _vm: &VirtualMachine) -> PyFloatRef { + fn float(zelf: PyRef) -> PyFloatRef { zelf } #[pymethod(name = "__hash__")] - fn hash(&self, _vm: &VirtualMachine) -> pyhash::PyHash { + fn hash(&self) -> pyhash::PyHash { pyhash::hash_float(self.value) } #[pyproperty] - fn real(zelf: PyRef, _vm: &VirtualMachine) -> PyFloatRef { + fn real(zelf: PyRef) -> PyFloatRef { zelf } #[pyproperty] - fn imag(&self, _vm: &VirtualMachine) -> f64 { + fn imag(&self) -> f64 { 0.0f64 } #[pymethod(name = "conjugate")] - fn conjugate(zelf: PyRef, _vm: &VirtualMachine) -> PyFloatRef { + fn conjugate(zelf: PyRef) -> PyFloatRef { zelf } #[pymethod(name = "is_integer")] - fn is_integer(&self, _vm: &VirtualMachine) -> bool { + fn is_integer(&self) -> bool { let v = self.value; (v - v.round()).abs() < std::f64::EPSILON } @@ -592,7 +592,7 @@ impl PyFloat { } #[pymethod] - fn hex(&self, _vm: &VirtualMachine) -> String { + fn hex(&self) -> String { to_hex(self.value) } } diff --git a/vm/src/obj/objframe.rs b/vm/src/obj/objframe.rs index 73067bd4b..48e419154 100644 --- a/vm/src/obj/objframe.rs +++ b/vm/src/obj/objframe.rs @@ -20,27 +20,27 @@ impl FrameRef { } #[pymethod(name = "__repr__")] - fn repr(self, _vm: &VirtualMachine) -> String { + fn repr(self) -> String { "".to_owned() } #[pymethod] - fn clear(self, _vm: &VirtualMachine) { + fn clear(self) { // TODO } #[pyproperty] - fn f_globals(self, _vm: &VirtualMachine) -> PyDictRef { + fn f_globals(self) -> PyDictRef { self.scope.globals.clone() } #[pyproperty] - fn f_locals(self, _vm: &VirtualMachine) -> PyDictRef { + fn f_locals(self) -> PyDictRef { self.scope.get_locals() } #[pyproperty] - fn f_code(self, _vm: &VirtualMachine) -> PyCodeRef { + fn f_code(self) -> PyCodeRef { self.code.clone() } diff --git a/vm/src/obj/objfunction.rs b/vm/src/obj/objfunction.rs index d3532d01a..b9994712d 100644 --- a/vm/src/obj/objfunction.rs +++ b/vm/src/obj/objfunction.rs @@ -250,17 +250,17 @@ impl PyFunction { } #[pyproperty(magic)] - fn code(&self, _vm: &VirtualMachine) -> PyCodeRef { + fn code(&self) -> PyCodeRef { self.code.clone() } #[pyproperty(magic)] - fn defaults(&self, _vm: &VirtualMachine) -> Option { + fn defaults(&self) -> Option { self.defaults.clone() } #[pyproperty(magic)] - fn kwdefaults(&self, _vm: &VirtualMachine) -> Option { + fn kwdefaults(&self) -> Option { self.kw_only_defaults.clone() } } diff --git a/vm/src/obj/objgenerator.rs b/vm/src/obj/objgenerator.rs index a42519d7f..8d72218c4 100644 --- a/vm/src/obj/objgenerator.rs +++ b/vm/src/obj/objgenerator.rs @@ -45,7 +45,7 @@ impl PyGenerator { } #[pymethod(name = "__iter__")] - fn iter(zelf: PyGeneratorRef, _vm: &VirtualMachine) -> PyGeneratorRef { + fn iter(zelf: PyGeneratorRef) -> PyGeneratorRef { zelf } diff --git a/vm/src/obj/objint.rs b/vm/src/obj/objint.rs index 3af40eef9..9b5d0185b 100644 --- a/vm/src/obj/objint.rs +++ b/vm/src/obj/objint.rs @@ -413,17 +413,17 @@ impl PyInt { } #[pymethod(name = "__neg__")] - fn neg(&self, _vm: &VirtualMachine) -> BigInt { + fn neg(&self) -> BigInt { -(&self.value) } #[pymethod(name = "__hash__")] - pub fn hash(&self, _vm: &VirtualMachine) -> pyhash::PyHash { + pub fn hash(&self) -> pyhash::PyHash { pyhash::hash_bigint(&self.value) } #[pymethod(name = "__abs__")] - fn abs(&self, _vm: &VirtualMachine) -> BigInt { + fn abs(&self) -> BigInt { self.value.abs() } @@ -457,12 +457,12 @@ impl PyInt { } #[pymethod(name = "__int__")] - fn int(zelf: PyRef, _vm: &VirtualMachine) -> PyIntRef { + fn int(zelf: PyRef) -> PyIntRef { zelf } #[pymethod(name = "__pos__")] - fn pos(&self, _vm: &VirtualMachine) -> BigInt { + fn pos(&self) -> BigInt { self.value.clone() } @@ -472,32 +472,32 @@ impl PyInt { } #[pymethod(name = "__trunc__")] - fn trunc(zelf: PyRef, _vm: &VirtualMachine) -> PyIntRef { + fn trunc(zelf: PyRef) -> PyIntRef { zelf } #[pymethod(name = "__floor__")] - fn floor(zelf: PyRef, _vm: &VirtualMachine) -> PyIntRef { + fn floor(zelf: PyRef) -> PyIntRef { zelf } #[pymethod(name = "__ceil__")] - fn ceil(zelf: PyRef, _vm: &VirtualMachine) -> PyIntRef { + fn ceil(zelf: PyRef) -> PyIntRef { zelf } #[pymethod(name = "__index__")] - fn index(zelf: PyRef, _vm: &VirtualMachine) -> PyIntRef { + fn index(zelf: PyRef) -> PyIntRef { zelf } #[pymethod(name = "__invert__")] - fn invert(&self, _vm: &VirtualMachine) -> BigInt { + fn invert(&self) -> BigInt { !(&self.value) } #[pymethod(name = "__repr__")] - fn repr(&self, _vm: &VirtualMachine) -> String { + fn repr(&self) -> String { self.value.to_string() } @@ -512,22 +512,22 @@ impl PyInt { } #[pymethod(name = "__bool__")] - fn bool(&self, _vm: &VirtualMachine) -> bool { + fn bool(&self) -> bool { !self.value.is_zero() } #[pymethod(name = "__sizeof__")] - fn sizeof(&self, _vm: &VirtualMachine) -> usize { + fn sizeof(&self) -> usize { size_of::() + ((self.value.bits() + 7) & !7) / 8 } #[pymethod] - fn bit_length(&self, _vm: &VirtualMachine) -> usize { + fn bit_length(&self) -> usize { self.value.bits() } #[pymethod] - fn conjugate(zelf: PyRef, _vm: &VirtualMachine) -> PyIntRef { + fn conjugate(zelf: PyRef) -> PyIntRef { zelf } @@ -631,17 +631,17 @@ impl PyInt { } #[pyproperty] - fn imag(&self, _vm: &VirtualMachine) -> usize { + fn imag(&self) -> usize { 0 } #[pyproperty] - fn numerator(zelf: PyRef, _vm: &VirtualMachine) -> PyIntRef { + fn numerator(zelf: PyRef) -> PyIntRef { zelf } #[pyproperty] - fn denominator(&self, _vm: &VirtualMachine) -> usize { + fn denominator(&self) -> usize { 1 } } diff --git a/vm/src/obj/objiter.rs b/vm/src/obj/objiter.rs index 2d98a0403..5c1e06a6b 100644 --- a/vm/src/obj/objiter.rs +++ b/vm/src/obj/objiter.rs @@ -174,7 +174,7 @@ impl PySequenceIterator { } #[pymethod(name = "__iter__")] - fn iter(zelf: PyRef, _vm: &VirtualMachine) -> PyRef { + fn iter(zelf: PyRef) -> PyRef { zelf } @@ -193,7 +193,7 @@ impl PySequenceIterator { } } -pub fn seq_iter_method(obj: PyObjectRef, _vm: &VirtualMachine) -> PySequenceIterator { +pub fn seq_iter_method(obj: PyObjectRef) -> PySequenceIterator { PySequenceIterator { position: Cell::new(0), obj, diff --git a/vm/src/obj/objlist.rs b/vm/src/obj/objlist.rs index 94b854873..db4c981ee 100644 --- a/vm/src/obj/objlist.rs +++ b/vm/src/obj/objlist.rs @@ -147,7 +147,7 @@ pub type PyListRef = PyRef; #[pyimpl(flags(BASETYPE))] impl PyList { #[pymethod] - pub(crate) fn append(&self, x: PyObjectRef, _vm: &VirtualMachine) { + pub(crate) fn append(&self, x: PyObjectRef) { self.elements.borrow_mut().push(x); } @@ -159,7 +159,7 @@ impl PyList { } #[pymethod] - fn insert(&self, position: isize, element: PyObjectRef, _vm: &VirtualMachine) { + fn insert(&self, position: isize, element: PyObjectRef) { let mut vec = self.elements.borrow_mut(); let vec_len = vec.len().to_isize().unwrap(); // This unbounded position can be < 0 or > vec.len() @@ -201,12 +201,12 @@ impl PyList { } #[pymethod(name = "__bool__")] - fn bool(&self, _vm: &VirtualMachine) -> bool { + fn bool(&self) -> bool { !self.elements.borrow().is_empty() } #[pymethod] - fn clear(&self, _vm: &VirtualMachine) { + fn clear(&self) { self.elements.borrow_mut().clear(); } @@ -216,22 +216,22 @@ impl PyList { } #[pymethod(name = "__len__")] - fn len(&self, _vm: &VirtualMachine) -> usize { + fn len(&self) -> usize { self.elements.borrow().len() } #[pymethod(name = "__sizeof__")] - fn sizeof(&self, _vm: &VirtualMachine) -> usize { + fn sizeof(&self) -> usize { size_of::() + self.elements.borrow().capacity() * size_of::() } #[pymethod] - fn reverse(&self, _vm: &VirtualMachine) { + fn reverse(&self) { self.elements.borrow_mut().reverse(); } #[pymethod(name = "__reversed__")] - fn reversed(zelf: PyRef, _vm: &VirtualMachine) -> PyListReverseIterator { + fn reversed(zelf: PyRef) -> PyListReverseIterator { let final_position = zelf.elements.borrow().len(); PyListReverseIterator { position: Cell::new(final_position), @@ -250,7 +250,7 @@ impl PyList { } #[pymethod(name = "__iter__")] - fn iter(zelf: PyRef, _vm: &VirtualMachine) -> PyListIterator { + fn iter(zelf: PyRef) -> PyListIterator { PyListIterator { position: Cell::new(0), list: zelf, @@ -481,7 +481,7 @@ impl PyList { } #[pymethod(name = "__imul__")] - fn imul(zelf: PyRef, counter: isize, _vm: &VirtualMachine) -> PyRef { + fn imul(zelf: PyRef, counter: isize) -> PyRef { let new_elements = sequence::seq_mul(&zelf.borrow_sequence(), counter) .cloned() .collect(); @@ -868,12 +868,12 @@ impl PyListIterator { } #[pymethod(name = "__iter__")] - fn iter(zelf: PyRef, _vm: &VirtualMachine) -> PyRef { + fn iter(zelf: PyRef) -> PyRef { zelf } #[pymethod(name = "__length_hint__")] - fn length_hint(&self, _vm: &VirtualMachine) -> usize { + fn length_hint(&self) -> usize { self.list.elements.borrow().len() - self.position.get() } } @@ -906,12 +906,12 @@ impl PyListReverseIterator { } #[pymethod(name = "__iter__")] - fn iter(zelf: PyRef, _vm: &VirtualMachine) -> PyRef { + fn iter(zelf: PyRef) -> PyRef { zelf } #[pymethod(name = "__length_hint__")] - fn length_hint(&self, _vm: &VirtualMachine) -> usize { + fn length_hint(&self) -> usize { self.position.get() } } diff --git a/vm/src/obj/objmap.rs b/vm/src/obj/objmap.rs index 86ff0fdc6..a90b1c025 100644 --- a/vm/src/obj/objmap.rs +++ b/vm/src/obj/objmap.rs @@ -55,7 +55,7 @@ impl PyMap { } #[pymethod(name = "__iter__")] - fn iter(zelf: PyRef, _vm: &VirtualMachine) -> PyRef { + fn iter(zelf: PyRef) -> PyRef { zelf } diff --git a/vm/src/obj/objnone.rs b/vm/src/obj/objnone.rs index cb42e879e..f618927e1 100644 --- a/vm/src/obj/objnone.rs +++ b/vm/src/obj/objnone.rs @@ -40,12 +40,12 @@ impl PyNone { } #[pymethod(name = "__repr__")] - fn repr(&self, _vm: &VirtualMachine) -> PyResult { + fn repr(&self) -> PyResult { Ok("None".to_owned()) } #[pymethod(name = "__bool__")] - fn bool(&self, _vm: &VirtualMachine) -> PyResult { + fn bool(&self) -> PyResult { Ok(false) } diff --git a/vm/src/obj/objobject.rs b/vm/src/obj/objobject.rs index bafec4abb..5878108c6 100644 --- a/vm/src/obj/objobject.rs +++ b/vm/src/obj/objobject.rs @@ -37,7 +37,7 @@ impl PyBaseObject { } #[pymethod(magic)] - fn eq(zelf: PyObjectRef, other: PyObjectRef, _vm: &VirtualMachine) -> PyComparisonValue { + fn eq(zelf: PyObjectRef, other: PyObjectRef) -> PyComparisonValue { if zelf.is(&other) { Implemented(true) } else { @@ -64,27 +64,27 @@ impl PyBaseObject { } #[pymethod(magic)] - fn lt(_zelf: PyObjectRef, _other: PyObjectRef, _vm: &VirtualMachine) -> PyComparisonValue { + fn lt(_zelf: PyObjectRef, _other: PyObjectRef) -> PyComparisonValue { NotImplemented } #[pymethod(magic)] - fn le(_zelf: PyObjectRef, _other: PyObjectRef, _vm: &VirtualMachine) -> PyComparisonValue { + fn le(_zelf: PyObjectRef, _other: PyObjectRef) -> PyComparisonValue { NotImplemented } #[pymethod(magic)] - fn gt(_zelf: PyObjectRef, _other: PyObjectRef, _vm: &VirtualMachine) -> PyComparisonValue { + fn gt(_zelf: PyObjectRef, _other: PyObjectRef) -> PyComparisonValue { NotImplemented } #[pymethod(magic)] - fn ge(_zelf: PyObjectRef, _other: PyObjectRef, _vm: &VirtualMachine) -> PyComparisonValue { + fn ge(_zelf: PyObjectRef, _other: PyObjectRef) -> PyComparisonValue { NotImplemented } #[pymethod(magic)] - fn hash(zelf: PyObjectRef, _vm: &VirtualMachine) -> pyhash::PyHash { + fn hash(zelf: PyObjectRef) -> pyhash::PyHash { zelf.get_id() as pyhash::PyHash } @@ -126,7 +126,7 @@ impl PyBaseObject { } #[pymethod(magic)] - fn repr(zelf: PyObjectRef, _vm: &VirtualMachine) -> String { + fn repr(zelf: PyObjectRef) -> String { format!("<{} object at 0x{:x}>", zelf.class().name, zelf.get_id()) } @@ -175,7 +175,7 @@ impl PyBaseObject { } #[pyproperty(name = "__class__")] - fn get_class(obj: PyObjectRef, _vm: &VirtualMachine) -> PyObjectRef { + fn get_class(obj: PyObjectRef) -> PyObjectRef { obj.class().into_object() } diff --git a/vm/src/obj/objproperty.rs b/vm/src/obj/objproperty.rs index cb6c21cd1..f97c9a8ed 100644 --- a/vm/src/obj/objproperty.rs +++ b/vm/src/obj/objproperty.rs @@ -129,21 +129,21 @@ impl PyProperty { // Access functions #[pyproperty] - fn fget(&self, _vm: &VirtualMachine) -> Option { + fn fget(&self) -> Option { self.getter.clone() } #[pyproperty] - fn fset(&self, _vm: &VirtualMachine) -> Option { + fn fset(&self) -> Option { self.setter.clone() } #[pyproperty] - fn fdel(&self, _vm: &VirtualMachine) -> Option { + fn fdel(&self) -> Option { self.deleter.clone() } - fn doc_getter(&self, _vm: &VirtualMachine) -> Option { + fn doc_getter(&self) -> Option { self.doc.borrow().clone() } diff --git a/vm/src/obj/objrange.rs b/vm/src/obj/objrange.rs index 569dc4b47..a0dc60d27 100644 --- a/vm/src/obj/objrange.rs +++ b/vm/src/obj/objrange.rs @@ -154,22 +154,22 @@ impl PyRange { } #[pyproperty(name = "start")] - fn start(&self, _vm: &VirtualMachine) -> PyIntRef { + fn start(&self) -> PyIntRef { self.start.clone() } #[pyproperty(name = "stop")] - fn stop(&self, _vm: &VirtualMachine) -> PyIntRef { + fn stop(&self) -> PyIntRef { self.stop.clone() } #[pyproperty(name = "step")] - fn step(&self, _vm: &VirtualMachine) -> PyIntRef { + fn step(&self) -> PyIntRef { self.step.clone() } #[pymethod(name = "__iter__")] - fn iter(zelf: PyRef, _vm: &VirtualMachine) -> PyRangeIterator { + fn iter(zelf: PyRef) -> PyRangeIterator { PyRangeIterator { position: Cell::new(0), range: zelf, @@ -210,12 +210,12 @@ impl PyRange { } #[pymethod(name = "__len__")] - fn len(&self, _vm: &VirtualMachine) -> BigInt { + fn len(&self) -> BigInt { self.length() } #[pymethod(name = "__repr__")] - fn repr(&self, _vm: &VirtualMachine) -> String { + fn repr(&self) -> String { if self.step.as_bigint().is_one() { format!("range({}, {})", self.start, self.stop) } else { @@ -224,12 +224,12 @@ impl PyRange { } #[pymethod(name = "__bool__")] - fn bool(&self, _vm: &VirtualMachine) -> bool { + fn bool(&self) -> bool { !self.is_empty() } #[pymethod(name = "__contains__")] - fn contains(&self, needle: PyObjectRef, _vm: &VirtualMachine) -> bool { + fn contains(&self, needle: PyObjectRef) -> bool { if let Ok(int) = needle.downcast::() { match self.offset(int.as_bigint()) { Some(ref offset) => offset.is_multiple_of(self.step.as_bigint()), @@ -323,7 +323,7 @@ impl PyRange { } #[pymethod(name = "count")] - fn count(&self, item: PyObjectRef, _vm: &VirtualMachine) -> usize { + fn count(&self, item: PyObjectRef) -> usize { if let Ok(int) = item.downcast::() { if self.index_of(int.as_bigint()).is_some() { 1 @@ -341,8 +341,8 @@ impl PyRange { RangeIndex::Slice(slice) => { let (mut substart, mut substop, mut substep) = slice.inner_indices(&self.length(), vm)?; - let range_step = self.step(vm); - let range_start = self.start(vm); + let range_step = &self.step; + let range_start = &self.start; substep *= range_step.as_bigint(); substart = (substart * range_step.as_bigint()) + range_start.as_bigint(); @@ -371,14 +371,14 @@ impl PyRange { } else if length.is_one() { vec![ vm.ctx.new_int(length), - zelf.start(vm).into_object(), + zelf.start().into_object(), vm.get_none(), ] } else { vec![ vm.ctx.new_int(length), - zelf.start(vm).into_object(), - zelf.step(vm).into_object(), + zelf.start().into_object(), + zelf.step().into_object(), ] }; pyhash::hash_iter(elements.iter(), vm) @@ -427,7 +427,7 @@ impl PyRangeIterator { } #[pymethod(name = "__iter__")] - fn iter(zelf: PyRef, _vm: &VirtualMachine) -> PyRangeIteratorRef { + fn iter(zelf: PyRef) -> PyRangeIteratorRef { zelf } } diff --git a/vm/src/obj/objset.rs b/vm/src/obj/objset.rs index 73e48ad24..146d8511b 100644 --- a/vm/src/obj/objset.rs +++ b/vm/src/obj/objset.rs @@ -343,17 +343,17 @@ impl PySet { } #[pymethod(name = "__len__")] - fn len(&self, _vm: &VirtualMachine) -> usize { + fn len(&self) -> usize { self.inner.borrow().len() } #[pymethod(name = "__sizeof__")] - fn sizeof(&self, _vm: &VirtualMachine) -> usize { + fn sizeof(&self) -> usize { std::mem::size_of::() + self.inner.borrow().sizeof() } #[pymethod] - fn copy(&self, _vm: &VirtualMachine) -> Self { + fn copy(&self) -> Self { Self { inner: RefCell::new(self.inner.borrow().copy()), } @@ -513,7 +513,7 @@ impl PySet { } #[pymethod] - fn clear(&self, _vm: &VirtualMachine) { + fn clear(&self) { self.inner.borrow_mut().clear() } @@ -599,17 +599,17 @@ impl PyFrozenSet { } #[pymethod(name = "__len__")] - fn len(&self, _vm: &VirtualMachine) -> usize { + fn len(&self) -> usize { self.inner.len() } #[pymethod(name = "__sizeof__")] - fn sizeof(&self, _vm: &VirtualMachine) -> usize { + fn sizeof(&self) -> usize { std::mem::size_of::() + self.inner.sizeof() } #[pymethod] - fn copy(&self, _vm: &VirtualMachine) -> Self { + fn copy(&self) -> Self { Self { inner: self.inner.copy(), } diff --git a/vm/src/obj/objslice.rs b/vm/src/obj/objslice.rs index 51ceb237d..3c21ea789 100644 --- a/vm/src/obj/objslice.rs +++ b/vm/src/obj/objslice.rs @@ -51,14 +51,14 @@ impl PySlice { } #[pymethod(name = "__repr__")] - fn repr(&self, _vm: &VirtualMachine) -> PyResult { - let start = self.start(_vm); - let stop = self.stop(_vm); - let step = self.step(_vm); + fn repr(&self, vm: &VirtualMachine) -> PyResult { + let start = self.start(vm); + let stop = self.stop(vm); + let step = self.step(vm); - let start_repr = _vm.to_repr(&start)?; - let stop_repr = _vm.to_repr(&stop)?; - let step_repr = _vm.to_repr(&step)?; + let start_repr = vm.to_repr(&start)?; + let stop_repr = vm.to_repr(&stop)?; + let step_repr = vm.to_repr(&step)?; Ok(format!( "slice({}, {}, {})", diff --git a/vm/src/obj/objstr.rs b/vm/src/obj/objstr.rs index 9be051230..a2c8acc0b 100644 --- a/vm/src/obj/objstr.rs +++ b/vm/src/obj/objstr.rs @@ -127,7 +127,7 @@ impl PyStringIterator { } #[pymethod(name = "__iter__")] - fn iter(zelf: PyRef, _vm: &VirtualMachine) -> PyRef { + fn iter(zelf: PyRef) -> PyRef { zelf } } @@ -163,7 +163,7 @@ impl PyStringReverseIterator { } #[pymethod(name = "__iter__")] - fn iter(zelf: PyRef, _vm: &VirtualMachine) -> PyRef { + fn iter(zelf: PyRef) -> PyRef { zelf } } @@ -225,7 +225,7 @@ impl PyString { } #[pymethod(name = "__bool__")] - fn bool(&self, _vm: &VirtualMachine) -> bool { + fn bool(&self) -> bool { !self.value.is_empty() } @@ -248,7 +248,7 @@ impl PyString { } #[pymethod(name = "__contains__")] - fn contains(&self, needle: PyStringRef, _vm: &VirtualMachine) -> bool { + fn contains(&self, needle: PyStringRef) -> bool { self.value.contains(&needle.value) } @@ -285,27 +285,27 @@ impl PyString { } #[pymethod(name = "__gt__")] - fn gt(&self, other: PyStringRef, _vm: &VirtualMachine) -> bool { + fn gt(&self, other: PyStringRef) -> bool { self.value > other.value } #[pymethod(name = "__ge__")] - fn ge(&self, other: PyStringRef, _vm: &VirtualMachine) -> bool { + fn ge(&self, other: PyStringRef) -> bool { self.value >= other.value } #[pymethod(name = "__lt__")] - fn lt(&self, other: PyStringRef, _vm: &VirtualMachine) -> bool { + fn lt(&self, other: PyStringRef) -> bool { self.value < other.value } #[pymethod(name = "__le__")] - fn le(&self, other: PyStringRef, _vm: &VirtualMachine) -> bool { + fn le(&self, other: PyStringRef) -> bool { self.value <= other.value } #[pymethod(name = "__hash__")] - fn hash(&self, _vm: &VirtualMachine) -> pyhash::PyHash { + fn hash(&self) -> pyhash::PyHash { match self.hash.get() { Some(hash) => hash, None => { @@ -317,12 +317,12 @@ impl PyString { } #[pymethod(name = "__len__")] - fn len(&self, _vm: &VirtualMachine) -> usize { + fn len(&self) -> usize { self.value.chars().count() } #[pymethod(name = "__sizeof__")] - fn sizeof(&self, _vm: &VirtualMachine) -> usize { + fn sizeof(&self) -> usize { size_of::() + self.value.capacity() * size_of::() } @@ -343,12 +343,12 @@ impl PyString { } #[pymethod(name = "__str__")] - fn str(zelf: PyRef, _vm: &VirtualMachine) -> PyStringRef { + fn str(zelf: PyRef) -> PyStringRef { zelf } #[pymethod(name = "__repr__")] - fn repr(&self, _vm: &VirtualMachine) -> String { + fn repr(&self) -> String { let value = &self.value; let quote_char = if count_char(value, '\'') > count_char(value, '"') { '"' @@ -390,23 +390,23 @@ impl PyString { } #[pymethod] - fn lower(&self, _vm: &VirtualMachine) -> String { + fn lower(&self) -> String { self.value.to_lowercase() } // casefold is much more aggressive than lower #[pymethod] - fn casefold(&self, _vm: &VirtualMachine) -> String { + fn casefold(&self) -> String { caseless::default_case_fold_str(&self.value) } #[pymethod] - fn upper(&self, _vm: &VirtualMachine) -> String { + fn upper(&self) -> String { self.value.to_uppercase() } #[pymethod] - fn capitalize(&self, _vm: &VirtualMachine) -> String { + fn capitalize(&self) -> String { let (first_part, lower_str) = self.value.split_at(1); format!("{}{}", first_part.to_uppercase(), lower_str) } @@ -471,7 +471,7 @@ impl PyString { } #[pymethod] - fn strip(&self, chars: OptionalArg, _vm: &VirtualMachine) -> String { + fn strip(&self, chars: OptionalArg) -> String { let chars = match chars { OptionalArg::Present(ref chars) => &chars.value, OptionalArg::Missing => return self.value.trim().to_owned(), @@ -480,7 +480,7 @@ impl PyString { } #[pymethod] - fn lstrip(&self, chars: OptionalArg, _vm: &VirtualMachine) -> String { + fn lstrip(&self, chars: OptionalArg) -> String { let chars = match chars { OptionalArg::Present(ref chars) => &chars.value, OptionalArg::Missing => return self.value.trim_start().to_owned(), @@ -491,7 +491,7 @@ impl PyString { } #[pymethod] - fn rstrip(&self, chars: OptionalArg, _vm: &VirtualMachine) -> String { + fn rstrip(&self, chars: OptionalArg) -> String { let chars = match chars { OptionalArg::Present(ref chars) => &chars.value, OptionalArg::Missing => return self.value.trim_end().to_owned(), @@ -554,17 +554,17 @@ impl PyString { } #[pymethod] - fn isalnum(&self, _vm: &VirtualMachine) -> bool { + fn isalnum(&self) -> bool { !self.value.is_empty() && self.value.chars().all(char::is_alphanumeric) } #[pymethod] - fn isnumeric(&self, _vm: &VirtualMachine) -> bool { + fn isnumeric(&self) -> bool { !self.value.is_empty() && self.value.chars().all(char::is_numeric) } #[pymethod] - fn isdigit(&self, _vm: &VirtualMachine) -> bool { + fn isdigit(&self) -> bool { // python's isdigit also checks if exponents are digits, these are the unicodes for exponents let valid_unicodes: [u16; 10] = [ 0x2070, 0x00B9, 0x00B2, 0x00B3, 0x2074, 0x2075, 0x2076, 0x2077, 0x2078, 0x2079, @@ -581,7 +581,7 @@ impl PyString { } #[pymethod] - fn isdecimal(&self, _vm: &VirtualMachine) -> bool { + fn isdecimal(&self) -> bool { if self.value.is_empty() { false } else { @@ -660,7 +660,7 @@ impl PyString { /// Return a titlecased version of the string where words start with an /// uppercase character and the remaining characters are lowercase. #[pymethod] - fn title(&self, _vm: &VirtualMachine) -> String { + fn title(&self) -> String { let mut title = String::with_capacity(self.value.len()); let mut previous_is_cased = false; for c in self.value.chars() { @@ -687,7 +687,7 @@ impl PyString { } #[pymethod] - fn swapcase(&self, _vm: &VirtualMachine) -> String { + fn swapcase(&self) -> String { let mut swapped_str = String::with_capacity(self.value.len()); for c in self.value.chars() { // to_uppercase returns an iterator, to_ascii_uppercase returns the char @@ -703,18 +703,12 @@ impl PyString { } #[pymethod] - fn isalpha(&self, _vm: &VirtualMachine) -> bool { + fn isalpha(&self) -> bool { !self.value.is_empty() && self.value.chars().all(char::is_alphanumeric) } #[pymethod] - fn replace( - &self, - old: PyStringRef, - new: PyStringRef, - num: OptionalArg, - _vm: &VirtualMachine, - ) -> String { + fn replace(&self, old: PyStringRef, new: PyStringRef, num: OptionalArg) -> String { match num.into_option() { Some(num) => self.value.replacen(&old.value, &new.value, num), None => self.value.replace(&old.value, &new.value), @@ -737,7 +731,7 @@ impl PyString { /// * Zp Separator, Paragraph ('\u2029', PARAGRAPH SEPARATOR) /// * Zs (Separator, Space) other than ASCII space('\x20'). #[pymethod] - fn isprintable(&self, _vm: &VirtualMachine) -> bool { + fn isprintable(&self) -> bool { self.value .chars() .all(|c| c == '\u{0020}' || char_is_printable(c)) @@ -746,13 +740,13 @@ impl PyString { // cpython's isspace ignores whitespace, including \t and \n, etc, unless the whole string is empty // which is why isspace is using is_ascii_whitespace. Same for isupper & islower #[pymethod] - fn isspace(&self, _vm: &VirtualMachine) -> bool { + fn isspace(&self) -> bool { !self.value.is_empty() && self.value.chars().all(|c| c.is_ascii_whitespace()) } // Return true if all cased characters in the string are uppercase and there is at least one cased character, false otherwise. #[pymethod] - fn isupper(&self, _vm: &VirtualMachine) -> bool { + fn isupper(&self) -> bool { let mut cased = false; for c in self.value.chars() { if is_cased(c) && c.is_uppercase() { @@ -766,7 +760,7 @@ impl PyString { // Return true if all cased characters in the string are lowercase and there is at least one cased character, false otherwise. #[pymethod] - fn islower(&self, _vm: &VirtualMachine) -> bool { + fn islower(&self) -> bool { let mut cased = false; for c in self.value.chars() { if is_cased(c) && c.is_lowercase() { @@ -779,7 +773,7 @@ impl PyString { } #[pymethod] - fn isascii(&self, _vm: &VirtualMachine) -> bool { + fn isascii(&self) -> bool { !self.value.is_empty() && self.value.chars().all(|c| c.is_ascii()) } @@ -821,13 +815,7 @@ impl PyString { } #[pymethod] - fn find( - &self, - sub: PyStringRef, - start: OptionalArg, - end: OptionalArg, - _vm: &VirtualMachine, - ) -> isize { + fn find(&self, sub: PyStringRef, start: OptionalArg, end: OptionalArg) -> isize { let value = &self.value; if let Some((start, end)) = adjust_indices(start, end, value.len()) { match value[start..end].find(&sub.value) { @@ -840,13 +828,7 @@ impl PyString { } #[pymethod] - fn rfind( - &self, - sub: PyStringRef, - start: OptionalArg, - end: OptionalArg, - _vm: &VirtualMachine, - ) -> isize { + fn rfind(&self, sub: PyStringRef, start: OptionalArg, end: OptionalArg) -> isize { let value = &self.value; if let Some((start, end)) = adjust_indices(start, end, value.len()) { match value[start..end].rfind(&sub.value) { @@ -938,7 +920,7 @@ impl PyString { /// Return `true` if the sequence is ASCII titlecase and the sequence is not /// empty, `false` otherwise. #[pymethod] - fn istitle(&self, _vm: &VirtualMachine) -> bool { + fn istitle(&self) -> bool { if self.value.is_empty() { return false; } @@ -966,13 +948,7 @@ impl PyString { } #[pymethod] - fn count( - &self, - sub: PyStringRef, - start: OptionalArg, - end: OptionalArg, - _vm: &VirtualMachine, - ) -> usize { + fn count(&self, sub: PyStringRef, start: OptionalArg, end: OptionalArg) -> usize { let value = &self.value; if let Some((start, end)) = adjust_indices(start, end, value.len()) { self.value[start..end].matches(&sub.value).count() @@ -982,7 +958,7 @@ impl PyString { } #[pymethod] - fn zfill(&self, len: usize, _vm: &VirtualMachine) -> String { + fn zfill(&self, len: usize) -> String { let value = &self.value; if len <= value.len() { value.to_owned() @@ -1073,7 +1049,7 @@ impl PyString { } #[pymethod] - fn expandtabs(&self, tab_stop: OptionalArg, _vm: &VirtualMachine) -> String { + fn expandtabs(&self, tab_stop: OptionalArg) -> String { let tab_stop = tab_stop.into_option().unwrap_or(8 as usize); let mut expanded_str = String::with_capacity(self.value.len()); let mut tab_size = tab_stop; @@ -1097,7 +1073,7 @@ impl PyString { } #[pymethod] - fn isidentifier(&self, _vm: &VirtualMachine) -> bool { + fn isidentifier(&self) -> bool { let mut chars = self.value.chars(); let is_identifier_start = chars.next().map_or(false, |c| c == '_' || is_xid_start(c)); // a string is not an identifier if it has whitespace or starts with a number @@ -1151,7 +1127,7 @@ impl PyString { if let OptionalArg::Present(to_str) = to_str { match dict_or_str.downcast::() { Ok(from_str) => { - if to_str.len(vm) == from_str.len(vm) { + if to_str.len() == from_str.len() { for (c1, c2) in from_str.value.chars().zip(to_str.value.chars()) { new_dict.set_item(&vm.new_int(c1 as u32), vm.new_int(c2 as u32), vm)?; } @@ -1184,7 +1160,7 @@ impl PyString { vm, )?; } else if let Some(string) = key.payload::() { - if string.len(vm) == 1 { + if string.len() == 1 { let num_value = string.value.chars().next().unwrap() as u32; new_dict.set_item(&num_value.into_pyobject(vm)?, val, vm)?; } else { @@ -1214,7 +1190,7 @@ impl PyString { } #[pymethod(name = "__iter__")] - fn iter(zelf: PyRef, _vm: &VirtualMachine) -> PyStringIterator { + fn iter(zelf: PyRef) -> PyStringIterator { PyStringIterator { byte_position: Cell::new(0), string: zelf, @@ -1222,7 +1198,7 @@ impl PyString { } #[pymethod(name = "__reversed__")] - fn reversed(zelf: PyRef, _vm: &VirtualMachine) -> PyStringReverseIterator { + fn reversed(zelf: PyRef) -> PyStringReverseIterator { let begin = zelf.value.chars().count(); PyStringReverseIterator { @@ -1735,7 +1711,7 @@ mod tests { ("Greek ῼitlecases ...", "greek ῳitlecases ..."), ]; for (title, input) in tests { - assert_eq!(PyString::from(input).title(&vm).as_str(), title); + assert_eq!(PyString::from(input).title().as_str(), title); } } @@ -1753,7 +1729,7 @@ mod tests { ]; for s in pos { - assert!(PyString::from(s).istitle(&vm)); + assert!(PyString::from(s).istitle()); } let neg = vec![ @@ -1766,7 +1742,7 @@ mod tests { "NOT", ]; for s in neg { - assert!(!PyString::from(s).istitle(&vm)); + assert!(!PyString::from(s).istitle()); } } diff --git a/vm/src/obj/objsuper.rs b/vm/src/obj/objsuper.rs index 89520235b..0fcc7fd83 100644 --- a/vm/src/obj/objsuper.rs +++ b/vm/src/obj/objsuper.rs @@ -35,7 +35,7 @@ impl PyValue for PySuper { #[pyimpl] impl PySuper { #[pymethod(name = "__repr__")] - fn repr(&self, _vm: &VirtualMachine) -> String { + fn repr(&self) -> String { let class_type_str = if let Ok(type_class) = self.typ.clone().downcast::() { type_class.name.clone() } else { diff --git a/vm/src/obj/objtraceback.rs b/vm/src/obj/objtraceback.rs index 4a49bebec..ff49abbf1 100644 --- a/vm/src/obj/objtraceback.rs +++ b/vm/src/obj/objtraceback.rs @@ -32,22 +32,22 @@ impl PyTraceback { } #[pyproperty(name = "tb_frame")] - fn frame(&self, _vm: &VirtualMachine) -> FrameRef { + fn frame(&self) -> FrameRef { self.frame.clone() } #[pyproperty(name = "tb_lasti")] - fn lasti(&self, _vm: &VirtualMachine) -> usize { + fn lasti(&self) -> usize { self.lasti } #[pyproperty(name = "tb_lineno")] - fn lineno(&self, _vm: &VirtualMachine) -> usize { + fn lineno(&self) -> usize { self.lineno } #[pyproperty(name = "tb_next")] - fn next_get(&self, _vm: &VirtualMachine) -> Option { + fn next_get(&self) -> Option { self.next.as_ref().cloned() } } diff --git a/vm/src/obj/objtuple.rs b/vm/src/obj/objtuple.rs index 27be3b360..d868216a6 100644 --- a/vm/src/obj/objtuple.rs +++ b/vm/src/obj/objtuple.rs @@ -127,7 +127,7 @@ impl PyTuple { } #[pymethod(name = "__bool__")] - fn bool(&self, _vm: &VirtualMachine) -> bool { + fn bool(&self) -> bool { !self.elements.is_empty() } @@ -158,7 +158,7 @@ impl PyTuple { } #[pymethod(name = "__iter__")] - fn iter(zelf: PyRef, _vm: &VirtualMachine) -> PyTupleIterator { + fn iter(zelf: PyRef) -> PyTupleIterator { PyTupleIterator { position: Cell::new(0), tuple: zelf, @@ -166,7 +166,7 @@ impl PyTuple { } #[pymethod(name = "__len__")] - fn len(&self, _vm: &VirtualMachine) -> usize { + fn len(&self) -> usize { self.elements.len() } @@ -191,18 +191,14 @@ impl PyTuple { } #[pymethod(name = "__mul__")] - fn mul(&self, counter: isize, _vm: &VirtualMachine) -> PyTuple { + #[pymethod(name = "__rmul__")] + fn mul(&self, counter: isize) -> PyTuple { let new_elements: Vec<_> = sequence::seq_mul(&self.elements, counter) .cloned() .collect(); new_elements.into() } - #[pymethod(name = "__rmul__")] - fn rmul(&self, counter: isize, vm: &VirtualMachine) -> PyTuple { - self.mul(counter, vm) - } - #[pymethod(name = "__getitem__")] fn getitem(zelf: PyRef, needle: PyObjectRef, vm: &VirtualMachine) -> PyResult { get_item(vm, zelf.as_object(), &zelf.elements, needle.clone()) @@ -271,7 +267,7 @@ impl PyTupleIterator { } #[pymethod(name = "__iter__")] - fn iter(zelf: PyRef, _vm: &VirtualMachine) -> PyRef { + fn iter(zelf: PyRef) -> PyRef { zelf } } diff --git a/vm/src/obj/objtype.rs b/vm/src/obj/objtype.rs index 922993c98..3d5f75ca5 100644 --- a/vm/src/obj/objtype.rs +++ b/vm/src/obj/objtype.rs @@ -80,7 +80,7 @@ impl PyClassRef { } #[pyproperty(name = "__mro__")] - fn get_mro(self, _vm: &VirtualMachine) -> PyTuple { + fn get_mro(self) -> PyTuple { let elements: Vec = _mro(&self).iter().map(|x| x.as_object().clone()).collect(); PyTuple::from(elements) @@ -103,22 +103,22 @@ impl PyClassRef { } #[pymethod(magic)] - fn instancecheck(self, obj: PyObjectRef, _vm: &VirtualMachine) -> bool { + fn instancecheck(self, obj: PyObjectRef) -> bool { isinstance(&obj, &self) } #[pymethod(magic)] - fn subclasscheck(self, subclass: PyClassRef, _vm: &VirtualMachine) -> bool { + fn subclasscheck(self, subclass: PyClassRef) -> bool { issubclass(&subclass, &self) } #[pyproperty(magic)] - fn name(self, _vm: &VirtualMachine) -> String { + fn name(self) -> String { self.name.clone() } #[pymethod(magic)] - fn repr(self, _vm: &VirtualMachine) -> String { + fn repr(self) -> String { format!("", self.name) } @@ -239,7 +239,7 @@ impl PyClassRef { } #[pymethod(magic)] - fn subclasses(self, _vm: &VirtualMachine) -> PyList { + fn subclasses(self) -> PyList { let mut subclasses = self.subclasses.borrow_mut(); subclasses.retain(|x| x.upgrade().is_some()); PyList::from( diff --git a/vm/src/obj/objzip.rs b/vm/src/obj/objzip.rs index bc024cd42..751a9731f 100644 --- a/vm/src/obj/objzip.rs +++ b/vm/src/obj/objzip.rs @@ -45,7 +45,7 @@ impl PyZip { } #[pymethod(name = "__iter__")] - fn iter(zelf: PyRef, _vm: &VirtualMachine) -> PyRef { + fn iter(zelf: PyRef) -> PyRef { zelf } } diff --git a/vm/src/stdlib/array.rs b/vm/src/stdlib/array.rs index 970d817f8..9ea0d5bf5 100644 --- a/vm/src/stdlib/array.rs +++ b/vm/src/stdlib/array.rs @@ -217,12 +217,12 @@ impl PyArray { } #[pyproperty] - fn typecode(&self, _vm: &VirtualMachine) -> String { + fn typecode(&self) -> String { self.array.borrow().typecode().to_string() } #[pyproperty] - fn itemsize(&self, _vm: &VirtualMachine) -> usize { + fn itemsize(&self) -> usize { self.array.borrow().itemsize() } @@ -232,7 +232,7 @@ impl PyArray { } #[pymethod] - fn buffer_info(&self, _vm: &VirtualMachine) -> (usize, usize) { + fn buffer_info(&self) -> (usize, usize) { let array = self.array.borrow(); (array.addr(), array.len()) } @@ -301,7 +301,7 @@ impl PyArray { } #[pymethod] - fn tobytes(&self, _vm: &VirtualMachine) -> Vec { + fn tobytes(&self) -> Vec { self.array.borrow().tobytes() } @@ -316,7 +316,7 @@ impl PyArray { } #[pymethod] - fn reverse(&self, _vm: &VirtualMachine) { + fn reverse(&self) { self.array.borrow_mut().reverse() } @@ -349,12 +349,12 @@ impl PyArray { } #[pymethod(name = "__len__")] - fn len(&self, _vm: &VirtualMachine) -> usize { + fn len(&self) -> usize { self.array.borrow().len() } #[pymethod(name = "__iter__")] - fn iter(zelf: PyRef, _vm: &VirtualMachine) -> PyArrayIter { + fn iter(zelf: PyRef) -> PyArrayIter { PyArrayIter { position: Cell::new(0), array: zelf, @@ -394,7 +394,7 @@ impl PyArrayIter { } #[pymethod(name = "__iter__")] - fn iter(zelf: PyRef, _vm: &VirtualMachine) -> PyRef { + fn iter(zelf: PyRef) -> PyRef { zelf } } diff --git a/vm/src/stdlib/binascii.rs b/vm/src/stdlib/binascii.rs index 6b4469660..18db3e7d9 100644 --- a/vm/src/stdlib/binascii.rs +++ b/vm/src/stdlib/binascii.rs @@ -56,7 +56,7 @@ fn hex_nibble(n: u8) -> u8 { } } -fn binascii_hexlify(data: PyBytesLike, _vm: &VirtualMachine) -> Vec { +fn binascii_hexlify(data: PyBytesLike) -> Vec { data.with_ref(|bytes| { let mut hex = Vec::::with_capacity(bytes.len() * 2); for b in bytes.iter() { @@ -124,11 +124,7 @@ fn binascii_a2b_base64(s: SerializedData, vm: &VirtualMachine) -> PyResult Vec { +fn binascii_b2a_base64(data: PyBytesLike, NewlineArg { newline }: NewlineArg) -> Vec { let mut encoded = data.with_ref(base64::encode).into_bytes(); if newline { encoded.push(b'\n'); diff --git a/vm/src/stdlib/collections.rs b/vm/src/stdlib/collections.rs index 245fc1969..5a5c6b9ea 100644 --- a/vm/src/stdlib/collections.rs +++ b/vm/src/stdlib/collections.rs @@ -57,7 +57,7 @@ impl PyDeque { } #[pymethod] - fn append(&self, obj: PyObjectRef, _vm: &VirtualMachine) { + fn append(&self, obj: PyObjectRef) { let mut deque = self.deque.borrow_mut(); if self.maxlen.get() == Some(deque.len()) { deque.pop_front(); @@ -66,7 +66,7 @@ impl PyDeque { } #[pymethod] - fn appendleft(&self, obj: PyObjectRef, _vm: &VirtualMachine) { + fn appendleft(&self, obj: PyObjectRef) { let mut deque = self.deque.borrow_mut(); if self.maxlen.get() == Some(deque.len()) { deque.pop_back(); @@ -75,12 +75,12 @@ impl PyDeque { } #[pymethod] - fn clear(&self, _vm: &VirtualMachine) { + fn clear(&self) { self.deque.borrow_mut().clear() } #[pymethod] - fn copy(&self, _vm: &VirtualMachine) -> Self { + fn copy(&self) -> Self { self.clone() } @@ -99,7 +99,7 @@ impl PyDeque { fn extend(&self, iter: PyIterable, vm: &VirtualMachine) -> PyResult<()> { // TODO: use length_hint here and for extendleft for elem in iter.iter(vm)? { - self.append(elem?, vm); + self.append(elem?); } Ok(()) } @@ -107,7 +107,7 @@ impl PyDeque { #[pymethod] fn extendleft(&self, iter: PyIterable, vm: &VirtualMachine) -> PyResult<()> { for elem in iter.iter(vm)? { - self.appendleft(elem?, vm); + self.appendleft(elem?); } Ok(()) } @@ -191,13 +191,13 @@ impl PyDeque { } #[pymethod] - fn reverse(&self, _vm: &VirtualMachine) { + fn reverse(&self) { self.deque .replace_with(|deque| deque.iter().cloned().rev().collect()); } #[pymethod] - fn rotate(&self, mid: OptionalArg, _vm: &VirtualMachine) { + fn rotate(&self, mid: OptionalArg) { let mut deque = self.deque.borrow_mut(); let mid = mid.unwrap_or(1); if mid < 0 { @@ -208,12 +208,12 @@ impl PyDeque { } #[pyproperty] - fn maxlen(&self, _vm: &VirtualMachine) -> Option { + fn maxlen(&self) -> Option { self.maxlen.get() } #[pyproperty(setter)] - fn set_maxlen(&self, maxlen: Option, _vm: &VirtualMachine) { + fn set_maxlen(&self, maxlen: Option) { self.maxlen.set(maxlen); } @@ -326,7 +326,7 @@ impl PyDeque { } #[pymethod(name = "__mul__")] - fn mul(&self, n: isize, _vm: &VirtualMachine) -> Self { + fn mul(&self, n: isize) -> Self { let deque: &VecDeque<_> = &self.deque.borrow(); let mul = sequence::seq_mul(deque, n); let skipped = if let Some(maxlen) = self.maxlen.get() { @@ -342,12 +342,12 @@ impl PyDeque { } #[pymethod(name = "__len__")] - fn len(&self, _vm: &VirtualMachine) -> usize { + fn len(&self) -> usize { self.deque.borrow().len() } #[pymethod(name = "__iter__")] - fn iter(zelf: PyRef, _vm: &VirtualMachine) -> PyDequeIterator { + fn iter(zelf: PyRef) -> PyDequeIterator { PyDequeIterator { position: Cell::new(0), deque: zelf, @@ -382,7 +382,7 @@ impl PyDequeIterator { } #[pymethod(name = "__iter__")] - fn iter(zelf: PyRef, _vm: &VirtualMachine) -> PyRef { + fn iter(zelf: PyRef) -> PyRef { zelf } } diff --git a/vm/src/stdlib/faulthandler.rs b/vm/src/stdlib/faulthandler.rs index d8d4b7166..9fe27cbc0 100644 --- a/vm/src/stdlib/faulthandler.rs +++ b/vm/src/stdlib/faulthandler.rs @@ -20,7 +20,7 @@ fn dump_traceback(_file: OptionalArg, _all_threads: OptionalArg, vm: } } -fn enable(_file: OptionalArg, _all_threads: OptionalArg, _vm: &VirtualMachine) { +fn enable(_file: OptionalArg, _all_threads: OptionalArg) { // TODO } @@ -29,7 +29,6 @@ fn register( _file: OptionalArg, _all_threads: OptionalArg, _chain: OptionalArg, - _vm: &VirtualMachine, ) { // TODO } diff --git a/vm/src/stdlib/hashlib.rs b/vm/src/stdlib/hashlib.rs index 98a7ce9dd..318994e45 100644 --- a/vm/src/stdlib/hashlib.rs +++ b/vm/src/stdlib/hashlib.rs @@ -49,7 +49,7 @@ impl PyHasher { } #[pyproperty(name = "name")] - fn name(&self, _vm: &VirtualMachine) -> String { + fn name(&self) -> String { self.name.clone() } @@ -65,13 +65,13 @@ impl PyHasher { } #[pymethod(name = "digest")] - fn digest(&self, _vm: &VirtualMachine) -> PyBytes { + fn digest(&self) -> PyBytes { let result = self.get_digest(); PyBytes::new(result) } #[pymethod(name = "hexdigest")] - fn hexdigest(&self, _vm: &VirtualMachine) -> String { + fn hexdigest(&self) -> String { let result = self.get_digest(); hex::encode(result) } diff --git a/vm/src/stdlib/imp.rs b/vm/src/stdlib/imp.rs index 4274121b4..ee0d78de6 100644 --- a/vm/src/stdlib/imp.rs +++ b/vm/src/stdlib/imp.rs @@ -47,7 +47,7 @@ fn imp_create_builtin(spec: PyObjectRef, vm: &VirtualMachine) -> PyResult { } } -fn imp_exec_builtin(_mod: PyModuleRef, _vm: &VirtualMachine) -> i32 { +fn imp_exec_builtin(_mod: PyModuleRef) -> i32 { // TOOD: Should we do something here? 0 } @@ -80,7 +80,7 @@ fn imp_is_frozen_package(name: PyStringRef, vm: &VirtualMachine) -> PyResult bool { + fn seekable(self) -> bool { true } @@ -186,11 +186,11 @@ impl PyStringIORef { Ok(()) } - fn closed(self, _vm: &VirtualMachine) -> bool { + fn closed(self) -> bool { self.buffer.borrow().is_none() } - fn close(self, _vm: &VirtualMachine) { + fn close(self) { self.buffer.replace(None); } } @@ -271,7 +271,7 @@ impl PyBytesIORef { } } - fn seekable(self, _vm: &VirtualMachine) -> bool { + fn seekable(self) -> bool { true } @@ -293,11 +293,11 @@ impl PyBytesIORef { Ok(()) } - fn closed(self, _vm: &VirtualMachine) -> bool { + fn closed(self) -> bool { self.buffer.borrow().is_none() } - fn close(self, _vm: &VirtualMachine) { + fn close(self) { self.buffer.replace(None); } } @@ -318,7 +318,7 @@ fn bytes_io_new( .into_ref_with_type(vm, cls) } -fn io_base_cm_enter(instance: PyObjectRef, _vm: &VirtualMachine) -> PyObjectRef { +fn io_base_cm_enter(instance: PyObjectRef) -> PyObjectRef { instance.clone() } @@ -328,15 +328,15 @@ fn io_base_cm_exit(instance: PyObjectRef, _args: PyFuncArgs, vm: &VirtualMachine } // TODO Check if closed, then if so raise ValueError -fn io_base_flush(_self: PyObjectRef, _vm: &VirtualMachine) {} +fn io_base_flush(_self: PyObjectRef) {} -fn io_base_seekable(_self: PyObjectRef, _vm: &VirtualMachine) -> bool { +fn io_base_seekable(_self: PyObjectRef) -> bool { false } -fn io_base_readable(_self: PyObjectRef, _vm: &VirtualMachine) -> bool { +fn io_base_readable(_self: PyObjectRef) -> bool { false } -fn io_base_writable(_self: PyObjectRef, _vm: &VirtualMachine) -> bool { +fn io_base_writable(_self: PyObjectRef) -> bool { false } @@ -435,7 +435,7 @@ fn io_base_checkseekable( } } -fn io_base_iter(instance: PyObjectRef, _vm: &VirtualMachine) -> PyObjectRef { +fn io_base_iter(instance: PyObjectRef) -> PyObjectRef { instance } fn io_base_next(instance: PyObjectRef, vm: &VirtualMachine) -> PyResult { @@ -505,7 +505,7 @@ fn buffered_reader_read( ) } -fn buffered_reader_seekable(_self: PyObjectRef, _vm: &VirtualMachine) -> bool { +fn buffered_reader_seekable(_self: PyObjectRef) -> bool { true } @@ -680,7 +680,7 @@ mod fileio { Ok(()) } - fn file_io_seekable(_self: PyObjectRef, _vm: &VirtualMachine) -> bool { + fn file_io_seekable(_self: PyObjectRef) -> bool { true } @@ -709,7 +709,7 @@ fn buffered_writer_write(instance: PyObjectRef, obj: PyObjectRef, vm: &VirtualMa vm.call_method(&raw, "write", vec![obj.clone()]) } -fn buffered_writer_seekable(_self: PyObjectRef, _vm: &VirtualMachine) -> bool { +fn buffered_writer_seekable(_self: PyObjectRef) -> bool { true } @@ -722,7 +722,7 @@ fn text_io_wrapper_init( Ok(()) } -fn text_io_wrapper_seekable(_self: PyObjectRef, _vm: &VirtualMachine) -> bool { +fn text_io_wrapper_seekable(_self: PyObjectRef) -> bool { true } diff --git a/vm/src/stdlib/itertools.rs b/vm/src/stdlib/itertools.rs index e0a104041..f7ba1d336 100644 --- a/vm/src/stdlib/itertools.rs +++ b/vm/src/stdlib/itertools.rs @@ -67,7 +67,7 @@ impl PyItertoolsChain { } #[pymethod(name = "__iter__")] - fn iter(zelf: PyRef, _vm: &VirtualMachine) -> PyRef { + fn iter(zelf: PyRef) -> PyRef { zelf } @@ -134,7 +134,7 @@ impl PyItertoolsCompress { } #[pymethod(name = "__iter__")] - fn iter(zelf: PyRef, _vm: &VirtualMachine) -> PyRef { + fn iter(zelf: PyRef) -> PyRef { zelf } } @@ -178,14 +178,14 @@ impl PyItertoolsCount { } #[pymethod(name = "__next__")] - fn next(&self, _vm: &VirtualMachine) -> PyResult { + fn next(&self) -> PyResult { let result = self.cur.borrow().clone(); *self.cur.borrow_mut() += &self.step; Ok(PyInt::new(result)) } #[pymethod(name = "__iter__")] - fn iter(zelf: PyRef, _vm: &VirtualMachine) -> PyRef { + fn iter(zelf: PyRef) -> PyRef { zelf } } @@ -252,7 +252,7 @@ impl PyItertoolsCycle { } #[pymethod(name = "__iter__")] - fn iter(zelf: PyRef, _vm: &VirtualMachine) -> PyRef { + fn iter(zelf: PyRef) -> PyRef { zelf } } @@ -304,7 +304,7 @@ impl PyItertoolsRepeat { } #[pymethod(name = "__iter__")] - fn iter(zelf: PyRef, _vm: &VirtualMachine) -> PyRef { + fn iter(zelf: PyRef) -> PyRef { zelf } @@ -353,7 +353,7 @@ impl PyItertoolsStarmap { } #[pymethod(name = "__iter__")] - fn iter(zelf: PyRef, _vm: &VirtualMachine) -> PyRef { + fn iter(zelf: PyRef) -> PyRef { zelf } } @@ -412,7 +412,7 @@ impl PyItertoolsTakewhile { } #[pymethod(name = "__iter__")] - fn iter(zelf: PyRef, _vm: &VirtualMachine) -> PyRef { + fn iter(zelf: PyRef) -> PyRef { zelf } } @@ -470,7 +470,7 @@ impl PyItertoolsDropwhile { } #[pymethod(name = "__iter__")] - fn iter(zelf: PyRef, _vm: &VirtualMachine) -> PyRef { + fn iter(zelf: PyRef) -> PyRef { zelf } } @@ -596,7 +596,7 @@ impl PyItertoolsIslice { } #[pymethod(name = "__iter__")] - fn iter(zelf: PyRef, _vm: &VirtualMachine) -> PyRef { + fn iter(zelf: PyRef) -> PyRef { zelf } } @@ -652,7 +652,7 @@ impl PyItertoolsFilterFalse { } #[pymethod(name = "__iter__")] - fn iter(zelf: PyRef, _vm: &VirtualMachine) -> PyRef { + fn iter(zelf: PyRef) -> PyRef { zelf } } @@ -711,7 +711,7 @@ impl PyItertoolsAccumulate { } #[pymethod(name = "__iter__")] - fn iter(zelf: PyRef, _vm: &VirtualMachine) -> PyRef { + fn iter(zelf: PyRef) -> PyRef { zelf } } @@ -810,7 +810,7 @@ impl PyItertoolsTee { } #[pymethod(name = "__iter__")] - fn iter(zelf: PyRef, _vm: &VirtualMachine) -> PyRef { + fn iter(zelf: PyRef) -> PyRef { zelf } } @@ -927,7 +927,7 @@ impl PyItertoolsProduct { } #[pymethod(name = "__iter__")] - fn iter(zelf: PyRef, _vm: &VirtualMachine) -> PyRef { + fn iter(zelf: PyRef) -> PyRef { zelf } } @@ -977,7 +977,7 @@ impl PyItertoolsCombinations { } #[pymethod(name = "__iter__")] - fn iter(zelf: PyRef, _vm: &VirtualMachine) -> PyRef { + fn iter(zelf: PyRef) -> PyRef { zelf } @@ -1076,7 +1076,7 @@ impl PyItertoolsCombinationsWithReplacement { } #[pymethod(name = "__iter__")] - fn iter(zelf: PyRef, _vm: &VirtualMachine) -> PyRef { + fn iter(zelf: PyRef) -> PyRef { zelf } @@ -1184,7 +1184,7 @@ impl PyItertoolsPermutations { } #[pymethod(name = "__iter__")] - fn iter(zelf: PyRef, _vm: &VirtualMachine) -> PyRef { + fn iter(zelf: PyRef) -> PyRef { zelf } @@ -1333,7 +1333,7 @@ impl PyItertoolsZiplongest { } #[pymethod(name = "__iter__")] - fn iter(zelf: PyRef, _vm: &VirtualMachine) -> PyRef { + fn iter(zelf: PyRef) -> PyRef { zelf } } diff --git a/vm/src/stdlib/marshal.rs b/vm/src/stdlib/marshal.rs index ad2c50fb1..1be96e919 100644 --- a/vm/src/stdlib/marshal.rs +++ b/vm/src/stdlib/marshal.rs @@ -4,7 +4,7 @@ use crate::obj::objcode::{PyCode, PyCodeRef}; use crate::pyobject::{PyObjectRef, PyResult}; use crate::vm::VirtualMachine; -fn marshal_dumps(co: PyCodeRef, _vm: &VirtualMachine) -> PyBytes { +fn marshal_dumps(co: PyCodeRef) -> PyBytes { PyBytes::new(co.code.to_bytes()) } diff --git a/vm/src/stdlib/math.rs b/vm/src/stdlib/math.rs index 608b968a1..c922a4487 100644 --- a/vm/src/stdlib/math.rs +++ b/vm/src/stdlib/math.rs @@ -25,7 +25,7 @@ use std::cmp::Ordering; // Helper macro: macro_rules! make_math_func { ( $fname:ident, $fun:ident ) => { - fn $fname(value: IntoPyFloat, _vm: &VirtualMachine) -> f64 { + fn $fname(value: IntoPyFloat) -> f64 { value.to_f64().$fun() } }; @@ -33,7 +33,7 @@ macro_rules! make_math_func { macro_rules! make_math_func_bool { ( $fname:ident, $fun:ident ) => { - fn $fname(value: IntoPyFloat, _vm: &VirtualMachine) -> bool { + fn $fname(value: IntoPyFloat) -> bool { value.to_f64().$fun() } }; @@ -98,7 +98,7 @@ fn math_isclose(args: IsCloseArgs, vm: &VirtualMachine) -> PyResult { Ok((diff <= (rel_tol * b).abs()) || (diff <= (rel_tol * a).abs()) || (diff <= abs_tol)) } -fn math_copysign(a: IntoPyFloat, b: IntoPyFloat, _vm: &VirtualMachine) -> f64 { +fn math_copysign(a: IntoPyFloat, b: IntoPyFloat) -> f64 { let a = a.to_f64(); let b = b.to_f64(); if a.is_nan() || b.is_nan() { @@ -112,18 +112,18 @@ fn math_copysign(a: IntoPyFloat, b: IntoPyFloat, _vm: &VirtualMachine) -> f64 { make_math_func!(math_exp, exp); make_math_func!(math_expm1, exp_m1); -fn math_log(x: IntoPyFloat, base: OptionalArg, _vm: &VirtualMachine) -> f64 { +fn math_log(x: IntoPyFloat, base: OptionalArg) -> f64 { base.map_or_else(|| x.to_f64().ln(), |base| x.to_f64().log(base.to_f64())) } -fn math_log1p(x: IntoPyFloat, _vm: &VirtualMachine) -> f64 { +fn math_log1p(x: IntoPyFloat) -> f64 { (x.to_f64() + 1.0).ln() } make_math_func!(math_log2, log2); make_math_func!(math_log10, log10); -fn math_pow(x: IntoPyFloat, y: IntoPyFloat, _vm: &VirtualMachine) -> f64 { +fn math_pow(x: IntoPyFloat, y: IntoPyFloat) -> f64 { x.to_f64().powf(y.to_f64()) } @@ -134,24 +134,24 @@ make_math_func!(math_acos, acos); make_math_func!(math_asin, asin); make_math_func!(math_atan, atan); -fn math_atan2(y: IntoPyFloat, x: IntoPyFloat, _vm: &VirtualMachine) -> f64 { +fn math_atan2(y: IntoPyFloat, x: IntoPyFloat) -> f64 { y.to_f64().atan2(x.to_f64()) } make_math_func!(math_cos, cos); -fn math_hypot(x: IntoPyFloat, y: IntoPyFloat, _vm: &VirtualMachine) -> f64 { +fn math_hypot(x: IntoPyFloat, y: IntoPyFloat) -> f64 { x.to_f64().hypot(y.to_f64()) } make_math_func!(math_sin, sin); make_math_func!(math_tan, tan); -fn math_degrees(x: IntoPyFloat, _vm: &VirtualMachine) -> f64 { +fn math_degrees(x: IntoPyFloat) -> f64 { x.to_f64() * (180.0 / std::f64::consts::PI) } -fn math_radians(x: IntoPyFloat, _vm: &VirtualMachine) -> f64 { +fn math_radians(x: IntoPyFloat) -> f64 { x.to_f64() * (std::f64::consts::PI / 180.0) } @@ -164,7 +164,7 @@ make_math_func!(math_sinh, sinh); make_math_func!(math_tanh, tanh); // Special functions: -fn math_erf(x: IntoPyFloat, _vm: &VirtualMachine) -> f64 { +fn math_erf(x: IntoPyFloat) -> f64 { let x = x.to_f64(); if x.is_nan() { x @@ -173,7 +173,7 @@ fn math_erf(x: IntoPyFloat, _vm: &VirtualMachine) -> f64 { } } -fn math_erfc(x: IntoPyFloat, _vm: &VirtualMachine) -> f64 { +fn math_erfc(x: IntoPyFloat) -> f64 { let x = x.to_f64(); if x.is_nan() { x @@ -182,7 +182,7 @@ fn math_erfc(x: IntoPyFloat, _vm: &VirtualMachine) -> f64 { } } -fn math_gamma(x: IntoPyFloat, _vm: &VirtualMachine) -> f64 { +fn math_gamma(x: IntoPyFloat) -> f64 { let x = x.to_f64(); if x.is_finite() { gamma(x) @@ -193,7 +193,7 @@ fn math_gamma(x: IntoPyFloat, _vm: &VirtualMachine) -> f64 { } } -fn math_lgamma(x: IntoPyFloat, _vm: &VirtualMachine) -> f64 { +fn math_lgamma(x: IntoPyFloat) -> f64 { let x = x.to_f64(); if x.is_finite() { ln_gamma(x) @@ -251,7 +251,7 @@ fn math_floor(value: PyObjectRef, vm: &VirtualMachine) -> PyResult { } } -fn math_frexp(value: IntoPyFloat, _vm: &VirtualMachine) -> (f64, i32) { +fn math_frexp(value: IntoPyFloat) -> (f64, i32) { let value = value.to_f64(); if value.is_finite() { let (m, e) = objfloat::ufrexp(value); @@ -261,11 +261,11 @@ fn math_frexp(value: IntoPyFloat, _vm: &VirtualMachine) -> (f64, i32) { } } -fn math_ldexp(value: PyFloatRef, i: PyIntRef, _vm: &VirtualMachine) -> f64 { +fn math_ldexp(value: PyFloatRef, i: PyIntRef) -> f64 { value.to_f64() * (2_f64).powf(i.as_bigint().to_f64().unwrap()) } -fn math_gcd(a: PyIntRef, b: PyIntRef, _vm: &VirtualMachine) -> BigInt { +fn math_gcd(a: PyIntRef, b: PyIntRef) -> BigInt { use num_integer::Integer; a.as_bigint().gcd(b.as_bigint()) } @@ -281,7 +281,7 @@ fn math_factorial(value: PyIntRef, vm: &VirtualMachine) -> PyResult { Ok(ret) } -fn math_modf(x: IntoPyFloat, _vm: &VirtualMachine) -> (f64, f64) { +fn math_modf(x: IntoPyFloat) -> (f64, f64) { let x = x.to_f64(); if !x.is_finite() { if x.is_infinite() { diff --git a/vm/src/stdlib/os.rs b/vm/src/stdlib/os.rs index b96ec766d..fe4a729be 100644 --- a/vm/src/stdlib/os.rs +++ b/vm/src/stdlib/os.rs @@ -87,7 +87,7 @@ fn make_path(_vm: &VirtualMachine, path: PyStringRef, dir_fd: &DirFd) -> PyStrin } } -fn os_close(fileno: i64, _vm: &VirtualMachine) { +fn os_close(fileno: i64) { //The File type automatically closes when it goes out of scope. //To enable us to close these file descriptors (and hence prevent leaks) //we seek to create the relevant File and simply let it pass out of scope! @@ -519,11 +519,11 @@ struct FollowSymlinks { } impl DirEntryRef { - fn name(self, _vm: &VirtualMachine) -> String { + fn name(self) -> String { self.entry.file_name().into_string().unwrap() } - fn path(self, _vm: &VirtualMachine) -> String { + fn path(self) -> String { self.entry.path().to_str().unwrap().to_owned() } @@ -568,7 +568,7 @@ impl DirEntryRef { fn stat(self, dir_fd: DirFd, follow_symlinks: FollowSymlinks, vm: &VirtualMachine) -> PyResult { os_stat( - Either::A(self.path(vm).try_into_ref(vm)?), + Either::A(self.path().try_into_ref(vm)?), dir_fd, follow_symlinks, vm, @@ -610,23 +610,23 @@ impl ScandirIterator { } #[pymethod] - fn close(&self, _vm: &VirtualMachine) { + fn close(&self) { self.exhausted.set(true); } #[pymethod(name = "__iter__")] - fn iter(zelf: PyRef, _vm: &VirtualMachine) -> PyRef { + fn iter(zelf: PyRef) -> PyRef { zelf } #[pymethod(name = "__enter__")] - fn enter(zelf: PyRef, _vm: &VirtualMachine) -> PyRef { + fn enter(zelf: PyRef) -> PyRef { zelf } #[pymethod(name = "__exit__")] - fn exit(zelf: PyRef, _args: PyFuncArgs, vm: &VirtualMachine) { - zelf.close(vm) + fn exit(zelf: PyRef, _args: PyFuncArgs) { + zelf.close() } } @@ -814,7 +814,6 @@ fn os_stat( _file: Either, _dir_fd: DirFd, _follow_symlinks: FollowSymlinks, - _vm: &VirtualMachine, ) -> PyResult { unimplemented!(); } @@ -980,7 +979,7 @@ fn os_pipe2(flags: libc::c_int, vm: &VirtualMachine) -> PyResult<(RawFd, RawFd)> } #[cfg(unix)] -fn os_system(command: PyStringRef, _vm: &VirtualMachine) -> PyResult { +fn os_system(command: PyStringRef) -> PyResult { use libc::system; use std::ffi::CString; @@ -1039,7 +1038,7 @@ fn os_cpu_count(vm: &VirtualMachine) -> PyObjectRef { vm.new_int(cpu_count) } -fn os_exit(code: i32, _vm: &VirtualMachine) { +fn os_exit(code: i32) { std::process::exit(code) } @@ -1203,7 +1202,7 @@ macro_rules! suppress_iph { }}; } -fn os_isatty(fd: i32, _vm: &VirtualMachine) -> bool { +fn os_isatty(fd: i32) -> bool { unsafe { suppress_iph!(libc::isatty(fd)) != 0 } } diff --git a/vm/src/stdlib/pwd.rs b/vm/src/stdlib/pwd.rs index 0ad3942a4..5c2872e11 100644 --- a/vm/src/stdlib/pwd.rs +++ b/vm/src/stdlib/pwd.rs @@ -14,31 +14,31 @@ impl PyValue for Passwd { type PasswdRef = PyRef; impl PasswdRef { - fn pw_name(self, _vm: &VirtualMachine) -> String { + fn pw_name(self) -> String { self.name.clone() } - fn pw_passwd(self, _vm: &VirtualMachine) -> Option { + fn pw_passwd(self) -> Option { self.passwd.clone() } - fn pw_uid(self, _vm: &VirtualMachine) -> u32 { + fn pw_uid(self) -> u32 { self.uid } - fn pw_gid(self, _vm: &VirtualMachine) -> u32 { + fn pw_gid(self) -> u32 { self.gid } - fn pw_gecos(self, _vm: &VirtualMachine) -> Option { + fn pw_gecos(self) -> Option { self.gecos.clone() } - fn pw_dir(self, _vm: &VirtualMachine) -> String { + fn pw_dir(self) -> String { self.dir.clone() } - fn pw_shell(self, _vm: &VirtualMachine) -> String { + fn pw_shell(self) -> String { self.shell.clone() } } diff --git a/vm/src/stdlib/re.rs b/vm/src/stdlib/re.rs index 25203ba1c..d819c8609 100644 --- a/vm/src/stdlib/re.rs +++ b/vm/src/stdlib/re.rs @@ -312,7 +312,7 @@ fn re_compile( make_regex(vm, pattern.as_str(), flags) } -fn re_escape(pattern: PyStringRef, _vm: &VirtualMachine) -> String { +fn re_escape(pattern: PyStringRef) -> String { regex::escape(pattern.as_str()) } diff --git a/vm/src/stdlib/signal.rs b/vm/src/stdlib/signal.rs index 62a388ac8..e8ae72991 100644 --- a/vm/src/stdlib/signal.rs +++ b/vm/src/stdlib/signal.rs @@ -81,7 +81,7 @@ fn getsignal(signalnum: i32, vm: &VirtualMachine) -> PyResult { } #[cfg(unix)] -fn alarm(time: u32, _vm: &VirtualMachine) -> u32 { +fn alarm(time: u32) -> u32 { let prev_time = if time == 0 { sig_alarm::cancel() } else { diff --git a/vm/src/stdlib/socket.rs b/vm/src/stdlib/socket.rs index 220d01a8b..4548cb119 100644 --- a/vm/src/stdlib/socket.rs +++ b/vm/src/stdlib/socket.rs @@ -231,12 +231,12 @@ impl PySocket { } #[pymethod] - fn close(&self, _vm: &VirtualMachine) { + fn close(&self) { self.sock.replace(invalid_sock()); } #[pymethod] - fn fileno(&self, _vm: &VirtualMachine) -> RawSocket { + fn fileno(&self) -> RawSocket { sock_fileno(&self.sock()) } @@ -361,15 +361,15 @@ impl PySocket { } #[pyproperty(name = "type")] - fn kind(&self, _vm: &VirtualMachine) -> i32 { + fn kind(&self) -> i32 { self.kind.get() } #[pyproperty] - fn family(&self, _vm: &VirtualMachine) -> i32 { + fn family(&self) -> i32 { self.family.get() } #[pyproperty] - fn proto(&self, _vm: &VirtualMachine) -> i32 { + fn proto(&self) -> i32 { self.proto.get() } } @@ -445,14 +445,6 @@ fn socket_inet_ntoa(packed_ip: PyBytesRef, vm: &VirtualMachine) -> PyResult { Ok(vm.new_str(Ipv4Addr::from(ip_num).to_string())) } -fn socket_hton(host: U, _vm: &VirtualMachine) -> U { - U::to_be(host) -} - -fn socket_ntoh(network: U, _vm: &VirtualMachine) -> U { - U::from_be(network) -} - #[derive(FromArgs)] struct GAIOptions { #[pyarg(positional_only)] @@ -618,10 +610,10 @@ pub fn make_module(vm: &VirtualMachine) -> PyObjectRef { "inet_aton" => ctx.new_function(socket_inet_aton), "inet_ntoa" => ctx.new_function(socket_inet_ntoa), "gethostname" => ctx.new_function(socket_gethostname), - "htonl" => ctx.new_function(socket_hton::), - "htons" => ctx.new_function(socket_hton::), - "ntohl" => ctx.new_function(socket_ntoh::), - "ntohs" => ctx.new_function(socket_ntoh::), + "htonl" => ctx.new_function(u32::to_be), + "htons" => ctx.new_function(u16::to_be), + "ntohl" => ctx.new_function(u32::from_be), + "ntohs" => ctx.new_function(u16::from_be), "getdefaulttimeout" => ctx.new_function(|vm: &VirtualMachine| vm.get_none()), "has_ipv6" => ctx.new_bool(false), // constants diff --git a/vm/src/stdlib/subprocess.rs b/vm/src/stdlib/subprocess.rs index 35ae5115a..403ba7ab4 100644 --- a/vm/src/stdlib/subprocess.rs +++ b/vm/src/stdlib/subprocess.rs @@ -134,11 +134,11 @@ impl PopenRef { .into_ref_with_type(vm, cls) } - fn poll(self, _vm: &VirtualMachine) -> Option { + fn poll(self) -> Option { self.process.borrow_mut().poll() } - fn return_code(self, _vm: &VirtualMachine) -> Option { + fn return_code(self) -> Option { self.process.borrow().exit_status() } @@ -209,11 +209,11 @@ impl PopenRef { }) } - fn pid(self, _vm: &VirtualMachine) -> Option { + fn pid(self) -> Option { self.process.borrow().pid() } - fn enter(self, _vm: &VirtualMachine) -> Self { + fn enter(self) -> Self { self } @@ -222,7 +222,6 @@ impl PopenRef { _exception_type: PyObjectRef, _exception_value: PyObjectRef, _traceback: PyObjectRef, - _vm: &VirtualMachine, ) { let mut process = self.process.borrow_mut(); process.stdout.take(); @@ -230,7 +229,7 @@ impl PopenRef { process.stderr.take(); } - fn args(self, _vm: &VirtualMachine) -> PyObjectRef { + fn args(self) -> PyObjectRef { self.args.clone() } } diff --git a/vm/src/stdlib/symtable.rs b/vm/src/stdlib/symtable.rs index d32afd44a..f95c9fc91 100644 --- a/vm/src/stdlib/symtable.rs +++ b/vm/src/stdlib/symtable.rs @@ -87,17 +87,17 @@ impl PyValue for PySymbolTable { #[pyimpl] impl PySymbolTable { #[pymethod(name = "get_name")] - fn get_name(&self, _vm: &VirtualMachine) -> String { + fn get_name(&self) -> String { self.symtable.name.clone() } #[pymethod(name = "get_type")] - fn get_type(&self, _vm: &VirtualMachine) -> String { + fn get_type(&self) -> String { self.symtable.typ.to_string() } #[pymethod(name = "get_lineno")] - fn get_lineno(&self, _vm: &VirtualMachine) -> usize { + fn get_lineno(&self) -> usize { self.symtable.line_number } @@ -137,7 +137,7 @@ impl PySymbolTable { } #[pymethod(name = "has_children")] - fn has_children(&self, _vm: &VirtualMachine) -> bool { + fn has_children(&self) -> bool { !self.symtable.sub_tables.is_empty() } @@ -173,42 +173,42 @@ impl PyValue for PySymbol { #[pyimpl] impl PySymbol { #[pymethod(name = "get_name")] - fn get_name(&self, _vm: &VirtualMachine) -> String { + fn get_name(&self) -> String { self.symbol.name.clone() } #[pymethod(name = "is_global")] - fn is_global(&self, _vm: &VirtualMachine) -> bool { + fn is_global(&self) -> bool { self.symbol.is_global() } #[pymethod(name = "is_local")] - fn is_local(&self, _vm: &VirtualMachine) -> bool { + fn is_local(&self) -> bool { self.symbol.is_local() } #[pymethod(name = "is_referenced")] - fn is_referenced(&self, _vm: &VirtualMachine) -> bool { + fn is_referenced(&self) -> bool { self.symbol.is_referenced } #[pymethod(name = "is_assigned")] - fn is_assigned(&self, _vm: &VirtualMachine) -> bool { + fn is_assigned(&self) -> bool { self.symbol.is_assigned } #[pymethod(name = "is_parameter")] - fn is_parameter(&self, _vm: &VirtualMachine) -> bool { + fn is_parameter(&self) -> bool { self.symbol.is_parameter } #[pymethod(name = "is_free")] - fn is_free(&self, _vm: &VirtualMachine) -> bool { + fn is_free(&self) -> bool { self.symbol.is_free } #[pymethod(name = "is_namespace")] - fn is_namespace(&self, _vm: &VirtualMachine) -> bool { + fn is_namespace(&self) -> bool { // TODO false } diff --git a/vm/src/stdlib/thread.rs b/vm/src/stdlib/thread.rs index d32d65b9f..44d345847 100644 --- a/vm/src/stdlib/thread.rs +++ b/vm/src/stdlib/thread.rs @@ -16,7 +16,7 @@ fn rlock_acquire(vm: &VirtualMachine, _args: PyFuncArgs) -> PyResult { Ok(vm.get_none()) } -fn rlock_release(_zelf: PyObjectRef, _vm: &VirtualMachine) {} +fn rlock_release(_zelf: PyObjectRef) {} fn rlock_enter(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult { arg_check!(vm, args, required = [(instance, None)]); diff --git a/vm/src/stdlib/time_module.rs b/vm/src/stdlib/time_module.rs index c51354a16..a80753552 100644 --- a/vm/src/stdlib/time_module.rs +++ b/vm/src/stdlib/time_module.rs @@ -33,7 +33,7 @@ fn time_sleep(dur: Duration, vm: &VirtualMachine) -> PyResult<()> { } #[cfg(not(unix))] -fn time_sleep(dur: Duration, _vm: &VirtualMachine) { +fn time_sleep(dur: Duration) { std::thread::sleep(dur); } @@ -125,7 +125,7 @@ fn time_asctime(t: OptionalArg, vm: &VirtualMachine) -> PyResult { Ok(vm.ctx.new_str(formatted_time)) } -fn time_ctime(secs: OptionalArg>, _vm: &VirtualMachine) -> String { +fn time_ctime(secs: OptionalArg>) -> String { let instant = optional_or_localtime(secs); instant.format(&CFMT).to_string() } diff --git a/vm/src/stdlib/unicodedata.rs b/vm/src/stdlib/unicodedata.rs index 9507d337f..713de4fe1 100644 --- a/vm/src/stdlib/unicodedata.rs +++ b/vm/src/stdlib/unicodedata.rs @@ -165,7 +165,7 @@ impl PyUCD { } #[pyproperty] - fn unidata_version(&self, _vm: &VirtualMachine) -> String { + fn unidata_version(&self) -> String { self.unic_version.to_string() } } diff --git a/vm/src/stdlib/weakref.rs b/vm/src/stdlib/weakref.rs index 00045e7de..0e2243233 100644 --- a/vm/src/stdlib/weakref.rs +++ b/vm/src/stdlib/weakref.rs @@ -9,7 +9,7 @@ use crate::pyobject::PyObjectRef; use crate::vm::VirtualMachine; use std::rc::Rc; -fn weakref_getweakrefcount(obj: PyObjectRef, _vm: &VirtualMachine) -> usize { +fn weakref_getweakrefcount(obj: PyObjectRef) -> usize { Rc::weak_count(&obj) } @@ -18,7 +18,7 @@ fn weakref_getweakrefs(_obj: PyObjectRef, vm: &VirtualMachine) -> PyObjectRef { vm.ctx.new_list(vec![]) } -fn weakref_remove_dead_weakref(_obj: PyObjectRef, _key: PyObjectRef, _vm: &VirtualMachine) { +fn weakref_remove_dead_weakref(_obj: PyObjectRef, _key: PyObjectRef) { // TODO } diff --git a/vm/src/sysmodule.rs b/vm/src/sysmodule.rs index fdb04de47..431952c8b 100644 --- a/vm/src/sysmodule.rs +++ b/vm/src/sysmodule.rs @@ -97,11 +97,11 @@ impl SysFlags { } } -fn sys_getrefcount(obj: PyObjectRef, _vm: &VirtualMachine) -> usize { +fn sys_getrefcount(obj: PyObjectRef) -> usize { Rc::strong_count(&obj) } -fn sys_getsizeof(obj: PyObjectRef, _vm: &VirtualMachine) -> usize { +fn sys_getsizeof(obj: PyObjectRef) -> usize { // TODO: implement default optional argument. mem::size_of_val(&obj) } @@ -170,7 +170,7 @@ fn sys_setrecursionlimit(recursion_limit: usize, vm: &VirtualMachine) -> PyResul } // TODO implement string interning, this will be key for performance -fn sys_intern(value: PyStringRef, _vm: &VirtualMachine) -> PyStringRef { +fn sys_intern(value: PyStringRef) -> PyStringRef { value } diff --git a/vm/src/vm.rs b/vm/src/vm.rs index 53ef276cf..6d3493bf3 100644 --- a/vm/src/vm.rs +++ b/vm/src/vm.rs @@ -1220,7 +1220,7 @@ impl VirtualMachine { pub fn _hash(&self, obj: &PyObjectRef) -> PyResult { let hash_obj = self.call_method(obj, "__hash__", vec![])?; if let Some(hash_value) = hash_obj.payload_if_subclass::(self) { - Ok(hash_value.hash(self)) + Ok(hash_value.hash()) } else { Err(self.new_type_error("__hash__ method should return an integer".to_owned())) } diff --git a/wasm/lib/src/js_module.rs b/wasm/lib/src/js_module.rs index bd7e5250a..72497c43a 100644 --- a/wasm/lib/src/js_module.rs +++ b/wasm/lib/src/js_module.rs @@ -72,22 +72,22 @@ impl PyJsValue { } #[pymethod] - fn null(&self, _vm: &VirtualMachine) -> PyJsValue { + fn null(&self) -> PyJsValue { PyJsValue::new(JsValue::NULL) } #[pymethod] - fn undefined(&self, _vm: &VirtualMachine) -> PyJsValue { + fn undefined(&self) -> PyJsValue { PyJsValue::new(JsValue::UNDEFINED) } #[pymethod] - fn new_from_str(&self, s: PyStringRef, _vm: &VirtualMachine) -> PyJsValue { + fn new_from_str(&self, s: PyStringRef) -> PyJsValue { PyJsValue::new(s.as_str()) } #[pymethod] - fn new_from_float(&self, n: PyFloatRef, _vm: &VirtualMachine) -> PyJsValue { + fn new_from_float(&self, n: PyFloatRef) -> PyJsValue { PyJsValue::new(n.to_f64()) } @@ -185,29 +185,29 @@ impl PyJsValue { } #[pymethod] - fn as_str(&self, _vm: &VirtualMachine) -> Option { + fn as_str(&self) -> Option { self.value.as_string() } #[pymethod] - fn as_float(&self, _vm: &VirtualMachine) -> Option { + fn as_float(&self) -> Option { self.value.as_f64() } #[pymethod] - fn as_bool(&self, _vm: &VirtualMachine) -> Option { + fn as_bool(&self) -> Option { self.value.as_bool() } #[pymethod(name = "typeof")] - fn type_of(&self, _vm: &VirtualMachine) -> String { + fn type_of(&self) -> String { type_of(&self.value) } #[pymethod] /// Checks that `typeof self == "object" && self !== null`. Use instead /// of `value.typeof() == "object"` - fn is_object(&self, _vm: &VirtualMachine) -> bool { + fn is_object(&self) -> bool { self.value.is_object() } @@ -217,7 +217,7 @@ impl PyJsValue { } #[pymethod(name = "__repr__")] - fn repr(&self, _vm: &VirtualMachine) -> String { + fn repr(&self) -> String { format!("{:?}", self.value) } }