# HG changeset patch # User Paul Boddie # Date 1477782962 -7200 # Node ID a32be37ae7dc5e6a6f6203b1b67dba37df5a97f3 # Parent ba2614628b3f95212fc2fe06db9c5c8983b26a3c Added result conversion for access instructions, fixed __get_class_and_load. diff -r ba2614628b3f -r a32be37ae7dc encoders.py --- a/encoders.py Sun Oct 30 00:51:06 2016 +0200 +++ b/encoders.py Sun Oct 30 01:16:02 2016 +0200 @@ -167,13 +167,19 @@ # Output program encoding. -attribute_ops = ( - "__load_via_class", "__load_via_object", +attribute_loading_ops = ( + "__load_via_class", "__load_via_object", "__get_class_and_load", + ) + +attribute_ops = attribute_loading_ops + ( "__store_via_object", ) -checked_ops = ( +checked_loading_ops = ( "__check_and_load_via_class", "__check_and_load_via_object", "__check_and_load_via_any", + ) + +checked_ops = checked_loading_ops + ( "__check_and_store_via_class", "__check_and_store_via_object", "__check_and_store_via_any", ) @@ -189,6 +195,9 @@ "__load_static", ) +reference_acting_ops = attribute_ops + checked_ops + typename_ops +attribute_producing_ops = attribute_loading_ops + checked_loading_ops + def encode_access_instruction(instruction, subs): """ @@ -210,8 +219,10 @@ # Encode the arguments. a = [] + converting_op = op for arg in args: - a.append(encode_access_instruction_arg(arg, subs)) + a.append(encode_access_instruction_arg(arg, subs, converting_op)) + converting_op = None # Modify certain arguments. @@ -260,12 +271,19 @@ return "%s%s" % (op, argstr) -def encode_access_instruction_arg(arg, subs): +def encode_access_instruction_arg(arg, subs, op): "Encode 'arg' using 'subs' to define substitutions." if isinstance(arg, tuple): - return encode_access_instruction(arg, subs) + encoded = encode_access_instruction(arg, subs) + + # Convert attribute results to references where required. + + if op and op in reference_acting_ops and arg[0] in attribute_producing_ops: + return "%s.value" % encoded + else: + return encoded # Special values only need replacing, not encoding. diff -r ba2614628b3f -r a32be37ae7dc templates/ops.c --- a/templates/ops.c Sun Oct 30 00:51:06 2016 +0200 +++ b/templates/ops.c Sun Oct 30 01:16:02 2016 +0200 @@ -35,10 +35,10 @@ __attr __get_class_and_load(__ref obj, int pos) { - if (!__is_instance(obj)) + if (__is_instance(obj)) + return __load_via_class(obj, pos); + else return __load_via_object(obj, pos); - else - return __load_via_class(obj, pos); } /* Direct storage operations. */ diff -r ba2614628b3f -r a32be37ae7dc templates/ops.h --- a/templates/ops.h Sun Oct 30 00:51:06 2016 +0200 +++ b/templates/ops.h Sun Oct 30 01:16:02 2016 +0200 @@ -18,6 +18,7 @@ __attr __load_via_class(__ref obj, int pos); __attr __load_via_object(__ref obj, int pos); +__attr __get_class_and_load(__ref obj, int pos); /* Direct storage operations. */