1.1 --- a/encoders.py Sun Oct 30 00:51:06 2016 +0200
1.2 +++ b/encoders.py Sun Oct 30 01:16:02 2016 +0200
1.3 @@ -167,13 +167,19 @@
1.4
1.5 # Output program encoding.
1.6
1.7 -attribute_ops = (
1.8 - "__load_via_class", "__load_via_object",
1.9 +attribute_loading_ops = (
1.10 + "__load_via_class", "__load_via_object", "__get_class_and_load",
1.11 + )
1.12 +
1.13 +attribute_ops = attribute_loading_ops + (
1.14 "__store_via_object",
1.15 )
1.16
1.17 -checked_ops = (
1.18 +checked_loading_ops = (
1.19 "__check_and_load_via_class", "__check_and_load_via_object", "__check_and_load_via_any",
1.20 + )
1.21 +
1.22 +checked_ops = checked_loading_ops + (
1.23 "__check_and_store_via_class", "__check_and_store_via_object", "__check_and_store_via_any",
1.24 )
1.25
1.26 @@ -189,6 +195,9 @@
1.27 "__load_static",
1.28 )
1.29
1.30 +reference_acting_ops = attribute_ops + checked_ops + typename_ops
1.31 +attribute_producing_ops = attribute_loading_ops + checked_loading_ops
1.32 +
1.33 def encode_access_instruction(instruction, subs):
1.34
1.35 """
1.36 @@ -210,8 +219,10 @@
1.37 # Encode the arguments.
1.38
1.39 a = []
1.40 + converting_op = op
1.41 for arg in args:
1.42 - a.append(encode_access_instruction_arg(arg, subs))
1.43 + a.append(encode_access_instruction_arg(arg, subs, converting_op))
1.44 + converting_op = None
1.45
1.46 # Modify certain arguments.
1.47
1.48 @@ -260,12 +271,19 @@
1.49
1.50 return "%s%s" % (op, argstr)
1.51
1.52 -def encode_access_instruction_arg(arg, subs):
1.53 +def encode_access_instruction_arg(arg, subs, op):
1.54
1.55 "Encode 'arg' using 'subs' to define substitutions."
1.56
1.57 if isinstance(arg, tuple):
1.58 - return encode_access_instruction(arg, subs)
1.59 + encoded = encode_access_instruction(arg, subs)
1.60 +
1.61 + # Convert attribute results to references where required.
1.62 +
1.63 + if op and op in reference_acting_ops and arg[0] in attribute_producing_ops:
1.64 + return "%s.value" % encoded
1.65 + else:
1.66 + return encoded
1.67
1.68 # Special values only need replacing, not encoding.
1.69
2.1 --- a/templates/ops.c Sun Oct 30 00:51:06 2016 +0200
2.2 +++ b/templates/ops.c Sun Oct 30 01:16:02 2016 +0200
2.3 @@ -35,10 +35,10 @@
2.4
2.5 __attr __get_class_and_load(__ref obj, int pos)
2.6 {
2.7 - if (!__is_instance(obj))
2.8 + if (__is_instance(obj))
2.9 + return __load_via_class(obj, pos);
2.10 + else
2.11 return __load_via_object(obj, pos);
2.12 - else
2.13 - return __load_via_class(obj, pos);
2.14 }
2.15
2.16 /* Direct storage operations. */
3.1 --- a/templates/ops.h Sun Oct 30 00:51:06 2016 +0200
3.2 +++ b/templates/ops.h Sun Oct 30 01:16:02 2016 +0200
3.3 @@ -18,6 +18,7 @@
3.4
3.5 __attr __load_via_class(__ref obj, int pos);
3.6 __attr __load_via_object(__ref obj, int pos);
3.7 +__attr __get_class_and_load(__ref obj, int pos);
3.8
3.9 /* Direct storage operations. */
3.10