1.1 --- a/docs/syspython.txt Fri Oct 25 00:59:37 2013 +0200
1.2 +++ b/docs/syspython.txt Fri Oct 25 01:02:10 2013 +0200
1.3 @@ -216,6 +216,11 @@
1.4
1.5 loadattr(obj, attrname) # preserve retrieved context
1.6
1.7 + # Constant attribute operations:
1.8 +
1.9 + static(value) # see above
1.10 + loadconstant(value, obj) # replace context with obj
1.11 +
1.12 # Static attribute operations:
1.13
1.14 loadaddress(parent, attrname) # preserve retrieved context
2.1 --- a/micropython/syspython.py Fri Oct 25 00:59:37 2013 +0200
2.2 +++ b/micropython/syspython.py Fri Oct 25 01:02:10 2013 +0200
2.3 @@ -53,9 +53,11 @@
2.4 # observations are being made.
2.5
2.6 assattr_functions = ("storeattrcontext", "storeattrcontext",
2.7 - "storeattr", "storeattrindexcontextcond")
2.8 + "storeattr", "storeattrindexcontextcond",
2.9 + None)
2.10 getattr_functions = ("loadattrcontext", "loadattrcontextcond",
2.11 - "loadattr", "loadattrindexcontextcond")
2.12 + "loadattr", "loadattrindexcontextcond",
2.13 + "loadconstant")
2.14
2.15 # Source code classes.
2.16
2.17 @@ -518,7 +520,7 @@
2.18
2.19 # Choose the appropriate special functions.
2.20
2.21 - (opattrcontext, opattrcontextcond, opattr, opattrindexcontextcond) = \
2.22 + (opattrcontext, opattrcontextcond, opattr, opattrindexcontextcond, opconstant) = \
2.23 expr and assattr_functions or getattr_functions
2.24
2.25 accessor = self.dispatch(node.expr)
2.26 @@ -526,7 +528,15 @@
2.27 # Generate already-deduced accesses.
2.28
2.29 if node._access_type == "constant":
2.30 - return self._generateValue(node._value_deduced)
2.31 + value = self._generateValue(node._value_deduced)
2.32 +
2.33 + # Where constant attributes are accessed via instances, a special
2.34 + # operation setting the context is needed.
2.35 +
2.36 + if node._set_context == "set":
2.37 + return compiler.ast.CallFunc(special_name(opconstant), accessor)
2.38 + else:
2.39 + return value
2.40
2.41 # Generate accesses via static objects and instances.
2.42