1.1 --- a/encoders.py Tue Oct 25 23:06:37 2016 +0200
1.2 +++ b/encoders.py Tue Oct 25 23:10:29 2016 +0200
1.3 @@ -281,6 +281,33 @@
1.4
1.5 return "__new_%s" % encode_path(path)
1.6
1.7 +def encode_literal_constant(n):
1.8 +
1.9 + "Encode a name for the literal constant with the number 'n'."
1.10 +
1.11 + return "__const%d" % n
1.12 +
1.13 +def encode_literal_constant_member(value):
1.14 +
1.15 + "Encode the member name for the 'value' in the final program."
1.16 +
1.17 + return "%svalue" % value.__class__.__name__
1.18 +
1.19 +def encode_literal_constant_value(value):
1.20 +
1.21 + "Encode the given 'value' in the final program."
1.22 +
1.23 + if isinstance(value, (int, float)):
1.24 + return str(value)
1.25 + else:
1.26 + return '"%s"' % str(value).replace('"', '\\"')
1.27 +
1.28 +def encode_literal_reference(n):
1.29 +
1.30 + "Encode a reference to a literal constant with the number 'n'."
1.31 +
1.32 + return "__constvalue%d" % n
1.33 +
1.34 def encode_path(path):
1.35
1.36 "Encode 'path' as an output program object, translating special symbols."
1.37 @@ -290,6 +317,12 @@
1.38 else:
1.39 return path.replace("#", "__").replace("$", "__").replace(".", "_")
1.40
1.41 +def encode_predefined_reference(path):
1.42 +
1.43 + "Encode a reference to a predefined constant value for 'path'."
1.44 +
1.45 + return "__predefined_%s" % encode_path(path)
1.46 +
1.47 def encode_symbol(symbol_type, path=None):
1.48
1.49 "Encode a symbol with the given 'symbol_type' and optional 'path'."