[pypy-svn] r14324 - in pypy/branch/dist-2.4.1/pypy: interpreter interpreter/test module/__builtin__ tool

arigo at codespeak.net arigo at codespeak.net
Wed Jul 6 13:17:53 CEST 2005


Author: arigo
Date: Wed Jul  6 13:17:48 2005
New Revision: 14324

Modified:
   pypy/branch/dist-2.4.1/pypy/interpreter/baseobjspace.py
   pypy/branch/dist-2.4.1/pypy/interpreter/pycompiler.py
   pypy/branch/dist-2.4.1/pypy/interpreter/test/test_interpreter.py
   pypy/branch/dist-2.4.1/pypy/module/__builtin__/compiling.py
   pypy/branch/dist-2.4.1/pypy/tool/option.py
Log:
- simplified for now the command-line options (--compiler and --parsermodule)

- made test_interpreter independent of the default --compiler option

- skip the huge expression test with the recparser

- bug fix in pycompiler.py

- check before crashing if the app-level compile() is called with a invalid
  'mode'



Modified: pypy/branch/dist-2.4.1/pypy/interpreter/baseobjspace.py
==============================================================================
--- pypy/branch/dist-2.4.1/pypy/interpreter/baseobjspace.py	(original)
+++ pypy/branch/dist-2.4.1/pypy/interpreter/baseobjspace.py	Wed Jul  6 13:17:48 2005
@@ -185,17 +185,14 @@
 
     def createcompiler(self):
         "Factory function creating a compiler object."
-        if self.options.parser == 'recparser':
-            if self.options.compiler == 'cpython':
-                return PythonCompiler(self)
-            else:
-                return PyPyCompiler(self)
-        elif self.options.compiler == 'pyparse':
-            # <=> options.parser == 'cpython'
+        # XXX simple selection logic for now
+        if self.options.compiler == 'pyparse':
             return PythonCompiler(self)
-        else:
-            # <=> options.compiler == 'cpython' and options.parser == 'cpython'
+        elif self.options.compiler == 'cpython':
             return CPythonCompiler(self)
+        else:
+            raise ValueError('unknown --compiler option value: %r' % (
+                self.options.compiler,))
 
     # Following is a friendly interface to common object space operations
     # that can be defined in term of more primitive ones.  Subclasses

Modified: pypy/branch/dist-2.4.1/pypy/interpreter/pycompiler.py
==============================================================================
--- pypy/branch/dist-2.4.1/pypy/interpreter/pycompiler.py	(original)
+++ pypy/branch/dist-2.4.1/pypy/interpreter/pycompiler.py	Wed Jul  6 13:17:48 2005
@@ -200,6 +200,7 @@
         from pypy.interpreter.stablecompiler.pycodegen import InteractiveCodeGenerator
         from pypy.interpreter.stablecompiler.pycodegen import ExpressionCodeGenerator
         from pypy.interpreter.stablecompiler.transformer import Transformer
+        space = self.space
         try:
             transformer = Transformer()
             tree = transformer.compile_node(tuples)

Modified: pypy/branch/dist-2.4.1/pypy/interpreter/test/test_interpreter.py
==============================================================================
--- pypy/branch/dist-2.4.1/pypy/interpreter/test/test_interpreter.py	(original)
+++ pypy/branch/dist-2.4.1/pypy/interpreter/test/test_interpreter.py	Wed Jul  6 13:17:48 2005
@@ -1,12 +1,13 @@
 import py 
 import sys
-from pypy.interpreter.pycompiler import PythonCompiler
 
 class TestInterpreter: 
+    from pypy.interpreter.pycompiler import CPythonCompiler as CompilerClass
+
     def codetest(self, source, functionname, args):
         """Compile and run the given code string, and then call its function
         named by 'functionname' with arguments 'args'."""
-        from pypy.interpreter import baseobjspace, executioncontext
+        from pypy.interpreter import baseobjspace
         from pypy.interpreter import pyframe, gateway, module
         space = self.space
 
