Lichen

Change of generator.py

1041:fb368817a23b
generator.py value-replacement-generic
     1.1 --- a/generator.py	Mon May 20 01:06:05 2024 +0200
     1.2 +++ b/generator.py	Mon May 20 21:26:54 2024 +0200
     1.3 @@ -3,7 +3,7 @@
     1.4  """
     1.5  Generate C code from object layouts and other deduced information.
     1.6  
     1.7 -Copyright (C) 2015-2019, 2021, 2023 Paul Boddie <paul@boddie.org.uk>
     1.8 +Copyright (C) 2015-2019, 2021, 2023, 2024 Paul Boddie <paul@boddie.org.uk>
     1.9  
    1.10  This program is free software; you can redistribute it and/or modify it under
    1.11  the terms of the GNU General Public License as published by the Free Software
    1.12 @@ -70,6 +70,13 @@
    1.13          dict_type, list_type, tuple_type
    1.14          )
    1.15  
    1.16 +    # Copiable types.
    1.17 +
    1.18 +    copiable_types = [
    1.19 +        "__builtins__.core.wrapper",
    1.20 +        float_type,
    1.21 +        ]
    1.22 +
    1.23      # Data types with a trailing data member of the given native types.
    1.24  
    1.25      trailing_data_types = {
    1.26 @@ -859,6 +866,7 @@
    1.27  typedef struct {
    1.28      const __table * table;
    1.29      __pos pos;
    1.30 +    __int obj_size;
    1.31      __attr attrs[%s];
    1.32  %s
    1.33  } %s;
    1.34 @@ -880,6 +888,10 @@
    1.35          obj_type = ref.has_kind("<instance>") and encode_symbol("obj", origin) or "__obj"
    1.36          obj_name = encode_path(structure_name)
    1.37  
    1.38 +        obj_size = ref.has_kind("<class>") and structure_name in self.copiable_types and \
    1.39 +            "sizeof(%s)" % encode_symbol("obj", structure_name) or \
    1.40 +            "0"
    1.41 +
    1.42          if f_decls:
    1.43              print >>f_decls, "extern %s %s;\n" % (obj_type, obj_name)
    1.44  
    1.45 @@ -887,6 +899,7 @@
    1.46  %s %s = {
    1.47      &%s,
    1.48      %s,
    1.49 +    %s,
    1.50      {
    1.51          %s
    1.52      },
    1.53 @@ -896,6 +909,7 @@
    1.54              obj_type, obj_name,
    1.55              table_name,
    1.56              pos,
    1.57 +            obj_size,
    1.58              ",\n        ".join(structure),
    1.59              trailing and ",\n    ".join(trailing) or "")
    1.60