[pypy-svn] r29949 - in pypy/dist/pypy: config config/test objspace/std objspace/std/test tool translator/goal
cfbolz at codespeak.net
cfbolz at codespeak.net
Tue Jul 11 15:19:38 CEST 2006
Author: cfbolz
Date: Tue Jul 11 15:19:35 2006
New Revision: 29949
Added:
pypy/dist/pypy/translator/goal/target22c3.py
- copied unchanged from r29943, pypy/dist/pypy/translator/goal/target22c3.py
pypy/dist/pypy/translator/goal/targetebnflexer.py
- copied unchanged from r29943, pypy/dist/pypy/translator/goal/targetebnflexer.py
pypy/dist/pypy/translator/goal/targetlogic.py
- copied unchanged from r29943, pypy/dist/pypy/translator/goal/targetlogic.py
pypy/dist/pypy/translator/goal/targetpypy_stacklesstest.py
- copied unchanged from r29943, pypy/dist/pypy/translator/goal/targetpypy_stacklesstest.py
pypy/dist/pypy/translator/goal/targetrdicttest.py
- copied unchanged from r29943, pypy/dist/pypy/translator/goal/targetrdicttest.py
pypy/dist/pypy/translator/goal/targetrdicttest2.py
- copied unchanged from r29943, pypy/dist/pypy/translator/goal/targetrdicttest2.py
pypy/dist/pypy/translator/goal/targetrlisttest.py
- copied unchanged from r29943, pypy/dist/pypy/translator/goal/targetrlisttest.py
Removed:
pypy/dist/pypy/objspace/std/dictstrobject.py
pypy/dist/pypy/objspace/std/test/test_dictstrobject.py
Modified:
pypy/dist/pypy/config/config.py
pypy/dist/pypy/config/pypyoption.py
pypy/dist/pypy/config/test/test_config.py
pypy/dist/pypy/objspace/std/dictobject.py
pypy/dist/pypy/objspace/std/dicttype.py
pypy/dist/pypy/objspace/std/marshal_impl.py
pypy/dist/pypy/objspace/std/model.py
pypy/dist/pypy/objspace/std/objspace.py
pypy/dist/pypy/objspace/std/test/test_dictobject.py
pypy/dist/pypy/tool/option.py
pypy/dist/pypy/translator/goal/targetlogicstandalone.py
pypy/dist/pypy/translator/goal/targetmultiplespaces.py
pypy/dist/pypy/translator/goal/targetpypymain.py
pypy/dist/pypy/translator/goal/targetpypystandalone.py
pypy/dist/pypy/translator/goal/targetthunkstandalone.py
Log:
svn merge -r 29944:29943
revert previous messed up merge attempt
Modified: pypy/dist/pypy/config/config.py
==============================================================================
--- pypy/dist/pypy/config/config.py (original)
+++ pypy/dist/pypy/config/config.py Tue Jul 11 15:19:35 2006
@@ -1,7 +1,13 @@
-import optparse
-
class Config(object):
+ """main config
+
+ there's 3 levels of configuration values: default ones, stuff from
+ config files and command-line options, all cascading
+
+ config is divided in groups, each group is an instance on the root
+ (this object)
+ """
_frozen = False
def __init__(self, descr, **overrides):
@@ -17,8 +23,7 @@
elif isinstance(child, OptionDescription):
self.__dict__[child._name] = Config(child)
for name, value in overrides.iteritems():
- subconfig, name = self._get_by_path(name)
- setattr(subconfig, name, value)
+ setattr(self, name, value)
def __setattr__(self, name, value):
if self._frozen:
@@ -53,7 +58,7 @@
return self, path[-1]
def _freeze_(self):
- self.__dict__['_frozen'] = True
+ self._frozen = True
return True
def getkey(self):
@@ -73,28 +78,7 @@
if isinstance(child, Option):
yield child._name, getattr(self, child._name)
- def __str__(self):
- result = "[%s]\n" % (self._descr._name, )
- for child in self._descr._children:
- if isinstance(child, Option):
- if self._value_owners[child._name] == 'default':
- continue
- result += " %s = %s\n" % (
- child._name, getattr(self, child._name))
- else:
- substr = str(getattr(self, child._name))
- substr = " " + substr[:-1].replace("\n", "\n ") + "\n"
- result += substr
- return result
-
-
-
class Option(object):
- def __init__(self, name, doc, cmdline=None):
- self._name = name
- self.doc = doc
- self.cmdline = cmdline
-
def validate(self, value):
raise NotImplementedError('abstract base class')
@@ -110,32 +94,19 @@
def getkey(self, value):
return value
- def add_optparse_option(self, argnames, parser, config):
- raise NotImplemented('abstract base class')
-
class ChoiceOption(Option):
- def __init__(self, name, doc, values, default, cmdline=None):
- super(ChoiceOption, self).__init__(name, doc, cmdline)
+ def __init__(self, name, doc, values, default):
+ self._name = name
+ self.doc = doc
self.values = values
self.default = default
def validate(self, value):
return value in self.values
- def add_optparse_option(self, argnames, parser, config):
- def _callback(option, opt_str, value, parser, *args, **kwargs):
- try:
- config.setoption(self._name, value.strip(), who='cmdline')
- except ValueError, e:
- raise optparse.OptionValueError(e.args[0])
- parser.add_option(help=self.doc,
- action='callback', type='string',
- callback=_callback, *argnames)
-
class BoolOption(ChoiceOption):
- def __init__(self, name, doc, default=True, requires=None, cmdline=None):
- super(BoolOption, self).__init__(name, doc, [True, False], default,
- cmdline=cmdline)
+ def __init__(self, name, doc, default=True, requires=None):
+ super(BoolOption, self).__init__(name, doc, [True, False], default)
self._requires = requires or []
def setoption(self, config, value):
@@ -145,19 +116,27 @@
subconfig.require(name, reqvalue)
super(BoolOption, self).setoption(config, value)
- def add_optparse_option(self, argnames, parser, config):
- def _callback(option, opt_str, value, parser, *args, **kwargs):
- try:
- config.setoption(self._name, True, who='cmdline')
- except ValueError, e:
- raise optparse.OptionValueError(e.args[0])
- parser.add_option(help=self.doc,
- action='callback',
- callback=_callback, *argnames)
+class IntOption(Option):
+ def __init__(self, name, doc, default=True):
+ self._name = name
+ self.doc = doc
+ self.default = default
+
+ def validate(self, value):
+ try:
+ int(value)
+ except TypeError:
+ return False
+ return True
+
+ def setoption(self, config, value):
+ super(IntOption, self).setoption(config, int(value))
+
class IntOption(Option):
- def __init__(self, name, doc, default=0, cmdline=None):
- super(IntOption, self).__init__(name, doc, cmdline)
+ def __init__(self, name, doc, default=0):
+ self._name = name
+ self.doc = doc
self.default = default
def validate(self, value):
@@ -173,16 +152,11 @@
except TypeError, e:
raise ValueError(*e.args)
- def add_optparse_option(self, argnames, parser, config):
- def _callback(option, opt_str, value, parser, *args, **kwargs):
- config.setoption(self._name, value, who='cmdline')
- parser.add_option(help=self.doc,
- action='callback', type='int',
- callback=_callback, *argnames)
class FloatOption(Option):
- def __init__(self, name, doc, default=0.0, cmdline=None):
- super(FloatOption, self).__init__(name, doc, cmdline)
+ def __init__(self, name, doc, default=0.0):
+ self._name = name
+ self.doc = doc
self.default = default
def validate(self, value):
@@ -198,19 +172,12 @@
except TypeError, e:
raise ValueError(*e.args)
- def add_optparse_option(self, argnames, parser, config):
- def _callback(option, opt_str, value, parser, *args, **kwargs):
- config.setoption(self._name, value, who='cmdline')
- parser.add_option(help=self.doc,
- action='callback', type='float',
- callback=_callback, *argnames)
class OptionDescription(object):
- def __init__(self, name, children, cmdline=None):
+ def __init__(self, name, children):
self._name = name
self._children = children
self._build()
- self.cmdline = cmdline
def _build(self):
for child in self._children:
@@ -219,47 +186,3 @@
def getkey(self, config):
return tuple([child.getkey(getattr(config, child._name))
for child in self._children])
-
- def add_optparse_option(self, argnames, parser, config):
- for child in self._children:
- if not isinstance(child, BoolOption):
- raise ValueError(
- "cannot make OptionDescription %s a cmdline option" % (
- self._name, ))
- def _callback(option, opt_str, value, parser, *args, **kwargs):
- try:
- values = value.split(",")
- for value in values:
- value = value.strip()
- option = getattr(self, value, None)
- if option is None:
- raise ValueError("did not find option %s" % (value, ))
- getattr(config, self._name).setoption(
- value, True, who='cmdline')
- except ValueError, e:
- raise optparse.OptionValueError(e.args[0])
- parser.add_option(help=self._name, action='callback', type='string',
- callback=_callback, *argnames)
-
-
-def to_optparse(config, useoptions, parser=None):
- if parser is None:
- parser = optparse.OptionParser()
- for path in useoptions:
- if path.endswith("*"):
- assert path.endswith("*")
- path = path[:-2]
- subconf, name = config._get_by_path(path)
- children = [
- path + "." + child._name
- for child in getattr(subconf, name)._descr._children]
- useoptions.extend(children)
- else:
- subconf, name = config._get_by_path(path)
- option = getattr(subconf._descr, name)
- if option.cmdline is None:
- chunks = ('--%s' % (path.replace('.', '-'),),)
- else:
- chunks = option.cmdline.split(' ')
- option.add_optparse_option(chunks, parser, subconf)
- return parser
Modified: pypy/dist/pypy/config/pypyoption.py
==============================================================================
--- pypy/dist/pypy/config/pypyoption.py (original)
+++ pypy/dist/pypy/config/pypyoption.py Tue Jul 11 15:19:35 2006
@@ -1,6 +1,6 @@
import py
from pypy.config.config import OptionDescription, BoolOption, IntOption
-from pypy.config.config import ChoiceOption, to_optparse, Config
+from pypy.config.config import ChoiceOption
modulepath = py.magic.autopath().dirpath().dirpath().join("module")
all_modules = [p.basename for p in modulepath.listdir()
@@ -13,8 +13,7 @@
pypy_optiondescription = OptionDescription("pypy", [
OptionDescription("objspace", [
ChoiceOption("name", "Object Space name",
- ["std", "flow", "logic", "thunk", "cpy"], "std",
- cmdline='--objspace -o'),
+ ["std", "flow", "logic", "thunk", "cpy"], "std"),
ChoiceOption("parser", "parser",
["pypy", "cpython"], "pypy"),
@@ -49,10 +48,10 @@
default=False, requires=[("withsmallint", False)]),
IntOption("prebuiltintfrom", "lowest integer which is prebuilt",
- default=-5, cmdline="--prebuiltinfrom"),
+ default=-5),
IntOption("prebuiltintto", "highest integer which is prebuilt",
- default=100, cmdline="--prebuiltintto"),
+ default=100),
BoolOption("withstrjoin", "use strings optimized for addition",
default=False),
@@ -60,10 +59,6 @@
BoolOption("withstrslice", "use strings optimized for slicing",
default=False),
- BoolOption("withstrdict",
- "use dictionaries optimized for string keys",
- default=False),
-
BoolOption("oldstyle",
"specify whether the default metaclass should be classobj",
default=False),
@@ -75,14 +70,3 @@
BoolOption("translating", "indicates whether we are translating currently",
default=False),
])
-
-if __name__ == '__main__':
- config = Config(pypy_optiondescription)
- parser = to_optparse(config, ["objspace.name",
- "objspace.std.*",
- "objspace.std.withsmallint",
- "objspace.std.withprebuiltint",
- "objspace.usemodules",
- "objspace.std.prebuiltintfrom",])
- option, args = parser.parse_args()
- print config
Modified: pypy/dist/pypy/config/test/test_config.py
==============================================================================
--- pypy/dist/pypy/config/test/test_config.py (original)
+++ pypy/dist/pypy/config/test/test_config.py Tue Jul 11 15:19:35 2006
@@ -17,6 +17,7 @@
descr = OptionDescription('pypy', [gcgroup, booloption, objspaceoption,
wantref_option, intoption])
return descr
+
def test_base_config():
descr = make_description()
@@ -76,7 +77,7 @@
assert len(block.exits) == 1
assert block.operations[0].opname == 'int_add'
- assert config._freeze_()
+ # the config should be frozen now
py.test.raises(TypeError, 'config.gc.name = "framework"')
def test_compare_configs():
@@ -99,107 +100,3 @@
assert name == gname
assert value == gvalue
-def test_to_optparse():
- gcoption = ChoiceOption('name', 'GC name', ['ref', 'framework'], 'ref',
- cmdline='--gc -g')
- gcgroup = OptionDescription('gc', [gcoption])
- descr = OptionDescription('pypy', [gcgroup])
- config = Config(descr)
-
- parser = to_optparse(config, ['gc.name'])
- (options, args) = parser.parse_args(args=['--gc=framework'])
-
- assert config.gc.name == 'framework'
-
- (options, args) = parser.parse_args(args=['-g ref'])
- assert config.gc.name == 'ref'
-
- # XXX strange exception
- py.test.raises(SystemExit,
- "(options, args) = parser.parse_args(args=['-g foobar'])")
-
-def test_to_optparse_number():
- intoption = IntOption('int', 'Int option test', cmdline='--int -i')
- floatoption = FloatOption('float', 'Float option test',
- cmdline='--float -f')
- descr = OptionDescription('test', [intoption, floatoption])
- config = Config(descr)
-
- parser = to_optparse(config, ['int', 'float'])
- (options, args) = parser.parse_args(args=['-i 2', '--float=0.1'])
-
- assert config.int == 2
- assert config.float == 0.1
-
- py.test.raises(SystemExit,
- "(options, args) = parser.parse_args(args=['--int=foo', '-f bar'])")
-
-def test_to_optparse_bool():
- booloption = BoolOption('bool', 'Boolean option test', default=False,
- cmdline='--bool -b')
- descr = OptionDescription('test', [booloption])
- config = Config(descr)
-
- parser = to_optparse(config, ['bool'])
- (options, args) = parser.parse_args(args=['-b'])
-
- assert config.bool
-
- config = Config(descr)
- parser = to_optparse(config, ['bool'])
- (options, args) = parser.parse_args(args=[])
- assert not config.bool
-
- py.test.raises(SystemExit,
- "(options, args) = parser.parse_args(args=['-bfoo'])")
-
-def test_optparse_boolgroup():
- group = OptionDescription("test", [
- BoolOption("smallint", "use tagged integers",
- default=False),
- BoolOption("strjoin", "use strings optimized for addition",
- default=False),
- BoolOption("strslice", "use strings optimized for slicing",
- default=False),
- BoolOption("strdict", "use dictionaries optimized for string keys",
- default=False),
- ], cmdline="--test")
- descr = OptionDescription("all", [group])
- config = Config(descr)
- parser = to_optparse(config, ['test'])
- (options, args) = parser.parse_args(
- args=['--test=smallint,strjoin,strdict'])
-
- assert config.test.smallint
- assert config.test.strjoin
- assert config.test.strdict
-
- config = Config(descr)
- parser = to_optparse(config, ['test'])
- (options, args) = parser.parse_args(
- args=['--test=smallint'])
-
- assert config.test.smallint
- assert not config.test.strjoin
- assert not config.test.strdict
-
-def test_config_start():
- descr = make_description()
- config = Config(descr)
- parser = to_optparse(config, ["gc.*"])
-
- options, args = parser.parse_args(args=["--gc-name=framework", "--gc-dummy"])
- assert config.gc.name == "framework"
- assert config.gc.dummy
-
-
-def test_optparse_path_options():
- gcoption = ChoiceOption('name', 'GC name', ['ref', 'framework'], 'ref')
- gcgroup = OptionDescription('gc', [gcoption])
- descr = OptionDescription('pypy', [gcgroup])
- config = Config(descr)
-
- parser = to_optparse(config, ['gc.name'])
- (options, args) = parser.parse_args(args=['--gc-name=framework'])
-
- assert config.gc.name == 'framework'
Modified: pypy/dist/pypy/objspace/std/dictobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/dictobject.py (original)
+++ pypy/dist/pypy/objspace/std/dictobject.py Tue Jul 11 15:19:35 2006
@@ -35,12 +35,6 @@
result[space.unwrap(w_key)] = space.unwrap(w_value)
return result
- def len(w_self):
- return len(w_self.content)
-
- def set_str_keyed_item(w_dict, w_key, w_value):
- w_dict.content[w_key] = w_value
-
registerimplementation(W_DictObject)
Modified: pypy/dist/pypy/objspace/std/dicttype.py
==============================================================================
--- pypy/dist/pypy/objspace/std/dicttype.py (original)
+++ pypy/dist/pypy/objspace/std/dicttype.py Tue Jul 11 15:19:35 2006
@@ -124,8 +124,9 @@
# ____________________________________________________________
def descr__new__(space, w_dicttype, __args__):
- w_obj = space.allocate_instance(space.DictObjectCls, w_dicttype)
- space.DictObjectCls.__init__(w_obj, space)
+ from pypy.objspace.std.dictobject import W_DictObject
+ w_obj = space.allocate_instance(W_DictObject, w_dicttype)
+ W_DictObject.__init__(w_obj, space)
return w_obj
# ____________________________________________________________
@@ -164,12 +165,8 @@
a registration with copy_reg, instead.
"""
from pypy.interpreter.mixedmodule import MixedModule
- if space.config.objspace.std.withstrdict:
- from pypy.objspace.std.dictstrobject import \
- W_DictIter_Keys, W_DictIter_Values, W_DictIter_Items
- else:
- from pypy.objspace.std.dictobject import \
- W_DictIter_Keys, W_DictIter_Values, W_DictIter_Items
+ from pypy.objspace.std.dictobject import \
+ W_DictIter_Keys, W_DictIter_Values, W_DictIter_Items
w_mod = space.getbuiltinmodule('_pickle_support')
mod = space.interp_w(MixedModule, w_mod)
new_inst = mod.get('dictiter_surrogate_new')
@@ -186,8 +183,6 @@
# we cannot call __init__ since we don't have the original dict
w_clone.space = space
w_clone.content = w_self.content
- if space.config.objspace.std.withstrdict:
- w_clone.content_str = w_self.content_str
w_clone.len = w_self.len
w_clone.pos = 0
w_clone.setup_iterator()
Modified: pypy/dist/pypy/objspace/std/marshal_impl.py
==============================================================================
--- pypy/dist/pypy/objspace/std/marshal_impl.py (original)
+++ pypy/dist/pypy/objspace/std/marshal_impl.py Tue Jul 11 15:19:35 2006
@@ -25,7 +25,6 @@
from pypy.objspace.std.tupleobject import W_TupleObject
from pypy.objspace.std.listobject import W_ListObject
from pypy.objspace.std.dictobject import W_DictObject
-from pypy.objspace.std.dictstrobject import W_DictStrObject
from pypy.objspace.std.stringobject import W_StringObject
from pypy.objspace.std.typeobject import W_TypeObject
from pypy.objspace.std.longobject import W_LongObject
@@ -348,29 +347,18 @@
m.put_w_obj(w_value)
m.atom(TYPE_NULL)
-def marshal_w__DictStr(space, w_dict, m):
- m.start(TYPE_DICT)
- if w_dict.content is not None:
- for w_key, w_value in w_dict.content.iteritems():
- m.put_w_obj(w_key)
- m.put_w_obj(w_value)
- else:
- for key, w_value in w_dict.content_str.iteritems():
- m.put_w_obj(space.wrap(key))
- m.put_w_obj(w_value)
- m.atom(TYPE_NULL)
-
def unmarshal_Dict(space, u, tc):
# since primitive lists are not optimized and we don't know
# the dict size in advance, use the dict's setitem instead
# of building a list of tuples.
- w_dic = space.newdict([])
+ w_dic = W_DictObject(space)
+ setter = dictobject.setitem__Dict_ANY_ANY
while 1:
w_key = u.get_w_obj(True)
if w_key is None:
break
w_value = u.get_w_obj(False)
- space.setitem(w_dic, w_key, w_value)
+ setter(space, w_dic, w_key, w_value)
return w_dic
register(TYPE_DICT, unmarshal_Dict)
Modified: pypy/dist/pypy/objspace/std/model.py
==============================================================================
--- pypy/dist/pypy/objspace/std/model.py (original)
+++ pypy/dist/pypy/objspace/std/model.py Tue Jul 11 15:19:35 2006
@@ -8,17 +8,14 @@
import pypy.interpreter.pycode
import pypy.interpreter.special
-option_to_typename = {
- "withsmallint" : ["smallintobject.W_SmallIntObject"],
- "withstrslice" : ["strsliceobject.W_StringSliceObject"],
- "withstrjoin" : ["strjoinobject.W_StringJoinObject"],
- "withstrdict" : ["dictstrobject.W_DictStrObject",
- "dictstrobject.W_DictStrIterObject"],
-}
+WITHSMALLINT = False
+WITHPREBUILTINT = None # or e.g. range(-5, 100); not used if WITHSMALLINT
+WITHSTRSLICE = False
+WITHSTRJOIN = False
class StdTypeModel:
- def __init__(self, config):
+ def __init__(self):
"""NOT_RPYTHON: inititialization only"""
# All the Python types that we want to provide in this StdObjSpace
class result:
@@ -53,14 +50,16 @@
from pypy.objspace.std import floatobject
from pypy.objspace.std import complexobject
from pypy.objspace.std import setobject
- from pypy.objspace.std import smallintobject
+ if WITHSMALLINT:
+ from pypy.objspace.std import smallintobject
from pypy.objspace.std import tupleobject
from pypy.objspace.std import listobject
from pypy.objspace.std import dictobject
- from pypy.objspace.std import dictstrobject
from pypy.objspace.std import stringobject
- from pypy.objspace.std import strsliceobject
- from pypy.objspace.std import strjoinobject
+ if WITHSTRSLICE:
+ from pypy.objspace.std import strsliceobject
+ if WITHSTRJOIN:
+ from pypy.objspace.std import strjoinobject
from pypy.objspace.std import typeobject
from pypy.objspace.std import sliceobject
from pypy.objspace.std import longobject
@@ -99,39 +98,25 @@
self.typeorder[setobject.W_SetObject] = []
self.typeorder[setobject.W_FrozensetObject] = []
self.typeorder[setobject.W_SetIterObject] = []
+ if WITHSMALLINT:
+ self.typeorder[smallintobject.W_SmallIntObject] = []
+ if WITHSTRSLICE:
+ self.typeorder[strsliceobject.W_StringSliceObject] = []
+ if WITHSTRJOIN:
+ self.typeorder[strjoinobject.W_StringJoinObject] = []
+ for type in self.typeorder:
+ self.typeorder[type].append((type, None))
- imported_but_not_registered = {
- dictobject.W_DictObject: True,
- dictobject.W_DictIterObject: True,
- }
- for option, value in config.objspace.std:
- if option.startswith("with") and option in option_to_typename:
- for classname in option_to_typename[option]:
- implcls = eval(classname)
- if value:
- self.typeorder[implcls] = []
- else:
- imported_but_not_registered[implcls] = True
-
- if config.objspace.std.withstrdict:
- del self.typeorder[dictobject.W_DictObject]
- del self.typeorder[dictobject.W_DictIterObject]
-
- #check if we missed implementations
+ # check if we missed implementations
from pypy.objspace.std.objspace import _registered_implementations
for implcls in _registered_implementations:
- assert (implcls in self.typeorder or
- implcls in imported_but_not_registered), (
+ assert implcls in self.typeorder, (
"please add %r in StdTypeModel.typeorder" % (implcls,))
-
- for type in self.typeorder:
- self.typeorder[type].append((type, None))
-
# register the order in which types are converted into each others
# when trying to dispatch multimethods.
# XXX build these lists a bit more automatically later
- if config.objspace.std.withsmallint:
+ if WITHSMALLINT:
self.typeorder[boolobject.W_BoolObject] += [
(smallintobject.W_SmallIntObject, boolobject.delegate_Bool2SmallInt),
]
@@ -166,14 +151,14 @@
(unicodeobject.W_UnicodeObject, unicodeobject.delegate_String2Unicode),
]
- if config.objspace.std.withstrslice:
+ if WITHSTRSLICE:
self.typeorder[strsliceobject.W_StringSliceObject] += [
(stringobject.W_StringObject,
strsliceobject.delegate_slice2str),
(unicodeobject.W_UnicodeObject,
strsliceobject.delegate_slice2unicode),
]
- if config.objspace.std.withstrjoin:
+ if WITHSTRJOIN:
self.typeorder[strjoinobject.W_StringJoinObject] += [
(stringobject.W_StringObject,
strjoinobject.delegate_join2str),
@@ -186,20 +171,6 @@
for type in self.typeorder:
self.typeorder[type].append((W_Root, None))
- # ____________________________________________________________
- # Prebuilt common integer values
-
- if config.objspace.std.withprebuiltint:
- intobject.W_IntObject.PREBUILT = []
- for i in range(config.objspace.std.prebuiltintfrom,
- config.objspace.std.prebuiltintto):
- intobject.W_IntObject.PREBUILT.append(intobject.W_IntObject(i))
- del i
- else:
- intobject.W_IntObject.PREBUILT = None
-
- # ____________________________________________________________
-
# ____________________________________________________________
Modified: pypy/dist/pypy/objspace/std/objspace.py
==============================================================================
--- pypy/dist/pypy/objspace/std/objspace.py (original)
+++ pypy/dist/pypy/objspace/std/objspace.py Tue Jul 11 15:19:35 2006
@@ -54,14 +54,6 @@
# Import all the object types and implementations
self.model = StdTypeModel()
- # XXX store the dict class on the space to access it in various places
- if self.config.objspace.std.withstrdict:
- from pypy.objspace.std import dictstrobject
- self.DictObjectCls = dictstrobject.W_DictStrObject
- else:
- from pypy.objspace.std import dictobject
- self.DictObjectCls = dictobject.W_DictObject
-
# install all the MultiMethods into the space instance
for name, mm in self.MM.__dict__.items():
if isinstance(mm, StdObjSpaceMultiMethod) and not hasattr(self, name):
@@ -382,7 +374,7 @@
return W_ListObject(list_w)
def newdict(self, list_pairs_w):
- w_result = self.DictObjectCls(self)
+ w_result = W_DictObject(self)
w_result.initialize_content(list_pairs_w)
return w_result
@@ -454,25 +446,23 @@
return w_one is w_two
def is_true(self, w_obj):
- if type(w_obj) is self.DictObjectCls:
- return w_obj.len() != 0
+ # XXX don't look!
+ if type(w_obj) is W_DictObject:
+ return len(w_obj.content) != 0
else:
return DescrOperation.is_true(self, w_obj)
def finditem(self, w_obj, w_key):
# performance shortcut to avoid creating the OperationError(KeyError)
- if type(w_obj) is self.DictObjectCls:
- if not self.config.objspace.std.withstrdict:
- return w_obj.content.get(w_key, None)
- else:
- # XXX fix this here
- pass
- return ObjSpace.finditem(self, w_obj, w_key)
+ if type(w_obj) is W_DictObject:
+ return w_obj.content.get(w_key, None)
+ else:
+ return ObjSpace.finditem(self, w_obj, w_key)
def set_str_keyed_item(self, w_obj, w_key, w_value):
# performance shortcut to avoid creating the OperationError(KeyError)
- if type(w_obj) is self.DictObjectCls:
- w_obj.set_str_keyed_item(w_key, w_value)
+ if type(w_obj) is W_DictObject:
+ w_obj.content[w_key] = w_value
else:
self.setitem(w_obj, w_key, w_value)
Modified: pypy/dist/pypy/objspace/std/test/test_dictobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/test/test_dictobject.py (original)
+++ pypy/dist/pypy/objspace/std/test/test_dictobject.py Tue Jul 11 15:19:35 2006
@@ -1,21 +1,19 @@
import autopath
from pypy.objspace.std.dictobject import W_DictObject
-from pypy.conftest import gettestobjspace
-class TestW_DictObject:
- def setup_class(cls):
- cls.space = gettestobjspace(**{"objspace.std.withstrdict": False})
+
+class TestW_DictObject:
def test_empty(self):
space = self.space
- d = self.space.DictObjectCls(space)
+ d = W_DictObject(space)
assert not self.space.is_true(d)
def test_nonempty(self):
space = self.space
wNone = space.w_None
- d = self.space.DictObjectCls(space)
+ d = W_DictObject(space)
d.initialize_content([(wNone, wNone)])
assert space.is_true(d)
i = space.getitem(d, wNone)
@@ -26,7 +24,7 @@
space = self.space
wk1 = space.wrap('key')
wone = space.wrap(1)
- d = self.space.DictObjectCls(space)
+ d = W_DictObject(space)
d.initialize_content([(space.wrap('zero'),space.wrap(0))])
space.setitem(d,wk1,wone)
wback = space.getitem(d,wk1)
@@ -35,7 +33,7 @@
def test_delitem(self):
space = self.space
wk1 = space.wrap('key')
- d = self.space.DictObjectCls(space)
+ d = W_DictObject(space)
d.initialize_content( [(space.wrap('zero'),space.wrap(0)),
(space.wrap('one'),space.wrap(1)),
(space.wrap('two'),space.wrap(2))])
@@ -46,7 +44,7 @@
space.getitem,d,space.wrap('one'))
def test_wrap_dict(self):
- assert isinstance(self.space.wrap({}), self.space.DictObjectCls)
+ assert isinstance(self.space.wrap({}), W_DictObject)
def test_dict_compare(self):
@@ -356,10 +354,6 @@
eq_w = eq
def newlist(self, l):
return []
- DictObjectCls = W_DictObject
- def type(self, w_obj):
- return type(w_obj)
- w_str = str
from pypy.objspace.std.dictobject import getitem__Dict_ANY, setitem__Dict_ANY_ANY
@@ -370,7 +364,7 @@
def test_stressdict(self):
from random import randint
- d = self.space.DictObjectCls(self.space)
+ d = W_DictObject(self.space)
N = 10000
pydict = {}
for i in range(N):
Modified: pypy/dist/pypy/tool/option.py
==============================================================================
--- pypy/dist/pypy/tool/option.py (original)
+++ pypy/dist/pypy/tool/option.py Tue Jul 11 15:19:35 2006
@@ -74,46 +74,3 @@
op.add_options(optionlist)
options, args = op.parse_args(argv, input_options)
return args
-
-def make_config(cmdlineopt, **kwds):
- """ make a config from cmdline options (which overrides everything)
- and kwds """
-
- # XXX this whole file should sooner or later go away and the cmd line
- # options be generated from the option description. it's especially messy
- # since we have to check whether the default was actually overwritten
- from pypy.config.pypyoption import pypy_optiondescription
- from pypy.config.config import Config
- conf = Config(pypy_optiondescription)
- if kwds.get("objspace", None) is not None:
- conf.objspace.name = kwds["objspace"]
- if getattr(cmdlineopt, "objspace", None) is not None:
- conf.objspace.name = cmdlineopt.objspace
- modnames = getattr(cmdlineopt, "usemodules", [])
- if modnames:
- for modname in modnames:
- setattr(conf.objspace.usemodules, modname, True)
- for modname in kwds.get("usemodules", []):
- setattr(conf.objspace.usemodules, modname, True)
- if getattr(cmdlineopt, "nofaking", False) or kwds.get("nofaking", False):
- conf.objspace.nofaking = True
- if (getattr(cmdlineopt, "uselibfile", False) or
- kwds.get("uselibfile", False)):
- conf.objspace.uselibfile = True
- if getattr(cmdlineopt, "oldstyle", False) or kwds.get("oldstyle", False):
- conf.objspace.oldstyle = True
- if hasattr(cmdlineopt, "parser") and cmdlineopt.parser is not None:
- conf.objspace.parser = cmdlineopt.parser
- if kwds.get("compiler") is not None:
- conf.obspace.compiler = kwds['compiler']
- if getattr(cmdlineopt, "compiler", None) is not None:
- conf.objspace.compiler = cmdlineopt.compiler
- for names, value in kwds.iteritems():
- if "." not in names:
- continue
- names = names.split(".")
- subconf = conf
- for name in names[:-1]:
- subconf = getattr(subconf, name)
- setattr(subconf, names[-1], value)
- return conf
Modified: pypy/dist/pypy/translator/goal/targetlogicstandalone.py
==============================================================================
--- pypy/dist/pypy/translator/goal/targetlogicstandalone.py (original)
+++ pypy/dist/pypy/translator/goal/targetlogicstandalone.py Tue Jul 11 15:19:35 2006
@@ -1,7 +1,4 @@
import os, sys
-
-from pypy.tool.option import make_config
-
from pypy.objspace.logic import Space
# XXX from pypy.annotation.model import *
# since we are execfile()'ed this would pull some
@@ -47,35 +44,12 @@
opt_defaults = {'stackless' : True}
-take_options = True
-
-def opt_parser():
- import py
- defl = {'thread': False, 'usemodules': ''}
- parser = py.compat.optparse.OptionParser(usage="target PyPy standalone",
- add_help_option=False)
- parser.set_defaults(**defl)
- # XXX threading doesn't work
- #parser.add_option("--thread", action="store_true", dest="thread",
- # help="enable threading")
- return parser
-
-def print_help():
- opt_parser().print_help()
-
def target(driver, args):
options = driver.options
- tgt_options, _ = opt_parser().parse_args(args)
-
- config = make_config(tgt_options)
-
- translate.log_options(tgt_options, "target PyPy options in effect")
-
global space, w_entry_point
- if getattr(options, "lowmem", False):
- config.objspace.geninterp = False
+ geninterp = not getattr(options, 'lowmem', False)
# obscure hack to stuff the translation options into the translated PyPy
import pypy.module.sys
@@ -84,17 +58,20 @@
# disable translation of the whole of classobjinterp.py
Space.setup_old_style_classes = lambda self: None
-
- config.objspace.nofaking = True
- config.objspace.compiler = "ast"
- config.translating = True
-
- # XXX threading is borken
- config.objspace.usemodules.thread = False
- config.objspace.usemodules._stackless = True
-
- space = Space(config)
-
+ # XXX threads are not working right now!
+ #if options.gc == 'boehm':
+ # #print "disabling thread with boehm for stabilitiy (combination not tested)"
+ # #print "trying threads and boehm"
+ # usemodules = []
+ #else:
+ # usemodules = ['thread']
+ usemodules = ['_stackless']
+
+ space = Space(nofaking=True,
+ compiler="ast", # interpreter/astcompiler
+ translating=True,
+ usemodules=usemodules,
+ geninterp=geninterp)
# manually imports app_main.py
filename = os.path.join(this_dir, 'app_main.py')
w_dict = space.newdict([])
Modified: pypy/dist/pypy/translator/goal/targetmultiplespaces.py
==============================================================================
--- pypy/dist/pypy/translator/goal/targetmultiplespaces.py (original)
+++ pypy/dist/pypy/translator/goal/targetmultiplespaces.py Tue Jul 11 15:19:35 2006
@@ -1,7 +1,4 @@
import os, sys
-
-from pypy.tool.option import make_config
-
from pypy.objspace.std.objspace import StdObjSpace
# XXX from pypy.annotation.model import *
# since we are execfile()'ed this would pull some
@@ -59,14 +56,9 @@
def opt_parser():
import py
defl = {'thread': False}
- parser = py.compat.optparse.OptionParser(usage="target multiple spaces",
- add_help_option=False)
+ parser = py.compat.optparse.OptionParser(usage="target PyPy standalone", add_help_option=False)
parser.set_defaults(**defl)
- parser.add_option("--thread", action="store_true", dest="thread",
- help="enable threading")
- parser.add_option("--usemodules", action="store", type="string",
- dest="usemodules", help=("list of mixed modules to "
- "include, comma-separated"))
+ parser.add_option("--thread", action="store_true", dest="thread", help="enable threading")
return parser
def print_help():
@@ -78,16 +70,13 @@
tgt_options, _ = opt_parser().parse_args(args)
- config = make_config(tgt_options)
-
translate.log_options(tgt_options, "target PyPy options in effect")
options.thread = tgt_options.thread
global space1, space2, w_entry_point_1, w_entry_point_2
- if getattr(options, "lowmem", False):
- config.objspace.geninterp = False
+ geninterp = not getattr(options, 'lowmem', False)
# obscure hack to stuff the translation options into the translated PyPy
import pypy.module.sys
@@ -98,21 +87,21 @@
StdObjSpace.setup_old_style_classes = lambda self: None
usemodules = []
- if tgt_options.usemodules:
- for modname in tgt_options.usemodules.split(","):
- setattr(config.objspace.usemodules, modname, True)
- if tgt_options.thread:
+ if options.thread:
print "threads unsupported right now: need thread-safe stack_too_big"
raise SystemExit
- config.objspace.usemodules.thread = True
- if options.stackless:
- config.objspace.usemodules._stackless = True
- config.objspace.nofaking = True
- config.objspace.compiler = "ast"
- config.translating = True
-
- space1 = StdObjSpace(config)
- space2 = StdObjSpace(config)
+ usemodules.append('thread')
+
+ space1 = StdObjSpace(nofaking=True,
+ compiler="ast", # interpreter/astcompiler
+ translating=True,
+ usemodules=usemodules,
+ geninterp=geninterp)
+ space2 = StdObjSpace(nofaking=True,
+ compiler="ast", # interpreter/astcompiler
+ translating=True,
+ usemodules=usemodules,
+ geninterp=geninterp)
space1.setattr(space1.getbuiltinmodule('sys'),
space1.wrap('pypy_space'),
Modified: pypy/dist/pypy/translator/goal/targetpypymain.py
==============================================================================
--- pypy/dist/pypy/translator/goal/targetpypymain.py (original)
+++ pypy/dist/pypy/translator/goal/targetpypymain.py Tue Jul 11 15:19:35 2006
@@ -8,8 +8,6 @@
from pypy.interpreter.error import OperationError
from pypy.translator.goal.ann_override import PyPyAnnotatorPolicy
-from pypy.tool.option import make_config
-
# WARNING: this requires the annotator.
# There is no easy way to build all caches manually,
# but the annotator can do it for us for free.
@@ -50,57 +48,20 @@
# _____ Define and setup target ___
-take_options = True
-
-def opt_parser():
- import py
- defl = {'thread': False, 'usemodules': ''}
- parser = py.compat.optparse.OptionParser(usage="target PyPy main",
- add_help_option=False)
- parser.set_defaults(**defl)
- parser.add_option("--thread", action="store_true", dest="thread",
- help="enable threading")
- parser.add_option("--usemodules", action="store", type="string",
- dest="usemodules", help=("list of mixed modules to "
- "include, comma-separated"))
- return parser
-
-def print_help():
- opt_parser().print_help()
-
def target(driver, args):
options = driver.options
- tgt_options, _ = opt_parser().parse_args(args)
-
- config = make_config(tgt_options)
-
- translate.log_options(tgt_options, "target PyPy options in effect")
-
global space, w_entry_point
- if getattr(options, "lowmem", False):
- config.objspace.geninterp = False
+ geninterp = not getattr(options, 'lowmem', False)
# disable translation of the whole of classobjinterp.py
StdObjSpace.setup_old_style_classes = lambda self: None
-
- usemodules = []
- if tgt_options.usemodules:
- for modname in tgt_options.usemodules.split(","):
- setattr(config.objspace.usemodules, modname, True)
- if tgt_options.thread:
- config.objspace.usemodules.thread = True
- if options.stackless:
- config.objspace.usemodules._stackless = True
- config.objspace.nofaking = True
- config.objspace.compiler = "ast"
- config.translating = True
-
- #config.usemodules.marshal = True
- #config.usemodules._sre = True
-
- space = StdObjSpace(config)
+ space = StdObjSpace(nofaking=True,
+ compiler="ast", # interpreter/astcompiler
+ translating=True,
+ #usemodules=['marshal', '_sre'],
+ geninterp=geninterp)
# manually imports app_main.py
filename = os.path.join(this_dir, 'app_main.py')
Modified: pypy/dist/pypy/translator/goal/targetpypystandalone.py
==============================================================================
--- pypy/dist/pypy/translator/goal/targetpypystandalone.py (original)
+++ pypy/dist/pypy/translator/goal/targetpypystandalone.py Tue Jul 11 15:19:35 2006
@@ -1,7 +1,5 @@
import os, sys
-from pypy.tool.option import make_config
-
# as of revision 27081, multimethod.py uses the InstallerVersion1 by default
# because it is much faster both to initialize and run on top of CPython.
# The InstallerVersion2 is optimized for making a translator-friendly
@@ -73,14 +71,11 @@
def opt_parser():
import py
defl = {'thread': False, 'usemodules': ''}
- parser = py.compat.optparse.OptionParser(usage="target PyPy standalone",
- add_help_option=False)
+ parser = py.compat.optparse.OptionParser(usage="target PyPy standalone", add_help_option=False)
parser.set_defaults(**defl)
- parser.add_option("--thread", action="store_true", dest="thread",
- help="enable threading")
- parser.add_option("--usemodules", action="store", type="string",
- dest="usemodules", help=("list of mixed modules to "
- "include, comma-separated"))
+ parser.add_option("--thread", action="store_true", dest="thread", help="enable threading")
+ parser.add_option("--usemodules", action="store", type="string", dest="usemodules",
+ help="list of mixed modules to include, comma-separated")
return parser
def print_help():
@@ -100,15 +95,12 @@
tgt_options, _ = opt_parser().parse_args(args)
- config = make_config(tgt_options)
-
translate.log_options(tgt_options, "target PyPy options in effect")
# expose the following variables to ease debugging
global space, entry_point
- if getattr(options, "lowmem", False):
- config.objspace.geninterp = False
+ geninterp = not getattr(options, 'lowmem', False)
# obscure hack to stuff the translation options into the translated PyPy
import pypy.module.sys
@@ -120,18 +112,18 @@
usemodules = []
if tgt_options.usemodules:
- for modname in tgt_options.usemodules.split(","):
- setattr(config.objspace.usemodules, modname, True)
+ usemodules.extend(tgt_options.usemodules.split(","))
if tgt_options.thread:
- config.objspace.usemodules.thread = True
+ # thread might appear twice now, but the objspace can handle this
+ usemodules.append('thread')
if options.stackless:
- config.objspace.usemodules._stackless = True
- config.objspace.nofaking = True
- config.objspace.compiler = "ast"
- config.translating = True
+ usemodules.append('_stackless')
- space = StdObjSpace(config)
-
+ space = StdObjSpace(nofaking=True,
+ compiler="ast", # interpreter/astcompiler
+ translating=True,
+ usemodules=usemodules,
+ geninterp=geninterp)
# manually imports app_main.py
filename = os.path.join(this_dir, 'app_main.py')
w_dict = space.newdict([])
Modified: pypy/dist/pypy/translator/goal/targetthunkstandalone.py
==============================================================================
--- pypy/dist/pypy/translator/goal/targetthunkstandalone.py (original)
+++ pypy/dist/pypy/translator/goal/targetthunkstandalone.py Tue Jul 11 15:19:35 2006
@@ -7,8 +7,6 @@
from pypy.interpreter.error import OperationError
from pypy.translator.goal.ann_override import PyPyAnnotatorPolicy
-from pypy.tool.option import make_config
-
# WARNING: this requires the annotator.
# There is no easy way to build all caches manually,
# but the annotator can do it for us for free.
@@ -44,35 +42,12 @@
# _____ Define and setup target ___
-take_options = True
-
-def opt_parser():
- import py
- defl = {'thread': False, 'usemodules': ''}
- parser = py.compat.optparse.OptionParser(usage="target thunk standalone",
- add_help_option=False)
- parser.set_defaults(**defl)
- parser.add_option("--usemodules", action="store", type="string",
- dest="usemodules", help=("list of mixed modules "
- "to include, comma-separated"))
- return parser
-
-def print_help():
- opt_parser().print_help()
-
def target(driver, args):
options = driver.options
global space, w_entry_point
- tgt_options, _ = opt_parser().parse_args(args)
-
- config = make_config(tgt_options)
-
- translate.log_options(tgt_options, "target PyPy options in effect")
-
- if getattr(options, "lowmem", False):
- config.objspace.geninterp = False
+ geninterp = not getattr(options, 'lowmem', False)
# obscure hack to stuff the translation options into the translated PyPy
import pypy.module.sys
@@ -81,20 +56,20 @@
# disable translation of the whole of classobjinterp.py
Space.setup_old_style_classes = lambda self: None
-
- if tgt_options.usemodules:
- for modname in tgt_options.usemodules.split(','):
- setattr(config.objspace.usemodules, modname, True)
-
- if options.stackless:
- config.objspace.usemodules._stackless = True
-
- config.objspace.nofaking = True
- config.objspace.compiler = 'ast'
- config.translating = True
-
- space = Space(config)
-
+ # XXX threads are not working right now!
+ #if options.gc == 'boehm':
+ # #print "disabling thread with boehm for stabilitiy (combination not tested)"
+ # #print "trying threads and boehm"
+ # usemodules = []
+ #else:
+ # usemodules = ['thread']
+ usemodules = []
+
+ space = Space(nofaking=True,
+ compiler="ast", # interpreter/astcompiler
+ translating=True,
+ usemodules=usemodules,
+ geninterp=geninterp)
# manually imports app_main.py
filename = os.path.join(this_dir, 'app_main.py')
w_dict = space.newdict([])
More information about the Pypy-commit
mailing list