# HG changeset patch # User Paul Boddie # Date 1487461708 -3600 # Node ID 6a11001c93ce499e9f4113e4e82d813865e25b8c # Parent 60c18e54c8dbbf417c44b2edb927ea4aed103780 Reordered conditional clauses and added some comments. diff -r 60c18e54c8db -r 6a11001c93ce optimiser.py --- a/optimiser.py Sat Feb 18 20:20:06 2017 +0100 +++ b/optimiser.py Sun Feb 19 00:48:28 2017 +0100 @@ -351,9 +351,13 @@ first_method, final_method, \ origin, accessor_kinds = access_plan + # Emit instructions by appending them to a list. + instructions = [] emit = instructions.append + # Identify any static original accessor. + if base: original_accessor = base else: @@ -466,9 +470,17 @@ # Set the context, if appropriate. if remaining == 1 and final_method != "assign" and context == "final-accessor": + + # Invoked attributes employ a separate context accessed + # during invocation. + if final_method in ("access-invoke", "static-invoke"): emit(("", accessor)) accessor = context_var = "" + + # A private context within the access is otherwise + # retained. + else: emit(("", accessor)) accessor = context_var = "" @@ -497,9 +509,17 @@ # Set the context, if appropriate. if remaining == 1 and final_method != "assign" and context == "final-accessor": + + # Invoked attributes employ a separate context accessed + # during invocation. + if final_method in ("access-invoke", "static-invoke"): emit(("", accessor)) accessor = context_var = "" + + # A private context within the access is otherwise + # retained. + else: emit(("", accessor)) accessor = context_var = "" @@ -531,12 +551,27 @@ # Wrap accesses in context operations. if context_test == "test": + + # Test and combine the context with static attribute details. + if final_method == "static": emit(("__load_static_test", context_var, origin)) + + # Test the context, storing it separately if required for the + # immediately invoked static attribute. + elif final_method == "static-invoke": emit(("", context_var, origin)) + + # Test the context, storing it separately if required for an + # immediately invoked attribute. + elif final_method == "access-invoke": emit(("", context_var, accessor)) + + # Test the context and update the attribute details if + # appropriate. + else: emit(("__test_context", context_var, accessor)) @@ -553,13 +588,16 @@ elif final_method == "static-invoke": pass - # Only update any context if no separate context is used. + # If a separate context is used for an immediate invocation, + # produce the attribute details unchanged. - elif final_method != "access-invoke": - emit(("__update_context", context_var, accessor)) + elif final_method == "access-invoke": + emit(accessor) + + # Update the context in the attribute details. else: - emit(accessor) + emit(("__update_context", context_var, accessor)) # Omit the accessor for assignments and for invocations of static # targets.