[pypy-svn] r66345 - pypy/branch/parser-compiler/pypy/interpreter/astcompiler/tools

benjamin at codespeak.net benjamin at codespeak.net
Sat Jul 18 04:13:48 CEST 2009


Author: benjamin
Date: Sat Jul 18 04:13:47 2009
New Revision: 66345

Modified:
   pypy/branch/parser-compiler/pypy/interpreter/astcompiler/tools/asdl_py.py
Log:
add __slots__ to ast

Modified: pypy/branch/parser-compiler/pypy/interpreter/astcompiler/tools/asdl_py.py
==============================================================================
--- pypy/branch/parser-compiler/pypy/interpreter/astcompiler/tools/asdl_py.py	(original)
+++ pypy/branch/parser-compiler/pypy/interpreter/astcompiler/tools/asdl_py.py	Sat Jul 18 04:13:47 2009
@@ -67,7 +67,9 @@
             self.emit("")
         else:
             self.emit("class %s(AST):" % (base,))
-            self.emit("pass", 1)
+            self.emit("")
+            slots = ", ".join(repr(attr.name.value) for attr in sum.attributes)
+            self.emit("__slots__ = (%s)" % (slots,), 1)
             self.emit("")
             for cons in sum.types:
                 self.visit(cons, base, sum.attributes, simple)
@@ -75,6 +77,8 @@
 
     def visitProduct(self, product, name, simple):
         self.emit("class %s(AST):" % (name,))
+        slots = ", ".join(repr(field.name.value) for field in product.fields)
+        self.emit("__slots__ = (%s)" % (slots,), 1)
         self.emit("")
         self.make_constructor(product.fields)
         self.emit("")
@@ -95,7 +99,11 @@
     def visitConstructor(self, cons, base, extra_attributes, simple):
         self.emit("class %s(%s):" % (cons.name, base))
         self.emit("")
-        self.make_constructor(cons.fields + extra_attributes)
+        all_fields = cons.fields + extra_attributes
+        slots = ", ".join(repr(field.name.value) for field in all_fields)
+        self.emit("__slots__ = (%s)" % (slots,), 1)
+        self.emit("")
+        self.make_constructor(all_fields)
         self.emit("")
         self.emit("def walkabout(self, visitor):", 1)
         self.emit("visitor.visit_%s(self)" % (cons.name,), 2)



More information about the Pypy-commit mailing list