1.1 --- a/translator.py Sun Oct 30 13:14:45 2016 +0100
1.2 +++ b/translator.py Sun Oct 30 17:54:27 2016 +0100
1.3 @@ -281,10 +281,18 @@
1.4
1.5 return self.importer.objects.get(self.get_namespace_path())
1.6
1.7 - def get_builtin(self, name):
1.8 - return self.importer.get_object("__builtins__.%s" % name)
1.9 + def get_builtin_class(self, name):
1.10 +
1.11 + "Return a reference to the actual object providing 'name'."
1.12 +
1.13 + # NOTE: This makes assumptions about the __builtins__ structure.
1.14
1.15 - def in_method(self, path):
1.16 + return self.importer.get_object("__builtins__.%s.%s" % (name, name))
1.17 +
1.18 + def is_method(self, path):
1.19 +
1.20 + "Return whether 'path' is a method."
1.21 +
1.22 class_name, method_name = path.rsplit(".", 1)
1.23 return self.importer.classes.has_key(class_name) and class_name
1.24
1.25 @@ -362,7 +370,7 @@
1.26 For node 'n', return a reference for the type of the given 'name'.
1.27 """
1.28
1.29 - ref = self.get_builtin(name)
1.30 + ref = self.get_builtin_class(name)
1.31
1.32 if name in ("dict", "list", "tuple"):
1.33 return self.process_literal_sequence_node(n, name, ref, TrLiteralSequenceRef)
1.34 @@ -842,12 +850,6 @@
1.35 else:
1.36 parameters = None
1.37
1.38 - stages = []
1.39 -
1.40 - # First, the invocation target is presented.
1.41 -
1.42 - stages.append("__tmp_target = %s" % expr)
1.43 -
1.44 # Arguments are presented in a temporary frame array with any context
1.45 # always being the first argument (although it may be set to null for
1.46 # invocations where it would be unused).
1.47 @@ -904,19 +906,20 @@
1.48 kwargstr = kwargs and ("__ARGS(%s)" % ", ".join(kwargs)) or "0"
1.49 kwcodestr = kwcodes and ("__KWARGS(%s)" % ", ".join(kwcodes)) or "0"
1.50
1.51 - # The callable is then obtained.
1.52 + # First, the invocation expression is presented.
1.53
1.54 - if target:
1.55 - callable = target
1.56 + stages = []
1.57 +
1.58 + # Without a known specific callable, the expression provides the target.
1.59
1.60 - elif self.always_callable:
1.61 - callable = "__load_via_object(__tmp_target.value, %s)" % \
1.62 - encode_symbol("pos", "__fn__")
1.63 + if not target:
1.64 + stages.append(str(expr))
1.65 +
1.66 + # Any specific callable is then obtained.
1.67 +
1.68 else:
1.69 - callable = "__check_and_load_via_object(__tmp_target.value, %s, %s)" % (
1.70 - encode_symbol("pos", "__fn__"), encode_symbol("code", "__fn__"))
1.71 -
1.72 - stages.append(callable)
1.73 + stages.append("__tmp_target = %s" % expr)
1.74 + stages.append(target)
1.75
1.76 # With a known target, the function is obtained directly and called.
1.77
1.78 @@ -927,8 +930,9 @@
1.79 # the callable and argument collections.
1.80
1.81 else:
1.82 - output = "__invoke(\n(\n%s\n),\n%d, %s, %s,\n%d, %s\n)" % (
1.83 + output = "__invoke(\n(\n%s\n),\n%d, %d, %s, %s,\n%d, %s\n)" % (
1.84 ",\n".join(stages),
1.85 + self.always_callable and 1 or 0,
1.86 len(kwargs), kwcodestr, kwargstr,
1.87 len(args), argstr)
1.88
1.89 @@ -1022,8 +1026,7 @@
1.90 # Convert literal references.
1.91
1.92 elif n.name.startswith("$L"):
1.93 - literal_name = n.name[len("$L"):]
1.94 - ref = self.importer.get_object("__builtins__.%s" % literal_name)
1.95 + ref = self.importer.get_module(self.name).special.get(n.name)
1.96 return TrResolvedNameRef(n.name, ref)
1.97
1.98 # Convert operator function names to references.
1.99 @@ -1323,7 +1326,7 @@
1.100
1.101 # Generate any self reference.
1.102
1.103 - if self.in_method(name):
1.104 + if self.is_method(name):
1.105 if define:
1.106 self.writeline("#define self (__args[0])")
1.107 else: