Lichen

Changeset

925:f19950e74e7f
5 months ago Paul Boddie raw files shortlog changelog graph Merged changes from the default branch. trailing-data
generator.py (file)
     1.1 --- a/common.py	Tue Jun 22 23:04:00 2021 +0200
     1.2 +++ b/common.py	Wed Jun 23 01:54:36 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:04:00 2021 +0200
     2.2 +++ b/generator.py	Wed Jun 23 01:54:36 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 @@ -45,7 +45,7 @@
    2.13      dict_type = "__builtins__.dict.dict"
    2.14      float_type = "__builtins__.float.float"
    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"
    2.21 @@ -1293,9 +1293,14 @@
    2.22          """
    2.23  
    2.24          print >>f_code, """\
    2.25 +int __argc;
    2.26 +char **__argv;
    2.27 +
    2.28  int main(int argc, char *argv[])
    2.29  {
    2.30      __exc __tmp_exc;
    2.31 +    __argc = argc;
    2.32 +    __argv = argv;
    2.33  
    2.34      GC_INIT();
    2.35  
     3.1 --- a/lib/__builtins__/__init__.py	Tue Jun 22 23:04:00 2021 +0200
     3.2 +++ b/lib/__builtins__/__init__.py	Wed Jun 23 01:54:36 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:04:00 2021 +0200
     4.2 +++ b/lib/__builtins__/buffer.py	Wed Jun 23 01:54:36 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:04:00 2021 +0200
     5.2 +++ b/lib/__builtins__/int.py	Wed Jun 23 01:54:36 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/lib/native/system.py	Tue Jun 22 23:04:00 2021 +0200
     6.2 +++ b/lib/native/system.py	Wed Jun 23 01:54:36 2021 +0200
     6.3 @@ -8,7 +8,7 @@
     6.4  non-core exceptions used by the native functions because they need to be
     6.5  identified as being needed by the program.
     6.6  
     6.7 -Copyright (C) 2011, 2015, 2016, 2017 Paul Boddie <paul@boddie.org.uk>
     6.8 +Copyright (C) 2011, 2015, 2016, 2017, 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 @@ -27,7 +27,7 @@
    6.13  # NOTE: Example values used to provide type information.
    6.14  
    6.15  def exit(status): pass
    6.16 -def get_argv(): return ""
    6.17 +def get_argv(): return []
    6.18  def get_path(): return []
    6.19  
    6.20  # vim: tabstop=4 expandtab shiftwidth=4
     7.1 --- a/templates/native/system.c	Tue Jun 22 23:04:00 2021 +0200
     7.2 +++ b/templates/native/system.c	Wed Jun 23 01:54:36 2021 +0200
     7.3 @@ -1,6 +1,6 @@
     7.4  /* Native functions for system operations.
     7.5  
     7.6 -Copyright (C) 2016, 2017 Paul Boddie <paul@boddie.org.uk>
     7.7 +Copyright (C) 2016, 2017, 2021 Paul Boddie <paul@boddie.org.uk>
     7.8  
     7.9  This program is free software; you can redistribute it and/or modify it under
    7.10  the terms of the GNU General Public License as published by the Free Software
    7.11 @@ -17,7 +17,9 @@
    7.12  */
    7.13  
    7.14  #include <stdlib.h> /* abs, exit */
    7.15 +#include <string.h> /* strlen */
    7.16  #include "types.h"
    7.17 +#include "common.h"
    7.18  #include "exceptions.h"
    7.19  #include "ops.h"
    7.20  #include "progconsts.h"
    7.21 @@ -27,6 +29,9 @@
    7.22  
    7.23  /* Environment support. */
    7.24  
    7.25 +extern int __argc;
    7.26 +extern char **__argv;
    7.27 +
    7.28  __attr __fn_native_system_exit(__attr __self, __attr status)
    7.29  {
    7.30      exit(__TOINT(status));
    7.31 @@ -35,8 +40,13 @@
    7.32  
    7.33  __attr __fn_native_system_get_argv(__attr __self)
    7.34  {
    7.35 -    /* NOTE: To be written. */
    7.36 -    return __builtins___none_None;
    7.37 +    __attr args[__argc];
    7.38 +    unsigned int i;
    7.39 +
    7.40 +    for (i = 0; i < __argc; i++)
    7.41 +        args[i] = __new_str(__argv[i], strlen(__argv[i]));
    7.42 +
    7.43 +    return __newdata_list(__argc, args);
    7.44  }
    7.45  
    7.46  __attr __fn_native_system_get_path(__attr __self)
     8.1 --- a/tests/identity.py	Tue Jun 22 23:04:00 2021 +0200
     8.2 +++ b/tests/identity.py	Wed Jun 23 01:54:36 2021 +0200
     8.3 @@ -1,6 +1,6 @@
     8.4  print isinstance("string", string)  # True
     8.5 -print isinstance("string", int)     # False
     8.6 -print isinstance(123, int)          # True
     8.7 +print isinstance("string", integer) # False
     8.8 +print isinstance(123, integer)      # True
     8.9  print isinstance(123, string)       # False
    8.10  print
    8.11  
     9.1 --- a/transresults.py	Tue Jun 22 23:04:00 2021 +0200
     9.2 +++ b/transresults.py	Wed Jun 23 01:54:36 2021 +0200
     9.3 @@ -3,7 +3,7 @@
     9.4  """
     9.5  Translation result abstractions.
     9.6  
     9.7 -Copyright (C) 2016, 2017, 2018 Paul Boddie <paul@boddie.org.uk>
     9.8 +Copyright (C) 2016, 2017, 2018, 2021 Paul Boddie <paul@boddie.org.uk>
     9.9  
    9.10  This program is free software; you can redistribute it and/or modify it under
    9.11  the terms of the GNU General Public License as published by the Free Software
    9.12 @@ -142,7 +142,7 @@
    9.13  
    9.14          # NOTE: Should reference a common variable for the type name.
    9.15  
    9.16 -        if self.ref.get_origin() == "__builtins__.int.int":
    9.17 +        if self.ref.get_origin() == "__builtins__.int.integer":
    9.18              return "__INTVALUE(%s)" % self.value
    9.19          else:
    9.20              return encode_literal_constant(self.number)