diff --git a/python/collections.py b/python/collections.py index 1c95d1c7..654b50c6 100644 --- a/python/collections.py +++ b/python/collections.py @@ -15,6 +15,34 @@ class deque: for value in iterable: self.append(value) + def __getitem__(self, index): + assert 0 <= index < len(self) + node = self.head.next + for _ in range(index): + node = node.next + return node.value + + def __setitem__(self, index, value): + assert 0 <= index < len(self) + node = self.head.next + for _ in range(index): + node = node.next + node.value = value + + def __delitem__(self, index): + assert 0 <= index < len(self) + node = self.head.next + for _ in range(index): + node = node.next + node.prev.next = node.next + node.next.prev = node.prev + self.size -= 1 + + def clear(self): + self.head.next = self.tail + self.tail.prev = self.head + self.size = 0 + def append(self, value): node = _LinkedListNode(self.tail.prev, self.tail, value) self.tail.prev.next = node diff --git a/src/compiler.h b/src/compiler.h index 5a7b24e5..165ffcf7 100644 --- a/src/compiler.h +++ b/src/compiler.h @@ -952,7 +952,7 @@ __SUBSCR_END: consume(TK("=")); PyObject* value = read_literal(); if(value == nullptr){ - SyntaxError(Str("expect a literal, not ") + TK_STR(curr().type)); + SyntaxError(Str("default argument must be a literal")); } decl->kwargs.push_back(FuncDecl::KwArg{index, value}); } break;