@@ -33,11 +34,14 @@
         else:
             return space.unwrap(w_output)
 
-    #def setup_class(cls):
-    #    cls.space = testit.objspace()
+    def setup_method(self, arg):
+        ec = self.space.getexecutioncontext() 
+        self.saved_compiler = ec.compiler
+        ec.compiler = self.CompilerClass(self.space)
 
-    #def teardown_class(cls): 
-    #    del cls.space 
+    def teardown_method(self, arg):
+        ec = self.space.getexecutioncontext() 
+        ec.compiler = self.saved_compiler
 
     def test_exception_trivial(self):
         x = self.codetest('''\
@@ -227,19 +231,14 @@
         assert self.codetest(code, 'g', [12, {}]) ==    ()
         assert self.codetest(code, 'g', [12, {3:1}]) == (3,)
 
+
 class TestPyPyInterpreter(TestInterpreter):
     """Runs the previous test with the pypy parser"""
-    def setup_class(klass):
-        sys.setrecursionlimit(10000)
+    from pypy.interpreter.pycompiler import PythonCompiler as CompilerClass
 
-    def setup_method(self,arg):
-        ec = self.space.getexecutioncontext() 
-        self.saved_compiler = ec.compiler
-        ec.compiler = PythonCompiler(self.space)
+    def test_extended_arg(self):
+        py.test.skip("expression too large for the recursive parser")
 
-    def teardown_method(self,arg):
-        ec = self.space.getexecutioncontext() 
-        ec.compiler = self.saved_compiler
 
 class AppTestInterpreter: 
     def test_trivial(self):

Modified: pypy/branch/dist-2.4.1/pypy/module/__builtin__/compiling.py
==============================================================================
--- pypy/branch/dist-2.4.1/pypy/module/__builtin__/compiling.py	(original)
+++ pypy/branch/dist-2.4.1/pypy/module/__builtin__/compiling.py	Wed Jul  6 13:17:48 2005
@@ -22,6 +22,11 @@
         else:
             flags |= ec.compiler.getcodeflags(caller.code)
 
+    if mode not in ('exec', 'eval', 'single'):
+        raise OperationError(space.w_ValueError,
+                             space.wrap("compile() arg 3 must be 'exec' "
+                                        "or 'eval' or 'single'"))
+
     code = ec.compiler.compile(str_, filename, mode, flags)
     return space.wrap(code)
 #

Modified: pypy/branch/dist-2.4.1/pypy/tool/option.py
==============================================================================
--- pypy/branch/dist-2.4.1/pypy/tool/option.py	(original)
+++ pypy/branch/dist-2.4.1/pypy/tool/option.py	Wed Jul  6 13:17:48 2005
@@ -10,9 +10,8 @@
     spaces = []
     oldstyle = 0
     uselibfile = 0
-    useparsermodule = "cpython" # "cpython" / "recparser" / "parser"
-    parser = "cpython" # "cpython" / "pyparse"
-    compiler = "cpython" # "cpython"
+    useparsermodule = "recparser" # "cpython" / "recparser" / "parser"
+    compiler = "pyparse" # "cpython"
                          # "pyparse" pypy parser, cpython compiler
                          # "pycomp" pypy parser and compiler (TBD)
     version = "2.4" # "native" / "2.3" / "2.4"
@@ -46,8 +45,9 @@
         callback=run_tb_server,
         help="use web browser for traceback info"))
     options.append(make_option(
-        '--pyparse', action="store_const", dest="compiler", const="pyparse",
-        help="enable the internal pypy parser with CPython compiler"))
+        '--compiler', action="store", type="string", dest="compiler",
+        help="select the parser/compiler to use internally",
+        metavar="[cpython|pyparse]"))
     options.append(make_option(
         '--parsermodule', action="store",type="string", dest="useparsermodule",
         help="select the parser module to use",



More information about the Pypy-commit mailing list