# HG changeset patch # User Paul Boddie # Date 1373040234 -7200 # Node ID 02feed1a9aa3022c097a6e37b565678e7789953e # Parent ad6b88ecbf3cc79385a02f09cd7f84f2de22c86e Added keyword argument names to the syspython module output. Added a proper translation of slice objects. diff -r ad6b88ecbf3c -r 02feed1a9aa3 docs/syspython.txt --- a/docs/syspython.txt Fri Jul 05 17:16:07 2013 +0200 +++ b/docs/syspython.txt Fri Jul 05 18:03:54 2013 +0200 @@ -35,6 +35,11 @@ constants(...) +Each module may feature keyword arguments, and a list of such names is +provided as follows: + + keywords(...) + Explicit structure declaration is still performed using class statements, but base classes are omitted and attributes are declared explicitly as follows: @@ -183,11 +188,12 @@ In general, attribute access must use an explicit function indicating the kind of access operation being performed. For example: - # context effect - # -------------- + # context effect + loadattr(obj, attrname) # preserve context loadattrcontext(parent, attrname, obj) # replace context with obj loadattrcontextcond(parent, attrname, obj) # run-time context decision + loadattrindex(obj, attrname) # preserve context loadattrindexcontextcond(obj, attrname) # run-time context decision @@ -195,6 +201,10 @@ storeattrcontext(parent, attrname, value, obj) # replace context with obj storeattrindex(obj, attrname, value) +Recall that for loadattrindex family functions, the location of the attribute +is obtained from the object table and the nature of the attribute is +determined from the stored context value. + Temporary variables could employ similar functions: loadtemp(0) diff -r ad6b88ecbf3c -r 02feed1a9aa3 micropython/syspython.py --- a/micropython/syspython.py Fri Jul 05 17:16:07 2013 +0200 +++ b/micropython/syspython.py Fri Jul 05 18:03:54 2013 +0200 @@ -91,6 +91,15 @@ definitions = self.process_definitions(node) + # keywords(name, ...) + + keywords = module.keyword_names and [ + compiler.ast.CallFunc( + special_name("keywords"), + [special_name(name) for name in module.keyword_names] + ) + ] or [] + # globalnames(name, ...) globalnames = module.module_attribute_names() and [ @@ -113,7 +122,7 @@ self.in_main = False self.units.pop() - return compiler.ast.Module(node.doc, compiler.ast.Stmt(definitions + [main])) + return compiler.ast.Module(node.doc, compiler.ast.Stmt(keywords + definitions + [main])) # Statements. @@ -1026,7 +1035,11 @@ ) def visitSliceobj(self, node): - return compiler.ast.Sliceobj([self.dispatch(n) for n in node.nodes]) + return compiler.ast.CallFunc( + special_name("apply"), + [module_attribute("__builtins__", "slice")] + + [self.dispatch(n) for n in node.nodes] + ) def visitSub(self, node): return self._visitBinary(node)