[pypy-svn] r12433 - in pypy/dist/pypy: documentation interpreter interpreter/test/mixedmodule module/_sre_pypy module/builtin module/parser module/recparser module/sys2
hpk at codespeak.net
hpk at codespeak.net
Wed May 18 12:32:19 CEST 2005
Author: hpk
Date: Wed May 18 12:32:18 2005
New Revision: 12433
Added:
pypy/dist/pypy/interpreter/mixedmodule.py
- copied, changed from r12432, pypy/dist/pypy/interpreter/lazymodule.py
Removed:
pypy/dist/pypy/interpreter/lazymodule.py
Modified:
pypy/dist/pypy/documentation/getting_started.txt
pypy/dist/pypy/interpreter/test/mixedmodule/__init__.py
pypy/dist/pypy/module/_sre_pypy/__init__.py
pypy/dist/pypy/module/builtin/__init__.py
pypy/dist/pypy/module/parser/__init__.py
pypy/dist/pypy/module/recparser/__init__.py
pypy/dist/pypy/module/sys2/__init__.py
Log:
renaming LazyModule to MixedModule
Modified: pypy/dist/pypy/documentation/getting_started.txt
==============================================================================
--- pypy/dist/pypy/documentation/getting_started.txt (original)
+++ pypy/dist/pypy/documentation/getting_started.txt Wed May 18 12:32:18 2005
@@ -284,7 +284,7 @@
in pyopcode.py_, frame and code objects in eval.py_ and pyframe.py_,
function objects and argument passing in function.py_ and argument.py_,
the object space interface definition in baseobjspace.py_, modules in
- module.py_ and lazymodule.py_. Core types supporting the interpreter are
+ module.py_ and mixedmodule.py_. Core types supporting the interpreter are
defined in typedef.py_.
* `pypy/objspace/std`_ contains the `Standard object space`_. The main file
@@ -380,7 +380,7 @@
.. _argument.py: http://codespeak.net/svn/pypy/dist/pypy/interpreter/argument.py
.. _baseobjspace.py: http://codespeak.net/svn/pypy/dist/pypy/interpreter/baseobjspace.py
.. _module.py: http://codespeak.net/svn/pypy/dist/pypy/interpreter/module.py
-.. _lazymodule.py: http://codespeak.net/svn/pypy/dist/pypy/interpreter/lazymodule.py
+.. _mixedmodule.py: http://codespeak.net/svn/pypy/dist/pypy/interpreter/mixedmodule.py
.. _typedef.py: http://codespeak.net/svn/pypy/dist/pypy/interpreter/typedef.py
.. _pypy/objspace/std: http://codespeak.net/svn/pypy/dist/pypy/objspace/std/
.. _Standard object space: http://codespeak.net/pypy/index.cgi?doc/stdobjspace.html
Deleted: /pypy/dist/pypy/interpreter/lazymodule.py
==============================================================================
--- /pypy/dist/pypy/interpreter/lazymodule.py Wed May 18 12:32:18 2005
+++ (empty file)
@@ -1,164 +0,0 @@
-from pypy.interpreter.module import Module
-from pypy.interpreter.function import Function, BuiltinFunction
-from pypy.interpreter import gateway
-from pypy.interpreter.error import OperationError
-from pypy.interpreter.baseobjspace import W_Root
-import os
-
-import inspect
-
-class LazyModule(Module):
-
- NOT_RPYTHON_ATTRIBUTES = ['loaders']
-
- def __init__(self, space, w_name):
- """ NOT_RPYTHON """
- Module.__init__(self, space, w_name)
- self.lazy = True
- self.__class__.buildloaders()
-
- def get(self, name):
- space = self.space
- w_value = self.getdictvalue(space, name)
- if w_value is None:
- raise OperationError(space.w_AttributeError, space.wrap(name))
- return w_value
-
- def call(self, name, *args_w):
- w_builtin = self.get(name)
- return self.space.call_function(w_builtin, *args_w)
-
- def getdictvalue(self, space, name):
- try:
- return space.getitem(self.w_dict, space.wrap(name))
- except OperationError, e:
- if not e.match(space, space.w_KeyError):
- raise
- if not self.lazy:
- return None
- try:
- loader = self.loaders[name]
- except KeyError:
- return None
- else:
- #print "trying to load", name
- w_value = loader(space)
- #print "loaded", w_value
- # obscure
- func = space.interpclass_w(w_value)
- if type(func) is Function:
- try:
- bltin = func._builtinversion_
- except AttributeError:
- bltin = BuiltinFunction(func)
- bltin.w_module = self.w_name
- func._builtinversion_ = bltin
- w_value = space.wrap(bltin)
- space.setitem(self.w_dict, space.wrap(name), w_value)
- return w_value
-
- def getdict(self):
- if self.lazy:
- space = self.space
- for name in self.loaders:
- w_value = self.get(name)
- space.setitem(self.w_dict, space.wrap(name), w_value)
- self.lazy = False
- return self.w_dict
-
- def _freeze_(self):
- self.getdict()
- # hint for the annotator: Modules can hold state, so they are
- # not constant
- return False
-
- def buildloaders(cls):
- """ NOT_RPYTHON """
- if not hasattr(cls, 'loaders'):
- # build a constant dictionary out of
- # applevel/interplevel definitions
- cls.loaders = loaders = {}
- pkgroot = cls.__module__
- for name, spec in cls.interpleveldefs.items():
- loaders[name] = getinterpevalloader(pkgroot, spec)
- for name, spec in cls.appleveldefs.items():
- loaders[name] = getappfileloader(pkgroot, spec)
- assert '__file__' not in loaders
- loaders['__file__'] = cls.get__file__
-
- buildloaders = classmethod(buildloaders)
-
- def get__file__(cls, space):
- """ NOT_RPYTHON.
- return the __file__ attribute of a LazyModule
- which is the root-directory for the various
- applevel and interplevel snippets that make
- up the module.
- """
- try:
- fname = cls._fname
- except AttributeError:
- pkgroot = cls.__module__
- mod = __import__(pkgroot, None, None, ['__doc__'])
- fname = mod.__file__
- assert os.path.basename(fname).startswith('__init__.py')
- cls._fname = fname
- return space.wrap(fname)
-
- get__file__ = classmethod(get__file__)
-
-
-def getinterpevalloader(pkgroot, spec):
- """ NOT_RPYTHON """
- def ifileloader(space):
- d = {'space' : space}
- # EVIL HACK (but it works, and this is not RPython :-)
- while 1:
- try:
- value = eval(spec, d)
- except NameError, ex:
- #assert name not in d, "huh, am i looping?"
- name = ex.args[0].split("'")[1] # super-Evil
- try:
- d[name] = __import__(pkgroot+'.'+name, None, None, [name])
- except ImportError:
- d[name] = __import__(name, None, None, [name])
- else:
- #print spec, "->", value
- if hasattr(value, 'func_code'): # semi-evil
- return space.wrap(gateway.interp2app(value))
-
- try:
- is_type = issubclass(value, W_Root) # pseudo-evil
- except TypeError:
- is_type = False
- if is_type:
- return space.gettypeobject(value.typedef)
-
- assert isinstance(value, W_Root), (
- "interpleveldef %s.%s must return a wrapped object "
- "(got %r instead)" % (pkgroot, spec, value))
- return value
- return ifileloader
-
-applevelcache = {}
-def getappfileloader(pkgroot, spec):
- """ NOT_RPYTHON """
- # hum, it's a bit more involved, because we usually
- # want the import at applevel
- modname, attrname = spec.split('.')
- impbase = pkgroot + '.' + modname
- mod = __import__(impbase, None, None, ['attrname'])
- try:
- app = applevelcache[mod]
- except KeyError:
- source = inspect.getsource(mod)
- fn = mod.__file__
- if fn.endswith('.pyc') or fn.endswith('.pyo'):
- fn = fn[:-1]
- app = gateway.applevel(source, filename=fn)
- applevelcache[mod] = app
-
- def afileloader(space):
- return app.wget(space, attrname)
- return afileloader
Copied: pypy/dist/pypy/interpreter/mixedmodule.py (from r12432, pypy/dist/pypy/interpreter/lazymodule.py)
==============================================================================
--- pypy/dist/pypy/interpreter/lazymodule.py (original)
+++ pypy/dist/pypy/interpreter/mixedmodule.py Wed May 18 12:32:18 2005
@@ -7,7 +7,7 @@
import inspect
-class LazyModule(Module):
+class MixedModule(Module):
NOT_RPYTHON_ATTRIBUTES = ['loaders']
@@ -90,7 +90,7 @@
def get__file__(cls, space):
""" NOT_RPYTHON.
- return the __file__ attribute of a LazyModule
+ return the __file__ attribute of a MixedModule
which is the root-directory for the various
applevel and interplevel snippets that make
up the module.
Modified: pypy/dist/pypy/interpreter/test/mixedmodule/__init__.py
==============================================================================
--- pypy/dist/pypy/interpreter/test/mixedmodule/__init__.py (original)
+++ pypy/dist/pypy/interpreter/test/mixedmodule/__init__.py Wed May 18 12:32:18 2005
@@ -1,6 +1,6 @@
-from pypy.interpreter.lazymodule import LazyModule
+from pypy.interpreter.mixedmodule import MixedModule
-class Module(LazyModule):
+class Module(MixedModule):
interpleveldefs = {
'__name__' : '(space.wrap("mixedmodule"))',
'__doc__' : '(space.wrap("mixedmodule doc"))',
Modified: pypy/dist/pypy/module/_sre_pypy/__init__.py
==============================================================================
--- pypy/dist/pypy/module/_sre_pypy/__init__.py (original)
+++ pypy/dist/pypy/module/_sre_pypy/__init__.py Wed May 18 12:32:18 2005
@@ -9,10 +9,10 @@
allows us to do so one piece at a time.
"""
-from pypy.interpreter.lazymodule import LazyModule
+from pypy.interpreter.mixedmodule import MixedModule
-class Module(LazyModule):
+class Module(MixedModule):
"""_sre_pypy module"""
appleveldefs = {
Modified: pypy/dist/pypy/module/builtin/__init__.py
==============================================================================
--- pypy/dist/pypy/module/builtin/__init__.py (original)
+++ pypy/dist/pypy/module/builtin/__init__.py Wed May 18 12:32:18 2005
@@ -1,8 +1,8 @@
from pypy.interpreter.error import OperationError
from pypy.interpreter import module
-from pypy.interpreter.lazymodule import LazyModule
+from pypy.interpreter.mixedmodule import MixedModule
-class Module(LazyModule):
+class Module(MixedModule):
"""Built-in functions, exceptions, and other objects."""
appleveldefs = {
Modified: pypy/dist/pypy/module/parser/__init__.py
==============================================================================
--- pypy/dist/pypy/module/parser/__init__.py (original)
+++ pypy/dist/pypy/module/parser/__init__.py Wed May 18 12:32:18 2005
@@ -1,8 +1,8 @@
from pypy.interpreter.error import OperationError
from pypy.interpreter import module
-from pypy.interpreter.lazymodule import LazyModule
+from pypy.interpreter.mixedmodule import MixedModule
-class Module(LazyModule):
+class Module(MixedModule):
"""The builtin parser module.
"""
appleveldefs = {
Modified: pypy/dist/pypy/module/recparser/__init__.py
==============================================================================
--- pypy/dist/pypy/module/recparser/__init__.py (original)
+++ pypy/dist/pypy/module/recparser/__init__.py Wed May 18 12:32:18 2005
@@ -1,6 +1,6 @@
from pypy.interpreter.error import OperationError, debug_print
from pypy.interpreter import module
-from pypy.interpreter.lazymodule import LazyModule
+from pypy.interpreter.mixedmodule import MixedModule
import pythonutil
@@ -8,7 +8,7 @@
debug_print( "Loading grammar %s" % pythonutil.PYTHON_GRAMMAR )
PYTHON_PARSER = pythonutil.python_grammar()
-class Module(LazyModule):
+class Module(MixedModule):
"""The builtin parser module.
"""
Modified: pypy/dist/pypy/module/sys2/__init__.py
==============================================================================
--- pypy/dist/pypy/module/sys2/__init__.py (original)
+++ pypy/dist/pypy/module/sys2/__init__.py Wed May 18 12:32:18 2005
@@ -1,7 +1,7 @@
-from pypy.interpreter.lazymodule import LazyModule
+from pypy.interpreter.mixedmodule import MixedModule
from pypy.interpreter.error import OperationError
-class Module(LazyModule):
+class Module(MixedModule):
"""Sys Builtin Module. """
def __init__(self, space, w_name):
"""NOT_RPYTHON""" # because parent __init__ isn't
@@ -93,7 +93,7 @@
def getdictvalue(self, space, attr):
""" specialize access to dynamic exc_* attributes. """
- value = LazyModule.getdictvalue(self, space, attr)
+ value = MixedModule.getdictvalue(self, space, attr)
if value is not None:
return value
if attr == 'exc_type':
More information about the Pypy-commit
mailing list