[pypy-commit] pypy default: Throw away and restart another attempt at pypy/bin/checkmodule.
arigo
noreply at buildbot.pypy.org
Wed Dec 7 17:39:58 CET 2011
Author: Armin Rigo <arigo at tunes.org>
Branch:
Changeset: r50255:0cec1f036691
Date: 2011-12-07 12:48 +0100
http://bitbucket.org/pypy/pypy/changeset/0cec1f036691/
Log: Throw away and restart another attempt at pypy/bin/checkmodule.
diff --git a/pypy/bin/checkmodule.py b/pypy/bin/checkmodule.py
--- a/pypy/bin/checkmodule.py
+++ b/pypy/bin/checkmodule.py
@@ -1,15 +1,10 @@
#! /usr/bin/env python
"""
-Usage: checkmodule.py [-b backend] <module-name>
+Usage: checkmodule.py <module-name>
-Compiles the PyPy extension module from pypy/module/<module-name>/
-into a fake program which does nothing. Useful for testing whether a
-modules compiles without doing a full translation. Default backend is cli.
-
-WARNING: this is still incomplete: there are chances that the
-compilation fails with strange errors not due to the module. If a
-module is known to compile during a translation but don't pass
-checkmodule.py, please report the bug (or, better, correct it :-).
+Check annotation and rtyping of the PyPy extension module from
+pypy/module/<module-name>/. Useful for testing whether a
+modules compiles without doing a full translation.
"""
import autopath
import sys
@@ -17,27 +12,19 @@
from pypy.objspace.fake.checkmodule import checkmodule
def main(argv):
- try:
- assert len(argv) in (2, 4)
- if len(argv) == 2:
- backend = 'cli'
- modname = argv[1]
- if modname in ('-h', '--help'):
- print >> sys.stderr, __doc__
- sys.exit(0)
- if modname.startswith('-'):
- print >> sys.stderr, "Bad command line"
- print >> sys.stderr, __doc__
- sys.exit(1)
- else:
- _, b, backend, modname = argv
- assert b == '-b'
- except AssertionError:
+ if len(argv) != 2:
print >> sys.stderr, __doc__
sys.exit(2)
- else:
- checkmodule(modname, backend, interactive=True)
- print 'Module compiled succesfully'
+ modname = argv[1]
+ if modname in ('-h', '--help'):
+ print >> sys.stderr, __doc__
+ sys.exit(0)
+ if modname.startswith('-'):
+ print >> sys.stderr, "Bad command line"
+ print >> sys.stderr, __doc__
+ sys.exit(1)
+ checkmodule(modname)
+ print 'Passed.'
if __name__ == '__main__':
main(sys.argv)
diff --git a/pypy/objspace/fake/__init__.py b/pypy/objspace/fake/__init__.py
--- a/pypy/objspace/fake/__init__.py
+++ b/pypy/objspace/fake/__init__.py
@@ -1,2 +0,0 @@
-from objspace import FakeObjSpace
-Space = FakeObjSpace
diff --git a/pypy/objspace/fake/checkmodule.py b/pypy/objspace/fake/checkmodule.py
--- a/pypy/objspace/fake/checkmodule.py
+++ b/pypy/objspace/fake/checkmodule.py
@@ -1,108 +1,7 @@
-import re
-from copy import copy
-from pypy.tool.error import debug
-from pypy.interpreter.argument import Arguments
-from pypy.interpreter.gateway import interp2app
-from pypy.rlib.nonconst import NonConstant
+from pypy.objspace.fake.objspace import FakeObjSpace
+from pypy.translator.driver import TranslationDriver
-def my_import(name):
- mod = __import__(name)
- components = name.split('.')
- for comp in components[1:]:
- mod = getattr(mod, comp)
- return mod
-def find_gateways(modname, basepath, module):
- identifier = r'[a-zA-Z0-9][a-zA-Z0-9_]*'
- r_simplename = re.compile(r'(%s)[.](%s)$' % (identifier, identifier))
- res = []
- for name in module.interpleveldefs.values():
- match = r_simplename.match(name)
- if match:
- submod_name, obj_name = match.groups()
- submod_name = '%s.%s.%s' % (basepath, modname, submod_name)
- submod = my_import(submod_name)
- obj = getattr(submod, obj_name)
- res += find_gw_in_obj(obj)
- return res
-
-def find_gw_in_obj(obj):
- if hasattr(obj, 'typedef'):
- typedef = obj.typedef
- return [gw for gw in typedef.rawdict.values()
- if isinstance(gw, interp2app)]
- elif hasattr(obj, 'func_code'):
- return [interp2app(obj)]
- else:
- assert False
-
-## Since the fake objspace is more a hack than a real object space, it
-## happens that the annotator complains about operations that cannot
-## succeed because it knows too much about the objects involved. For
-## example, if it knows that a list is always empty, it will block
-## each operations that tries to access that list. This is not what we
-## want, because we know that with real objectspaces that operations
-## will succeed.
-
-## As a workaround, we insert dummy rpython code (the function
-## dummy_rpython) that manipulates the variables in order to give
-## them a more sensible annotation. This is the preferred way to solve
-## the problems so far.
-
-## If the solution above doesn't work, the alternative is to
-## substitute the interpreter code with something that doesn't hurt
-## the annotator. It's a very ugly hack, better solutions are welcome
-## :-)
-
-
-# dummy rpython code to give some variables more sensible annotations
-def dummy_rpython(dummy_function):
- # to make the annotator flow-in without executing the code
- if NonConstant(False):
- dummy_function.defs_w = [None] # else the annotator would see an always empty list
-
-def patch_pypy():
- from pypy.interpreter.baseobjspace import W_Root
-
- def descr_call_mismatch(self, space, opname, RequiredClass, args):
- from pypy.interpreter.error import OperationError
- msg = 'This message will never be displayed :-)'
- raise OperationError(space.w_TypeError, space.wrap(msg))
- W_Root.descr_call_mismatch = descr_call_mismatch
-
-
-def checkmodule(modname, backend, interactive=False, basepath='pypy.module'):
- "Compile a fake PyPy module."
- from pypy.objspace.fake.objspace import FakeObjSpace, W_Object
- from pypy.translator.driver import TranslationDriver
-
+def checkmodule(modname):
space = FakeObjSpace()
- space.config.translating = True
- ModuleClass = __import__(basepath + '.%s' % modname,
- None, None, ['Module']).Module
- module = ModuleClass(space, space.wrap(modname))
- w_moduledict = module.getdict(space)
-
- gateways = find_gateways(modname, basepath, module)
- functions = [gw.__spacebind__(space) for gw in gateways]
- arguments = Arguments.frompacked(space, W_Object(), W_Object())
- dummy_function = copy(functions[0])
-
- def main(argv): # use the standalone mode not to allow SomeObject
- dummy_rpython(dummy_function)
- for func in functions:
- func.call_args(arguments)
- return 0
-
- patch_pypy()
- driver = TranslationDriver()
- driver.setup(main, None)
- try:
- driver.proceed(['compile_' + backend])
- except SystemExit:
- raise
- except:
- if not interactive:
- raise
- debug(driver)
- raise SystemExit(1)
+ xxx
diff --git a/pypy/objspace/fake/objspace.py b/pypy/objspace/fake/objspace.py
--- a/pypy/objspace/fake/objspace.py
+++ b/pypy/objspace/fake/objspace.py
@@ -1,147 +1,39 @@
-from pypy.interpreter.baseobjspace import ObjSpace, Wrappable, W_Root
-from pypy.interpreter.typedef import TypeDef
-from pypy.rlib.nonconst import NonConstant
-from pypy.rlib.rarithmetic import r_uint
-from pypy.rlib.rbigint import rbigint
+from pypy.interpreter.baseobjspace import W_Root, ObjSpace
+from pypy.translator.driver import TranslationDriver
+from pypy.annotation.model import SomeInstance, s_None
+from pypy.rpython.extregistry import ExtRegistryEntry
+from pypy.rpython.lltypesystem import lltype
-#class W_Type(W_Root):
-# _attrs_ = ()
-class W_Object(W_Root):
- _attrs_ = ()
-W_Object.typedef = TypeDef('foobar')
+def is_root(w_obj):
+ assert isinstance(w_obj, W_Root)
-def make_dummy(a=W_Object(), b=W_Object()):
- def fn(*args):
- if NonConstant(True):
- return a
- else:
- return b
- return fn
+class Entry(ExtRegistryEntry):
+ _about_ = is_root
-int_dummy = make_dummy(42, 43)
-float_dummy = make_dummy(42.0, 42.1)
-uint_dummy = make_dummy(r_uint(42), r_uint(43))
-str_dummy = make_dummy('foo', 'bar')
-bool_dummy = make_dummy(True, False)
-unicode_dummy = make_dummy(u'abc', u'cde')
-bigint_dummy = make_dummy(rbigint.fromint(0), rbigint.fromint(1))
+ def compute_result_annotation(self, s_w_obj):
+ s_inst = SomeInstance(self.bookkeeper.getuniqueclassdef(W_Root))
+ assert s_inst.contains(s_w_obj)
+ return s_None
+
+ def specialize_call(self, hop):
+ return hop.inputconst(lltype.Void, None)
+
+# ____________________________________________________________
+
class FakeObjSpace(ObjSpace):
- w_None = W_Object()
- w_False = W_Object()
- w_True = W_Object()
- w_Ellipsis = W_Object()
- w_NotImplemented = W_Object()
- w_int = W_Object()
- w_dict = W_Object()
- w_float = W_Object()
- w_long = W_Object()
- w_tuple = W_Object()
- w_str = W_Object()
- w_basestring = W_Object()
- w_unicode = W_Object()
- w_type = W_Object()
- w_instance = W_Object()
- w_slice = W_Object()
- w_hex = W_Object()
- w_oct = W_Object()
-
- def initialize(self):
- self.config.objspace.geninterp = False
- self.config.objspace.disable_call_speedhacks = True
- self.wrap_cache = {}
- self.make_builtins()
- def _freeze_(self):
- return True
+ def translates(self, func, argtypes=None):
+ if argtypes is None:
+ nb_args = func.func_code.co_argcount
+ argtypes = [W_Root] * nb_args
+ #
+ driver = TranslationDriver()
+ driver.setup(func, argtypes)
+ driver.proceed(['rtype_lltype'])
- def wrap(self, x):
- if isinstance(x, Wrappable):
- w_result = x.__spacebind__(self)
- return w_result
- return W_Object()
- wrap._annspecialcase_ = "specialize:argtype(1)"
-
- def unwrap(self, w_obj):
- assert isinstance(w_obj, W_Object)
- return None
-
- lookup = make_dummy()
- allocate_instance = make_dummy()
- getattr = make_dummy()
- setattr = make_dummy()
- getitem = make_dummy()
- setitem = make_dummy()
- delitem = make_dummy()
- int_w = int_dummy
- uint_w = uint_dummy
- float_w = float_dummy
- unicode_w = unicode_dummy
- bigint_w = bigint_dummy
- iter = make_dummy()
- type = make_dummy()
- str = make_dummy()
- int = make_dummy()
- float = make_dummy()
- repr = make_dummy()
- id = make_dummy()
- len = make_dummy()
- str_w = str_dummy
- call_args = make_dummy()
- new_interned_str = make_dummy()
- newint = make_dummy()
- newlong = make_dummy()
- newfloat = make_dummy()
- def newdict(self, module=False):
- return self.newfloat()
- newlist = make_dummy()
- emptylist = make_dummy()
- newtuple = make_dummy()
- newslice = make_dummy()
- lt = make_dummy()
- le = make_dummy()
- eq = make_dummy()
- ne = make_dummy()
- gt = make_dummy()
- ge = make_dummy()
- lt_w = bool_dummy
- le_w = bool_dummy
- eq_w = bool_dummy
- ne_w = bool_dummy
- gt_w = bool_dummy
- ge_w = bool_dummy
- is_w = bool_dummy
- is_ = make_dummy()
- next = make_dummy()
- is_true = bool_dummy
- nonzero = make_dummy()
- issubtype = make_dummy()
- ord = make_dummy()
- hash = make_dummy()
- delattr = make_dummy() # should return None?
- contains = make_dummy()
- hex = make_dummy()
- oct = make_dummy()
- pow = make_dummy()
- inplace_pow = make_dummy()
- cmp = make_dummy()
-
- # XXsX missing operations
- def coerce(self, *args): raise NotImplementedError("space.coerce()")
- def get(self, *args): raise NotImplementedError("space.get()")
- def set(self, *args): raise NotImplementedError("space.set()")
- def delete(self, *args): raise NotImplementedError("space.delete()")
- def userdel(self, *args): raise NotImplementedError("space.userdel()")
- def marshal_w(self, *args):raise NotImplementedError("space.marshal_w()")
-
- gettypefor = make_dummy()
- gettypeobject = make_dummy()
- unpackiterable = make_dummy([W_Object()], [W_Object()])
-
-
-## Register all exceptions
-import exceptions
-for name in ObjSpace.ExceptionTable:
- exc = getattr(exceptions, name)
- setattr(FakeObjSpace, 'w_' + name, W_Object())
+ def add(self, w_x, w_y):
+ is_root(w_x)
+ is_root(w_y)
+ return W_Root()
diff --git a/pypy/objspace/fake/test/__init__.py b/pypy/objspace/fake/test/__init__.py
deleted file mode 100644
diff --git a/pypy/objspace/fake/test/test_checkmodule.py b/pypy/objspace/fake/test/test_checkmodule.py
deleted file mode 100644
--- a/pypy/objspace/fake/test/test_checkmodule.py
+++ /dev/null
@@ -1,7 +0,0 @@
-import py
-from pypy.objspace.fake.checkmodule import checkmodule
-
-def test_dotnet():
- # the only module known to pass checkmodule is _dotnet so far
- py.test.skip('fixme')
- checkmodule('_dotnet', 'cli')
diff --git a/pypy/objspace/fake/test/test_objspace.py b/pypy/objspace/fake/test/test_objspace.py
new file mode 100644
--- /dev/null
+++ b/pypy/objspace/fake/test/test_objspace.py
@@ -0,0 +1,13 @@
+from pypy.objspace.fake.objspace import FakeObjSpace
+
+def test_create():
+ FakeObjSpace()
+
+
+class TestTranslate:
+ def setup_method(self, meth):
+ self.space = FakeObjSpace()
+
+ def test_simple(self):
+ space = self.space
+ space.translates(lambda w_x, w_y: space.add(w_x, w_y))
More information about the pypy-commit
mailing list