Lichen

Changeset

920:b4b4179c39f2
5 months ago Paul Boddie raw files shortlog changelog graph Renamed the int class to integer and introduced an int function. int-as-function
common.py (file) generator.py (file) lib/__builtins__/__init__.py (file) lib/__builtins__/buffer.py (file) lib/__builtins__/int.py (file) transresults.py (file)
     1.1 --- a/common.py	Tue Jun 22 23:03:52 2021 +0200
     1.2 +++ b/common.py	Tue Jun 22 23:36:04 2021 +0200
     1.3 @@ -3,8 +3,7 @@
     1.4  """
     1.5  Common functions.
     1.6  
     1.7 -Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016,
     1.8 -              2017, 2018, 2019 Paul Boddie <paul@boddie.org.uk>
     1.9 +Copyright (C) 2007-2019, 2021 Paul Boddie <paul@boddie.org.uk>
    1.10  
    1.11  This program is free software; you can redistribute it and/or modify it under
    1.12  the terms of the GNU General Public License as published by the Free Software
    1.13 @@ -1595,7 +1594,9 @@
    1.14  
    1.15      "Return the module name containing the given type 'name'."
    1.16  
    1.17 -    if name == "string":
    1.18 +    if name == "integer":
    1.19 +        modname = "int"
    1.20 +    elif name == "string":
    1.21          modname = "str"
    1.22      elif name == "utf8string":
    1.23          modname = "unicode"
    1.24 @@ -1610,7 +1611,9 @@
    1.25  
    1.26      "Return the type name provided by the given Python value 'name'."
    1.27  
    1.28 -    if name == "str":
    1.29 +    if name == "int":
    1.30 +        return "integer"
    1.31 +    elif name == "str":
    1.32          return "string"
    1.33      elif name == "unicode":
    1.34          return "utf8string"
     2.1 --- a/generator.py	Tue Jun 22 23:03:52 2021 +0200
     2.2 +++ b/generator.py	Tue Jun 22 23:36:04 2021 +0200
     2.3 @@ -3,7 +3,7 @@
     2.4  """
     2.5  Generate C code from object layouts and other deduced information.
     2.6  
     2.7 -Copyright (C) 2015, 2016, 2017, 2018, 2019 Paul Boddie <paul@boddie.org.uk>
     2.8 +Copyright (C) 2015, 2016, 2017, 2018, 2019, 2021 Paul Boddie <paul@boddie.org.uk>
     2.9  
    2.10  This program is free software; you can redistribute it and/or modify it under
    2.11  the terms of the GNU General Public License as published by the Free Software
    2.12 @@ -43,7 +43,7 @@
    2.13  
    2.14      dict_type = "__builtins__.dict.dict"
    2.15      function_type = "__builtins__.core.function"
    2.16 -    int_type = "__builtins__.int.int"
    2.17 +    int_type = "__builtins__.int.integer"
    2.18      list_type = "__builtins__.list.list"
    2.19      none_type = "__builtins__.none.NoneType"
    2.20      string_type = "__builtins__.str.string"
     3.1 --- a/lib/__builtins__/__init__.py	Tue Jun 22 23:03:52 2021 +0200
     3.2 +++ b/lib/__builtins__/__init__.py	Tue Jun 22 23:36:04 2021 +0200
     3.3 @@ -61,7 +61,7 @@
     3.4  from __builtins__.dict import dict
     3.5  from __builtins__.file import file
     3.6  from __builtins__.float import float
     3.7 -from __builtins__.int import int
     3.8 +from __builtins__.int import int, integer
     3.9  from __builtins__.span import range, slice, xrange
    3.10  from __builtins__.list import list
    3.11  from __builtins__.long import long
     4.1 --- a/lib/__builtins__/buffer.py	Tue Jun 22 23:03:52 2021 +0200
     4.2 +++ b/lib/__builtins__/buffer.py	Tue Jun 22 23:36:04 2021 +0200
     4.3 @@ -3,7 +3,7 @@
     4.4  """
     4.5  Buffer object.
     4.6  
     4.7 -Copyright (C) 2015, 2016, 2017 Paul Boddie <paul@boddie.org.uk>
     4.8 +Copyright (C) 2015, 2016, 2017, 2021 Paul Boddie <paul@boddie.org.uk>
     4.9  
    4.10  This program is free software; you can redistribute it and/or modify it under
    4.11  the terms of the GNU General Public License as published by the Free Software
    4.12 @@ -31,7 +31,7 @@
    4.13  
    4.14          if args is not None:
    4.15              n = len(args)
    4.16 -        elif isinstance(size, int):
    4.17 +        elif isinstance(size, integer):
    4.18              n = size
    4.19          else:
    4.20              raise ValueError(size)
     5.1 --- a/lib/__builtins__/int.py	Tue Jun 22 23:03:52 2021 +0200
     5.2 +++ b/lib/__builtins__/int.py	Tue Jun 22 23:36:04 2021 +0200
     5.3 @@ -3,7 +3,7 @@
     5.4  """
     5.5  Integer objects.
     5.6  
     5.7 -Copyright (C) 2015, 2016, 2017, 2018 Paul Boddie <paul@boddie.org.uk>
     5.8 +Copyright (C) 2015, 2016, 2017, 2018, 2021 Paul Boddie <paul@boddie.org.uk>
     5.9  
    5.10  This program is free software; you can redistribute it and/or modify it under
    5.11  the terms of the GNU General Public License as published by the Free Software
    5.12 @@ -26,18 +26,19 @@
    5.13                     int_neg, int_not, int_or, int_pow, int_rshift, int_str, \
    5.14                     int_sub, int_xor
    5.15  
    5.16 -class int:
    5.17 +def int(number_or_string):
    5.18 +
    5.19 +    "Initialise the integer with the given 'number_or_string'."
    5.20 +
    5.21 +    if is_int(number_or_string):
    5.22 +        return number_or_string
    5.23 +    else:
    5.24 +        raise TypeError
    5.25 +
    5.26 +class integer:
    5.27  
    5.28      "An integer abstraction."
    5.29  
    5.30 -    def __init__(self, number_or_string=None):
    5.31 -
    5.32 -        "Initialise the integer with the given 'number_or_string'."
    5.33 -
    5.34 -        # NOTE: To be implemented.
    5.35 -
    5.36 -        pass
    5.37 -
    5.38      def __hash__(self):
    5.39  
    5.40          "Return a value for hashing purposes."
     6.1 --- a/transresults.py	Tue Jun 22 23:03:52 2021 +0200
     6.2 +++ b/transresults.py	Tue Jun 22 23:36:04 2021 +0200
     6.3 @@ -3,7 +3,7 @@
     6.4  """
     6.5  Translation result abstractions.
     6.6  
     6.7 -Copyright (C) 2016, 2017, 2018 Paul Boddie <paul@boddie.org.uk>
     6.8 +Copyright (C) 2016, 2017, 2018, 2021 Paul Boddie <paul@boddie.org.uk>
     6.9  
    6.10  This program is free software; you can redistribute it and/or modify it under
    6.11  the terms of the GNU General Public License as published by the Free Software
    6.12 @@ -142,7 +142,7 @@
    6.13  
    6.14          # NOTE: Should reference a common variable for the type name.
    6.15  
    6.16 -        if self.ref.get_origin() == "__builtins__.int.int":
    6.17 +        if self.ref.get_origin() == "__builtins__.int.integer":
    6.18              return "__INTVALUE(%s)" % self.value
    6.19          else:
    6.20              return encode_literal_constant(self.number)