[pypy-svn] r39991 - pypy/dist/pypy/interpreter/astcompiler

afayolle at codespeak.net afayolle at codespeak.net
Tue Mar 6 18:18:52 CET 2007


Author: afayolle
Date: Tue Mar  6 18:18:46 2007
New Revision: 39991

Modified:
   pypy/dist/pypy/interpreter/astcompiler/ast.py
   pypy/dist/pypy/interpreter/astcompiler/ast.txt
   pypy/dist/pypy/interpreter/astcompiler/astgen.py
Log:
(adim, ludal, cfbolz, alf)
 - fix ast.txt and astgen.py :
         * removed some duplicated code
         * properly initialize Function objects from app level code
 - regenerate ast.py



Modified: pypy/dist/pypy/interpreter/astcompiler/ast.py
==============================================================================
--- pypy/dist/pypy/interpreter/astcompiler/ast.py	(original)
+++ pypy/dist/pypy/interpreter/astcompiler/ast.py	Tue Mar  6 18:18:46 2007
@@ -1709,7 +1709,6 @@
 
 
 
-
 Compare.typedef = TypeDef('Compare', Node.typedef, 
                      __new__ = interp2app(descr_Compare_new, unwrap_spec=[ObjSpace, W_Root, W_Root, W_Root, int]),
                      accept=interp2app(descr_Compare_accept, unwrap_spec=[ObjSpace, W_Root, W_Root] ),
@@ -2653,7 +2652,7 @@
     def fset_code( space, self, w_arg):
         self.code = space.interp_w(Node, w_arg, can_be_None=False)
 
-def descr_Function_new(space, w_subtype, w_decorators, w_name, w_argnames, w_defaults, w_flags, w_w_doc, w_code, lineno=-1):
+def descr_Function_new(space, w_subtype, w_decorators, w_name, w_argnames, w_defaults, w_flags, w_doc, w_code, lineno=-1):
     self = space.allocate_instance(Function, w_subtype)
     decorators = space.interp_w(Node, w_decorators, can_be_None=True)
     self.decorators = decorators
@@ -2664,15 +2663,22 @@
     defaults = [space.interp_w(Node, w_node) for w_node in space.unpackiterable(w_defaults)]
     self.defaults = defaults
     flags = space.int_w(w_flags)
-    self.flags = flags
-    # This dummy assingment is auto-generated, astgen.py should be fixed to avoid that
-    w_doc = w_w_doc
+    self.flags = flags    
     self.w_doc = w_doc
     code = space.interp_w(Node, w_code, can_be_None=False)
     self.code = code
     self.lineno = lineno
+
+    self.varargs = 0
+    self.kwargs = 0
+    if flags & CO_VARARGS:
+        self.varargs = 1
+    if flags & CO_VARKEYWORDS:
+        self.kwargs = 1
     return space.wrap(self)
 
+
+
 def descr_Function_accept( space, w_self, w_visitor):
     return space.call_method(w_visitor, 'visitFunction', w_self)
 

Modified: pypy/dist/pypy/interpreter/astcompiler/ast.txt
==============================================================================
--- pypy/dist/pypy/interpreter/astcompiler/ast.txt	(original)
+++ pypy/dist/pypy/interpreter/astcompiler/ast.txt	Tue Mar  6 18:18:46 2007
@@ -289,6 +289,31 @@
     self.lineno = lineno
     return space.wrap(self)
 
+def descr_Function_new(space, w_subtype, w_decorators, w_name, w_argnames, w_defaults, w_flags, w_doc, w_code, lineno=-1):
+    self = space.allocate_instance(Function, w_subtype)
+    decorators = space.interp_w(Node, w_decorators, can_be_None=True)
+    self.decorators = decorators
+    name = space.str_w(w_name)
+    self.name = name
+    argnames = [space.interp_w(Node, w_node) for w_node in space.unpackiterable(w_argnames)]
+    self.argnames = argnames
+    defaults = [space.interp_w(Node, w_node) for w_node in space.unpackiterable(w_defaults)]
+    self.defaults = defaults
+    flags = space.int_w(w_flags)
+    self.flags = flags    
+    self.w_doc = w_doc
+    code = space.interp_w(Node, w_code, can_be_None=False)
+    self.code = code
+    self.lineno = lineno
+
+    self.varargs = 0
+    self.kwargs = 0
+    if flags & CO_VARARGS:
+        self.varargs = 1
+    if flags & CO_VARKEYWORDS:
+        self.kwargs = 1
+    return space.wrap(self)
+
 def descr_Import_new(space, w_subtype, w_names, lineno=-1):
     self = space.allocate_instance(Import, w_subtype)
     names = []
@@ -336,32 +361,6 @@
     space.setattr(w_self, space.wrap("ops"), w_newlist)
     return space.call_method(w_visitor, "visitCompare", w_self)
 
-
-def descr_Compare_mutate(space, w_self, w_visitor): 
-    w_expr = space.getattr(w_self, space.wrap("expr"))
-    w_mutate_expr = space.getattr(w_expr, space.wrap("mutate"))
-    w_mutate_expr_args = Arguments(space, [ w_visitor ])
-    w_new_expr = space.call_args(w_mutate_expr, w_mutate_expr_args)
-    space.setattr(w_self, space.wrap("expr"), w_new_expr)
-
-    w_list = space.getattr(w_self, space.wrap("ops"))
-    list_w = space.unpackiterable(w_list)
-    newlist_w = []
-    for w_item in list_w:
-        w_opname, w_node = space.unpackiterable(w_item, 2)
-        
-        w_node_mutate = space.getattr(w_node, space.wrap("mutate"))
-        w_node_mutate_args = Arguments(space, [ w_visitor ])
-        w_newnode = space.call_args(w_node_mutate, w_node_mutate_args)
-        
-        newlist_w.append(space.newtuple([w_opname, w_newnode]))
-    w_newlist = space.newlist(newlist_w)
-    space.setattr(w_self, space.wrap("ops"), w_newlist)
-    w_visitCompare = space.getattr(w_visitor, space.wrap("visitCompare"))
-    w_visitCompare_args = Arguments(space, [ w_self ])
-    return space.call_args(w_visitCompare, w_visitCompare_args)
-
-
 def descr_Dict_new(space, w_subtype, w_items, lineno=-1):
     self = space.allocate_instance(Dict, w_subtype)
     items = []

Modified: pypy/dist/pypy/interpreter/astcompiler/astgen.py
==============================================================================
--- pypy/dist/pypy/interpreter/astcompiler/astgen.py	(original)
+++ pypy/dist/pypy/interpreter/astcompiler/astgen.py	Tue Mar  6 18:18:46 2007
@@ -297,27 +297,6 @@
         print >> buf, "    def accept(self, visitor):"
         print >> buf, "        return visitor.visit%s(self)" % self.name
 
-    def _gen_mutate(self, buf):
-        print >> buf, "    def mutate(self, visitor):"
-        if len(self.argnames) != 0:
-            for argname in self.argnames:
-                if argname in self.mutate_nodes:
-                    for line in self.mutate_nodes[argname]:
-                        if line.strip():
-                            print >> buf, '    ' + line
-                elif self.argprops[argname] == P_NODE:
-                    print >> buf, "        self.%s = self.%s.mutate(visitor)" % (argname,argname)
-                elif self.argprops[argname] == P_NONE:
-                    print >> buf, "        if self.%s is not None:" % (argname,)
-                    print >> buf, "            self.%s = self.%s.mutate(visitor)" % (argname,argname)
-                elif self.argprops[argname] == P_NESTED:
-                    print >> buf, "        newlist = []"
-                    print >> buf, "        for n in self.%s:"%(argname)
-                    print >> buf, "            item = n.mutate(visitor)"
-                    print >> buf, "            if item is not None:"
-                    print >> buf, "                newlist.append(item)"
-                    print >> buf, "        self.%s[:] = newlist"%(argname)
-        print >> buf, "        return visitor.visit%s(self)" % self.name
 
     def _gen_insertnodes_func(self, buf):
         print >> buf, "    def descr_insert_after(space, self, node, w_added_nodes):"



More information about the Pypy-commit mailing list