# HG changeset patch # User Paul Boddie # Date 1477583728 -7200 # Node ID 37644d46a4142a4cdc8e616cb44f9249beb3cedd # Parent f06dc96f9ab769af95e6b6e5c337c87d0df23c86 Renamed the bool class to boolean, adding a bool function to test objects. Introduced various native methods to support boolean and other operations. diff -r f06dc96f9ab7 -r 37644d46a414 lib/__builtins__/bool.py --- a/lib/__builtins__/bool.py Wed Oct 26 16:36:17 2016 +0200 +++ b/lib/__builtins__/bool.py Thu Oct 27 17:55:28 2016 +0200 @@ -19,14 +19,17 @@ this program. If not, see . """ -class bool(object): +class boolean(object): def __bool__(self): "Identity operation." return self def __str__(self): return self is True and "True" or "False" -False = bool() -True = bool() +False = boolean() +True = boolean() + +def bool(obj): + return obj.__bool__() # vim: tabstop=4 expandtab shiftwidth=4 diff -r f06dc96f9ab7 -r 37644d46a414 lib/__builtins__/list.py --- a/lib/__builtins__/list.py Wed Oct 26 16:36:17 2016 +0200 +++ b/lib/__builtins__/list.py Thu Oct 27 17:55:28 2016 +0200 @@ -21,6 +21,7 @@ from __builtins__.iterator import listiterator from __builtins__.sequence import _getitem, _getslice +import native class list(object): @@ -33,9 +34,9 @@ if args is not None: self.extend(args) - def __new__(self): # Reserve space for a fragment reference. - self._elements = None + + self.__data__ = None def __getitem__(self, index): @@ -68,7 +69,13 @@ def pop(self): pass def reverse(self): pass def sort(self, cmp=None, key=None, reverse=0): pass - def __len__(self): pass + + def __len__(self): + + "Return the length of the list." + + return native._list_len(self) + def __add__(self, other): pass def __iadd__(self, other): pass def __str__(self): pass @@ -77,7 +84,7 @@ "Lists are true if non-empty." - return self.__len__() != 0 + return native._list_nonempty(self) def __iter__(self): @@ -87,6 +94,10 @@ # Special implementation methods. - def __get_single_item__(self, index): pass + def __get_single_item__(self, index): + + "Return the item at 'index'." + + return native._list_element(self, index) # vim: tabstop=4 expandtab shiftwidth=4 diff -r f06dc96f9ab7 -r 37644d46a414 lib/__builtins__/str.py --- a/lib/__builtins__/str.py Wed Oct 26 16:36:17 2016 +0200 +++ b/lib/__builtins__/str.py Thu Oct 27 17:55:28 2016 +0200 @@ -71,11 +71,13 @@ "Return a new boolean for the comparison." return _negate(self.__eq__(other)) - def __len__(self): pass + def __len__(self): + return native._str_len(self) + def __str__(self): pass def __bool__(self): - return _negate(native._str_eq(self, "")) + return native._str_nonempty(self) def endswith(self, s): pass def find(self, sub, start=None, end=None): pass diff -r f06dc96f9ab7 -r 37644d46a414 lib/native.py --- a/lib/native.py Wed Oct 26 16:36:17 2016 +0200 +++ b/lib/native.py Thu Oct 27 17:55:28 2016 +0200 @@ -45,6 +45,12 @@ def _str_lt(self, other): pass def _str_gt(self, other): pass def _str_eq(self, other): pass +def _str_len(self): pass +def _str_nonempty(self): pass + +def _list_len(self): pass +def _list_nonempty(self): pass +def _list_element(self, index): pass def _isinstance(obj, cls): pass