# HG changeset patch # User Paul Boddie # Date 1476394037 -7200 # Node ID a0f513d3a7b1e85f718dfdb16ff44cb788d0cc11 # Parent 43a71138c9c719725bec2edaa13dfa9199acef33 Fixed instruction plan test operations, optimised the initial accessor to avoid redundant assignments and to use the context where appropriate, introduced accessor and attribute name parameterisation in the generated instructions, introduced a generic expression placeholder in place of any local name. diff -r 43a71138c9c7 -r a0f513d3a7b1 optimiser.py --- a/optimiser.py Wed Oct 12 18:07:48 2016 +0200 +++ b/optimiser.py Thu Oct 13 23:27:17 2016 +0200 @@ -1,7 +1,7 @@ #!/usr/bin/env python """ -Optimise object layouts. +Optimise object layouts and generate access instruction plans. Copyright (C) 2014, 2015, 2016 Paul Boddie @@ -392,7 +392,7 @@ if base: original_accessor = base else: - original_accessor = name + original_accessor = "" # use a generic placeholder # Prepare for any first attribute access. @@ -405,29 +405,31 @@ access_first_attribute = final_method == "access" or traversed or attrnames - if context == "final-accessor" or access_first_attribute: - emit(("set_accessor", original_accessor)) - # Set the context if already available. if context == "original-accessor": emit(("set_context", original_accessor)) + accessor = "context" elif context == "base": emit(("set_context", base)) + accessor = "context" + elif context == "final-accessor" or access_first_attribute: + emit(("set_accessor", original_accessor)) + accessor = "accessor" # Apply any test. - if test_type == "specific-type": + if test == "specific-type": emit(("test_specific_type", accessor, test_type)) - elif test_type == "specific-instance": + elif test == "specific-instance": emit(("test_specific_instance", accessor, test_type)) - elif test_type == "specific-object": + elif test == "specific-object": emit(("test_specific_object", accessor, test_type)) - elif test_type == "common-type": + elif test == "common-type": emit(("test_common_type", accessor, test_type)) - elif test_type == "common-instance": + elif test == "common-instance": emit(("test_common_instance", accessor, test_type)) - elif test_type == "common-object": + elif test == "common-object": emit(("test_common_object", accessor, test_type)) # Perform the first or final access. @@ -436,17 +438,17 @@ if access_first_attribute: if first_method == "relative-class": - emit(("set_accessor", ("load_via_class", "accessor", "attrname"))) + emit(("set_accessor", ("load_via_class", accessor, attrname))) elif first_method == "relative-object": - emit(("set_accessor", ("load_via_object", "accessor", "attrname"))) + emit(("set_accessor", ("load_via_object", accessor, attrname))) elif first_method == "relative-object-class": - emit(("set_accessor", ("get_class_and_load", "accessor", "attrname"))) + emit(("set_accessor", ("get_class_and_load", accessor, attrname))) elif first_method == "check-class": - emit(("set_accessor", ("check_and_load_via_class", "accessor", "attrname"))) + emit(("set_accessor", ("check_and_load_via_class", accessor, attrname))) elif first_method == "check-object": - emit(("set_accessor", ("check_and_load_via_object", "accessor", "attrname"))) + emit(("set_accessor", ("check_and_load_via_object", accessor, attrname))) elif first_method == "check-object-class": - emit(("set_accessor", ("get_class_check_and_load", "accessor", "attrname"))) + emit(("set_accessor", ("get_class_check_and_load", accessor, attrname))) # Obtain an accessor.