# HG changeset patch # User Paul Boddie # Date 1382655730 -7200 # Node ID c9630f7ba1dc07aa65941006ca9dbd73f053b5f9 # Parent 5dfc14c89f254c731745b00a97d4d40377b38933 Added support for access to constant attributes via instances, setting the context. diff -r 5dfc14c89f25 -r c9630f7ba1dc docs/syspython.txt --- a/docs/syspython.txt Fri Oct 25 00:59:37 2013 +0200 +++ b/docs/syspython.txt Fri Oct 25 01:02:10 2013 +0200 @@ -216,6 +216,11 @@ loadattr(obj, attrname) # preserve retrieved context + # Constant attribute operations: + + static(value) # see above + loadconstant(value, obj) # replace context with obj + # Static attribute operations: loadaddress(parent, attrname) # preserve retrieved context diff -r 5dfc14c89f25 -r c9630f7ba1dc micropython/syspython.py --- a/micropython/syspython.py Fri Oct 25 00:59:37 2013 +0200 +++ b/micropython/syspython.py Fri Oct 25 01:02:10 2013 +0200 @@ -53,9 +53,11 @@ # observations are being made. assattr_functions = ("storeattrcontext", "storeattrcontext", - "storeattr", "storeattrindexcontextcond") + "storeattr", "storeattrindexcontextcond", + None) getattr_functions = ("loadattrcontext", "loadattrcontextcond", - "loadattr", "loadattrindexcontextcond") + "loadattr", "loadattrindexcontextcond", + "loadconstant") # Source code classes. @@ -518,7 +520,7 @@ # Choose the appropriate special functions. - (opattrcontext, opattrcontextcond, opattr, opattrindexcontextcond) = \ + (opattrcontext, opattrcontextcond, opattr, opattrindexcontextcond, opconstant) = \ expr and assattr_functions or getattr_functions accessor = self.dispatch(node.expr) @@ -526,7 +528,15 @@ # Generate already-deduced accesses. if node._access_type == "constant": - return self._generateValue(node._value_deduced) + value = self._generateValue(node._value_deduced) + + # Where constant attributes are accessed via instances, a special + # operation setting the context is needed. + + if node._set_context == "set": + return compiler.ast.CallFunc(special_name(opconstant), accessor) + else: + return value # Generate accesses via static objects and instances.