This commit is contained in:
blueloveTH 2023-06-25 17:50:23 +08:00
parent 5474e7b637
commit 718edd9b9d
2 changed files with 13 additions and 0 deletions

View File

@ -43,6 +43,10 @@ class deque:
self.tail.prev = self.head
self.size = 0
def extend(self, iterable):
for value in iterable:
self.append(value)
def append(self, value):
node = _LinkedListNode(self.tail.prev, self.tail, value)
self.tail.prev.next = node

View File

@ -449,6 +449,15 @@ inline void init_builtins(VM* _vm) {
for(i64 i = 0; i < n; i++) ss << self.sv();
return VAR(ss.str());
});
_vm->bind_method<1>("str", "__rmul__", [](VM* vm, ArgsView args) {
const Str& self = _CAST(Str&, args[0]);
i64 n = CAST(i64, args[1]);
std::stringstream ss;
for(i64 i = 0; i < n; i++) ss << self.sv();
return VAR(ss.str());
});
_vm->bind__contains__(_vm->tp_str, [](VM* vm, PyObject* lhs, PyObject* rhs) {
const Str& self = _CAST(Str&, lhs);
return VAR(self.index(CAST(Str&, rhs)) != -1);