mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 11:30:18 +00:00
...
This commit is contained in:
parent
2f5e2a20f5
commit
66052fadd5
@ -56,6 +56,13 @@ struct BoundMethod {
|
||||
PyObject* self;
|
||||
PyObject* 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 {
|
||||
|
@ -972,6 +972,18 @@ inline void VM::post_init(){
|
||||
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){
|
||||
return CAST(Slice&, args[0]).start;
|
||||
}));
|
||||
|
@ -12,3 +12,10 @@ def f(x):
|
||||
|
||||
assert f(2) == 1
|
||||
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
|
Loading…
x
Reference in New Issue
Block a user