1.1 --- a/generator.py Mon Feb 27 00:55:52 2017 +0100
1.2 +++ b/generator.py Mon Feb 27 11:57:15 2017 +0100
1.3 @@ -20,13 +20,14 @@
1.4 """
1.5
1.6 from common import CommonOutput, copy
1.7 -from encoders import encode_function_pointer, \
1.8 +from encoders import encode_code, \
1.9 + encode_function_pointer, \
1.10 encode_instantiator_pointer, \
1.11 encode_literal_constant, encode_literal_constant_member, \
1.12 encode_literal_constant_size, encode_literal_constant_value, \
1.13 encode_literal_data_initialiser, \
1.14 encode_literal_instantiator, encode_literal_reference, \
1.15 - encode_path, \
1.16 + encode_path, encode_pcode, encode_pos, encode_ppos, \
1.17 encode_predefined_reference, encode_size, \
1.18 encode_symbol, encode_tablename, \
1.19 encode_type_attribute, decode_type_attribute, \
1.20 @@ -154,6 +155,8 @@
1.21 print >>f_consts, """\
1.22 #ifndef __PROGCONSTS_H__
1.23 #define __PROGCONSTS_H__
1.24 +
1.25 +#include "types.h"
1.26 """
1.27 print >>f_decls, """\
1.28 #ifndef __PROGTYPES_H__
1.29 @@ -379,11 +382,15 @@
1.30
1.31 # Generate parameter codes.
1.32
1.33 - self.write_code_constants(f_consts, self.optimiser.all_paramnames, self.optimiser.arg_locations, "pcode", "ppos")
1.34 + self.write_code_constants(f_consts, self.optimiser.all_paramnames,
1.35 + self.optimiser.arg_locations,
1.36 + "pcode", "ppos", encode_pcode, encode_ppos)
1.37
1.38 # Generate attribute codes.
1.39
1.40 - self.write_code_constants(f_consts, self.optimiser.all_attrnames, self.optimiser.locations, "code", "pos")
1.41 + self.write_code_constants(f_consts, self.optimiser.all_attrnames,
1.42 + self.optimiser.locations,
1.43 + "code", "pos", encode_code, encode_pos)
1.44
1.45 # Output more boilerplate.
1.46
1.47 @@ -403,8 +410,8 @@
1.48 encode_path(self.function_type),
1.49 encode_size("<instance>", self.function_type),
1.50 encode_path(self.type_type),
1.51 - encode_symbol("pos", encode_type_attribute(self.type_type)),
1.52 - encode_symbol("code", encode_type_attribute(self.type_type)),
1.53 + encode_pos(encode_type_attribute(self.type_type)),
1.54 + encode_code(encode_type_attribute(self.type_type)),
1.55 )
1.56
1.57 print >>f_signatures, """\
1.58 @@ -620,7 +627,8 @@
1.59 f_consts.write(" %s = %d" % (encode_size(size_prefix, path), size + padding))
1.60 print >>f_consts, "\n };"
1.61
1.62 - def write_code_constants(self, f_consts, attrnames, locations, code_prefix, pos_prefix):
1.63 + def write_code_constants(self, f_consts, attrnames, locations, code_prefix,
1.64 + pos_prefix, code_encoder, pos_encoder):
1.65
1.66 """
1.67 Write code constants to 'f_consts' for the given 'attrnames' and
1.68 @@ -634,7 +642,7 @@
1.69 print >>f_consts, ","
1.70 else:
1.71 first = False
1.72 - f_consts.write(" %s = %d" % (encode_symbol(code_prefix, attrname), i))
1.73 + f_consts.write(" %s = %d" % (code_encoder(attrname), i))
1.74 print >>f_consts, "\n };"
1.75
1.76 print >>f_consts, "enum %s {" % encode_symbol(pos_prefix)
1.77 @@ -645,7 +653,7 @@
1.78 print >>f_consts, ","
1.79 else:
1.80 first = False
1.81 - f_consts.write(" %s = %d" % (encode_symbol(pos_prefix, attrname), i))
1.82 + f_consts.write(" %s = %d" % (pos_encoder(attrname), i))
1.83 print >>f_consts, "\n };"
1.84
1.85 def write_table(self, f_decls, f_defs, table_name, structure_size, table):
1.86 @@ -730,7 +738,7 @@
1.87 print >>f_decls, "extern __obj %s;\n" % encode_path(structure_name)
1.88
1.89 is_class = path and self.importer.get_object(path).has_kind("<class>")
1.90 - pos = is_class and encode_symbol("pos", encode_type_attribute(path)) or "0"
1.91 + pos = is_class and encode_pos(encode_type_attribute(path)) or "0"
1.92
1.93 print >>f_defs, """\
1.94 __obj %s = {
1.95 @@ -833,7 +841,7 @@
1.96 if attrname is None:
1.97 table.append("0")
1.98 else:
1.99 - table.append(encode_symbol("code", attrname))
1.100 + table.append(encode_code(attrname))
1.101
1.102 def populate_parameter_table(self, parameters, table):
1.103
1.104 @@ -940,8 +948,8 @@
1.105 # Special internal key member.
1.106
1.107 elif attrname == "__key__":
1.108 - structure.append("{.code=%s, .pos=%s}" % (attr and encode_symbol("code", attr) or "0",
1.109 - attr and encode_symbol("pos", attr) or "0"))
1.110 + structure.append("{.code=%s, .pos=%s}" % (attr and encode_code(attr) or "0",
1.111 + attr and encode_pos(attr) or "0"))
1.112 continue
1.113
1.114 # Special cases.
1.115 @@ -1187,10 +1195,10 @@
1.116 return 0;
1.117 }
1.118 """ % (
1.119 - encode_symbol("pos", "value"),
1.120 - encode_symbol("pos", "__data__"),
1.121 + encode_pos("value"),
1.122 + encode_pos("__data__"),
1.123 encode_function_pointer("__builtins__.str.str"),
1.124 - encode_symbol("pos", "__data__")
1.125 + encode_pos("__data__")
1.126 )
1.127
1.128 # vim: tabstop=4 expandtab shiftwidth=4