1.1 --- a/optimiser.py Sat Oct 15 23:32:15 2016 +0200
1.2 +++ b/optimiser.py Sat Oct 15 23:34:29 2016 +0200
1.3 @@ -344,7 +344,7 @@
1.4 # Obtain the access details.
1.5
1.6 name, test, test_type, base, traversed, traversal_modes, \
1.7 - attrnames, context, first_method, final_method, origin = access_plan
1.8 + attrnames, context, context_test, first_method, final_method, origin = access_plan
1.9
1.10 instructions = []
1.11 emit = instructions.append
1.12 @@ -383,7 +383,7 @@
1.13
1.14 # Assigning does not set the context.
1.15
1.16 - elif context in ("final-accessor", "unset"):
1.17 + elif context in ("final-accessor", "unset") and access_first_attribute:
1.18 emit(("set_accessor", original_accessor))
1.19 accessor = "accessor"
1.20
1.21 @@ -405,6 +405,8 @@
1.22 # Perform the first or final access.
1.23 # The access only needs performing if the resulting accessor is used.
1.24
1.25 + remaining = len(traversed + attrnames)
1.26 +
1.27 if access_first_attribute:
1.28
1.29 if first_method == "relative-class":
1.30 @@ -443,9 +445,7 @@
1.31 else:
1.32 emit(("set_accessor", ("check_and_load_via_any", accessor, attrname)))
1.33
1.34 - # Obtain an accessor.
1.35 -
1.36 - remaining = len(traversed + attrnames)
1.37 + # Traverse attributes using the accessor.
1.38
1.39 if traversed:
1.40 for attrname, traversal_mode in zip(traversed, traversal_modes):
1.41 @@ -496,7 +496,14 @@
1.42 if final_method == "static-assign":
1.43 emit(("store_member", origin, "<assexpr>"))
1.44 elif final_method == "static":
1.45 - emit(("load_static", origin))
1.46 + emit(("set_accessor", ("load_static", origin)))
1.47 +
1.48 + if context_test == "test":
1.49 + emit(("test_context", "context", "accessor"))
1.50 + elif context_test == "replace":
1.51 + emit(("replace_context", "context", "accessor"))
1.52 + else:
1.53 + emit(("get_accessor",))
1.54
1.55 self.access_instructions[access_location] = instructions
1.56