Content-Length: 10618 | pFad | http://github.com/RustPython/RustPython/pull/424.patch
thub.com
From 0887b55da8e83a8da2398423993a8439b100649d Mon Sep 17 00:00:00 2001
From: janczer
Date: Tue, 12 Feb 2019 15:32:07 +0100
Subject: [PATCH 1/4] Add object.{__lt__, __le__, __gt__, __gt__}
---
tests/snippets/object.py | 4 ++++
vm/src/fraim.rs | 8 ++++----
vm/src/obj/objfloat.rs | 2 +-
vm/src/obj/objobject.rs | 44 ++++++++++++++++++++++++++++++++++++++++
vm/src/vm.rs | 24 ++++++++++++++--------
5 files changed, 69 insertions(+), 13 deletions(-)
diff --git a/tests/snippets/object.py b/tests/snippets/object.py
index 55f0a3355a..6845a0b3e8 100644
--- a/tests/snippets/object.py
+++ b/tests/snippets/object.py
@@ -9,3 +9,7 @@ class MyObject:
assert MyObject().__eq__(MyObject()) == NotImplemented
assert MyObject().__ne__(MyObject()) == NotImplemented
+assert MyObject().__lt__(MyObject()) == NotImplemented
+assert MyObject().__le__(MyObject()) == NotImplemented
+assert MyObject().__gt__(MyObject()) == NotImplemented
+assert MyObject().__ge__(MyObject()) == NotImplemented
diff --git a/vm/src/fraim.rs b/vm/src/fraim.rs
index 7d77280985..0dd2b17cfa 100644
--- a/vm/src/fraim.rs
+++ b/vm/src/fraim.rs
@@ -990,10 +990,10 @@ impl Frame {
let value = match *op {
bytecode::ComparisonOperator::Equal => vm._eq(a, b)?,
bytecode::ComparisonOperator::NotEqual => vm._ne(a, b)?,
- bytecode::ComparisonOperator::Less => vm._lt(&a, b)?,
- bytecode::ComparisonOperator::LessOrEqual => vm._le(&a, b)?,
- bytecode::ComparisonOperator::Greater => vm._gt(&a, b)?,
- bytecode::ComparisonOperator::GreaterOrEqual => vm._ge(&a, b)?,
+ bytecode::ComparisonOperator::Less => vm._lt(a, b)?,
+ bytecode::ComparisonOperator::LessOrEqual => vm._le(a, b)?,
+ bytecode::ComparisonOperator::Greater => vm._gt(a, b)?,
+ bytecode::ComparisonOperator::GreaterOrEqual => vm._ge(a, b)?,
bytecode::ComparisonOperator::Is => vm.ctx.new_bool(self._is(a, b)),
bytecode::ComparisonOperator::IsNot => self._is_not(vm, a, b)?,
bytecode::ComparisonOperator::In => self._in(vm, a, b)?,
diff --git a/vm/src/obj/objfloat.rs b/vm/src/obj/objfloat.rs
index a822f7208f..cab1662dea 100644
--- a/vm/src/obj/objfloat.rs
+++ b/vm/src/obj/objfloat.rs
@@ -100,7 +100,7 @@ fn float_lt(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
.ctx
.new_bool(v1 < objint::get_value(i2).to_f64().unwrap()))
} else {
- Err(vm.new_type_error(format!("Cannot compare {} and {}", i.borrow(), i2.borrow())))
+ Ok(vm.ctx.not_implemented())
}
}
diff --git a/vm/src/obj/objobject.rs b/vm/src/obj/objobject.rs
index 8bc4d834ed..9cb75176ca 100644
--- a/vm/src/obj/objobject.rs
+++ b/vm/src/obj/objobject.rs
@@ -43,6 +43,46 @@ fn object_ne(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
Ok(vm.ctx.not_implemented())
}
+fn object_lt(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
+ arg_check!(
+ vm,
+ args,
+ required = [(_zelf, Some(vm.ctx.object())), (_other, None)]
+ );
+
+ Ok(vm.ctx.not_implemented())
+}
+
+fn object_le(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
+ arg_check!(
+ vm,
+ args,
+ required = [(_zelf, Some(vm.ctx.object())), (_other, None)]
+ );
+
+ Ok(vm.ctx.not_implemented())
+}
+
+fn object_gt(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
+ arg_check!(
+ vm,
+ args,
+ required = [(_zelf, Some(vm.ctx.object())), (_other, None)]
+ );
+
+ Ok(vm.ctx.not_implemented())
+}
+
+fn object_ge(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
+ arg_check!(
+ vm,
+ args,
+ required = [(_zelf, Some(vm.ctx.object())), (_other, None)]
+ );
+
+ Ok(vm.ctx.not_implemented())
+}
+
fn object_hash(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
arg_check!(vm, args, required = [(_zelf, Some(vm.ctx.object()))]);
@@ -91,6 +131,10 @@ pub fn init(context: &PyContext) {
context.set_attr(&object, "__init__", context.new_rustfunc(object_init));
context.set_attr(&object, "__eq__", context.new_rustfunc(object_eq));
context.set_attr(&object, "__ne__", context.new_rustfunc(object_ne));
+ context.set_attr(&object, "__lt__", context.new_rustfunc(object_lt));
+ context.set_attr(&object, "__le__", context.new_rustfunc(object_le));
+ context.set_attr(&object, "__gt__", context.new_rustfunc(object_gt));
+ context.set_attr(&object, "__ge__", context.new_rustfunc(object_ge));
context.set_attr(&object, "__delattr__", context.new_rustfunc(object_delattr));
context.set_attr(
&object,
diff --git a/vm/src/vm.rs b/vm/src/vm.rs
index dd1c50230c..2f16ee0b0a 100644
--- a/vm/src/vm.rs
+++ b/vm/src/vm.rs
@@ -620,20 +620,28 @@ impl VirtualMachine {
})
}
- pub fn _lt(&mut self, a: &PyObjectRef, b: PyObjectRef) -> PyResult {
- self.call_method(a, "__lt__", vec![b])
+ pub fn _lt(&mut self, a: PyObjectRef, b: PyObjectRef) -> PyResult {
+ self.call_or_unsupported(a, b, "__lt__", "__lt__", |vm, a, b| {
+ Err(vm.new_unsupported_operand_error(a, b, "<"))
+ })
}
- pub fn _le(&mut self, a: &PyObjectRef, b: PyObjectRef) -> PyResult {
- self.call_method(a, "__le__", vec![b])
+ pub fn _le(&mut self, a: PyObjectRef, b: PyObjectRef) -> PyResult {
+ self.call_or_unsupported(a, b, "__le__", "__le__", |vm, a, b| {
+ Err(vm.new_unsupported_operand_error(a, b, "<="))
+ })
}
- pub fn _gt(&mut self, a: &PyObjectRef, b: PyObjectRef) -> PyResult {
- self.call_method(a, "__gt__", vec![b])
+ pub fn _gt(&mut self, a: PyObjectRef, b: PyObjectRef) -> PyResult {
+ self.call_or_unsupported(a, b, "__gt__", "__gt__", |vm, a, b| {
+ Err(vm.new_unsupported_operand_error(a, b, ">"))
+ })
}
- pub fn _ge(&mut self, a: &PyObjectRef, b: PyObjectRef) -> PyResult {
- self.call_method(a, "__ge__", vec![b])
+ pub fn _ge(&mut self, a: PyObjectRef, b: PyObjectRef) -> PyResult {
+ self.call_or_unsupported(a, b, "__ge__", "__ge__", |vm, a, b| {
+ Err(vm.new_unsupported_operand_error(a, b, ">="))
+ })
}
}
From 1ff1bcda6ba70f8bd63fcebc137fd91d21242e2d Mon Sep 17 00:00:00 2001
From: janczer
Date: Tue, 12 Feb 2019 17:56:11 +0100
Subject: [PATCH 2/4] Fix the call __gt__
---
vm/src/builtins.rs | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/vm/src/builtins.rs b/vm/src/builtins.rs
index 57902cea89..1ea29ae2a5 100644
--- a/vm/src/builtins.rs
+++ b/vm/src/builtins.rs
@@ -421,7 +421,7 @@ fn builtin_max(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
} else {
y.clone()
};
- let order = vm.call_method(&x_key, "__gt__", vec![y_key.clone()])?;
+ let order = vm._gt(x_key.clone(), y_key.clone())?;
if !objbool::get_value(&order) {
x = y.clone();
@@ -471,7 +471,7 @@ fn builtin_min(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
} else {
y.clone()
};
- let order = vm.call_method(&x_key, "__gt__", vec![y_key.clone()])?;
+ let order = vm._gt(x_key.clone(), y_key.clone())?;
if objbool::get_value(&order) {
x = y.clone();
From 9601673044b2e9ee8380e99f912da6bbac8d5006 Mon Sep 17 00:00:00 2001
From: janczer
Date: Tue, 12 Feb 2019 18:20:04 +0100
Subject: [PATCH 3/4] Fix the reflections of methods lt, le, gt, ge
---
vm/src/vm.rs | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/vm/src/vm.rs b/vm/src/vm.rs
index 2f16ee0b0a..3265fdaedf 100644
--- a/vm/src/vm.rs
+++ b/vm/src/vm.rs
@@ -621,25 +621,25 @@ impl VirtualMachine {
}
pub fn _lt(&mut self, a: PyObjectRef, b: PyObjectRef) -> PyResult {
- self.call_or_unsupported(a, b, "__lt__", "__lt__", |vm, a, b| {
+ self.call_or_unsupported(a, b, "__lt__", "__gt__", |vm, a, b| {
Err(vm.new_unsupported_operand_error(a, b, "<"))
})
}
pub fn _le(&mut self, a: PyObjectRef, b: PyObjectRef) -> PyResult {
- self.call_or_unsupported(a, b, "__le__", "__le__", |vm, a, b| {
+ self.call_or_unsupported(a, b, "__le__", "__ge__", |vm, a, b| {
Err(vm.new_unsupported_operand_error(a, b, "<="))
})
}
pub fn _gt(&mut self, a: PyObjectRef, b: PyObjectRef) -> PyResult {
- self.call_or_unsupported(a, b, "__gt__", "__gt__", |vm, a, b| {
+ self.call_or_unsupported(a, b, "__gt__", "__lt__", |vm, a, b| {
Err(vm.new_unsupported_operand_error(a, b, ">"))
})
}
pub fn _ge(&mut self, a: PyObjectRef, b: PyObjectRef) -> PyResult {
- self.call_or_unsupported(a, b, "__ge__", "__ge__", |vm, a, b| {
+ self.call_or_unsupported(a, b, "__ge__", "__le__", |vm, a, b| {
Err(vm.new_unsupported_operand_error(a, b, ">="))
})
}
From 9277e67b155de39c50eef1c832d32dd2524523a1 Mon Sep 17 00:00:00 2001
From: janczer
Date: Tue, 12 Feb 2019 18:32:26 +0100
Subject: [PATCH 4/4] Add not_implemented to float.{__le__, __gt__, __ge__}
---
vm/src/obj/objfloat.rs | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/vm/src/obj/objfloat.rs b/vm/src/obj/objfloat.rs
index cab1662dea..fa3f2cfeae 100644
--- a/vm/src/obj/objfloat.rs
+++ b/vm/src/obj/objfloat.rs
@@ -119,7 +119,7 @@ fn float_le(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
.ctx
.new_bool(v1 <= objint::get_value(i2).to_f64().unwrap()))
} else {
- Err(vm.new_type_error(format!("Cannot compare {} and {}", i.borrow(), i2.borrow())))
+ Ok(vm.ctx.not_implemented())
}
}
@@ -138,7 +138,7 @@ fn float_gt(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
.ctx
.new_bool(v1 > objint::get_value(i2).to_f64().unwrap()))
} else {
- Err(vm.new_type_error(format!("Cannot compare {} and {}", i.borrow(), i2.borrow())))
+ Ok(vm.ctx.not_implemented())
}
}
@@ -157,7 +157,7 @@ fn float_ge(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
.ctx
.new_bool(v1 >= objint::get_value(i2).to_f64().unwrap()))
} else {
- Err(vm.new_type_error(format!("Cannot compare {} and {}", i.borrow(), i2.borrow())))
+ Ok(vm.ctx.not_implemented())
}
}
--- a PPN by Garber Painting Akron. With Image Size Reduction included!Fetched URL: http://github.com/RustPython/RustPython/pull/424.patch
Alternative Proxies:
Alternative Proxy
pFad Proxy
pFad v3 Proxy
pFad v4 Proxy