1.1 --- a/generator.py Sat Oct 29 20:22:30 2016 +0200
1.2 +++ b/generator.py Sat Oct 29 22:46:20 2016 +0200
1.3 @@ -25,7 +25,8 @@
1.4 encode_literal_constant, encode_literal_constant_member, \
1.5 encode_literal_constant_value, encode_literal_reference, \
1.6 encode_path, \
1.7 - encode_predefined_reference, encode_symbol, \
1.8 + encode_predefined_reference, encode_size, \
1.9 + encode_symbol, encode_tablename, \
1.10 encode_type_attribute
1.11 from os import listdir
1.12 from os.path import isdir, join, split
1.13 @@ -51,18 +52,6 @@
1.14
1.15 function_type = "__builtins__.core.function"
1.16
1.17 - table_name_prefixes = {
1.18 - "<class>" : "Class",
1.19 - "<module>" : "Module",
1.20 - "<instance>" : "Instance"
1.21 - }
1.22 -
1.23 - structure_size_prefixes = {
1.24 - "<class>" : "c",
1.25 - "<module>" : "m",
1.26 - "<instance>" : "i"
1.27 - }
1.28 -
1.29 predefined_constant_members = (
1.30 ("__builtins__.bool", "False"),
1.31 ("__builtins__.bool", "True"),
1.32 @@ -151,7 +140,7 @@
1.33 size_tables.sort()
1.34
1.35 for kind, sizes in size_tables:
1.36 - self.write_size_constants(f_consts, self.structure_size_prefixes[kind], sizes, 0)
1.37 + self.write_size_constants(f_consts, kind, sizes, 0)
1.38
1.39 # Generate parameter table size data.
1.40
1.41 @@ -190,8 +179,8 @@
1.42
1.43 kind = ref.get_kind()
1.44 path = ref.get_origin()
1.45 - table_name = encode_tablename(self.table_name_prefixes[kind], path)
1.46 - structure_size = encode_size(self.structure_size_prefixes[kind], path)
1.47 + table_name = encode_tablename(kind, path)
1.48 + structure_size = encode_size(kind, path)
1.49
1.50 # Generate structures for classes and modules.
1.51
1.52 @@ -256,8 +245,8 @@
1.53
1.54 for path in functions:
1.55 cls = self.function_type
1.56 - table_name = encode_tablename("Instance", cls)
1.57 - structure_size = encode_size(self.structure_size_prefixes["<instance>"], cls)
1.58 + table_name = encode_tablename("<instance>", cls)
1.59 + structure_size = encode_size("<instance>", cls)
1.60
1.61 # Set a special callable attribute on the instance.
1.62
1.63 @@ -326,7 +315,7 @@
1.64
1.65 #endif /* __PROGTYPES_H__ */""" % (
1.66 encode_path(self.function_type),
1.67 - encode_size(self.structure_size_prefixes["<instance>"], self.function_type)
1.68 + encode_size("<instance>", self.function_type)
1.69 )
1.70
1.71 print >>f_signatures, """\
1.72 @@ -400,8 +389,8 @@
1.73 # the constant in the program.
1.74
1.75 structure = []
1.76 - table_name = encode_tablename("Instance", cls)
1.77 - structure_size = encode_size(self.structure_size_prefixes["<instance>"], cls)
1.78 + table_name = encode_tablename("<instance>", cls)
1.79 + structure_size = encode_size("<instance>", cls)
1.80 self.populate_structure(ref, attrs, ref.get_kind(), structure)
1.81 self.write_structure(f_decls, f_defs, structure_name, table_name, structure_size, structure)
1.82
1.83 @@ -421,7 +410,7 @@
1.84 """
1.85
1.86 table = []
1.87 - table_name = encode_tablename("Function", path)
1.88 + table_name = encode_tablename("<function>", path)
1.89 structure_size = encode_size("pmax", path)
1.90 self.populate_parameter_table(function_path, table)
1.91 self.write_parameter_table(f_decls, f_defs, table_name, structure_size, table)
1.92 @@ -732,7 +721,7 @@
1.93 # Special argument specification member.
1.94
1.95 elif attrname == "__args__":
1.96 - structure.append("{.min=%s, .ptable=&%s}" % (attr, encode_tablename("Function", origin)))
1.97 + structure.append("{.min=%s, .ptable=&%s}" % (attr, encode_tablename("<function>", origin)))
1.98 continue
1.99
1.100 # Special internal data member.
1.101 @@ -822,7 +811,9 @@
1.102 }
1.103 """ % (
1.104 encode_instantiator_pointer(path),
1.105 - encode_tablename("Instance", path), encode_path(path), encode_symbol("obj", path),
1.106 + encode_tablename("<instance>", path),
1.107 + encode_path(path),
1.108 + encode_symbol("obj", path),
1.109 encode_function_pointer(init_ref.get_origin())
1.110 )
1.111
1.112 @@ -853,10 +844,4 @@
1.113 }
1.114 """
1.115
1.116 -def encode_size(table_type, path=None):
1.117 - return "__%ssize%s" % (table_type, path and "_%s" % encode_path(path) or "")
1.118 -
1.119 -def encode_tablename(table_type, path):
1.120 - return "__%sTable_%s" % (table_type, encode_path(path))
1.121 -
1.122 # vim: tabstop=4 expandtab shiftwidth=4