[pypy-svn] r9297 - in pypy/branch/dist-interpapp/pypy: interpreter module/builtin objspace/flow
pedronis at codespeak.net
pedronis at codespeak.net
Thu Feb 17 23:33:28 CET 2005
Author: pedronis
Date: Thu Feb 17 23:33:28 2005
New Revision: 9297
Modified:
pypy/branch/dist-interpapp/pypy/interpreter/baseobjspace.py
pypy/branch/dist-interpapp/pypy/interpreter/pyframe.py
pypy/branch/dist-interpapp/pypy/module/builtin/__init__.py
pypy/branch/dist-interpapp/pypy/objspace/flow/objspace.py
Log:
find a home for lookup builtin logic such that we don't have circular import problems.
The other placements would require moving the imports after the W_Root etc class defs in baseobjspace
Modified: pypy/branch/dist-interpapp/pypy/interpreter/baseobjspace.py
==============================================================================
--- pypy/branch/dist-interpapp/pypy/interpreter/baseobjspace.py (original)
+++ pypy/branch/dist-interpapp/pypy/interpreter/baseobjspace.py Thu Feb 17 23:33:28 2005
@@ -38,8 +38,6 @@
"""Same as BaseWrappable, just new-style instead."""
-from pypy.interpreter import module
-
class ObjSpace(object):
"""Base class for the interpreter-level implementations of object spaces.
http://codespeak.net/moin/pypy/moin.cgi/ObjectSpace"""
@@ -94,27 +92,6 @@
self.setitem(self.builtin.w_dict, self.wrap(name), value)
print "finished make_builtins", self
- def lookup_builtin(space, w_globals):
- "Look up the builtin module to use from the __builtins__ global"
- try:
- w_builtin = space.getitem(w_globals, space.wrap('__builtins__'))
- except OperationError, e:
- if not e.match(space, space.w_KeyError):
- raise
- else:
- if w_builtin is space.builtin: # common case
- return space.builtin
- if space.is_true(space.isinstance(w_builtin, space.w_dict)):
- return module.Module(space, None, w_builtin)
- builtin = space.interpclass_w(w_builtin)
- if isinstance(builtin, module.Module):
- return builtin
- # no builtin! make a default one. Given them None, at least.
- builtin = module.Module(space, None)
- space.setitem(builtin.w_dict, space.wrap('None'), space.w_None)
- return builtin
-
-
def XXXget_builtin_module(self, name):
if name not in self.sys.builtin_modules:
return None
Modified: pypy/branch/dist-interpapp/pypy/interpreter/pyframe.py
==============================================================================
--- pypy/branch/dist-interpapp/pypy/interpreter/pyframe.py (original)
+++ pypy/branch/dist-interpapp/pypy/interpreter/pyframe.py Thu Feb 17 23:33:28 2005
@@ -5,7 +5,6 @@
from pypy.interpreter.miscutils import Stack
from pypy.interpreter.error import OperationError
from pypy.interpreter import pytraceback
-from pypy.interpreter import module
import __future__
compiler_flags = 0
@@ -34,7 +33,7 @@
self.blockstack = Stack()
self.last_exception = None
self.next_instr = 0
- self.builtin = space.lookup_builtin(w_globals)
+ self.builtin = space.builtin.pick_builtin(w_globals)
# regular functions always have CO_OPTIMIZED and CO_NEWLOCALS.
# class bodies only have CO_NEWLOCALS.
if code.dictscope_needed():
Modified: pypy/branch/dist-interpapp/pypy/module/builtin/__init__.py
==============================================================================
--- pypy/branch/dist-interpapp/pypy/module/builtin/__init__.py (original)
+++ pypy/branch/dist-interpapp/pypy/module/builtin/__init__.py Thu Feb 17 23:33:28 2005
@@ -1,3 +1,5 @@
+from pypy.interpreter.error import OperationError
+from pypy.interpreter import module
from pypy.interpreter.newmodule import ExtModule
class Module(ExtModule):
@@ -102,3 +104,24 @@
'__import__' : 'importing.importhook',
}
+
+ def pick_builtin(self, w_globals):
+ "Look up the builtin module to use from the __builtins__ global"
+ space = self.space
+ try:
+ w_builtin = space.getitem(w_globals, space.wrap('__builtins__'))
+ except OperationError, e:
+ if not e.match(space, space.w_KeyError):
+ raise
+ else:
+ if w_builtin is space.builtin: # common case
+ return space.builtin
+ if space.is_true(space.isinstance(w_builtin, space.w_dict)):
+ return module.Module(space, None, w_builtin)
+ builtin = space.interpclass_w(w_builtin)
+ if isinstance(builtin, module.Module):
+ return builtin
+ # no builtin! make a default one. Given them None, at least.
+ builtin = module.Module(space, None)
+ space.setitem(builtin.w_dict, space.wrap('None'), space.w_None)
+ return builtin
Modified: pypy/branch/dist-interpapp/pypy/objspace/flow/objspace.py
==============================================================================
--- pypy/branch/dist-interpapp/pypy/objspace/flow/objspace.py (original)
+++ pypy/branch/dist-interpapp/pypy/objspace/flow/objspace.py Thu Feb 17 23:33:28 2005
@@ -37,6 +37,9 @@
import __builtin__
self.concrete_mode = 0
self.builtin = Module(self, Constant('__builtin__'), Constant(__builtin__.__dict__))
+ def pick_builtin(w_globals):
+ return self.builtin
+ self.builtin.pick_builtin = pick_builtin
self.sys = Module(self, Constant('sys'), Constant(sys.__dict__))
self.sys.recursionlimit = 100
self.w_None = Constant(None)
@@ -56,10 +59,6 @@
#self.make_builtins()
#self.make_sys()
-
- def lookup_builtin(self, w_globals):
- return self.builtin
-
def loadfromcache(self, key, builder, cache):
# when populating the caches, the flow space switches to
# "concrete mode". In this mode, only Constants are allowed
More information about the Pypy-commit
mailing list