[pypy-svn] r61313 - in pypy/trunk/pypy/module/recparser: . test

fijal at codespeak.net fijal at codespeak.net
Sat Jan 24 20:15:29 CET 2009


Author: fijal
Date: Sat Jan 24 20:15:29 2009
New Revision: 61313

Modified:
   pypy/trunk/pypy/module/recparser/__init__.py
   pypy/trunk/pypy/module/recparser/pyparser.py
   pypy/trunk/pypy/module/recparser/test/test_parser.py
Log:
provide compilest (needed by test_parser)


Modified: pypy/trunk/pypy/module/recparser/__init__.py
==============================================================================
--- pypy/trunk/pypy/module/recparser/__init__.py	(original)
+++ pypy/trunk/pypy/module/recparser/__init__.py	Sat Jan 24 20:15:29 2009
@@ -43,7 +43,7 @@
 ##         #'sequence2ast' : 'pyparser.sequence2ast',
 ##         #'tuple2ast'    : 'pyparser.tuple2ast',
 ##         #'_pickler'     : 'pyparser._pickler',
-##         #'compilest'    : 'pyparser.compilest',
+         'compilest'    : 'pyparser.compilest',
 
          # PyPy extension
          'source2ast' : "pyparser.source2ast",

Modified: pypy/trunk/pypy/module/recparser/pyparser.py
==============================================================================
--- pypy/trunk/pypy/module/recparser/pyparser.py	(original)
+++ pypy/trunk/pypy/module/recparser/pyparser.py	Sat Jan 24 20:15:29 2009
@@ -108,17 +108,18 @@
         """
         return self.node.name == symbol.file_input
 
-    def descr_compile(self, w_filename = "<syntax_tree>"):
+    def descr_compile(self, space, filename = "<syntax_tree>"):
         """STType.compile()
         """
         # We use the compiler module for that
         space = self.space
         w_tup = self.descr_totuple(line_info=True)
-        w_compileAST = mycompile(space, w_tup, w_filename)
+        w_compileAST = mycompile(space, w_tup, space.wrap(filename))
         if self.isexpr():
             return exprcompile(space, w_compileAST)
         else:
             return modcompile(space, w_compileAST)
+    descr_compile.unwrap_spec = ['self', ObjSpace, str]
 
 ASTType = STType
 
@@ -353,3 +354,9 @@
                              )
 
 Token.typedef = TypeDef("Token", GrammarElement.typedef )
+
+def compilest(space, w_st):
+    "Compiles an ST object into a code object."
+    w_st = space.interp_w(STType, w_st)
+    return w_st.descr_compile(space)
+compilest.unwrap_spec = [ObjSpace, W_Root]

Modified: pypy/trunk/pypy/module/recparser/test/test_parser.py
==============================================================================
--- pypy/trunk/pypy/module/recparser/test/test_parser.py	(original)
+++ pypy/trunk/pypy/module/recparser/test/test_parser.py	Sat Jan 24 20:15:29 2009
@@ -30,6 +30,13 @@
         """.strip()
         parser.suite(src)
 
+    def test_compilest(self):
+        import parser
+        code = parser.compilest(parser.suite('x = 2 + 3'))
+        d = {}
+        exec code in d
+        assert d['x'] == 5
+
 class AppTestRecparserErrors: 
     def setup_class(cls):
         cls.space = space



More information about the Pypy-commit mailing list