Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 3 additions & 3 deletions vm/src/builtins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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()
}

Expand Down Expand Up @@ -391,7 +391,7 @@ fn builtin_len(obj: PyObjectRef, vm: &VirtualMachine) -> PyResult<usize> {

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 {
Expand Down
56 changes: 10 additions & 46 deletions vm/src/exceptions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand All @@ -80,7 +80,7 @@ impl PyBaseException {
}

#[pyproperty(name = "__traceback__")]
fn get_traceback(&self) -> Option<PyTracebackRef> {
pub fn traceback(&self) -> Option<PyTracebackRef> {
self.traceback.borrow().clone()
}

Expand All @@ -90,51 +90,37 @@ impl PyBaseException {
}

#[pyproperty(name = "__cause__")]
fn get_cause(&self, _vm: &VirtualMachine) -> Option<PyBaseExceptionRef> {
pub fn cause(&self) -> Option<PyBaseExceptionRef> {
self.cause.borrow().clone()
}

#[pyproperty(name = "__cause__", setter)]
fn setter_cause(
&self,
cause: Option<PyBaseExceptionRef>,
_vm: &VirtualMachine,
) -> PyResult<()> {
pub fn set_cause(&self, cause: Option<PyBaseExceptionRef>) {
self.cause.replace(cause);
Ok(())
}

#[pyproperty(name = "__context__")]
fn get_context(&self, _vm: &VirtualMachine) -> Option<PyBaseExceptionRef> {
pub fn context(&self) -> Option<PyBaseExceptionRef> {
self.context.borrow().clone()
}

#[pyproperty(name = "__context__", setter)]
fn setter_context(
&self,
context: Option<PyBaseExceptionRef>,
_vm: &VirtualMachine,
) -> PyResult<()> {
pub fn set_context(&self, context: Option<PyBaseExceptionRef>) {
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<Self>,
tb: Option<PyTracebackRef>,
_vm: &VirtualMachine,
) -> PyResult {
fn with_traceback(zelf: PyRef<Self>, tb: Option<PyTracebackRef>) -> PyResult {
zelf.traceback.replace(tb);
Ok(zelf.as_object().clone())
}
Expand All @@ -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<PyTracebackRef> {
self.traceback.borrow().clone()
}

pub fn cause(&self) -> Option<PyBaseExceptionRef> {
self.cause.borrow().clone()
}
pub fn set_cause(&self, cause: Option<PyBaseExceptionRef>) {
self.cause.replace(cause);
}

pub fn context(&self) -> Option<PyBaseExceptionRef> {
self.context.borrow().clone()
}
pub fn set_context(&self, context: Option<PyBaseExceptionRef>) {
self.context.replace(context);
}
}

/// Print exception chain
Expand Down
2 changes: 1 addition & 1 deletion vm/src/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 } => {
Expand Down
2 changes: 1 addition & 1 deletion vm/src/obj/objbool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ pub fn get_py_int(obj: &PyObjectRef) -> &PyInt {
&obj.payload::<PyInt>().unwrap()
}

fn bool_repr(obj: bool, _vm: &VirtualMachine) -> String {
fn bool_repr(obj: bool) -> String {
if obj {
"True".to_owned()
} else {
Expand Down
75 changes: 31 additions & 44 deletions vm/src/obj/objbytearray.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,17 +99,17 @@ impl PyByteArray {
}

#[pymethod(name = "__repr__")]
fn repr(&self, _vm: &VirtualMachine) -> PyResult<String> {
fn repr(&self) -> PyResult<String> {
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>() + self.inner.borrow().len() * size_of::<u8>()
}

Expand Down Expand Up @@ -144,7 +144,7 @@ impl PyByteArray {
}

#[pymethod(name = "__iter__")]
fn iter(zelf: PyRef<Self>, _vm: &VirtualMachine) -> PyByteArrayIterator {
fn iter(zelf: PyRef<Self>) -> PyByteArrayIterator {
PyByteArrayIterator {
position: Cell::new(0),
bytearray: zelf,
Expand Down Expand Up @@ -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()
}

Expand Down Expand Up @@ -375,11 +375,7 @@ impl PyByteArray {
}

#[pymethod(name = "strip")]
fn strip(
&self,
chars: OptionalArg<PyByteInner>,
_vm: &VirtualMachine,
) -> PyResult<PyByteArray> {
fn strip(&self, chars: OptionalArg<PyByteInner>) -> PyResult<PyByteArray> {
Ok(self
.inner
.borrow()
Expand All @@ -388,11 +384,7 @@ impl PyByteArray {
}

#[pymethod(name = "lstrip")]
fn lstrip(
&self,
chars: OptionalArg<PyByteInner>,
_vm: &VirtualMachine,
) -> PyResult<PyByteArray> {
fn lstrip(&self, chars: OptionalArg<PyByteInner>) -> PyResult<PyByteArray> {
Ok(self
.inner
.borrow()
Expand All @@ -401,11 +393,7 @@ impl PyByteArray {
}

#[pymethod(name = "rstrip")]
fn rstrip(
&self,
chars: OptionalArg<PyByteInner>,
_vm: &VirtualMachine,
) -> PyResult<PyByteArray> {
fn rstrip(&self, chars: OptionalArg<PyByteInner>) -> PyResult<PyByteArray> {
Ok(self
.inner
.borrow()
Expand Down Expand Up @@ -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()
}

Expand All @@ -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()
}

Expand All @@ -487,18 +475,17 @@ impl PyByteArray {
old: PyByteInner,
new: PyByteInner,
count: OptionalArg<PyIntRef>,
_vm: &VirtualMachine,
) -> PyResult<PyByteArray> {
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()
}

Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -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(())
}
Expand Down Expand Up @@ -640,7 +627,7 @@ impl PyByteArrayIterator {
}

#[pymethod(name = "__iter__")]
fn iter(zelf: PyRef<Self>, _vm: &VirtualMachine) -> PyRef<Self> {
fn iter(zelf: PyRef<Self>) -> PyRef<Self> {
zelf
}
}
Loading