1.1 --- a/translator.py Tue Mar 21 18:45:42 2017 +0100
1.2 +++ b/translator.py Thu Mar 23 16:40:57 2017 +0100
1.3 @@ -542,7 +542,7 @@
1.4
1.5 subs = {
1.6 "<expr>" : attr_expr,
1.7 - "<name>" : "%s.value" % attr_expr,
1.8 + "<name>" : attr_expr,
1.9 "<assexpr>" : self.in_assignment,
1.10 }
1.11
1.12 @@ -884,16 +884,25 @@
1.13
1.14 # Produce an appropriate access to an attribute's value.
1.15
1.16 - parameters = self.importer.function_parameters.get(self.get_namespace_path())
1.17 - if parameters and name in parameters:
1.18 - name_to_value = "%s->value" % encode_path(name)
1.19 - else:
1.20 - name_to_value = "%s.value" % encode_path(name)
1.21 + name_as_attr = self.get_name_as_attribute(name)
1.22
1.23 # Write a test that raises a TypeError upon failure.
1.24
1.25 - self.writestmt("if (!__test_%s_%s(%s, %s)) __raise_type_error();" % (
1.26 - guard, guard_type, name_to_value, argstr))
1.27 + self.writestmt("if (!__test_%s_%s(__VALUE(%s), %s)) __raise_type_error();" % (
1.28 + guard, guard_type, name_as_attr, argstr))
1.29 +
1.30 + def get_name_as_attribute(self, name):
1.31 +
1.32 + "Return a generated expression for 'name' yielding an attribute."
1.33 +
1.34 + parameters = self.importer.function_parameters.get(self.get_namespace_path())
1.35 + parameter = name == "self" and self.in_method() or \
1.36 + parameters and name in parameters
1.37 +
1.38 + if parameter:
1.39 + return "*%s" % encode_path(name)
1.40 + else:
1.41 + return "%s" % encode_path(name)
1.42
1.43 def process_function_node(self, n):
1.44
1.45 @@ -963,6 +972,8 @@
1.46
1.47 if not instance_name:
1.48 instance_name = "&%s" % encode_path(objpath)
1.49 + else:
1.50 + instance_name = "__VALUE(%s)" % instance_name
1.51
1.52 # Where defaults are involved but cannot be identified, obtain a new
1.53 # instance of the lambda and populate the defaults.
1.54 @@ -1199,8 +1210,9 @@
1.55 if not target_identity:
1.56 self.record_temp("__tmp_targets")
1.57
1.58 - if context_identity and context_identity.startswith("__tmp_contexts"):
1.59 - self.record_temp("__tmp_contexts")
1.60 + if context_identity:
1.61 + if context_identity.startswith("__tmp_contexts"):
1.62 + self.record_temp("__tmp_contexts")
1.63
1.64 # Arguments are presented in a temporary frame array with any context
1.65 # always being the first argument. Where it would be unused, it may be
1.66 @@ -1210,7 +1222,7 @@
1.67
1.68 if context_required:
1.69 if have_access_context:
1.70 - args = ["__ATTRVALUE(%s)" % context_identity]
1.71 + args = [context_identity]
1.72 else:
1.73 args = ["__CONTEXT_AS_VALUE(%s)" % context_var]
1.74 else:
1.75 @@ -1355,19 +1367,19 @@
1.76 stages.append("__get_function(%s, %s)" % (
1.77 context_identity, target_var))
1.78 else:
1.79 - stages.append("__get_function(__CONTEXT_AS_VALUE(%s).value, %s)" % (
1.80 + stages.append("__get_function(__CONTEXT_AS_VALUE(%s), %s)" % (
1.81 context_var, target_var))
1.82 else:
1.83 - stages.append("__load_via_object(%s.value, __fn__).fn" % target_var)
1.84 + stages.append("__load_via_object(__VALUE(%s), __fn__).fn" % target_var)
1.85
1.86 # With known parameters, the target can be tested.
1.87
1.88 elif known_parameters:
1.89 context_arg = context_required and args[0] or "__NULL"
1.90 if self.always_callable(refs):
1.91 - stages.append("__get_function(%s.value, %s)" % (context_arg, target_var))
1.92 + stages.append("__get_function(%s, %s)" % (context_arg, target_var))
1.93 else:
1.94 - stages.append("__check_and_get_function(%s.value, %s)" % (context_arg, target_var))
1.95 + stages.append("__check_and_get_function(%s, %s)" % (context_arg, target_var))
1.96
1.97 # With a known target, the function is obtained directly and called.
1.98 # By putting the invocation at the end of the final element in the
1.99 @@ -1467,7 +1479,7 @@
1.100
1.101 else:
1.102 self.record_temp("__tmp_value")
1.103 - return make_expression("(__tmp_value = __COPY(&%s, sizeof(%s)), %s, __ATTRVALUE(__tmp_value))" % (
1.104 + return make_expression("(__tmp_value = __ATTRVALUE(__COPY(&%s, sizeof(%s))), %s, __tmp_value)" % (
1.105 encode_path(function_name),
1.106 encode_symbol("obj", function_name),
1.107 ", ".join(defaults)))
1.108 @@ -2018,16 +2030,16 @@
1.109 if self.uses_temp(name, "__tmp_targets"):
1.110 self.writeline("__attr __tmp_targets[%d];" % targets)
1.111 if self.uses_temp(name, "__tmp_contexts"):
1.112 - self.writeline("__ref __tmp_contexts[%d];" % targets)
1.113 + self.writeline("__attr __tmp_contexts[%d];" % targets)
1.114
1.115 # Add temporary variable usage details.
1.116
1.117 if self.uses_temp(name, "__tmp_private_context"):
1.118 - self.writeline("__ref __tmp_private_context;")
1.119 + self.writeline("__attr __tmp_private_context;")
1.120 if self.uses_temp(name, "__tmp_value"):
1.121 - self.writeline("__ref __tmp_value;")
1.122 + self.writeline("__attr __tmp_value;")
1.123 if self.uses_temp(name, "__tmp_target_value"):
1.124 - self.writeline("__ref __tmp_target_value;")
1.125 + self.writeline("__attr __tmp_target_value;")
1.126 if self.uses_temp(name, "__tmp_result"):
1.127 self.writeline("__attr __tmp_result;")
1.128