[pypy-svn] r9300 - in pypy/branch/dist-interpapp/pypy: interpreter interpreter/test module/test objspace objspace/std translator
hpk at codespeak.net
hpk at codespeak.net
Fri Feb 18 11:32:37 CET 2005
Author: hpk
Date: Fri Feb 18 11:32:37 2005
New Revision: 9300
Modified:
pypy/branch/dist-interpapp/pypy/interpreter/baseobjspace.py
pypy/branch/dist-interpapp/pypy/interpreter/test/test_main.py
pypy/branch/dist-interpapp/pypy/interpreter/test/test_objspace.py
pypy/branch/dist-interpapp/pypy/module/test/test_sysmodule.py
pypy/branch/dist-interpapp/pypy/objspace/std/objspace.py
pypy/branch/dist-interpapp/pypy/objspace/trivial.py
pypy/branch/dist-interpapp/pypy/translator/geninterplevel.py
Log:
- cleanup the initialization process for objectspaces
- get rid of space.w_sys and space.w_builtin
because instead of getitem(space.w_sys, ...)
you can do space.sys.get(unwrapped_name)
- trivial objectspace fails the tests but
it did before
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 Fri Feb 18 11:32:37 2005
@@ -55,50 +55,28 @@
def __repr__(self):
return self.__class__.__name__
- def make_builtins(self, for_builtins):
+ def make_builtins(self):
"NOT_RPYTHON: only for initializing the space."
- # initializing builtins may require creating a frame which in
- # turn already accesses space.w_builtins, provide a dummy one ...
- # XXX TEMPORARY
from pypy.module.sys2 import Module
w_name = self.wrap('sys')
self.sys = Module(self, w_name)
- self.w_sys = self.wrap(self.sys)
-
w_modules = self.sys.get('modules')
- self.setitem(w_modules, w_name, self.w_sys)
- print "initialized", self.w_sys
+ self.setitem(w_modules, w_name, self.wrap(self.sys))
+
from pypy.module.builtin import Module
w_name = self.wrap('__builtin__')
self.builtin = Module(self, w_name)
- self.w_builtin = self.wrap(self.builtin)
- #self.w_builtins = self.builtin.w_dict
- self.setitem(w_modules, w_name, self.w_builtin)
- self.setitem(self.builtin.w_dict, self.wrap('__builtins__'), self.w_builtin)
- print "initialized", self.w_builtin
-
- # do we need this?
- #for key, w_value in for_builtins.items():
- # self.setitem(self.builtin.w_dict, self.wrap(key), w_value)
+ w_builtin = self.wrap(self.builtin)
+ self.setitem(w_modules, w_name, w_builtin)
+ self.setitem(self.builtin.w_dict, self.wrap('__builtins__'), w_builtin)
# initialize with "bootstrap types" from objspace (e.g. w_None)
for name, value in self.__dict__.items():
if name.startswith('w_'):
name = name[2:]
- if name.startswith('builtin') or name.startswith('sys'):
- continue
#print "setitem: space instance %-20s into builtins" % name
self.setitem(self.builtin.w_dict, self.wrap(name), value)
- print "finished make_builtins", self
-
- def XXXget_builtin_module(self, name):
- if name not in self.sys.builtin_modules:
- return None
- module = self.sys.builtin_modules[name]
- w_module = self.wrap(module)
- self.sys.setbuiltinmodule(w_module, name)
- return w_module
def initialize(self):
"""NOT_RPYTHON: Abstract method that should put some minimal
Modified: pypy/branch/dist-interpapp/pypy/interpreter/test/test_main.py
==============================================================================
--- pypy/branch/dist-interpapp/pypy/interpreter/test/test_main.py (original)
+++ pypy/branch/dist-interpapp/pypy/interpreter/test/test_main.py Fri Feb 18 11:32:37 2005
@@ -17,10 +17,10 @@
testresultoutput = '11\n'
def checkoutput(space, expected_output,f,*args):
- w_sys = space.w_sys
- w_oldout = space.getattr(w_sys, space.wrap("stdout"))
+ w_oldout = space.sys.get('stdout')
capturefn = udir.join('capturefile')
capturefile = capturefn.open('w')
+ w_sys = space.sys.getmodule('sys')
space.setattr(w_sys, space.wrap("stdout"), space.wrap(capturefile))
try:
f(*(args + (space,)))
@@ -29,7 +29,6 @@
capturefile.close()
assert capturefn.read(mode='rU') == expected_output
-
testfn = 'tmp_hello_world.py'
class TestMain:
Modified: pypy/branch/dist-interpapp/pypy/interpreter/test/test_objspace.py
==============================================================================
--- pypy/branch/dist-interpapp/pypy/interpreter/test/test_objspace.py (original)
+++ pypy/branch/dist-interpapp/pypy/interpreter/test/test_objspace.py Fri Feb 18 11:32:37 2005
@@ -89,15 +89,14 @@
class TestModuleMinimal:
def test_sys_exists(self):
- w_sys = self.space.w_sys
- assert self.space.is_true(w_sys)
+ assert self.space.sys
def test_import_exists(self):
space = self.space
- w_builtin = space.w_builtin
- assert space.is_true(w_builtin)
+ assert space.builtin
w_name = space.wrap('__import__')
- w_import = self.space.getattr(w_builtin, w_name)
+ w_builtin = space.sys.getmodule('__builtin__')
+ w_import = self.space.getattr(w_builtin, w_name)
assert space.is_true(w_import)
def test_sys_import(self):
Modified: pypy/branch/dist-interpapp/pypy/module/test/test_sysmodule.py
==============================================================================
--- pypy/branch/dist-interpapp/pypy/module/test/test_sysmodule.py (original)
+++ pypy/branch/dist-interpapp/pypy/module/test/test_sysmodule.py Fri Feb 18 11:32:37 2005
@@ -9,10 +9,8 @@
b.cStringIO = cStringIO
b.sys = sys
-class TestSysTests:
- def test_stdout_exists(self):
- s = self.space
- assert s.is_true(s.getattr(s.w_sys, s.wrap("stdout")))
+def test_stdout_exists(space):
+ assert space.sys.get('stdout')
class AppTestAppSysTests:
def test_path_exists(self):
Modified: pypy/branch/dist-interpapp/pypy/objspace/std/objspace.py
==============================================================================
--- pypy/branch/dist-interpapp/pypy/objspace/std/objspace.py (original)
+++ pypy/branch/dist-interpapp/pypy/objspace/std/objspace.py Fri Feb 18 11:32:37 2005
@@ -55,40 +55,28 @@
self.w_None = W_NoneObject(self)
self.w_False = W_BoolObject(self, False)
self.w_True = W_BoolObject(self, True)
- from pypy.interpreter.special import NotImplemented, Ellipsis
+ from pypy.interpreter.special import NotImplemented, Ellipsis
self.w_NotImplemented = self.wrap(NotImplemented(self))
self.w_Ellipsis = self.wrap(Ellipsis(self))
- for_builtins = {"False": self.w_False,
- "True" : self.w_True,
- "None" : self.w_None,
- "NotImplemented": self.w_NotImplemented,
- "Ellipsis": self.w_Ellipsis,
- }
-
# types
self.types_w = {}
for typedef in self.model.pythontypes:
w_type = self.gettypeobject(typedef)
setattr(self, 'w_' + typedef.name, w_type)
- for_builtins[typedef.name] = w_type
+
+ # exceptions & builtins
+ mod = self.setup_exceptions()
+ self.make_builtins()
+ self.sys.setmodule(self.wrap(mod))
# dummy old-style classes types
self.w_classobj = W_TypeObject(self, 'classobj', [self.w_object], {})
self.w_instance = W_TypeObject(self, 'instance', [self.w_object], {})
- # exceptions
- mod = self.setup_exceptions(for_builtins)
-
# old-style classes
#self.setup_old_style_classes()
- # install things in the __builtin__ module
- self.make_builtins(for_builtins)
-
- w_exceptions = self.wrap(mod)
- self.sys.setbuiltinmodule(w_exceptions, 'exceptions')
-
def setup_old_style_classes(self):
"""NOT_RPYTHON"""
from pypy.module import classobjinterp
@@ -98,7 +86,7 @@
self.w_classobj = w_classobj
self.w_instance = w_instance
- def setup_exceptions(self, for_builtins):
+ def setup_exceptions(self):
"""NOT_RPYTHON"""
## hacking things in
from pypy.module import exceptionsinterp as ex
@@ -133,8 +121,6 @@
w_exc = self.getitem(w_dic, w_name)
setattr(self, "w_"+excname, w_exc)
- for_builtins[excname] = w_exc
-
# XXX refine things, clean up, create a builtin module...
# but for now, we do a regular one.
from pypy.interpreter.module import Module
Modified: pypy/branch/dist-interpapp/pypy/objspace/trivial.py
==============================================================================
--- pypy/branch/dist-interpapp/pypy/objspace/trivial.py (original)
+++ pypy/branch/dist-interpapp/pypy/objspace/trivial.py Fri Feb 18 11:32:37 2005
@@ -12,7 +12,8 @@
import __builtin__ as cpy_builtin
class CPyWrapper(object):
- pass
+ def getdictvalue(self, space, name):
+ return self.__dict__.get(name, None)
class TrivialObjSpace(ObjSpace, DescrOperation):
@@ -122,7 +123,10 @@
setattr(self, 'w_' + c.__name__, c)
newstuff[c.__name__] = c
newstuff.update(self.clone_exception_hierarchy())
- self.make_builtins(newstuff)
+ self.make_builtins()
+ # XXX Do we need the following still?
+ #for name, value in newstuff.items():
+ # self.builtin.w_dict[name] = value
# general stuff
def wrap(self, x):
Modified: pypy/branch/dist-interpapp/pypy/translator/geninterplevel.py
==============================================================================
--- pypy/branch/dist-interpapp/pypy/translator/geninterplevel.py (original)
+++ pypy/branch/dist-interpapp/pypy/translator/geninterplevel.py Fri Feb 18 11:32:37 2005
@@ -540,10 +540,10 @@
#self.initcode.append('m.%s = space.getattr(space.w_builtin, %s)'% (
# name, self.nameof(func.__name__)))
# be lazy
- return "(space.getattr(space.w_builtin, %s))" % self.nameof(func.__name__)
+ return "(space.builtin.get(space.str_w(%s)))" % self.nameof(func.__name__)
elif modname == 'sys':
# be lazy
- return "(space.getattr(space.w_sys, %s))" % self.nameof(func.__name__)
+ return "(space.sys.get(space.str_w(%s)))" % self.nameof(func.__name__)
else:
print ("WARNING: accessing builtin modules different from sys or __builtin__"
" is likely producing non-sense")
More information about the Pypy-commit
mailing list