From hpk at codespeak.net Thu Jan 1 17:47:09 2004 From: hpk at codespeak.net (hpk at codespeak.net) Date: Thu, 1 Jan 2004 17:47:09 +0100 (MET) Subject: [pypy-svn] r2715 - in pypy/trunk/src: goal goals Message-ID: <20040101164709.8D49E5AC54@thoth.codespeak.net> Author: hpk Date: Thu Jan 1 17:47:08 2004 New Revision: 2715 Added: pypy/trunk/src/goal/ (props changed) - copied from r2714, pypy/trunk/src/goals/ Removed: pypy/trunk/src/goals/ Log: renamed goals to goal according to our "no plural dir/file items" From alex at codespeak.net Fri Jan 2 18:15:12 2004 From: alex at codespeak.net (alex at codespeak.net) Date: Fri, 2 Jan 2004 18:15:12 +0100 (MET) Subject: [pypy-svn] r2716 - pypy/trunk/src/pypy/appspace Message-ID: <20040102171512.D2A905A678@thoth.codespeak.net> Author: alex Date: Fri Jan 2 18:15:11 2004 New Revision: 2716 Modified: pypy/trunk/src/pypy/appspace/pystone.py Log: new 'richer' version of pystone.py, as also committed to Python 2.4's current CVS sources. Modified: pypy/trunk/src/pypy/appspace/pystone.py ============================================================================== --- pypy/trunk/src/pypy/appspace/pystone.py (original) +++ pypy/trunk/src/pypy/appspace/pystone.py Fri Jan 2 18:15:11 2004 @@ -249,4 +249,19 @@ return FALSE if __name__ == '__main__': - main() + import sys + def error(msg): + print >>sys.stderr, msg, + print >>sys.stderr, "usage: %s [number_of_loops]" % sys.argv[0] + sys.exit(100) + nargs = len(sys.argv) - 1 + if nargs > 1: + error("%d arguments are too many;" % nargs) + elif nargs == 1: + try: loops = int(sys.argv[1]) + except ValueError: + error("Invalid argument %r;" % sys.argv[1]) + else: + loops = LOOPS + main(loops) + From hpk at codespeak.net Fri Jan 2 19:34:58 2004 From: hpk at codespeak.net (hpk at codespeak.net) Date: Fri, 2 Jan 2004 19:34:58 +0100 (MET) Subject: [pypy-svn] r2717 - pypy/trunk/src/pypy Message-ID: <20040102183458.0DC1B5A678@thoth.codespeak.net> Author: hpk Date: Fri Jan 2 19:34:52 2004 New Revision: 2717 Modified: pypy/trunk/src/pypy/TODO Log: update to the TODO file as i see it ... note that the items are *not* (and never have been) in a prioritized order. Modified: pypy/trunk/src/pypy/TODO ============================================================================== --- pypy/trunk/src/pypy/TODO (original) +++ pypy/trunk/src/pypy/TODO Fri Jan 2 19:34:52 2004 @@ -1,43 +1,36 @@ -Task: update pypy homepage +* provide an importer that can import packages + consider PEP 302, new import hooks try to write as much as + possible in app-level how would PyPy import CPython extension when + it runs on top of CPython? -Task: add more builtins! (like e.g. 'dir') +* slicing with assigments & more small things + lst[::-2] = lst2 -Task: fix interpreter-level object introspection from app-level - (make dis.dis(dis.dis) goal work as a side effect) +* (documentation) generate a nice dot-graph from the structure of PyPy -Task: provide an importer that can import packages - consider PEP 302, new import hooks - try to write as much as possible in app-level - how would PyPy import CPython extension when it runs on top of CPython? +* trash the standard unittest framework/enhance it (there already + is some new version-in-progress in tool/newtest.py) -Task: slicing with assigments & more small things (finish StdObjSpace review!) - lst[::-2] = lst2 +* (documentation) remove/retire all web-pages referencing e.g. + AnnSpace or other deprecated stuff -Task: try tests of CPython in PyPy - -Task: generate a nice dot-graph from the structure of PyPy - -Task: integrate the code in translator, with a script that can be - invoked from the command-line to play with sample source code -(Note: partially done with translator.py.) - -Task: trash the standard unittest framework/enhance it - -Task: complete the list of operations in type inference (annotation.py) - -Task: (documentation) remove/retire all web-pages referencing e.g. - AnnSpace or other deprecated stuff - -Task: (documentation) do more and enhance +* make application-level types work for (1) StdObjSpace types and (2) + core interpreter objects. -========================================================================== -New bigger tasks that we don't want to address during the Amsterdam sprint -========================================================================== +* Review, enhance the new mixed-level module mechanism + (e.g. the module/builtin*.py files comprise the builtin module) + and try to apply the same technique for the application level + type definitions (types.py) -* make application-level types work for (1) StdObjSpace types and (2) - core interpreter objects. +* review, * clear out and do a clean implementation of multimethod delegation. The idea is to give 'kinds' to arguments according to their use, e.g. 'numeric argument' or 'object whose identity is preserved'. - A 'kind' encapsulates a set of delegation functions. + A 'kind' encapsulates a set of delegation functions. Armin has + already written documentation for the envisioned new multimethod + implementation: + + http://codespeak.net/pypy/index.cgi?doc/objspace/multimethod + +* enhance the translator components to accept more of PyPy ... From arigo at codespeak.net Mon Jan 5 10:45:04 2004 From: arigo at codespeak.net (arigo at codespeak.net) Date: Mon, 5 Jan 2004 10:45:04 +0100 (MET) Subject: [pypy-svn] r2718 - pypy/trunk/doc Message-ID: <20040105094504.D8ECC5A678@thoth.codespeak.net> Author: arigo Date: Mon Jan 5 10:45:03 2004 New Revision: 2718 Added: pypy/trunk/doc/wrapping.txt (contents, props changed) Modified: pypy/trunk/doc/architecture.txt Log: New document about wrapping rules (w_xxx, xxx_w, functions to use to wrap and inspect wrapped objects, and application-level exceptions). Modified: pypy/trunk/doc/architecture.txt ============================================================================== --- pypy/trunk/doc/architecture.txt (original) +++ pypy/trunk/doc/architecture.txt Mon Jan 5 10:45:03 2004 @@ -244,6 +244,8 @@ application-level list -- it is for this reason that the length in question has to be explicitly recorded in ``ob_size``). +See ``wrapping.txt`` for more details. + RPython, the Flow Object Space and translation ============================================== Added: pypy/trunk/doc/wrapping.txt ============================================================================== --- (empty file) +++ pypy/trunk/doc/wrapping.txt Mon Jan 5 10:45:03 2004 @@ -0,0 +1,95 @@ +========================= + Wrapping rules +========================= + +Introduction +------------ + +PyPy is made of Python source code at two levels: there is on the one hand *application-level code* that looks like normal Python code, and that implements some functionalities as one would expect from Python code (e.g. one can give a pure Python implementation of some built-in functions like ``zip()``). There is also *interpreter-level code* for the functionalities that must more directly manipulate interpreter data and objects (e.g. the main loop of the interpreter, and the various object spaces). + +Application-level code doesn't see object spaces explicitely: it runs using an object space to support the objects it manipulates, but this is implicit. There is no need for particular conventions for application-level code. The sequel is only about interpreter-level code. (Ideally, no application-level variable should be called ``space`` or ``w_xxx`` to avoid confusion.) + + +Naming conventions +------------------ + +* ``space``: the object space is only visible at interpreter-level, where it is by convention in a variable called ``space``. + +* ``w_xxx``: any object seen by application-level code is an object explicitely managed by the object space. From the interpreter-level point of view, this is called a *wrapped* object. The ``w_`` prefix is used for any type of application-level object. + +* ``xxx_w``: an interpreter-level container for wrapped objects, for example a list or a dict containing wrapped objects. Not to be confused with a wrapped object that would be a list or a dict: these are normal wrapped objects, so they use the ``w_`` prefix. + + +Operations on ``w_xxx`` +----------------------- + +The core interpreter considers wrapped objects as black boxes. It is not allowed to inspect them directly. The allowed operations are all dependent on the object space: they are called ``space.xxx()``, where ``xxx`` is a standard operation name (``add``, ``getattr``, ``call``, ``eq``...). The list of standard operations is found in the large table near the end of ``pypy.interpreter.baseobjspace``. These operations take wrapped arguments and return a wrapped result (or sometimes just None). + +Also note some helpers: + +* ``space.call_function(w_callable, ...)``: collects the given (already-wrapped) arguments, builds a wrapped tuple for them, and uses ``space.call()`` to perform the call. + +* ``space.call_method(w_object, 'method', ...)``: uses ``space.getattr()`` to get the method object, and then ``space.call_function()`` to invoke it. + + +Building ``w_xxx`` objects +-------------------------- + +From the core interpreter, wrapped objects are usually built as the result of an object space operation. The ways to directly create a wrapped object are: + +* ``space.wrap(x)``: returns a wrapped object containing the value ``x``. Only works if ``x`` is either a simple value (integer, float, string) or an instance of an internal interpreter class (Function, Code, Frame...). + +* ``space.newlist([w_x, w_y, w_z...])``: returns a wrapped list from a list of already-wrapped objects. + +* ``space.newtuple([w_x, w_y, w_z...])``: returns a wrapped tuple from a list of already-wrapped objects. + +* ``space.newdict([])``: returns a new, empty wrapped dictionary. (The argument list can contain tuples ``(w_key, w_value)`` but it seems that such a use is not common.) + +* ``space.newbool(x)``: returns ``space.w_False`` or ``space.w_True`` depending on the truth value of ``x``. + +There are a few less common constructors, described in the comments at the end of ``pypy.interpreter.baseobjspace``. + + +Constant ``w_xxx`` objects +-------------------------- + +The object space holds a number of predefined wrapped objects. The most common ones are ``space.w_None`` and ``space.w_XxxError`` for each exception class ``XxxError`` (e.g. ``space.w_KeyError``, ``space.w_IndexError``, etc.). + + +Inspecting ``w_xxx`` objects +---------------------------- + +The most delicate operation is for the interpreter to inspect a wrapped object, which must be done via the object space. + +* ``space.is_true(w_x)``: checks if the given wrapped object is considered to be ``True`` or ``False``. You must never use the truth-value of ``w_x`` directly; doing so (e.g. writing ``if w_x:``) will give you an error reminding you of the problem. + +* ``w_x == w_y`` or ``w_x is w_y``: DON'T DO THAT. The only half-official exception is to check if ``w_x`` contains a wrapped ``None``: you can write ``w_x == space.w_None``. Follow this rule; the case of ``None`` is easy to fix globally later if we find out that we need to. The rationale for this rule is that there is no reason that two wrappers are related in any way even if they contain what looks like the same object at application-level. To check for equality, use ``space.is_true(space.eq(w_x, w_y))``. To check for identity, use ``space.is_true(space.is_(w_x, w_y))``. + +* ``space.unpackiterable(w_x)``: this helper iterates ``w_x`` (using ``space.iter()`` and ``space.next()``) and collects the resulting wrapped objects in a list. Of course, in cases where iterating directly is better than collecting the elements in a list first, you should use ``space.iter()`` and ``space.next()`` directly. + +* ``space.unwrap(w_x)``: inverse of ``space.wrap()``. Attention! Using ``space.unwrap()`` must be avoided whenever possible. Actually, it should only be used when you are sure that ``w_x`` contains a simple object or an internal interpreter object that was wrapped with ``space.wrap()``. This function is a bit buggy anyway, and it should probably be fixed at some point: we should specify what kind of unwrapped result is expected (and raise a TypeError appropriately). + +Remember that you can usually obtain the information you want by invoking operations or methods on the wrapped objects; e.g. ``space.call_method(w_dict, 'iterkeys')`` returns a wrapped iterable that you can decode with ``space.unpackiterable()``. + + +Application-level exceptions +---------------------------- + +Interpreter-level code can use exceptions freely. However, all application-level exceptions are represented as an ``OperationError`` at interpreter-level. In other words, all exceptions that are potentially visible at application-level are internally an ``OperationError``. This is the case of all errors reported by the object space operations (``space.add()`` etc.). + +To raise an application-level exception:: + + raise OperationError(space.w_XxxError, space.wrap("message")) + +To catch a specific application-level exception:: + + try: + ... + except OperationError, e: + if not e.match(space, space.w_XxxError): + raise + ... + +This construct catches all application-level exceptions, so we have to match it against the particular ``w_XxxError`` we are interested in and re-raise other exceptions. The exception instance ``e`` holds two attributes that you can inspect: ``e.w_type`` and ``e.w_value``. Do not use ``e.w_type`` to match an exception, as this will miss exceptions that are instances of subclasses. + +We are thinking about replacing ``OperationError`` with a family of common exception classes (e.g. ``AppKeyError``, ``AppIndexError``...) so that we can more easily catch them. The generic ``AppError`` would stand for all other application-level classes. From arigo at codespeak.net Mon Jan 5 10:45:52 2004 From: arigo at codespeak.net (arigo at codespeak.net) Date: Mon, 5 Jan 2004 10:45:52 +0100 (MET) Subject: [pypy-svn] r2719 - in pypy/trunk/doc: . devel irclog objspace sprintinfo translation Message-ID: <20040105094552.C51E75B9C9@thoth.codespeak.net> Author: arigo Date: Mon Jan 5 10:45:51 2004 New Revision: 2719 Modified: pypy/trunk/doc/ (props changed) pypy/trunk/doc/devel/ (props changed) pypy/trunk/doc/irclog/ (props changed) pypy/trunk/doc/objspace/ (props changed) pypy/trunk/doc/sprintinfo/ (props changed) pypy/trunk/doc/translation/ (props changed) Log: fixeol. From arigo at codespeak.net Mon Jan 5 17:43:26 2004 From: arigo at codespeak.net (arigo at codespeak.net) Date: Mon, 5 Jan 2004 17:43:26 +0100 (MET) Subject: [pypy-svn] r2720 - pypy/trunk/src/pypy/module Message-ID: <20040105164326.E86855B9C9@thoth.codespeak.net> Author: arigo Date: Mon Jan 5 17:43:26 2004 New Revision: 2720 Modified: pypy/trunk/src/pypy/module/__builtin__module.py Log: Quick bug fix. Modified: pypy/trunk/src/pypy/module/__builtin__module.py ============================================================================== --- pypy/trunk/src/pypy/module/__builtin__module.py (original) +++ pypy/trunk/src/pypy/module/__builtin__module.py Mon Jan 5 17:43:26 2004 @@ -397,10 +397,10 @@ raise TypeError("intern() argument 1 must be string.") return _stringtable.setdefault(s,s) -def copyright(self): +def copyright(): print 'Copyright 2003-2004 Pypy development team.\nAll rights reserved.\nFor further information see http://www.codespaek.net/pypy.\nSome materials may have a different copyright.\nIn these cases, this is explicitly noted in the source code file.' -def license(self): +def license(): print \ """ Copyright (c) <2003-2004> @@ -412,7 +412,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. """ -def help(self): +def help(): print "You must be joking." From arigo at codespeak.net Mon Jan 5 18:01:33 2004 From: arigo at codespeak.net (arigo at codespeak.net) Date: Mon, 5 Jan 2004 18:01:33 +0100 (MET) Subject: [pypy-svn] r2721 - in pypy/trunk/src/pypy: interpreter interpreter/test module Message-ID: <20040105170133.18CCC5B9C9@thoth.codespeak.net> Author: arigo Date: Mon Jan 5 18:01:32 2004 New Revision: 2721 Added: pypy/trunk/src/pypy/interpreter/test/foointerp.py (contents, props changed) pypy/trunk/src/pypy/interpreter/test/foomodule.py (contents, props changed) Removed: pypy/trunk/src/pypy/module/_randommodule.py pypy/trunk/src/pypy/module/_sremodule.py pypy/trunk/src/pypy/module/cStringIOmodule.py pypy/trunk/src/pypy/module/itertoolsmodule.py pypy/trunk/src/pypy/module/mathmodule.py pypy/trunk/src/pypy/module/os_modules.py pypy/trunk/src/pypy/module/timemodule.py Modified: pypy/trunk/src/pypy/interpreter/baseobjspace.py pypy/trunk/src/pypy/interpreter/extmodule.py pypy/trunk/src/pypy/interpreter/test/test_extmodule.py pypy/trunk/src/pypy/module/__builtin__interp.py pypy/trunk/src/pypy/module/__builtin__module.py pypy/trunk/src/pypy/module/__init__.py pypy/trunk/src/pypy/module/sysinterp.py pypy/trunk/src/pypy/module/sysmodule.py Log: Simplified a bit the handling of built-in modules: M pypy/interpreter/extmodule.py M pypy/interpreter/baseobjspace.py M pypy/module/__builtin__interp.py Removed obsolete code. M pypy/module/sysinterp.py New interp-level attributes for built-in module handling. Also contains the logic to hack a PyPy module out of a CPython module, for not-implemented-yet modules. M pypy/module/__builtin__module.py M pypy/module/sysmodule.py The app-level definition of a module must now use __interplevel__execfile() to run an interp- level section. AM pypy/interpreter/test/foomodule.py AM pypy/interpreter/test/foointerp.py M pypy/interpreter/test/test_extmodule.py A test for the BuiltinModule mecanisms. See foomodule and foointerp for a sample of all the ways to exchange data between app- and interp-level parts of a module. M pypy/module/__init__.py D pypy/module/os_modules.py D pypy/module/itertoolsmodule.py D pypy/module/_sremodule.py D pypy/module/mathmodule.py D pypy/module/timemodule.py D pypy/module/_randommodule.py D pypy/module/cStringIOmodule.py These hacks are now centralized in sysinterp.py. Modified: pypy/trunk/src/pypy/interpreter/baseobjspace.py ============================================================================== --- pypy/trunk/src/pypy/interpreter/baseobjspace.py (original) +++ pypy/trunk/src/pypy/interpreter/baseobjspace.py Mon Jan 5 18:01:32 2004 @@ -74,36 +74,26 @@ #print "setitem: space instance %-20s into builtins" % name self.setitem(self.w_builtins, self.wrap(name), value) - self.sys.setbuiltinmodule(self.w_builtin) - - #Now we can load all the builtin (interpreter level) modules. - self.make_builtin_modules() + self.sys.setbuiltinmodule(self.w_builtin, '__builtin__') def make_sys(self): from pypy.interpreter.extmodule import BuiltinModule assert not hasattr(self, 'sys') self.sys = BuiltinModule(self, 'sys') self.w_sys = self.wrap(self.sys) - self.sys.setbuiltinmodule(self.w_sys) - - def make_builtin_modules(self): - for filename, classname, spaces in pypy.module._builtin_modules: - if self.__class__.__name__ not in spaces: - continue - mod = __import__("pypy.module.%s"%filename, globals(), locals(), - [classname]) - klass = getattr(mod, classname) - module = klass(self) - if module is not None: - self.sys.setbuiltinmodule(self.wrap(module)) + self.sys.setbuiltinmodule(self.w_sys, 'sys') - # XXX get rid of this. def get_builtin_module(self, name): - if name == '__builtin__': - return self.w_builtin - elif name == 'sys': - return self.w_sys - return None + if name not in self.sys.builtin_modules: + return None + module = self.sys.builtin_modules[name] + if module is None: + from pypy.interpreter.extmodule import BuiltinModule + module = BuiltinModule(self, name) + self.sys.builtin_modules[name] = module + w_module = self.wrap(module) + self.sys.setbuiltinmodule(w_module, name) + return w_module def initialize(self): """Abstract method that should put some minimal content into the Modified: pypy/trunk/src/pypy/interpreter/extmodule.py ============================================================================== --- pypy/trunk/src/pypy/interpreter/extmodule.py (original) +++ pypy/trunk/src/pypy/interpreter/extmodule.py Mon Jan 5 18:01:32 2004 @@ -4,7 +4,7 @@ """ -from __future__ import generators +from __future__ import generators # for generators.compiler_flag import os, sys, types import autopath from pypy.interpreter import gateway @@ -16,30 +16,31 @@ class BuiltinModule(Module): - def __init__(self, space, modulename, w_dict=None): + def __init__(self, space, modulename, w_dict=None, sourcefile=None): Module.__init__(self, space, space.wrap(modulename), w_dict) w_dict = self.w_dict # Compile the xxxmodule.py source file - modulefile = os.path.join(autopath.pypydir, 'module', - modulename+'module.py') - f = open(modulefile, 'r') + self.__file__ = sourcefile or os.path.join(autopath.pypydir, 'module', + modulename+'module.py') + space.setitem(w_dict, space.wrap('__file__'), + space.wrap(self.__file__)) + f = open(self.__file__, 'r') modulesource = f.read() f.close() - code = compile(modulesource, modulefile, 'exec', + code = compile(modulesource, self.__file__, 'exec', generators.compiler_flag) pycode = PyCode()._from_code(code) # Set the hooks that call back from app-level to interp-level w_builtins = space.w_builtins self.__saved_hooks = {} - self.__file__ = os.path.join(autopath.pypydir, 'module', - modulename+'interp.py') - self.__import_interplevel = True newhooks = {} - for name, hook in [('__interplevel__exec', self.app_interplevelexec), - ('__interplevel__eval', self.app_interpleveleval), - ('__import__', self.app_interplevelimport)]: + for name, hook in [ + ('__interplevel__exec', self.app_interplevelexec), + ('__interplevel__eval', self.app_interpleveleval), + ('__interplevel__execfile', self.app_interplevelexecfile), + ('__import__', self.app_interplevelimport)]: w_name = space.wrap(name) try: self.__saved_hooks[name] = space.getitem(w_builtins, w_name) @@ -51,13 +52,14 @@ space.setitem(self.w_dict, space.wrap('__builtins__'), space.w_builtins) + # Temporarily install an '__applevel__' pseudo-module + sys.modules['__applevel__'] = BuiltinModule.AppModuleHack(self) + # Run the app-level module definition (xxxmodule.py) - space.setitem(w_dict, space.wrap('__file__'), space.wrap(modulefile)) pycode.exec_code(space, w_dict, w_dict) - # Run the interp-level definition (xxxinterp.py) - # if xxxmodule.py didn't do so already - self.loadinterplevelfile() + # Remove the pseudo-module + del sys.modules['__applevel__'] # Remove/restore the hooks unless they have been modified at app-level for name, w_hook in newhooks.items(): @@ -75,18 +77,6 @@ space.delitem(w_builtins, w_name) del self.__saved_hooks - def loadinterplevelfile(self): - try: - self.__import_interplevel - except AttributeError: - pass # already loaded - else: - del self.__import_interplevel - # temporarily install an '__applevel__' pseudo-module - sys.modules['__applevel__'] = BuiltinModule.AppModuleHack(self) - execfile(self.__file__, self.__dict__) - del sys.modules['__applevel__'] - def interplevelexec(self, w_codestring): codestring = self.space.unwrap(w_codestring) exec codestring in self.__dict__ @@ -100,16 +90,21 @@ w_result = space.w_None # else assume that it is already wrapped return w_result + def interplevelexecfile(self, w_filename): + filename = self.space.unwrap(w_filename) + filename = os.path.join(os.path.dirname(self.__file__), filename) + execfile(filename, self.__dict__) + return self.space.w_None + def interplevelimport(self, w_modulename, w_globals, w_locals, w_fromlist): space = self.space w = space.wrap if space.is_true(space.eq(w_modulename, w('__interplevel__'))): - self.loadinterplevelfile() if w_fromlist == space.w_None: raise ImportError, "must use 'from __interplevel__ import xx'" for w_name in space.unpacktuple(w_fromlist): name = space.unwrap(w_name) - if hasattr(self, name): + if not hasattr(self, 'w_' + name): f = getattr(self, name) code = gateway.BuiltinCode(f, ismethod=False, spacearg=False) @@ -125,9 +120,10 @@ w_modulename, w_globals, w_locals, w_fromlist) - app_interplevelexec = gateway.interp2app(interplevelexec) - app_interpleveleval = gateway.interp2app(interpleveleval) - app_interplevelimport = gateway.interp2app(interplevelimport) + app_interplevelexec = gateway.interp2app(interplevelexec) + app_interpleveleval = gateway.interp2app(interpleveleval) + app_interplevelexecfile = gateway.interp2app(interplevelexecfile) + app_interplevelimport = gateway.interp2app(interplevelimport) class AppModuleHack: def __init__(self, builtinmodule): @@ -138,63 +134,3 @@ def caller(*args, **kwds): return self.space.call_function(w_func, *args, **kwds) return caller - - -# XXX delete everything below. - - -from pypy.interpreter.miscutils import InitializedClass, RwDictProxy -from pypy.interpreter.module import Module - - -class ExtModule(Module): - """An empty extension module. - Non-empty extension modules are made by subclassing ExtModule.""" - - def __init__(self, space): - Module.__init__(self, space, space.wrap(self.__name__)) - - # to build the dictionary of the module we get all the objects - # accessible as 'self.xxx'. Methods are bound. - contents = {} - for cls in self.__class__.__mro__: - for name in cls.__dict__: - # ignore names in '_xyz' - if not name.startswith('_') or name.endswith('_'): - value = cls.__dict__[name] - if isinstance(value, gateway.Gateway): - name = value.name - # This hack allows a "leakage" of a private - # module function (starts off prefixed with - # 'private_'; ends up prefixed with '_') - if name.startswith('private_'): - name = name[7:] - value = value.__get__(self) # get a Method - elif hasattr(value, '__get__'): - continue # ignore CPython functions - - # ignore tricky class-attrs we can't send from interp to app-level - if name in ('__metaclass__','__module__','w_dict',): - continue - contents.setdefault(space.wrap(name), space.wrap(value)) - w_contents = space.newdict(contents.items()) - space.call_method(w_contents, 'update', self.w_dict) - self.w_dict = w_contents - gateway.export_values(space, self.__dict__, self.w_dict) - - __metaclass__ = InitializedClass - def __initclass__(cls): - gateway.exportall(RwDictProxy(cls)) # xxx() -> app_xxx() - gateway.importall(RwDictProxy(cls)) # app_xxx() -> xxx() - - def _eval_app_source(self, sourcestring): - """ compile/execute a sourcestring in the applevel module dictionary """ - w = self.space.wrap - w_code = self.compile(w(sourcestring), w(''), w('exec')) - code = self.space.unwrap(w_code) - code.exec_code(self.space, self.w_dict, self.w_dict) - - # XXX do we actually want an interp-proxy to the app-level thing here? - # or no interp-level "mirror" at all? - co = compile(sourcestring, '','exec', 4096) - exec co in self.__dict__ Added: pypy/trunk/src/pypy/interpreter/test/foointerp.py ============================================================================== --- (empty file) +++ pypy/trunk/src/pypy/interpreter/test/foointerp.py Mon Jan 5 18:01:32 2004 @@ -0,0 +1,9 @@ +w_foo2 = space.wrap("hello") +foo2 = "never mind" # should be hidden by w_foo2 + +def foobuilder(w_name): + name = space.unwrap(w_name) + return space.wrap("hi, %s!" % name) + +from __applevel__ import bar +fortytwo = bar(space.wrap(6), space.wrap(7)) Added: pypy/trunk/src/pypy/interpreter/test/foomodule.py ============================================================================== --- (empty file) +++ pypy/trunk/src/pypy/interpreter/test/foomodule.py Mon Jan 5 18:01:32 2004 @@ -0,0 +1,13 @@ + +__interplevel__exec("w_foo = space.w_Ellipsis") +foo1 = __interplevel__eval("w_foo") # foo1 is Ellipsis +from __interplevel__ import foo # Ellipsis too + +def bar(a, b): # visible from interp-level code + return a * b + +__interplevel__execfile("foointerp.py") # defines w_foo2 and foobuilder() + +from __interplevel__ import foo2 # from w_foo2, gives "hello" +from __interplevel__ import foobuilder +foo3 = foobuilder("guido") # gives "hi, guido!" Modified: pypy/trunk/src/pypy/interpreter/test/test_extmodule.py ============================================================================== --- pypy/trunk/src/pypy/interpreter/test/test_extmodule.py (original) +++ pypy/trunk/src/pypy/interpreter/test/test_extmodule.py Mon Jan 5 18:01:32 2004 @@ -1,46 +1,33 @@ import autopath +import os from pypy.tool import testit -from pypy.interpreter.extmodule import ExtModule +from pypy.interpreter.extmodule import BuiltinModule -class TestExtModule(testit.IntTestCase): +class TestBuiltinModule(testit.IntTestCase): def setUp(self): self.space = testit.objspace() - class M(ExtModule): - __name__ = 'm' - constant = 678 - def app_egg(self, x): - return -x - def foo(self, w_spam): - return self.space.neg(w_spam) - self.m = M(self.space) - - def test_app_method(self): - w = self.space.wrap - self.assertEqual_w(self.m.egg(w(42)), w(-42)) - - def test_app_exported(self): - w = self.space.wrap - w_m = w(self.m) - w_result = self.space.call_method(w_m, 'egg', w(42)) - self.assertEqual_w(w_result, w(-42)) - - def test_interp_method(self): - w = self.space.wrap - self.assertEqual_w(self.m.app_foo(w(42)), w(-42)) - - def test_interp_exported(self): - w = self.space.wrap - w_m = w(self.m) - w_result = self.space.call_method(w_m, 'foo', w(42)) - self.assertEqual_w(w_result, w(-42)) - - def test_constant(self): - w = self.space.wrap - w_m = w(self.m) - self.assertEqual_w(self.space.getattr(w_m, w('constant')), w(678)) + def test_foomodule(self): + space = self.space + sourcefile = os.path.join(autopath.this_dir, 'foomodule.py') + m = BuiltinModule(space, 'foo', sourcefile=sourcefile) + w = space.wrap + w_m = space.wrap(m) + self.assertEqual_w(space.getattr(w_m, w('__name__')), w('foo')) + self.assertEqual_w(space.getattr(w_m, w('__file__')), w(sourcefile)) + # check app-level definitions + self.assertEqual_w(m.w_foo, space.w_Ellipsis) + self.assertEqual_w(space.getattr(w_m, w('foo1')), space.w_Ellipsis) + self.assertEqual_w(space.getattr(w_m, w('foo')), space.w_Ellipsis) + self.assertEqual_w(space.call_method(w_m, 'bar', w(4), w(3)), w(12)) + self.assertEqual_w(space.getattr(w_m, w('foo2')), w('hello')) + self.assertEqual_w(space.getattr(w_m, w('foo3')), w('hi, guido!')) + # check interp-level definitions + self.assertEqual_w(m.w_foo2, w('hello')) + self.assertEqual_w(m.foobuilder(w('xyzzy')), w('hi, xyzzy!')) + self.assertEqual_w(m.fortytwo, w(42)) if __name__ == '__main__': Modified: pypy/trunk/src/pypy/module/__builtin__interp.py ============================================================================== --- pypy/trunk/src/pypy/module/__builtin__interp.py (original) +++ pypy/trunk/src/pypy/module/__builtin__interp.py Mon Jan 5 18:01:32 2004 @@ -53,7 +53,6 @@ raise w_mod = space.get_builtin_module(modulename) if w_mod is not None: - space.setitem(space.sys.w_modules, w_modulename, w_mod) return w_mod import os @@ -61,7 +60,7 @@ f = os.path.join(space.unwrap(path), modulename + '.py') if os.path.exists(f): w_mod = space.wrap(Module(space, w_modulename)) - space.setitem(space.sys.w_modules, w_modulename, w_mod) + space.sys.setmodule(w_mod) space.setattr(w_mod, w('__file__'), w(f)) w_dict = space.getattr(w_mod, w('__dict__')) execfile(w(f), w_dict, w_dict) Modified: pypy/trunk/src/pypy/module/__builtin__module.py ============================================================================== --- pypy/trunk/src/pypy/module/__builtin__module.py (original) +++ pypy/trunk/src/pypy/module/__builtin__module.py Mon Jan 5 18:01:32 2004 @@ -421,6 +421,8 @@ # Interpreter-level function definitions # +__interplevel__execfile('__builtin__interp.py') + from __interplevel__ import abs, chr, len, ord, pow, repr from __interplevel__ import hash, oct, hex, round from __interplevel__ import getattr, setattr, delattr, iter, hash, id Modified: pypy/trunk/src/pypy/module/__init__.py ============================================================================== --- pypy/trunk/src/pypy/module/__init__.py (original) +++ pypy/trunk/src/pypy/module/__init__.py Mon Jan 5 18:01:32 2004 @@ -1,37 +1 @@ - -# ObjSpaces that implement the standard Python semantics -_std_spaces = ['TrivialObjSpace','StdObjSpace'] - -_all_spaces = _std_spaces + ['FlowObjSpace'] - -# The following item ia a list of -# (filename, classname, [applicable spaces]) tuples describing the -# builtin modules (pypy.interpreter.extmodule.ExtModule) -# availible in the pypy.module directory. - -# classname should be a classname of a callable in 'filename' that returns -# an unwrapped builtin module instance (pypy.interpreter.extmodule.ExtModule -# instance) - it may return an unwrapped None if the builtin module is not -# to be loaded. (e.g. this is the wrong platform.) - -#Note: the builtin and sys modules are special cased for bootstrapping reasons. - -# But this is an example of what the list would look like: - -##_builtin_and_sys = [('builtin','__builtin__',_std_spaces), -## ('sysmodule','Sys',_std_spaces), -## ] - -_builtin_modules = [('os_modules','Posix',_std_spaces), - ('os_modules','Nt',_std_spaces), - ('os_modules','Os2',_std_spaces), - ('os_modules','Mac',_std_spaces), - ('os_modules','Ce',_std_spaces), - ('os_modules','Riscos',_std_spaces), - ('mathmodule','Math',_std_spaces), - ('timemodule','Time',_std_spaces), - ('_randommodule','RandomHelper',_std_spaces), - ('cStringIOmodule','CStringIO',_std_spaces), - ('itertoolsmodule','Itertools',_std_spaces), - ('_sremodule','SreHelper',_std_spaces), - ] +# empty Deleted: /pypy/trunk/src/pypy/module/_randommodule.py ============================================================================== --- /pypy/trunk/src/pypy/module/_randommodule.py Mon Jan 5 18:01:32 2004 +++ (empty file) @@ -1,16 +0,0 @@ -"""Bootstrap the builtin _random module. - -""" -from pypy.interpreter.extmodule import ExtModule - -# We use the second (metaclassish) meaning of type to construct a subclass -# of ExtModule - can't modify some attributes (like __doc__) after class -# creation, and wrapping code does not properly look at instance variables. - -def RandomHelper(space): - try: - import _random - except ImportError: - return None - _randomhelper = type('_random', (ExtModule,), _random.__dict__) - return _randomhelper(space) Deleted: /pypy/trunk/src/pypy/module/_sremodule.py ============================================================================== --- /pypy/trunk/src/pypy/module/_sremodule.py Mon Jan 5 18:01:32 2004 +++ (empty file) @@ -1,16 +0,0 @@ -"""Bootstrap the builtin _sre module. - -""" -from pypy.interpreter.extmodule import ExtModule - -# We use the second (metaclassish) meaning of type to construct a subclass -# of ExtModule - can't modify some attributes (like __doc__) after class -# creation, and wrapping code does not properly look at instance variables. - -def SreHelper(space): - try: - import _sre - except ImportError: - return None - _srehelper = type('_sre', (ExtModule,), _sre.__dict__) - return _srehelper(space) Deleted: /pypy/trunk/src/pypy/module/cStringIOmodule.py ============================================================================== --- /pypy/trunk/src/pypy/module/cStringIOmodule.py Mon Jan 5 18:01:32 2004 +++ (empty file) @@ -1,16 +0,0 @@ -"""Bootstrap the builtin cStringIO module. - -""" -from pypy.interpreter.extmodule import ExtModule - -# We use the second (metaclassish) meaning of type to construct a subclass -# of ExtModule - can't modify some attributes (like __doc__) after class -# creation, and wrapping code does not properly look at instance variables. - -def CStringIO(space): - try: - import cStringIO - except ImportError: - return None - _cStringIO = type('cStringIO', (ExtModule,), cStringIO.__dict__) - return _cStringIO(space) Deleted: /pypy/trunk/src/pypy/module/itertoolsmodule.py ============================================================================== --- /pypy/trunk/src/pypy/module/itertoolsmodule.py Mon Jan 5 18:01:32 2004 +++ (empty file) @@ -1,16 +0,0 @@ -"""Bootstrap the builtin itertools module. - -""" -from pypy.interpreter.extmodule import ExtModule - -# We use the second (metaclassish) meaning of type to construct a subclass -# of ExtModule - can't modify some attributes (like __doc__) after class -# creation, and wrapping code does not properly look at instance variables. - -def Itertools(space): - try: - import itertools - except ImportError: - return None - _itertools = type('itertools', (ExtModule,), itertools.__dict__) - return _itertools(space) Deleted: /pypy/trunk/src/pypy/module/mathmodule.py ============================================================================== --- /pypy/trunk/src/pypy/module/mathmodule.py Mon Jan 5 18:01:32 2004 +++ (empty file) @@ -1,16 +0,0 @@ -"""Bootstrap the builtin math module. - -""" -from pypy.interpreter.extmodule import ExtModule - -# We use the second (metaclassish) meaning of type to construct a subclass -# of ExtModule - can't modify some attributes (like __doc__) after class -# creation, and wrapping code does not properly look at instance variables. - -def Math(space): - try: - import math - except ImportError: - return None - _math = type('math', (ExtModule,), math.__dict__) - return _math(space) Deleted: /pypy/trunk/src/pypy/module/os_modules.py ============================================================================== --- /pypy/trunk/src/pypy/module/os_modules.py Mon Jan 5 18:01:32 2004 +++ (empty file) @@ -1,61 +0,0 @@ -"""Bootstrap the builtin modules which make up sys: -posix, nt, os2, mac, ce, etc. - -""" -import sys -import os - -from pypy.interpreter.extmodule import ExtModule - -_names = sys.builtin_module_names - -# We use the second (metaclassish) meaning of type to construct a subclass -# of ExtModule - can't modify some attributes (like __doc__) after class -# creation, and wrapping code does not properly look at instance variables. -def Posix(space): - if 'posix' in _names: - import posix - _posix = type('posix', (ExtModule,), posix.__dict__) - return _posix(space) - else: - return None - -def Nt(space): - if 'nt' in _names: - import nt - _nt = type('nt', (ExtModule,), nt.__dict__) - return _nt(space) - else: - return None - -def Os2(space): - if 'os2' in _names: - import os2 - _os2 = type('os2', (ExtModule,), os2.__dict__) - return _os2(space) - else: - return None - -def Mac(space): - if 'mac' in _names: - import mac - _mac = type('mac', (ExtModule,), mac.__dict__) - return _mac(space) - else: - return None - -def Ce(space): - if 'ce' in _names: - import ce - _ce = type('ce', (ExtModule,), ce.__dict__) - return _ce(space) - else: - return None - -def Riscos(space): - if 'riscos' in _names: - import riscos - _riscos = type('riscos', (ExtModule,), riscos.__dict__) - return _riscos(space) - else: - return None Modified: pypy/trunk/src/pypy/module/sysinterp.py ============================================================================== --- pypy/trunk/src/pypy/module/sysinterp.py (original) +++ pypy/trunk/src/pypy/module/sysinterp.py Mon Jan 5 18:01:32 2004 @@ -9,10 +9,54 @@ import sys as cpy_sys +def hack_cpython_module(modname): + "Steal a module from CPython." + cpy_module = __import__(modname, globals(), locals(), None) + # to build the dictionary of the module, we get all the objects + # accessible as 'self.xxx'. Methods are bound. + contents = [] + for name in cpy_module.__dict__: + # ignore names in '_xyz' + if not name.startswith('_') or name.endswith('_'): + value = cpy_module.__dict__[name] + contents.append((space.wrap(name), space.wrap(value))) + w_contents = space.newdict(contents) + return Module(space, space.wrap(modname), w_contents) + + +# ____________________________________________________________ +# +# List of built-in modules. +# It should contain the name of all the files 'module/*module.py'. +builtin_module_names = ['__builtin__', 'sys', + ] + +# Create the builtin_modules dictionary, mapping names to Module instances +builtin_modules = {} +for fn in builtin_module_names: + builtin_modules[fn] = None + +# The following built-in modules are not written in PyPy, so we +# steal them from Python. +for fn in ['posix', 'nt', 'os2', 'mac', 'ce', 'riscos', + 'cStringIO', 'itertools', 'math', + '_random', '_sre', 'time']: + if fn not in builtin_modules: + try: + builtin_modules[fn] = hack_cpython_module(fn) + except ImportError: + pass + else: + builtin_module_names.append(fn) + +# ____________________________________________________________ +# # Common data structures w_modules = space.newdict([]) w_warnoptions = space.newlist([]) -w_builtin_module_names = space.newlist([]) +builtin_module_names.sort() +w_builtin_module_names = space.newtuple([space.wrap(fn) + for fn in builtin_module_names]) # Initialize the default path srcdir = os.path.dirname(autopath.pypydir) @@ -29,18 +73,21 @@ w_stdout = space.wrap(cpy_sys.stdout) w_stderr = space.wrap(cpy_sys.stderr) +# ____________________________________________________________ def setmodule(w_module): - """ put a module into the modules list """ + """ put a module into the modules dict """ w_name = space.getattr(w_module, space.wrap('__name__')) space.setitem(w_modules, w_name, w_module) -def setbuiltinmodule(w_module): - """ put a module into modules list and builtin_module_names """ - w_name = space.getattr(w_module, space.wrap('__name__')) - w_append = space.getattr(w_builtin_module_names, space.wrap('append')) - space.call_function(w_append, w_name) - space.setitem(w_modules, w_name, w_module) +def setbuiltinmodule(w_module, name): + """ put a module into the modules builtin_modules dicts """ + if builtin_modules[name] is None: + builtin_modules[name] = space.unwrap(w_module) + else: + assert builtin_modules[name] is space.unwrap(w_module), ( + "trying to change the builtin-in module %r" % (name,)) + space.setitem(w_modules, space.wrap(name), w_module) def displayhook(w_x): w = space.wrap Modified: pypy/trunk/src/pypy/module/sysmodule.py ============================================================================== --- pypy/trunk/src/pypy/module/sysmodule.py (original) +++ pypy/trunk/src/pypy/module/sysmodule.py Mon Jan 5 18:01:32 2004 @@ -2,6 +2,8 @@ The 'sys' module. """ +__interplevel__execfile('sysinterp.py') + # Common data structures from __interplevel__ import path, modules, warnoptions, builtin_module_names Deleted: /pypy/trunk/src/pypy/module/timemodule.py ============================================================================== --- /pypy/trunk/src/pypy/module/timemodule.py Mon Jan 5 18:01:32 2004 +++ (empty file) @@ -1,16 +0,0 @@ -"""Bootstrap the builtin time module. - -""" -from pypy.interpreter.extmodule import ExtModule - -# We use the second (metaclassish) meaning of type to construct a subclass -# of ExtModule - can't modify some attributes (like __doc__) after class -# creation, and wrapping code does not properly look at instance variables. - -def Time(space): - try: - import time - except ImportError: - return None - _time = type('time', (ExtModule,), time.__dict__) - return _time(space) From arigo at codespeak.net Mon Jan 5 18:15:45 2004 From: arigo at codespeak.net (arigo at codespeak.net) Date: Mon, 5 Jan 2004 18:15:45 +0100 (MET) Subject: [pypy-svn] r2722 - pypy/trunk/src/pypy/interpreter Message-ID: <20040105171545.694F95B9C9@thoth.codespeak.net> Author: arigo Date: Mon Jan 5 18:15:44 2004 New Revision: 2722 Modified: pypy/trunk/src/pypy/interpreter/extmodule.py Log: Added a few comments. Modified: pypy/trunk/src/pypy/interpreter/extmodule.py ============================================================================== --- pypy/trunk/src/pypy/interpreter/extmodule.py (original) +++ pypy/trunk/src/pypy/interpreter/extmodule.py Mon Jan 5 18:15:44 2004 @@ -15,8 +15,21 @@ class BuiltinModule(Module): + """A Module subclass specifically for built-in modules.""" def __init__(self, space, modulename, w_dict=None, sourcefile=None): + """Load the named built-in module, by default from the source file + 'pypy/module/module.py', which is app-level Python code + with a few special features that allow it to include interp-level + bits. (See pypy/module/test/foomodule.py) + + The module has two parts: the interp-level objects, stored as + attributes of 'self', and the app-level objects, stored in the + dictionary 'self.w_dict'. The app-level definition of the module + runs with 'self.w_dict' as globals. The interp-level bits are + executed with 'self.__dict__' as globals, i.e. they can read and + change the attributes of 'self' as global variables. + """ Module.__init__(self, space, space.wrap(modulename), w_dict) w_dict = self.w_dict @@ -78,11 +91,14 @@ del self.__saved_hooks def interplevelexec(self, w_codestring): + "'exec' a string at interp-level." codestring = self.space.unwrap(w_codestring) exec codestring in self.__dict__ return self.space.w_None def interpleveleval(self, w_codestring): + """'eval' a string at interp-level. The result must be None or + a wrapped object, which is returned to the caller.""" space = self.space codestring = space.unwrap(w_codestring) w_result = eval(codestring, self.__dict__) @@ -91,12 +107,19 @@ return w_result def interplevelexecfile(self, w_filename): + """'exec' a file at interp-level. The file should be in the same + directory as the xxxmodule.py source file of the module.""" filename = self.space.unwrap(w_filename) filename = os.path.join(os.path.dirname(self.__file__), filename) execfile(filename, self.__dict__) return self.space.w_None def interplevelimport(self, w_modulename, w_globals, w_locals, w_fromlist): + """Hook for 'from __interplevel__ import something'. + If there is a wrapped interp-level object 'w_something', returns it. + If there is an interp-level function 'def something(w_x, w_y...)', + build an appropriate gateway and returns it. + """ space = self.space w = space.wrap if space.is_true(space.eq(w_modulename, w('__interplevel__'))): @@ -126,6 +149,9 @@ app_interplevelimport = gateway.interp2app(interplevelimport) class AppModuleHack: + """For interp-level convenience: 'from __applevel__ import func' + imports the app-level function 'func' via an appropriate gateway. + """ def __init__(self, builtinmodule): self.space = builtinmodule.space self.w_dict = builtinmodule.w_dict From arigo at codespeak.net Tue Jan 6 08:48:01 2004 From: arigo at codespeak.net (arigo at codespeak.net) Date: Tue, 6 Jan 2004 08:48:01 +0100 (MET) Subject: [pypy-svn] r2727 - pypy/trunk/src/pypy/module Message-ID: <20040106074801.1BEE75A98A@thoth.codespeak.net> Author: arigo Date: Tue Jan 6 08:48:00 2004 New Revision: 2727 Modified: pypy/trunk/src/pypy/module/sysinterp.py Log: Added '' at the front of sys.path, as in Python 2.3. Modified: pypy/trunk/src/pypy/module/sysinterp.py ============================================================================== --- pypy/trunk/src/pypy/module/sysinterp.py (original) +++ pypy/trunk/src/pypy/module/sysinterp.py Tue Jan 6 08:48:00 2004 @@ -61,7 +61,7 @@ # Initialize the default path srcdir = os.path.dirname(autopath.pypydir) appdir = os.path.join(autopath.pypydir, 'appspace') -w_path = space.newlist([space.wrap(appdir)] + +w_path = space.newlist([space.wrap(''), space.wrap(appdir)] + [space.wrap(p) for p in cpy_sys.path if p!= srcdir]) # XXX - Replace with appropriate PyPy version numbering From arigo at codespeak.net Wed Jan 7 19:13:21 2004 From: arigo at codespeak.net (arigo at codespeak.net) Date: Wed, 7 Jan 2004 19:13:21 +0100 (MET) Subject: [pypy-svn] r2735 - pypy/trunk/src/pypy/translator Message-ID: <20040107181321.DDCFC5A46C@thoth.codespeak.net> Author: arigo Date: Wed Jan 7 19:13:13 2004 New Revision: 2735 Modified: pypy/trunk/src/pypy/translator/translator.py Log: Module name fix. Modified: pypy/trunk/src/pypy/translator/translator.py ============================================================================== --- pypy/trunk/src/pypy/translator/translator.py (original) +++ pypy/trunk/src/pypy/translator/translator.py Wed Jan 7 19:13:13 2004 @@ -28,7 +28,7 @@ Try dir(test) for list of current snippets. """ -import testit.autopath +import test.autopath from pypy.objspace.flow.model import * from pypy.annotation.model import * From arigo at codespeak.net Wed Jan 7 19:14:11 2004 From: arigo at codespeak.net (arigo at codespeak.net) Date: Wed, 7 Jan 2004 19:14:11 +0100 (MET) Subject: [pypy-svn] r2736 - pypy/trunk/src/pypy/translator Message-ID: <20040107181411.CA00B5A46C@thoth.codespeak.net> Author: arigo Date: Wed Jan 7 19:14:08 2004 New Revision: 2736 Modified: pypy/trunk/src/pypy/translator/annrpython.py Log: Added type annotation for %. Modified: pypy/trunk/src/pypy/translator/annrpython.py ============================================================================== --- pypy/trunk/src/pypy/translator/annrpython.py (original) +++ pypy/trunk/src/pypy/translator/annrpython.py Wed Jan 7 19:14:08 2004 @@ -302,6 +302,7 @@ return result consider_op_and_ = consider_op_sub # trailing underline + consider_op_mod = consider_op_sub consider_op_inplace_lshift = consider_op_sub def consider_op_is_true(self, arg): From arigo at codespeak.net Thu Jan 8 11:26:28 2004 From: arigo at codespeak.net (arigo at codespeak.net) Date: Thu, 8 Jan 2004 11:26:28 +0100 (MET) Subject: [pypy-svn] r2743 - pypy/trunk/doc/translation Message-ID: <20040108102628.F110C5A46C@thoth.codespeak.net> Author: arigo Date: Thu Jan 8 11:26:28 2004 New Revision: 2743 Modified: pypy/trunk/doc/translation/annotation.txt Log: Minor rephrasing. Modified: pypy/trunk/doc/translation/annotation.txt ============================================================================== --- pypy/trunk/doc/translation/annotation.txt (original) +++ pypy/trunk/doc/translation/annotation.txt Thu Jan 8 11:26:28 2004 @@ -21,7 +21,7 @@ return 1 The flow objspace gives us the following graph (after the -simplification that makes ``simple_call``):: +simplification that turns ``call`` into ``simple_call``):: StartBlock(v1): v2 = ge(v1, 2) From arigo at codespeak.net Thu Jan 8 13:27:13 2004 From: arigo at codespeak.net (arigo at codespeak.net) Date: Thu, 8 Jan 2004 13:27:13 +0100 (MET) Subject: [pypy-svn] r2744 - pypy/trunk/src/pypy/objspace/std Message-ID: <20040108122713.DAE905A46C@thoth.codespeak.net> Author: arigo Date: Thu Jan 8 13:27:13 2004 New Revision: 2744 Added: pypy/trunk/src/pypy/objspace/std/mro.py (contents, props changed) Log: For reference, the MRO algorithm of Python 2.3. Added: pypy/trunk/src/pypy/objspace/std/mro.py ============================================================================== --- (empty file) +++ pypy/trunk/src/pypy/objspace/std/mro.py Thu Jan 8 13:27:13 2004 @@ -0,0 +1,80 @@ +""" +For reference, the MRO algorithm of Python 2.3. +""" + + +def MRO(cls): + + def register(cls): + try: + blocklist = blocking[cls] + except KeyError: + blocklist = blocking[cls] = [0] + prevlist = blocklist + for base in cls.__bases__: + prevlist.append(base) + prevlist = register(base) + blocklist[0] += 1 + return blocklist + + order = [] + blocking = {} + register(cls) + + unblock = [cls] + while unblock: + cls = unblock.pop() + blocklist = blocking[cls] + assert blocklist[0] > 0 + blocklist[0] -= 1 + if blocklist[0] == 0: + order.append(cls) + unblock += blocklist[:0:-1] + + if len(order) < len(blocking): + mro_error(blocking) + return order + + +def mro_error(blocking): + # look for a cycle + + def find_cycle(cls): + path.append(cls) + blocklist = blocking[cls] # raise KeyError when we complete the path + if blocklist[0] > 0: + del blocking[cls] + for cls2 in blocklist[1:]: + find_cycle(cls2) + blocking[cls] = blocklist + del path[-1] + + #import pprint; pprint.pprint(blocking) + path = [] + try: + for cls in blocking.keys(): + find_cycle(cls) + except KeyError: + i = path.index(path[-1]) + names = [cls.__name__ for cls in path[i:]] + raise TypeError, "Cycle among base classes: " + ' < '.join(names) + else: + # should not occur + raise TypeError, "Cannot create a consistent method resolution order (MRO)" + + +if __name__ == '__main__': + class ex_9: + class O: pass + class A(O): pass + class B(O): pass + class C(O): pass + class D(O): pass + class E(O): pass + class F(O): pass + class K1(A,B,C): pass + class K2(D,F,B,E): pass + class K3(D,A): pass + class Z(K1,K2,F,K3): pass + + print MRO(ex_9.Z) From arigo at codespeak.net Sat Jan 10 17:54:04 2004 From: arigo at codespeak.net (arigo at codespeak.net) Date: Sat, 10 Jan 2004 17:54:04 +0100 (MET) Subject: [pypy-svn] r2764 - pypy/trunk/src/pypy/interpreter Message-ID: <20040110165404.76BA25A0D4@thoth.codespeak.net> Author: arigo Date: Sat Jan 10 17:54:03 2004 New Revision: 2764 Modified: pypy/trunk/src/pypy/interpreter/py.py Log: Patrick: the line I'm removing seems to have made its way into your commit accidentally. It shouldn't be there, as far as I can tell. Modified: pypy/trunk/src/pypy/interpreter/py.py ============================================================================== --- pypy/trunk/src/pypy/interpreter/py.py (original) +++ pypy/trunk/src/pypy/interpreter/py.py Sat Jan 10 17:54:03 2004 @@ -38,7 +38,6 @@ except error.PyPyError, pypyerr: pypyerr.operationerr.print_detailed_traceback(pypyerr.space) elif args: - args = args[0].split()+args[1:] try: main.run_file(args[0], space) except error.PyPyError, pypyerr: From arigo at codespeak.net Sun Jan 11 16:51:26 2004 From: arigo at codespeak.net (arigo at codespeak.net) Date: Sun, 11 Jan 2004 16:51:26 +0100 (MET) Subject: [pypy-svn] r2766 - in pypy/trunk/src/pypy: interpreter module Message-ID: <20040111155126.375055A95D@thoth.codespeak.net> Author: arigo Date: Sun Jan 11 16:51:25 2004 New Revision: 2766 Modified: pypy/trunk/src/pypy/interpreter/py.py pypy/trunk/src/pypy/module/sysinterp.py pypy/trunk/src/pypy/module/sysmodule.py Log: Added 'sys.argv'. Now we can run appspace/pystone.py again, with a number of iterations limited to 5 or 10 :-) Modified: pypy/trunk/src/pypy/interpreter/py.py ============================================================================== --- pypy/trunk/src/pypy/interpreter/py.py (original) +++ pypy/trunk/src/pypy/interpreter/py.py Sun Jan 11 16:51:25 2004 @@ -33,6 +33,10 @@ go_interactive = Options.interactive banner = '' if Options.command: + args = ['-c'] + for arg in args: + space.call_method(space.sys.w_argv, 'append', space.wrap(arg)) + if Options.command: try: main.run_string(Options.command[0], '', space) except error.PyPyError, pypyerr: Modified: pypy/trunk/src/pypy/module/sysinterp.py ============================================================================== --- pypy/trunk/src/pypy/module/sysinterp.py (original) +++ pypy/trunk/src/pypy/module/sysinterp.py Sun Jan 11 16:51:25 2004 @@ -54,6 +54,7 @@ # Common data structures w_modules = space.newdict([]) w_warnoptions = space.newlist([]) +w_argv = space.newlist([]) builtin_module_names.sort() w_builtin_module_names = space.newtuple([space.wrap(fn) for fn in builtin_module_names]) Modified: pypy/trunk/src/pypy/module/sysmodule.py ============================================================================== --- pypy/trunk/src/pypy/module/sysmodule.py (original) +++ pypy/trunk/src/pypy/module/sysmodule.py Sun Jan 11 16:51:25 2004 @@ -5,7 +5,8 @@ __interplevel__execfile('sysinterp.py') # Common data structures -from __interplevel__ import path, modules, warnoptions, builtin_module_names +from __interplevel__ import path, modules, argv +from __interplevel__ import warnoptions, builtin_module_names # Objects from interpreter-level from __interplevel__ import stdin, stdout, stderr, maxint From hpk at codespeak.net Mon Jan 19 10:46:35 2004 From: hpk at codespeak.net (hpk at codespeak.net) Date: Mon, 19 Jan 2004 10:46:35 +0100 (MET) Subject: [pypy-svn] r2833 - pypy/trunk/src/pypy/tool Message-ID: <20040119094635.F010E5ACDB@thoth.codespeak.net> Author: hpk Date: Mon Jan 19 10:46:34 2004 New Revision: 2833 Modified: pypy/trunk/src/pypy/tool/traceinteractive.py Log: - small fixes and better error behaviour Modified: pypy/trunk/src/pypy/tool/traceinteractive.py ============================================================================== --- pypy/trunk/src/pypy/tool/traceinteractive.py (original) +++ pypy/trunk/src/pypy/tool/traceinteractive.py Mon Jan 19 10:46:34 2004 @@ -5,6 +5,8 @@ import keyword import linecache +assert sys.version_info >= (2,3), "sorry, can only run with python2.3 and greater" + try: import readline import rlcompleter @@ -162,7 +164,10 @@ readline.set_completer(Completer(s).complete) readline.parse_and_bind("tab: complete") readline.set_history_length(25000) - readline.read_history_file() + try: + readline.read_history_file() + except IOError: + pass # guess it doesn't exit import atexit atexit.register(readline.write_history_file) From rxe at codespeak.net Mon Jan 19 11:20:44 2004 From: rxe at codespeak.net (rxe at codespeak.net) Date: Mon, 19 Jan 2004 11:20:44 +0100 (MET) Subject: [pypy-svn] r2835 - pypy/trunk/src/pypy/tool Message-ID: <20040119102044.4AFD55ACDB@thoth.codespeak.net> Author: rxe Date: Mon Jan 19 11:20:43 2004 New Revision: 2835 Modified: pypy/trunk/src/pypy/tool/traceinteractive.py Log: Tidies to a premature checkin. ;-) Tab completion works a little better. Modified: pypy/trunk/src/pypy/tool/traceinteractive.py ============================================================================== --- pypy/trunk/src/pypy/tool/traceinteractive.py (original) +++ pypy/trunk/src/pypy/tool/traceinteractive.py Mon Jan 19 11:20:43 2004 @@ -1,15 +1,12 @@ -# Python imports +# Standard imports import sys import code -import repr import keyword -import linecache assert sys.version_info >= (2,3), "sorry, can only run with python2.3 and greater" try: import readline - import rlcompleter have_readline = True except: @@ -27,30 +24,44 @@ from pypy.objspace import trace -# Global -operations = dict([(r[0], r[0]) for r in ObjSpace.MethodTable]) - #////////////////////////////////////////////////////////////////////////// if have_readline: - class Completer(rlcompleter.Completer): - # TODO Tailor this for own means - def __init__(self, objspace): - self.objspace = objspace - + class Completer: + def __init__(self, space): + self.space = space + + def complete(self, text, state): + + if state == 0: + if "." in text: + self.matches = self.attr_matches(text) + else: + self.matches = self.global_matches(text) + try: + return self.matches[state] + + except IndexError: + return None + - # Very frustratingly, we have a lot of duplication of rlcompleter here def global_matches(self, text): - print "GERE" - locals = self.objspace.unwrap(self.objspace.w_locals) + + import __builtin__ + + w_res = self.space.call_method(self.space.w_globals, "keys") + namespace_keys = self.space.unwrap(w_res) + matches = [] n = len(text) - for l in [locals.keys(), __builtin__.__dict__.keys(), keyword.kwlist]: + + for l in [namespace_keys, __builtin__.__dict__.keys(), keyword.kwlist]: for word in l: if word[:n] == text and word != "__builtins__": matches.append(word) + return matches def attr_matches(self, text): @@ -60,43 +71,36 @@ return expr, attr = m.group(1, 3) - object = self.locals[expr] - words = dir(object) - if hasattr(object, '__class__'): - words.append('__class__') - words = words + self.get_class_members(object.__class__) - + s = self.space + w_obj = s.getitem(s.w_globals, s.wrap(expr)) + w_func = s.getitem(s.w_builtins, s.wrap("dir")) + w_res = s.call_function(w_func, w_obj) + words = s.unwrap(w_res) matches = [] n = len(attr) for word in words: if word[:n] == attr and word != "__builtins__": matches.append("%s.%s" % (expr, word)) - return matches - def get_class_members(self, klass): - ret = dir(klass) - if hasattr(klass, '__bases__'): - for base in klass.__bases__: - ret = ret + self.get_class_members(base) - return ret + return matches #////////////////////////////////////////////////////////////////////////// class TraceConsole(code.InteractiveConsole): - def __init__(self, objspace): + def __init__(self, space): code.InteractiveConsole.__init__(self) - s = self.space = trace.TraceObjSpace(objspace) + s = self.space = trace.TraceObjSpace(space) s.setitem(s.w_globals, s.wrap("__pytrace__"), s.w_True) - self.objspacename = objspace.__class__.__name__ + self.objspacename = space.__class__.__name__ def interact(self, banner=None): if banner is None: banner = "Python %s in pypy(trace)\n%s / %s - %s" % ( sys.version, self.__class__.__name__, - self.objspacename, + self.space, " [Use __pytrace__ flag to turn off tracing.]" ) code.InteractiveConsole.interact(self, banner) @@ -111,61 +115,71 @@ # 'code' is a CPython code object from pypy.interpreter.pycode import PyCode pycode = PyCode()._from_code(code) - try: - s = self.space - trace_flag = s.unwrap(s.getitem(s.w_globals, - s.wrap("__pytrace__"))) - if trace_flag: - s.settrace() + s = self.space + trace_flag = s.unwrap(s.getitem(s.w_globals, + s.wrap("__pytrace__"))) + if trace_flag: + s.settrace() + + try: pycode.exec_code(s, s.w_globals, s.w_globals) if trace_flag: res = s.getresult() s.settrace() print_result(res) - + except baseobjspace.OperationError, operationerr: + if trace_flag: + res = s.getresult() + s.settrace() + print_result(res) + # XXX insert exception info into the application-level sys.last_xxx + print operationerr.print_detailed_traceback(self.space) else: - try: - if sys.stdout.softspace: - print - - except AttributeError: - # Don't crash if user defined stdout doesn't have softspace - pass + print - def runsource(self, source, ignored_filename="", symbol="single"): - hacked_filename = '\n'+source + def runsource(self, source, ignored_filename = "", symbol = "single"): + hacked_filename = '\n' + source try: code = self.compile(source, hacked_filename, symbol) + except (OverflowError, SyntaxError, ValueError): self.showsyntaxerror(self.filename) - return 0 + return False + if code is None: - return 1 - self.runcode(code) - return 0 + return True + self.runcode(code) + return False +#////////////////////////////////////////////////////////////////////////// -def trace_interactive(objspace, banner = None): - s = objspace +def trace_interactive(space, banner = None): + s = space + # Create an execution context, and set the globals ec = s.getexecutioncontext() s.w_globals = ec.make_standard_w_globals() + s.setitem(s.w_globals, s.wrap("__name__"), s.wrap("__main__")) console = TraceConsole(s) + if have_readline: # Keep here to save windoze tears + readline.set_completer(Completer(s).complete) readline.parse_and_bind("tab: complete") readline.set_history_length(25000) + try: readline.read_history_file() + except IOError: pass # guess it doesn't exit @@ -175,15 +189,15 @@ console.interact(banner) -if __name__ == '__main__': +#////////////////////////////////////////////////////////////////////////// +if __name__ == '__main__': from pypy.tool import option - from pypy.tool import testit args = option.process_options(option.get_standard_options(), option.Options) # Create objspace... - objspace = option.objspace() - trace_interactive(objspace) + space = option.objspace() + trace_interactive(space) From jum at codespeak.net Fri Jan 30 18:59:38 2004 From: jum at codespeak.net (jum at codespeak.net) Date: Fri, 30 Jan 2004 18:59:38 +0100 (MET) Subject: [pypy-svn] r2912 - pypy/trunk/doc/devel Message-ID: <20040130175938.ACC145B025@thoth.codespeak.net> Author: jum Date: Fri Jan 30 18:59:38 2004 New Revision: 2912 Modified: pypy/trunk/doc/devel/howtosvn.txt Log: Updated OS X build to latest version. Modified: pypy/trunk/doc/devel/howtosvn.txt ============================================================================== --- pypy/trunk/doc/devel/howtosvn.txt (original) +++ pypy/trunk/doc/devel/howtosvn.txt Fri Jan 30 18:59:38 2004 @@ -122,7 +122,7 @@ .. _website: http://support.microsoft.com/default.aspx?scid=kb%3Ben-us%3B259403 .. _GUI: http://tortoisesvn.tigris.org/servlets/ProjectDocumentList?folderID=616 -.. _MacOS: http://codespeak.net/~jum/svn-0.35.1-darwin-ppc.tar.gz +.. _MacOS: http://codespeak.net/~jum/svn-0.37.0-darwin-ppc.tar.gz .. _versions: http://subversion.tigris.org/project_packages.html .. _Win: http://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=4B6140F9-2D36-4977-8FA1-6F8A0F5DCA8F