1.1 --- a/translator.py Tue Oct 25 23:06:37 2016 +0200
1.2 +++ b/translator.py Tue Oct 25 23:10:29 2016 +0200
1.3 @@ -108,7 +108,7 @@
1.4 "A constant value reference in the translation."
1.5
1.6 def __str__(self):
1.7 - return "const%d" % self.number
1.8 + return encode_literal_constant(self.number)
1.9
1.10 class TrLiteralSequenceRef(results.LiteralSequenceRef, TranslationResult):
1.11
1.12 @@ -137,7 +137,7 @@
1.13 return False
1.14
1.15 def __repr__(self):
1.16 - return "AttrResult(%r, %r)" % (self.s, self.origin)
1.17 + return "AttrResult(%r, %r)" % (self.s, self.get_origin())
1.18
1.19 class PredefinedConstantRef(AttrResult):
1.20
1.21 @@ -147,7 +147,14 @@
1.22 self.value = value
1.23
1.24 def __str__(self):
1.25 - return self.value
1.26 + if self.value in ("False", "True"):
1.27 + return encode_path("__builtins__.bool.%s" % self.value)
1.28 + elif self.value == "None":
1.29 + return encode_path("__builtins__.none.%s" % self.value)
1.30 + elif self.value == "NotImplemented":
1.31 + return encode_path("__builtins__.notimplemented.%s" % self.value)
1.32 + else:
1.33 + return self.value
1.34
1.35 def __repr__(self):
1.36 return "PredefinedConstantRef(%r)" % self.value
1.37 @@ -831,13 +838,6 @@
1.38 if not args[argnum+1]:
1.39 args[argnum+1] = "__GETDEFAULT(%s, %d)" % (target, i)
1.40
1.41 - if None in args:
1.42 - print self.get_namespace_path()
1.43 - print n
1.44 - print expr
1.45 - print target
1.46 - print args
1.47 -
1.48 argstr = "__ARGS(%s)" % ", ".join(args)
1.49 kwargstr = kwargs and ("__ARGS(%s)" % ", ".join(kwargs)) or "0"
1.50 kwcodestr = kwcodes and ("__KWARGS(%s)" % ", ".join(kwcodes)) or "0"
1.51 @@ -845,13 +845,13 @@
1.52 # The callable is then obtained.
1.53
1.54 if target:
1.55 - callable = "__tmp_target"
1.56 + callable = target
1.57
1.58 elif self.always_callable:
1.59 - callable = "__load_via_object(__tmp_target, %s)" % \
1.60 + callable = "__load_via_object(__tmp_target.value, %s).fn" % \
1.61 encode_symbol("pos", "__fn__")
1.62 else:
1.63 - callable = "__check_and_load_via_object(__tmp_target, %s, %s)" % (
1.64 + callable = "__check_and_load_via_object(__tmp_target.value, %s, %s).fn" % (
1.65 encode_symbol("pos", "__fn__"), encode_symbol("code", "__fn__"))
1.66
1.67 stages.append(callable)
1.68 @@ -859,7 +859,7 @@
1.69 # With a known target, the function is obtained directly and called.
1.70
1.71 if target:
1.72 - output = "(\n%s.fn\n)(%s)" % (",\n".join(stages), argstr)
1.73 + output = "(\n%s\n)(%s)" % (",\n".join(stages), argstr)
1.74
1.75 # With unknown targets, the generic invocation function is applied to
1.76 # the callable and argument collections.
1.77 @@ -942,8 +942,7 @@
1.78 # Convert operator function names to references.
1.79
1.80 elif n.name.startswith("$op"):
1.81 - opname = n.name[len("$op"):]
1.82 - ref = self.importer.get_object("operator.%s" % opname)
1.83 + ref = self.importer.get_module(self.name).special.get(n.name)
1.84 return TrResolvedNameRef(n.name, ref)
1.85
1.86 # Get the appropriate name for the name reference, using the same method
1.87 @@ -1095,7 +1094,8 @@
1.88 print >>self.out, "__attr %s(__attr __args[])" % encode_function_pointer(name)
1.89 print >>self.out, "{"
1.90 self.indent += 1
1.91 - self.writeline("__attr __tmp_context, __tmp_target, __tmp_value;")
1.92 + self.writeline("__ref __tmp_context, __tmp_value;")
1.93 + self.writeline("__attr __tmp_target;")
1.94
1.95 # Obtain local names from parameters.
1.96