This commit is contained in:
blueloveTH 2023-05-03 16:49:26 +08:00
parent 2f5e2a20f5
commit 66052fadd5
3 changed files with 27 additions and 1 deletions

View File

@ -56,6 +56,13 @@ struct BoundMethod {
PyObject* self; PyObject* self;
PyObject* func; PyObject* func;
BoundMethod(PyObject* self, PyObject* func) : self(self), func(func) {} BoundMethod(PyObject* self, PyObject* func) : self(self), func(func) {}
bool operator==(const BoundMethod& rhs) const noexcept {
return self == rhs.self && func == rhs.func;
}
bool operator!=(const BoundMethod& rhs) const noexcept {
return self != rhs.self || func != rhs.func;
}
}; };
struct Range { struct Range {

View File

@ -972,6 +972,18 @@ inline void VM::post_init(){
return CAST(BoundMethod&, args[0]).func; return CAST(BoundMethod&, args[0]).func;
})); }));
vm->bind_method<1>(_t(tp_bound_method), "__eq__", [](VM* vm, ArgsView args){
if(!is_non_tagged_type(args[1], vm->tp_bound_method)) return vm->False;
bool ok = _CAST(BoundMethod&, args[0]) == _CAST(BoundMethod&, args[1]);
return VAR(ok);
});
vm->bind_method<1>(_t(tp_bound_method), "__ne__", [](VM* vm, ArgsView args){
if(!is_non_tagged_type(args[1], vm->tp_bound_method)) return vm->True;
bool ok = _CAST(BoundMethod&, args[0]) != _CAST(BoundMethod&, args[1]);
return VAR(ok);
});
_t(tp_slice)->attr().set("start", property([](VM* vm, ArgsView args){ _t(tp_slice)->attr().set("start", property([](VM* vm, ArgsView args){
return CAST(Slice&, args[0]).start; return CAST(Slice&, args[0]).start;
})); }));

View File

@ -12,3 +12,10 @@ def f(x):
assert f(2) == 1 assert f(2) == 1
assert f(0) == None assert f(0) == None
a = [1, 2]
b = [3, 4]
assert a.append == a.append
assert a.append is not a.append
assert a.append is not b.append
assert a.append != b.append