2.1 --- a/generator.py Mon Feb 27 00:55:52 2017 +0100
2.2 +++ b/generator.py Mon Feb 27 11:57:15 2017 +0100
2.3 @@ -20,13 +20,14 @@
2.4 """
2.5
2.6 from common import CommonOutput, copy
2.7 -from encoders import encode_function_pointer, \
2.8 +from encoders import encode_code, \
2.9 + encode_function_pointer, \
2.10 encode_instantiator_pointer, \
2.11 encode_literal_constant, encode_literal_constant_member, \
2.12 encode_literal_constant_size, encode_literal_constant_value, \
2.13 encode_literal_data_initialiser, \
2.14 encode_literal_instantiator, encode_literal_reference, \
2.15 - encode_path, \
2.16 + encode_path, encode_pcode, encode_pos, encode_ppos, \
2.17 encode_predefined_reference, encode_size, \
2.18 encode_symbol, encode_tablename, \
2.19 encode_type_attribute, decode_type_attribute, \
2.20 @@ -154,6 +155,8 @@
2.21 print >>f_consts, """\
2.22 #ifndef __PROGCONSTS_H__
2.23 #define __PROGCONSTS_H__
2.24 +
2.25 +#include "types.h"
2.26 """
2.27 print >>f_decls, """\
2.28 #ifndef __PROGTYPES_H__
2.29 @@ -379,11 +382,15 @@
2.30
2.31 # Generate parameter codes.
2.32
2.33 - self.write_code_constants(f_consts, self.optimiser.all_paramnames, self.optimiser.arg_locations, "pcode", "ppos")
2.34 + self.write_code_constants(f_consts, self.optimiser.all_paramnames,
2.35 + self.optimiser.arg_locations,
2.36 + "pcode", "ppos", encode_pcode, encode_ppos)
2.37
2.38 # Generate attribute codes.
2.39
2.40 - self.write_code_constants(f_consts, self.optimiser.all_attrnames, self.optimiser.locations, "code", "pos")
2.41 + self.write_code_constants(f_consts, self.optimiser.all_attrnames,
2.42 + self.optimiser.locations,
2.43 + "code", "pos", encode_code, encode_pos)
2.44
2.45 # Output more boilerplate.
2.46
2.47 @@ -403,8 +410,8 @@
2.48 encode_path(self.function_type),
2.49 encode_size("<instance>", self.function_type),
2.50 encode_path(self.type_type),
2.51 - encode_symbol("pos", encode_type_attribute(self.type_type)),
2.52 - encode_symbol("code", encode_type_attribute(self.type_type)),
2.53 + encode_pos(encode_type_attribute(self.type_type)),
2.54 + encode_code(encode_type_attribute(self.type_type)),
2.55 )
2.56
2.57 print >>f_signatures, """\
2.58 @@ -620,7 +627,8 @@
2.59 f_consts.write(" %s = %d" % (encode_size(size_prefix, path), size + padding))
2.60 print >>f_consts, "\n };"
2.61
2.62 - def write_code_constants(self, f_consts, attrnames, locations, code_prefix, pos_prefix):
2.63 + def write_code_constants(self, f_consts, attrnames, locations, code_prefix,
2.64 + pos_prefix, code_encoder, pos_encoder):
2.65
2.66 """
2.67 Write code constants to 'f_consts' for the given 'attrnames' and
2.68 @@ -634,7 +642,7 @@
2.69 print >>f_consts, ","
2.70 else:
2.71 first = False
2.72 - f_consts.write(" %s = %d" % (encode_symbol(code_prefix, attrname), i))
2.73 + f_consts.write(" %s = %d" % (code_encoder(attrname), i))
2.74 print >>f_consts, "\n };"
2.75
2.76 print >>f_consts, "enum %s {" % encode_symbol(pos_prefix)
2.77 @@ -645,7 +653,7 @@
2.78 print >>f_consts, ","
2.79 else:
2.80 first = False
2.81 - f_consts.write(" %s = %d" % (encode_symbol(pos_prefix, attrname), i))
2.82 + f_consts.write(" %s = %d" % (pos_encoder(attrname), i))
2.83 print >>f_consts, "\n };"
2.84
2.85 def write_table(self, f_decls, f_defs, table_name, structure_size, table):
2.86 @@ -730,7 +738,7 @@
2.87 print >>f_decls, "extern __obj %s;\n" % encode_path(structure_name)
2.88
2.89 is_class = path and self.importer.get_object(path).has_kind("<class>")
2.90 - pos = is_class and encode_symbol("pos", encode_type_attribute(path)) or "0"
2.91 + pos = is_class and encode_pos(encode_type_attribute(path)) or "0"
2.92
2.93 print >>f_defs, """\
2.94 __obj %s = {
2.95 @@ -833,7 +841,7 @@
2.96 if attrname is None:
2.97 table.append("0")
2.98 else:
2.99 - table.append(encode_symbol("code", attrname))
2.100 + table.append(encode_code(attrname))
2.101
2.102 def populate_parameter_table(self, parameters, table):
2.103
2.104 @@ -940,8 +948,8 @@
2.105 # Special internal key member.
2.106
2.107 elif attrname == "__key__":
2.108 - structure.append("{.code=%s, .pos=%s}" % (attr and encode_symbol("code", attr) or "0",
2.109 - attr and encode_symbol("pos", attr) or "0"))
2.110 + structure.append("{.code=%s, .pos=%s}" % (attr and encode_code(attr) or "0",
2.111 + attr and encode_pos(attr) or "0"))
2.112 continue
2.113
2.114 # Special cases.
2.115 @@ -1187,10 +1195,10 @@
2.116 return 0;
2.117 }
2.118 """ % (
2.119 - encode_symbol("pos", "value"),
2.120 - encode_symbol("pos", "__data__"),
2.121 + encode_pos("value"),
2.122 + encode_pos("__data__"),
2.123 encode_function_pointer("__builtins__.str.str"),
2.124 - encode_symbol("pos", "__data__")
2.125 + encode_pos("__data__")
2.126 )
2.127
2.128 # vim: tabstop=4 expandtab shiftwidth=4
5.1 --- a/translator.py Mon Feb 27 00:55:52 2017 +0100
5.2 +++ b/translator.py Mon Feb 27 11:57:15 2017 +0100
5.3 @@ -23,10 +23,10 @@
5.4 first, get_builtin_class, init_item, is_newer, \
5.5 predefined_constants
5.6 from encoders import encode_access_instruction, encode_access_instruction_arg, \
5.7 - encode_function_pointer, encode_literal_constant, \
5.8 + encode_code, encode_function_pointer, encode_literal_constant, \
5.9 encode_literal_instantiator, encode_instantiator_pointer, \
5.10 - encode_instructions, \
5.11 - encode_path, encode_symbol, encode_type_attribute, \
5.12 + encode_instructions, encode_path, encode_pos, \
5.13 + encode_symbol, encode_type_attribute, \
5.14 is_type_attribute
5.15 from errors import InspectError, TranslateError
5.16 from os.path import exists, join
5.17 @@ -142,7 +142,7 @@
5.18
5.19 elif parent:
5.20 return "__store_via_object(&%s, %s, %s)" % (
5.21 - encode_path(parent), encode_symbol("pos", attrname), self.expr)
5.22 + encode_path(parent), encode_pos(attrname), self.expr)
5.23
5.24 # All other assignments involve the names as they were given.
5.25
5.26 @@ -160,7 +160,7 @@
5.27
5.28 elif parent:
5.29 return "__load_via_object(&%s, %s)" % (
5.30 - encode_path(parent), encode_symbol("pos", attrname))
5.31 + encode_path(parent), encode_pos(attrname))
5.32
5.33 # All other accesses involve the names as they were given.
5.34
5.35 @@ -979,8 +979,8 @@
5.36 parent, attrname = path.rsplit(".", 1)
5.37
5.38 self.writestmt("__store_via_object(&%s, %s, __load_via_object(&%s, %s));" % (
5.39 - encode_path(class_name), encode_symbol("pos", name),
5.40 - encode_path(parent), encode_symbol("pos", attrname)
5.41 + encode_path(class_name), encode_pos(name),
5.42 + encode_path(parent), encode_pos(attrname)
5.43 ))
5.44
5.45 def process_from_node(self, n):
5.46 @@ -1064,7 +1064,7 @@
5.47 elif guard == "common":
5.48 ref = first(self.deducer.accessor_all_general_types[location])
5.49 typeattr = encode_type_attribute(ref.get_origin())
5.50 - argstr = "%s, %s" % (encode_symbol("pos", typeattr), encode_symbol("code", typeattr))
5.51 + argstr = "%s, %s" % (encode_pos(typeattr), encode_code(typeattr))
5.52 else:
5.53 return
5.54
5.55 @@ -1369,8 +1369,7 @@
5.56 else:
5.57 kwargs.append(str(argexpr))
5.58 kwcodes.append("{%s, %s}" % (
5.59 - encode_symbol("ppos", arg.name),
5.60 - encode_symbol("pcode", arg.name)))
5.61 + encode_ppos(arg.name), encode_pcode(arg.name)))
5.62
5.63 # Store non-keyword arguments in the argument list, rejecting
5.64 # superfluous arguments.
5.65 @@ -1449,7 +1448,7 @@
5.66 target_var, target_var))
5.67 else:
5.68 stages.append("__load_via_object(%s.value, %s).fn" % (
5.69 - target_var, encode_symbol("pos", "__fn__")))
5.70 + target_var, encode_pos("__fn__")))
5.71
5.72 # With a known target, the function is obtained directly and called.
5.73 # By putting the invocation at the end of the final element in the