1.1 --- a/micropython/syspython.py Fri Jul 05 18:03:54 2013 +0200
1.2 +++ b/micropython/syspython.py Fri Jul 05 22:35:43 2013 +0200
1.3 @@ -34,7 +34,6 @@
1.4
1.5 # Convenience definitions.
1.6
1.7 -constant_attribute = compiler.ast.Getattr
1.8 special_name = compiler.ast.Name
1.9
1.10 def quoted_name(s):
1.11 @@ -46,14 +45,17 @@
1.12 def module_attribute(module_name, attrname):
1.13 return special_name(module_name + "." + attrname)
1.14
1.15 +def constant_attribute(parent, attrname):
1.16 + return compiler.ast.CallFunc("static", [quoted_name(parent.full_name() + "." + attrname)])
1.17 +
1.18 # Special function names.
1.19 # Some of the assignment operations cannot be supported unless attribute usage
1.20 # observations are being made.
1.21
1.22 -assattr_functions = ("storeattrcontext", "storeattrcontext", "storeattr",
1.23 - "storeattrindex", None)
1.24 -getattr_functions = ("loadattrcontext", "loadattrcontextcond", "loadattr",
1.25 - "loadattrindex", "loadattrindexcontextcond")
1.26 +assattr_functions = ("storeaddress", "storeaddresscontext", "storeaddresscontext",
1.27 + "storeattr", "storeattrindex", None)
1.28 +getattr_functions = ("loadaddress", "loadaddresscontext", "loadaddresscontextcond",
1.29 + "loadattr", "loadattrindex", "loadattrindexcontextcond")
1.30
1.31 # Source code classes.
1.32
1.33 @@ -516,8 +518,8 @@
1.34
1.35 # Choose the appropriate special functions.
1.36
1.37 - (opattrcontext, opattrcontextcond, opattr,
1.38 - opattrindex, opattrindexcontextcond) = expr and assattr_functions or getattr_functions
1.39 + (opaddress, opaddresscontext, opaddresscontextcond,
1.40 + opattr, opattrindex, opattrindexcontextcond) = expr and assattr_functions or getattr_functions
1.41
1.42 accessor = self.dispatch(node.expr)
1.43
1.44 @@ -529,12 +531,24 @@
1.45 # Generate accesses via static objects and instances.
1.46
1.47 if node._attr_deduced:
1.48 - if node._set_context == "set":
1.49 - op = opattrcontext
1.50 - elif node._set_context == "cond":
1.51 - op = opattrcontextcond
1.52 +
1.53 + # Static attributes may cause context replacement.
1.54 +
1.55 + if node._access_type == "static":
1.56 + if node._set_context == "set":
1.57 + op = opaddresscontext
1.58 + elif node._set_context == "cond":
1.59 + op = opaddresscontextcond
1.60 + else:
1.61 + op = opaddress
1.62 +
1.63 + parent = self._generateValue(node._attr_deduced.parent)
1.64 +
1.65 + # Non-static attributes.
1.66 +
1.67 else:
1.68 op = opattr
1.69 + parent = None
1.70
1.71 # Handle unsupported operations.
1.72
1.73 @@ -544,8 +558,7 @@
1.74 # Define the arguments: accessor, attribute name and optional value.
1.75
1.76 args = [
1.77 - node._access_type == "static" and \
1.78 - self._generateValue(node._attr_deduced.parent) or accessor,
1.79 + parent or accessor,
1.80 special_name(node.attrname)
1.81 ]
1.82
1.83 @@ -988,7 +1001,7 @@
1.84
1.85 elif attr is not None and not isinstance(attr, Instance):
1.86 if attr.is_constant():
1.87 - return constant_attribute(quoted_ref(attr.parent), node.name)
1.88 + return constant_attribute(attr.parent, node.name)
1.89 else:
1.90 return compiler.ast.CallFunc(
1.91 special_name("loadattr"),