# HG changeset patch # User Paul Boddie # Date 1487345437 -3600 # Node ID 316c1c90b643d0e6b049ce6c0434d2fceef994f2 # Parent 87f11937a8e860c0f8f50d6cb2d1aff6cd7ab581 Eliminated superfluous accessor instructions loading static invocation targets. Added a test of nested calls employing explicitly retained contexts. diff -r 87f11937a8e8 -r 316c1c90b643 optimiser.py --- a/optimiser.py Tue Feb 14 00:17:39 2017 +0100 +++ b/optimiser.py Fri Feb 17 16:30:37 2017 +0100 @@ -535,15 +535,24 @@ if final_method == "static": emit(("__load_static_replace", context_var, origin)) + # Omit the context update operation where the target is static + # and the context is recorded separately. + + elif final_method == "static-invoke": + pass + # Only update any context if no separate context is used. - elif final_method not in ("access-invoke", "static-invoke"): + elif final_method != "access-invoke": emit(("__update_context", context_var, accessor)) else: emit(accessor) - elif final_method not in ("assign", "static-assign"): + # Omit the accessor for assignments and for invocations of static + # targets. + + elif final_method not in ("assign", "static-assign", "static-invoke"): emit(accessor) self.access_instructions[access_location] = instructions diff -r 87f11937a8e8 -r 316c1c90b643 tests/nested_calls.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/nested_calls.py Fri Feb 17 16:30:37 2017 +0100 @@ -0,0 +1,15 @@ +class C: + def __init__(self, x): + self.x = x + + def value(self): + return self.x + + def length(self): + return self.double(self.value()) + + def double(self, x): + return x * 2 + +c = C(3) +print c.length() # 6 diff -r 87f11937a8e8 -r 316c1c90b643 translator.py --- a/translator.py Tue Feb 14 00:17:39 2017 +0100 +++ b/translator.py Fri Feb 17 16:30:37 2017 +0100 @@ -1339,8 +1339,11 @@ # Without a known specific callable, the expression provides the target. if not target or context_required: - self.record_temp("__tmp_targets") - stages.append("__tmp_targets[%d] = %s" % (self.function_target, expr)) + if target: + stages.append(str(expr)) + else: + self.record_temp("__tmp_targets") + stages.append("__tmp_targets[%d] = %s" % (self.function_target, expr)) # Any specific callable is then obtained.