Lichen

Changeset

140:37644d46a414
2016-10-27 Paul Boddie raw files shortlog changelog graph Renamed the bool class to boolean, adding a bool function to test objects. Introduced various native methods to support boolean and other operations.
lib/__builtins__/bool.py (file) lib/__builtins__/list.py (file) lib/__builtins__/str.py (file) lib/native.py (file)
     1.1 --- a/lib/__builtins__/bool.py	Wed Oct 26 16:36:17 2016 +0200
     1.2 +++ b/lib/__builtins__/bool.py	Thu Oct 27 17:55:28 2016 +0200
     1.3 @@ -19,14 +19,17 @@
     1.4  this program.  If not, see <http://www.gnu.org/licenses/>.
     1.5  """
     1.6  
     1.7 -class bool(object):
     1.8 +class boolean(object):
     1.9      def __bool__(self):
    1.10          "Identity operation."
    1.11          return self
    1.12      def __str__(self):
    1.13          return self is True and "True" or "False"
    1.14  
    1.15 -False = bool()
    1.16 -True = bool()
    1.17 +False = boolean()
    1.18 +True = boolean()
    1.19 +
    1.20 +def bool(obj):
    1.21 +    return obj.__bool__()
    1.22  
    1.23  # vim: tabstop=4 expandtab shiftwidth=4
     2.1 --- a/lib/__builtins__/list.py	Wed Oct 26 16:36:17 2016 +0200
     2.2 +++ b/lib/__builtins__/list.py	Thu Oct 27 17:55:28 2016 +0200
     2.3 @@ -21,6 +21,7 @@
     2.4  
     2.5  from __builtins__.iterator import listiterator
     2.6  from __builtins__.sequence import _getitem, _getslice
     2.7 +import native
     2.8  
     2.9  class list(object):
    2.10  
    2.11 @@ -33,9 +34,9 @@
    2.12          if args is not None:
    2.13              self.extend(args)
    2.14  
    2.15 -    def __new__(self):
    2.16          # Reserve space for a fragment reference.
    2.17 -        self._elements = None
    2.18 +
    2.19 +        self.__data__ = None
    2.20  
    2.21      def __getitem__(self, index):
    2.22  
    2.23 @@ -68,7 +69,13 @@
    2.24      def pop(self): pass
    2.25      def reverse(self): pass
    2.26      def sort(self, cmp=None, key=None, reverse=0): pass
    2.27 -    def __len__(self): pass
    2.28 +
    2.29 +    def __len__(self):
    2.30 +
    2.31 +        "Return the length of the list."
    2.32 +
    2.33 +        return native._list_len(self)
    2.34 +
    2.35      def __add__(self, other): pass
    2.36      def __iadd__(self, other): pass
    2.37      def __str__(self): pass
    2.38 @@ -77,7 +84,7 @@
    2.39  
    2.40          "Lists are true if non-empty."
    2.41  
    2.42 -        return self.__len__() != 0
    2.43 +        return native._list_nonempty(self)
    2.44  
    2.45      def __iter__(self):
    2.46  
    2.47 @@ -87,6 +94,10 @@
    2.48  
    2.49      # Special implementation methods.
    2.50  
    2.51 -    def __get_single_item__(self, index): pass
    2.52 +    def __get_single_item__(self, index):
    2.53 +
    2.54 +        "Return the item at 'index'."
    2.55 +
    2.56 +        return native._list_element(self, index)
    2.57  
    2.58  # vim: tabstop=4 expandtab shiftwidth=4
     3.1 --- a/lib/__builtins__/str.py	Wed Oct 26 16:36:17 2016 +0200
     3.2 +++ b/lib/__builtins__/str.py	Thu Oct 27 17:55:28 2016 +0200
     3.3 @@ -71,11 +71,13 @@
     3.4          "Return a new boolean for the comparison."
     3.5          return _negate(self.__eq__(other))
     3.6  
     3.7 -    def __len__(self): pass
     3.8 +    def __len__(self):
     3.9 +        return native._str_len(self)
    3.10 +
    3.11      def __str__(self): pass
    3.12  
    3.13      def __bool__(self):
    3.14 -        return _negate(native._str_eq(self, ""))
    3.15 +        return native._str_nonempty(self)
    3.16  
    3.17      def endswith(self, s): pass
    3.18      def find(self, sub, start=None, end=None): pass
     4.1 --- a/lib/native.py	Wed Oct 26 16:36:17 2016 +0200
     4.2 +++ b/lib/native.py	Thu Oct 27 17:55:28 2016 +0200
     4.3 @@ -45,6 +45,12 @@
     4.4  def _str_lt(self, other): pass
     4.5  def _str_gt(self, other): pass
     4.6  def _str_eq(self, other): pass
     4.7 +def _str_len(self): pass
     4.8 +def _str_nonempty(self): pass
     4.9 +
    4.10 +def _list_len(self): pass
    4.11 +def _list_nonempty(self): pass
    4.12 +def _list_element(self, index): pass
    4.13  
    4.14  def _isinstance(obj, cls): pass
    4.15