[pypy-svn] r33701 - in pypy/branch/even-more-config4/pypy: config config/test doc jit/codegen/i386/test objspace/flow objspace/flow/test rpython/lltypesystem/test rpython/memory/gctransform/test rpython/memory/test tool translator translator/backendopt translator/c translator/c/src translator/c/test translator/cli translator/goal translator/js translator/llvm translator/stackless/test translator/test
cfbolz at codespeak.net
cfbolz at codespeak.net
Tue Oct 24 22:18:25 CEST 2006
Author: cfbolz
Date: Tue Oct 24 22:18:14 2006
New Revision: 33701
Added:
pypy/branch/even-more-config4/pypy/doc/configuration.txt
- copied unchanged from r33694, pypy/branch/even-more-config3/pypy/doc/configuration.txt
Removed:
pypy/branch/even-more-config4/pypy/translator/c/src/ll_stackless.h
Modified:
pypy/branch/even-more-config4/pypy/config/config.py
pypy/branch/even-more-config4/pypy/config/pypyoption.py
pypy/branch/even-more-config4/pypy/config/test/test_config.py
pypy/branch/even-more-config4/pypy/config/test/test_pypyoption.py
pypy/branch/even-more-config4/pypy/jit/codegen/i386/test/test_genc_ts.py
pypy/branch/even-more-config4/pypy/objspace/flow/flowcontext.py
pypy/branch/even-more-config4/pypy/objspace/flow/objspace.py
pypy/branch/even-more-config4/pypy/objspace/flow/specialcase.py
pypy/branch/even-more-config4/pypy/objspace/flow/test/test_objspace.py
pypy/branch/even-more-config4/pypy/rpython/lltypesystem/test/test_rtagged.py
pypy/branch/even-more-config4/pypy/rpython/memory/gctransform/test/test_framework.py
pypy/branch/even-more-config4/pypy/rpython/memory/gctransform/test/test_refcounting.py
pypy/branch/even-more-config4/pypy/rpython/memory/gctransform/test/test_stacklessframework.py
pypy/branch/even-more-config4/pypy/rpython/memory/test/test_transformed_gc.py
pypy/branch/even-more-config4/pypy/tool/option.py
pypy/branch/even-more-config4/pypy/translator/backendopt/all.py
pypy/branch/even-more-config4/pypy/translator/c/database.py
pypy/branch/even-more-config4/pypy/translator/c/gc.py
pypy/branch/even-more-config4/pypy/translator/c/genc.py
pypy/branch/even-more-config4/pypy/translator/c/src/g_include.h
pypy/branch/even-more-config4/pypy/translator/c/test/test_backendoptimized.py
pypy/branch/even-more-config4/pypy/translator/c/test/test_boehm.py
pypy/branch/even-more-config4/pypy/translator/c/test/test_exception.py
pypy/branch/even-more-config4/pypy/translator/c/test/test_exceptiontransform.py
pypy/branch/even-more-config4/pypy/translator/c/test/test_genc.py
pypy/branch/even-more-config4/pypy/translator/c/test/test_lltyped.py
pypy/branch/even-more-config4/pypy/translator/c/test/test_newgc.py
pypy/branch/even-more-config4/pypy/translator/c/test/test_stackless.py
pypy/branch/even-more-config4/pypy/translator/c/test/test_symboltable.py
pypy/branch/even-more-config4/pypy/translator/c/test/test_typed.py
pypy/branch/even-more-config4/pypy/translator/cli/gencli.py
pypy/branch/even-more-config4/pypy/translator/cli/ilgenerator.py
pypy/branch/even-more-config4/pypy/translator/driver.py
pypy/branch/even-more-config4/pypy/translator/geninterplevel.py
pypy/branch/even-more-config4/pypy/translator/goal/targetlogicstandalone.py
pypy/branch/even-more-config4/pypy/translator/goal/targetmultiplespaces.py
pypy/branch/even-more-config4/pypy/translator/goal/targetpypystandalone.py
pypy/branch/even-more-config4/pypy/translator/goal/targetvarsized.py
pypy/branch/even-more-config4/pypy/translator/goal/translate.py
pypy/branch/even-more-config4/pypy/translator/interactive.py
pypy/branch/even-more-config4/pypy/translator/js/main.py
pypy/branch/even-more-config4/pypy/translator/llvm/gc.py
pypy/branch/even-more-config4/pypy/translator/llvm/genllvm.py
pypy/branch/even-more-config4/pypy/translator/stackless/test/test_transform.py
pypy/branch/even-more-config4/pypy/translator/test/test_driver.py
pypy/branch/even-more-config4/pypy/translator/test/test_interactive.py
pypy/branch/even-more-config4/pypy/translator/translator.py
Log:
merge:
svn merge -r 33156:HEAD http://codespeak.net/svn/pypy/branch/even-more-config3
Modified: pypy/branch/even-more-config4/pypy/config/config.py
==============================================================================
--- pypy/branch/even-more-config4/pypy/config/config.py (original)
+++ pypy/branch/even-more-config4/pypy/config/config.py Tue Oct 24 22:18:14 2006
@@ -1,69 +1,101 @@
from py.compat import optparse
+class AmbigousOptionError(Exception):
+ pass
+
+class NoMatchingOptionFound(AttributeError):
+ pass
+
class Config(object):
- _frozen = False
+ _cfgimpl_frozen = False
def __init__(self, descr, parent=None, **overrides):
- self._descr = descr
- self._value_owners = {}
- self._parent = parent
- self._build(overrides)
+ self._cfgimpl_descr = descr
+ self._cfgimpl_value_owners = {}
+ self._cfgimpl_parent = parent
+ self._cfgimpl_values = {}
+ self._cfgimpl_build(overrides)
- def _build(self, overrides):
- for child in self._descr._children:
+ def _cfgimpl_build(self, overrides):
+ for child in self._cfgimpl_descr._children:
if isinstance(child, Option):
- self.__dict__[child._name] = child.default
- self._value_owners[child._name] = 'default'
+ self._cfgimpl_values[child._name] = child.getdefault()
+ self._cfgimpl_value_owners[child._name] = 'default'
elif isinstance(child, OptionDescription):
- self.__dict__[child._name] = Config(child, parent=self)
+ self._cfgimpl_values[child._name] = Config(child, parent=self)
+ self.override(overrides)
+
+ def override(self, overrides):
for name, value in overrides.iteritems():
- subconfig, name = self._get_by_path(name)
- setattr(subconfig, name, value)
+ homeconfig, name = self._cfgimpl_get_home_by_path(name)
+ homeconfig.setoption(name, value, 'default')
def __setattr__(self, name, value):
- if self._frozen:
+ if self._cfgimpl_frozen and getattr(self, name) != value:
raise TypeError("trying to change a frozen option object")
- if name.startswith('_'):
+ if name.startswith('_cfgimpl_'):
self.__dict__[name] = value
return
self.setoption(name, value, 'user')
+ def __getattr__(self, name):
+ if '.' in name:
+ homeconfig, name = self._cfgimpl_get_home_by_path(name)
+ return getattr(homeconfig, name)
+ if name not in self._cfgimpl_values:
+ raise AttributeError("%s object has no attribute %s" %
+ (self.__class__, name))
+ return self._cfgimpl_values[name]
+
def setoption(self, name, value, who):
- if name not in self.__dict__:
- raise ValueError('unknown option %s' % (name,))
- child = getattr(self._descr, name)
- oldowner = self._value_owners[child._name]
+ if name not in self._cfgimpl_values:
+ raise AttributeError('unknown option %s' % (name,))
+ child = getattr(self._cfgimpl_descr, name)
+ oldowner = self._cfgimpl_value_owners[child._name]
oldvalue = getattr(self, name)
- if oldowner == 'required':
- if oldvalue != value:
- raise ValueError('can not override value %s for option %s' %
- (value, name))
- return
- child.setoption(self, value)
- self._value_owners[name] = who
-
- def require(self, name, value):
- self.setoption(name, value, "required")
+ if oldvalue != value and oldowner != "default":
+ if who == "default":
+ return
+ raise ValueError('can not override value %s for option %s' %
+ (value, name))
+ child.setoption(self, value, who)
+ self._cfgimpl_value_owners[name] = who
+
+ def set(self, **kwargs):
+ all_paths = [p.split(".") for p in self.getpaths()]
+ for key, value in kwargs.iteritems():
+ key_p = key.split('.')
+ candidates = [p for p in all_paths if p[-len(key_p):] == key_p]
+ if len(candidates) == 1:
+ name = '.'.join(candidates[0])
+ homeconfig, name = self._cfgimpl_get_home_by_path(name)
+ homeconfig.setoption(name, value, "user")
+ elif len(candidates) > 1:
+ raise AmbigousOptionError(
+ 'more than one option that ends with %s' % (key, ))
+ else:
+ raise NoMatchingOptionFound(
+ 'there is no option that matches %s' % (key, ))
- def _get_by_path(self, path):
+ def _cfgimpl_get_home_by_path(self, path):
"""returns tuple (config, name)"""
path = path.split('.')
for step in path[:-1]:
self = getattr(self, step)
return self, path[-1]
- def _get_toplevel(self):
- while self._parent is not None:
- self = self._parent
+ def _cfgimpl_get_toplevel(self):
+ while self._cfgimpl_parent is not None:
+ self = self._cfgimpl_parent
return self
def _freeze_(self):
- self.__dict__['_frozen'] = True
+ self.__dict__['_cfgimpl_frozen'] = True
return True
def getkey(self):
- return self._descr.getkey(self)
+ return self._cfgimpl_descr.getkey(self)
def __hash__(self):
return hash(self.getkey())
@@ -75,15 +107,15 @@
return not self == other
def __iter__(self):
- for child in self._descr._children:
+ for child in self._cfgimpl_descr._children:
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:
+ result = "[%s]\n" % (self._cfgimpl_descr._name, )
+ for child in self._cfgimpl_descr._children:
if isinstance(child, Option):
- if self._value_owners[child._name] == 'default':
+ if self._cfgimpl_value_owners[child._name] == 'default':
continue
result += " %s = %s\n" % (
child._name, getattr(self, child._name))
@@ -101,9 +133,9 @@
if currpath is None:
currpath = []
paths = []
- for option in self._descr._children:
+ for option in self._cfgimpl_descr._children:
attr = option._name
- if attr.startswith('_'):
+ if attr.startswith('_cfgimpl'):
continue
value = getattr(self, attr)
if isinstance(value, Config):
@@ -133,20 +165,73 @@
def getdefault(self):
return self.default
- def setoption(self, config, value):
+ def setoption(self, config, value, who):
name = self._name
- if not self.validate(value):
+ if who == "default" and value is None:
+ pass
+ elif not self.validate(value):
raise ValueError('invalid value %s for option %s' % (value, name))
- config.__dict__[name] = value
+ config._cfgimpl_values[name] = value
def getkey(self, value):
return value
+ def convert_from_cmdline(self, value):
+ return value
+
def add_optparse_option(self, argnames, parser, config):
- raise NotImplemented('abstract base class')
+ callback = ConfigUpdate(config, self)
+ option = parser.add_option(help=self.doc+" %default",
+ action='callback', type=self.opt_type,
+ callback=callback, metavar=self._name.upper(),
+ *argnames)
+
+class ConfigUpdate(object):
+
+ def __init__(self, config, option):
+ self.config = config
+ self.option = option
+
+ def convert_from_cmdline(self, value):
+ return self.option.convert_from_cmdline(value)
+
+ def __call__(self, option, opt_str, value, parser, *args, **kwargs):
+ try:
+ value = self.convert_from_cmdline(value)
+ self.config.setoption(self.option._name, value, who='cmdline')
+ except ValueError, e:
+ raise optparse.OptionValueError(e.args[0])
+
+ def help_default(self):
+ default = getattr(self.config, self.option._name)
+ owner = self.config._cfgimpl_value_owners[self.option._name]
+ if default is None:
+ if owner == 'default':
+ return ''
+ else:
+ default = '???'
+ return "%s: %s" % (owner, default)
+class BoolConfigUpdate(ConfigUpdate):
+ def __init__(self, config, option, which_value):
+ super(BoolConfigUpdate, self).__init__(config, option)
+ self.which_value = which_value
+
+ def convert_from_cmdline(self, value):
+ return self.which_value
+
+ def help_default(self):
+ default = getattr(self.config, self.option._name)
+ owner = self.config._cfgimpl_value_owners[self.option._name]
+ if default == self.which_value:
+ return owner
+ else:
+ return ""
+
class ChoiceOption(Option):
- def __init__(self, name, doc, values, default, requires=None,
+ opt_type = 'string'
+
+ def __init__(self, name, doc, values, default=None, requires=None,
cmdline=DEFAULT_OPTION_NAME):
super(ChoiceOption, self).__init__(name, doc, cmdline)
self.values = values
@@ -155,60 +240,70 @@
requires = {}
self._requires = requires
- def setoption(self, config, value):
+ def setoption(self, config, value, who):
name = self._name
for path, reqvalue in self._requires.get(value, []):
- subconfig, name = config._get_toplevel()._get_by_path(path)
- subconfig.require(name, reqvalue)
- super(ChoiceOption, self).setoption(config, value)
+ toplevel = config._cfgimpl_get_toplevel()
+ homeconfig, name = toplevel._cfgimpl_get_home_by_path(path)
+ homeconfig.setoption(name, reqvalue, who)
+ super(ChoiceOption, self).setoption(config, value, who)
def validate(self, value):
- return value in self.values
+ return value is None or 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)
+ def convert_from_cmdline(self, value):
+ return value.strip()
-class BoolOption(ChoiceOption):
- def __init__(self, name, doc, default=True, requires=None,
- cmdline=DEFAULT_OPTION_NAME):
- if requires is not None:
- requires = {True: requires}
- super(BoolOption, self).__init__(name, doc, [True, False], default,
- requires=requires,
- cmdline=cmdline)
+def _getnegation(optname):
+ if optname.startswith("without"):
+ return "with" + optname[len("without"):]
+ if optname.startswith("with"):
+ return "without" + optname[len("with"):]
+ return "no-" + optname
+
+class BoolOption(Option):
+ def __init__(self, name, doc, default=None, requires=None,
+ cmdline=DEFAULT_OPTION_NAME, negation=True):
+ super(BoolOption, self).__init__(name, doc, cmdline=cmdline)
+ self._requires = requires
+ self.default = default
+ self.negation = negation
+
+ def validate(self, value):
+ return isinstance(value, bool)
+
+ def setoption(self, config, value, who):
+ name = self._name
+ if value and self._requires is not None:
+ for path, reqvalue in self._requires:
+ toplevel = config._cfgimpl_get_toplevel()
+ homeconfig, name = toplevel._cfgimpl_get_home_by_path(path)
+ homeconfig.setoption(name, reqvalue, who)
+ super(BoolOption, self).setoption(config, value, who)
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)
- no_argnames = ["--no-" + argname.lstrip("-") for argname in argnames
- if argname.startswith("--")]
+ callback = BoolConfigUpdate(config, self, True)
+ option = parser.add_option(help=self.doc+" %default",
+ action='callback',
+ callback=callback, *argnames)
+ if not self.negation:
+ return
+ no_argnames = ["--" + _getnegation(argname.lstrip("-"))
+ for argname in argnames
+ if argname.startswith("--")]
if len(no_argnames) == 0:
- no_argnames = ["--no-" + argname.lstrip("-")
+ no_argnames = ["--" + _getnegation(argname.lstrip("-"))
for argname in argnames]
- def _callback(option, opt_str, value, parser, *args, **kwargs):
- try:
- config.setoption(self._name, False, who='cmdline')
- except ValueError, e:
- raise optparse.OptionValueError(e.args[0])
- parser.add_option(help="unset option set by %s" % (argnames[0], ),
- action='callback',
- callback=_callback, *no_argnames)
+ callback = BoolConfigUpdate(config, self, False)
+ option = parser.add_option(help="unset option set by %s %%default" % (argname, ),
+ action='callback',
+ callback=callback, *no_argnames)
+
class IntOption(Option):
- def __init__(self, name, doc, default=0, cmdline=DEFAULT_OPTION_NAME):
+ opt_type = 'int'
+
+ def __init__(self, name, doc, default=None, cmdline=DEFAULT_OPTION_NAME):
super(IntOption, self).__init__(name, doc, cmdline)
self.default = default
@@ -219,21 +314,16 @@
return False
return True
- def setoption(self, config, value):
+ def setoption(self, config, value, who):
try:
- super(IntOption, self).setoption(config, int(value))
+ super(IntOption, self).setoption(config, int(value), who)
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=DEFAULT_OPTION_NAME):
+ opt_type = 'float'
+
+ def __init__(self, name, doc, default=None, cmdline=DEFAULT_OPTION_NAME):
super(FloatOption, self).__init__(name, doc, cmdline)
self.default = default
@@ -244,26 +334,54 @@
return False
return True
- def setoption(self, config, value):
+ def setoption(self, config, value, who):
try:
- super(FloatOption, self).setoption(config, float(value))
+ super(FloatOption, self).setoption(config, float(value), who)
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 StrOption(Option):
+ opt_type = 'string'
+
+ def __init__(self, name, doc, default=None, cmdline=DEFAULT_OPTION_NAME):
+ super(StrOption, self).__init__(name, doc, cmdline)
+ self.default = default
+
+ def validate(self, value):
+ return isinstance(value, str)
+
+ def setoption(self, config, value, who):
+ try:
+ super(StrOption, self).setoption(config, value, who)
+ except TypeError, e:
+ raise ValueError(*e.args)
+
+class ArbitraryOption(Option):
+ def __init__(self, name, doc, default=None, defaultfactory=None):
+ super(ArbitraryOption, self).__init__(name, doc, cmdline=None)
+ self.default = default
+ self.defaultfactory = defaultfactory
+ if defaultfactory is not None:
+ assert default is None
+
+ def validate(self, value):
+ return True
+
+ def add_optparse_option(self, *args, **kwargs):
+ return
+
+ def getdefault(self):
+ if self.defaultfactory is not None:
+ return self.defaultfactory()
+ return self.default
class OptionDescription(object):
- def __init__(self, name, doc, children, cmdline=DEFAULT_OPTION_NAME):
+ cmdline = None
+ def __init__(self, name, doc, children):
self._name = name
self.doc = doc
self._children = children
self._build()
- self.cmdline = cmdline
def _build(self):
for child in self._children:
@@ -274,33 +392,55 @@
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()
- if value.startswith("-"):
- value = value[1:]
- set_to = False
- else:
- set_to = True
- option = getattr(self, value, None)
- if option is None:
- raise ValueError("did not find option %s" % (value, ))
- getattr(config, self._name).setoption(
- value, set_to, who='cmdline')
- except ValueError, e:
- raise optparse.OptionValueError(e.args[0])
- parser.add_option(help=self._name, action='callback', type='string',
- callback=_callback, *argnames)
+ return
-def to_optparse(config, useoptions=None, parser=None):
+class OptHelpFormatter(optparse.IndentedHelpFormatter):
+
+ def expand_default(self, option):
+ assert self.parser
+ dfls = self.parser.defaults
+ defl = ""
+ choices = None
+ if option.action == 'callback' and isinstance(option.callback, ConfigUpdate):
+ callback = option.callback
+ defl = callback.help_default()
+ if isinstance(callback.option, ChoiceOption):
+ choices = callback.option.values
+ else:
+ val = dfls.get(option.dest)
+ if val is None:
+ pass
+ elif isinstance(val, bool):
+ if val is True and option.action=="store_true":
+ defl = "default"
+ else:
+ defl = "default: %s" % val
+
+ if option.type == 'choice':
+ choices = option.choices
+
+ if choices is not None:
+ choices = "%s=%s" % (option.metavar, '|'.join(choices))
+ else:
+ choices = ""
+
+ if '%default' in option.help:
+ if choices and defl:
+ sep = ", "
+ else:
+ sep = ""
+ defl = '[%s%s%s]' % (choices, sep, defl)
+ if defl == '[]':
+ defl = ""
+ return option.help.replace("%default", defl)
+ elif choices:
+ return option.help + ' [%s]' % choices
+
+ return option.help
+
+def to_optparse(config, useoptions=None, parser=None,
+ parserargs=None, parserkwargs=None):
grps = {}
def get_group(name, doc):
steps = name.split('.')
@@ -313,31 +453,38 @@
return grp
if parser is None:
- parser = optparse.OptionParser()
+ if parserargs is None:
+ parserargs = []
+ if parserkwargs is None:
+ parserkwargs = {}
+ parser = optparse.OptionParser(
+ formatter=OptHelpFormatter(),
+ *parserargs, **parserkwargs)
if useoptions is None:
useoptions = config.getpaths(include_groups=True)
+ seen = {}
for path in useoptions:
if path.endswith(".*"):
path = path[:-2]
- subconf, name = config._get_by_path(path)
+ homeconf, name = config._cfgimpl_get_home_by_path(path)
+ subconf = getattr(homeconf, name)
children = [
- path + "." + child._name
- for child in getattr(subconf, name)._descr._children]
+ path + "." + child
+ for child in subconf.getpaths()]
useoptions.extend(children)
else:
- subconf, name = config._get_by_path(path)
- option = getattr(subconf._descr, name)
+ if path in seen:
+ continue
+ seen[path] = True
+ homeconf, name = config._cfgimpl_get_home_by_path(path)
+ option = getattr(homeconf._cfgimpl_descr, name)
if option.cmdline is DEFAULT_OPTION_NAME:
chunks = ('--%s' % (path.replace('.', '-'),),)
elif option.cmdline is None:
continue
else:
chunks = option.cmdline.split(' ')
- try:
- grp = get_group(path, subconf._descr.doc)
- option.add_optparse_option(chunks, grp, subconf)
- except ValueError:
- # an option group that does not only contain bool values
- pass
+ grp = get_group(path, homeconf._cfgimpl_descr.doc)
+ option.add_optparse_option(chunks, grp, homeconf)
return parser
Modified: pypy/branch/even-more-config4/pypy/config/pypyoption.py
==============================================================================
--- pypy/branch/even-more-config4/pypy/config/pypyoption.py (original)
+++ pypy/branch/even-more-config4/pypy/config/pypyoption.py Tue Oct 24 22:18:14 2006
@@ -1,7 +1,7 @@
import autopath
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, StrOption, to_optparse, Config
modulepath = py.magic.autopath().dirpath().dirpath().join("module")
all_modules = [p.basename for p in modulepath.listdir()
@@ -47,10 +47,11 @@
OptionDescription("usemodules", "Which Modules should be used", [
BoolOption(modname, "use module %s" % (modname, ),
default=modname in default_modules,
- cmdline=None)
- for modname in all_modules], cmdline="--usemodules"),
+ cmdline="--withmod-%s" % (modname, ))
+ for modname in all_modules]),
- BoolOption("geninterp", "specify whether geninterp should be used"),
+ BoolOption("geninterp", "specify whether geninterp should be used",
+ default=True),
BoolOption("logbytecodes",
"keep track of bytecode usage",
@@ -101,18 +102,105 @@
"specify whether the default metaclass should be classobj",
default=False, cmdline="--oldstyle"),
]),
+ BoolOption("lowmem", "Try to use little memory during translation",
+ default=False, cmdline="--lowmem",
+ requires=[("objspace.geninterp", False)]),
]),
BoolOption("translating", "indicates whether we are translating currently",
default=False, cmdline=None),
+
+ OptionDescription("translation", "Translation Options", [
+ BoolOption("stackless", "compile stackless features in",
+ default=False, cmdline="--stackless",
+ requires=[("translation.type_system", "lltype")]),
+ ChoiceOption("type_system", "Type system to use when RTyping",
+ ["lltype", "ootype"], cmdline=None),
+ ChoiceOption("backend", "Backend to use for code generation",
+ ["c", "llvm", "cli", "js", "squeak", "cl"],
+ requires={
+ "c": [("translation.type_system", "lltype")],
+ "llvm": [("translation.type_system", "lltype"),
+ ("translation.gc", "boehm"),
+ ("translation.backendopt.raisingop2direct_call", True)],
+ "cli": [("translation.type_system", "ootype")],
+ "js": [("translation.type_system", "ootype")],
+ "squeak": [("translation.type_system", "ootype")],
+ "cl": [("translation.type_system", "ootype")],
+ },
+ cmdline="-b --backend"),
+ ChoiceOption("gc", "Garbage Collection Strategy",
+ ["boehm", "ref", "framework", "none", "stacklessgc",
+ "exact_boehm"],
+ "boehm", requires={
+ "stacklessgc": [("translation.stackless", True)]},
+ cmdline="--gc"),
+
+ BoolOption("thread", "enable use of threading primitives",
+ default=False, cmdline="--thread"),
+ BoolOption("verbose", "Print extra information", default=False),
+ BoolOption("debug", "Record extra annotation information",
+ cmdline="-d --debug", default=False),
+ BoolOption("insist", "Try hard to go on RTyping", default=False,
+ cmdline="--insist"),
+ BoolOption("countmallocs", "Count mallocs and frees", default=False,
+ cmdline=None),
+
+ # misc
+ StrOption("cc", "Specify compiler", cmdline="--cc"),
+ StrOption("profopt", "Specify profile based optimization script",
+ cmdline="--profopt"),
+ BoolOption("debug_transform", "Perform the debug transformation",
+ default=False, cmdline="--debug-transform", negation=False),
+
+ # Flags of the TranslationContext:
+ BoolOption("simplifying", "Simplify flow graphs", default=True),
+ BoolOption("do_imports_immediately", "XXX", default=True,
+ cmdline=None),
+ BoolOption("builtins_can_raise_exceptions", "XXX", default=False,
+ cmdline=None),
+ BoolOption("list_comprehension_operations", "XXX", default=False,
+ cmdline=None),
+ ChoiceOption("fork_before",
+ "(UNIX) Create restartable checkpoint before step",
+ ["annotate", "rtype", "backendopt", "database", "source"],
+ default=None, cmdline="--fork-before"),
+
+ OptionDescription("backendopt", "Backend Optimization Options", [
+ BoolOption("print_statistics", "Print statistics while optimizing",
+ default=False),
+ BoolOption("merge_if_blocks", "Merge if ... elif chains",
+ cmdline="--if-block-merge", default=True),
+ BoolOption("raisingop2direct_call",
+ "Transform exception raising operations",
+ default=False, cmdline="--raisingop2direct_call"),
+ BoolOption("mallocs", "Remove mallocs", default=True),
+ BoolOption("propagate", "Constant propagation, deprecated",
+ default=False),
+ BoolOption("constfold", "Constant propagation",
+ default=True),
+ BoolOption("heap2stack", "Escape analysis and stack allocation",
+ default=False,
+ requires=[("translation.stackless", False)]),
+ BoolOption("clever_malloc_removal",
+ "Remove mallocs in a clever way", default=False),
+ IntOption("inline_threshold", "Threshold when to inline functions",
+ default=1, cmdline=None),
+ ]),
+
+ OptionDescription("cli", "GenCLI options", [
+ BoolOption("trace_calls", "Trace function calls", default=False,
+ cmdline="--cli-trace-calls")
+ ]),
+ ]),
])
if __name__ == '__main__':
config = Config(pypy_optiondescription)
print config.getpaths()
- parser = to_optparse(config)
+ parser = to_optparse(config) #, useoptions=["translation.*"])
option, args = parser.parse_args()
print config
Modified: pypy/branch/even-more-config4/pypy/config/test/test_config.py
==============================================================================
--- pypy/branch/even-more-config4/pypy/config/test/test_config.py (original)
+++ pypy/branch/even-more-config4/pypy/config/test/test_config.py Tue Oct 24 22:18:14 2006
@@ -6,16 +6,22 @@
gcdummy = BoolOption('dummy', 'dummy', default=False)
objspaceoption = ChoiceOption('objspace', 'Object space',
['std', 'logic'], 'std')
- booloption = BoolOption('bool', 'Test boolean option')
- intoption = IntOption('int', 'Test int option')
+ booloption = BoolOption('bool', 'Test boolean option', default=True)
+ intoption = IntOption('int', 'Test int option', default=0)
floatoption = FloatOption('float', 'Test float option', default=2.3)
+ stroption = StrOption('str', 'Test string option', default="abc")
wantref_option = BoolOption('wantref', 'Test requires', default=False,
requires=[('gc.name', 'ref')])
+ wantframework_option = BoolOption('wantframework', 'Test requires',
+ default=False,
+ requires=[('gc.name', 'framework')])
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption])
descr = OptionDescription('pypy', '', [gcgroup, booloption, objspaceoption,
- wantref_option, intoption])
+ wantref_option, stroption,
+ wantframework_option,
+ intoption])
return descr
def test_base_config():
@@ -25,6 +31,7 @@
assert config.gc.name == 'ref'
config.gc.name = 'framework'
assert config.gc.name == 'framework'
+ assert getattr(config, "gc.name") == 'framework'
assert config.objspace == 'std'
config.objspace = 'logic'
@@ -39,19 +46,40 @@
assert not config.wantref
+ assert config.str == "abc"
+ config.str = "def"
+ assert config.str == "def"
+
py.test.raises(ValueError, 'config.objspace = "foo"')
py.test.raises(ValueError, 'config.gc.name = "foo"')
- py.test.raises(ValueError, 'config.gc.foo = "bar"')
+ py.test.raises(AttributeError, 'config.gc.foo = "bar"')
py.test.raises(ValueError, 'config.bool = 123')
py.test.raises(ValueError, 'config.int = "hello"')
py.test.raises(ValueError, 'config.gc.float = None')
- # test whether the gc.name is set to 'ref' when wantref is true (note that
- # the current value of gc.name is 'framework')
- config.wantref = True
+ config = Config(descr, bool=False)
assert config.gc.name == 'ref'
- py.test.raises(ValueError, 'config.gc.name = "framework"')
- config.gc.name = "ref"
+ config.wantframework = True
+ py.test.raises(ValueError, 'config.gc.name = "ref"')
+ config.gc.name = "framework"
+
+def test_arbitrary_option():
+ descr = OptionDescription("top", "", [
+ ArbitraryOption("a", "no help", default=None)
+ ])
+ config = Config(descr)
+ config.a = []
+ config.a.append(1)
+ assert config.a == [1]
+
+ descr = OptionDescription("top", "", [
+ ArbitraryOption("a", "no help", defaultfactory=list)
+ ])
+ c1 = Config(descr)
+ c2 = Config(descr)
+ c1.a.append(1)
+ assert c2.a == []
+ assert c1.a == [1]
def test_annotator_folding():
from pypy.translator.interactive import Translation
@@ -77,6 +105,8 @@
assert block.operations[0].opname == 'int_add'
assert config._freeze_()
+ # does not raise, since it does not change the attribute
+ config.gc.name = "ref"
py.test.raises(TypeError, 'config.gc.name = "framework"')
def test_compare_configs():
@@ -111,6 +141,9 @@
assert config.gc.name == 'framework'
+
+ config = Config(descr)
+ parser = to_optparse(config, ['gc.name'])
(options, args) = parser.parse_args(args=['-g ref'])
assert config.gc.name == 'ref'
@@ -138,8 +171,13 @@
booloption1 = BoolOption('bool1', 'Boolean option test', default=False,
cmdline='--bool1 -b')
booloption2 = BoolOption('bool2', 'Boolean option test', default=True,
- cmdline='--bool2 -c')
- descr = OptionDescription('test', '', [booloption1, booloption2])
+ cmdline='--with-bool2 -c')
+ booloption3 = BoolOption('bool3', 'Boolean option test', default=True,
+ cmdline='--bool3')
+ booloption4 = BoolOption('bool4', 'Boolean option test', default=True,
+ cmdline='--bool4', negation=False)
+ descr = OptionDescription('test', '', [booloption1, booloption2,
+ booloption3, booloption4])
config = Config(descr)
parser = to_optparse(config, ['bool1', 'bool2'])
@@ -149,57 +187,17 @@
assert config.bool2
config = Config(descr)
- parser = to_optparse(config, ['bool1', 'bool2'])
- (options, args) = parser.parse_args(args=['--no-bool2'])
+ parser = to_optparse(config, ['bool1', 'bool2', 'bool3', 'bool4'])
+ (options, args) = parser.parse_args(args=['--without-bool2', '--no-bool3',
+ '--bool4'])
assert not config.bool1
assert not config.bool2
+ assert not config.bool3
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),
- BoolOption("normal", "do nothing special",
- default=True),
- ], 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
- assert config.test.normal
-
- 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
- assert config.test.normal
-
- config = Config(descr)
- parser = to_optparse(config, ['test'])
- (options, args) = parser.parse_args(
- args=['--test=-normal,smallint'])
-
- assert config.test.smallint
- assert not config.test.strjoin
- assert not config.test.strdict
- assert not config.test.normal
+ py.test.raises(SystemExit,
+ "(options, args) = parser.parse_args(args=['--no-bool4'])")
def test_config_start():
descr = make_description()
@@ -210,7 +208,35 @@
assert config.gc.name == "framework"
assert config.gc.dummy
+def test_star_works_recursively():
+ descr = OptionDescription("top", "", [
+ OptionDescription("a", "", [
+ BoolOption("b1", "", default=False, cmdline="--b1"),
+ OptionDescription("sub", "", [
+ BoolOption("b2", "", default=False, cmdline="--b2")
+ ])
+ ]),
+ BoolOption("b3", "", default=False, cmdline="--b3"),
+ ])
+ config = Config(descr)
+ assert not config.a.b1
+ assert not config.a.sub.b2
+ parser = to_optparse(config, ['a.*'])
+ options, args = parser.parse_args(args=["--b1", "--b2"])
+ assert config.a.b1
+ assert config.a.sub.b2
+ py.test.raises(SystemExit,
+ "(options, args) = parser.parse_args(args=['--b3'])")
+ config = Config(descr)
+ assert not config.a.b1
+ assert not config.a.sub.b2
+ # does not lead to an option conflict
+ parser = to_optparse(config, ['a.*', 'a.sub.*'])
+ options, args = parser.parse_args(args=["--b1", "--b2"])
+ assert config.a.b1
+ assert config.a.sub.b2
+
def test_optparse_path_options():
gcoption = ChoiceOption('name', 'GC name', ['ref', 'framework'], 'ref')
gcgroup = OptionDescription('gc', '', [gcoption])
@@ -222,16 +248,26 @@
assert config.gc.name == 'framework'
+
def test_getpaths():
descr = make_description()
config = Config(descr)
assert config.getpaths() == ['gc.name', 'gc.dummy', 'gc.float', 'bool',
- 'objspace', 'wantref', 'int']
+ 'objspace', 'wantref', 'str', 'wantframework',
+ 'int']
assert config.gc.getpaths() == ['name', 'dummy', 'float']
assert config.getpaths(include_groups=True) == [
'gc', 'gc.name', 'gc.dummy', 'gc.float',
- 'bool', 'objspace', 'wantref', 'int']
+ 'bool', 'objspace', 'wantref', 'str', 'wantframework', 'int']
+
+def test_underscore_in_option_name():
+ descr = OptionDescription("opt", "", [
+ BoolOption("_stackless", "", default=False),
+ ])
+ config = Config(descr)
+ parser = to_optparse(config)
+ assert parser.has_option("--_stackless")
def test_none():
dummy1 = BoolOption('dummy1', 'doc dummy', default=False, cmdline=None)
@@ -274,3 +310,93 @@
config.s.backend = "cli"
assert config.s.type_system == "oo"
+def test_choice_with_no_default():
+ descr = OptionDescription("test", "", [
+ ChoiceOption("backend", "", ["c", "llvm"])])
+ config = Config(descr)
+ assert config.backend is None
+ config.backend = "c"
+
+def test_overrides_are_defaults():
+ descr = OptionDescription("test", "", [
+ BoolOption("b1", "", default=False, requires=[("b2", False)]),
+ BoolOption("b2", "", default=False),
+ ])
+ config = Config(descr, b2=True)
+ assert config.b2
+ config.b1 = True
+ assert not config.b2
+ print config._cfgimpl_value_owners
+
+def test_overrides_require_as_default():
+ descr = OptionDescription("test", "", [
+ ChoiceOption("backend", "", ['c', 'cli'], 'c',
+ requires={'c': [('type_system', 'll')],
+ 'cli': [('type_system', 'oo')]}),
+ ChoiceOption("type_system", "", ['ll', 'oo'], 'll')
+ ])
+ config = Config(descr, backend='c')
+ config.set(backend=None, type_system=None)
+ config = Config(descr, backend='c')
+ config.set(backend='cli')
+ assert config.backend == 'cli'
+ assert config.type_system == 'oo'
+
+def test_overrides_dont_change_user_options():
+ descr = OptionDescription("test", "", [
+ BoolOption("b", "", default=False)])
+ config = Config(descr)
+ config.b = True
+ config.override({'b': False})
+ assert config.b
+
+def test_str():
+ descr = make_description()
+ c = Config(descr)
+ print c # does not crash
+
+def test_dwim_set():
+ descr = OptionDescription("opt", "", [
+ OptionDescription("sub", "", [
+ BoolOption("b1", ""),
+ ChoiceOption("c1", "", ['a', 'b', 'c'], 'a'),
+ BoolOption("d1", ""),
+ ]),
+ BoolOption("b2", ""),
+ BoolOption("d1", ""),
+ ])
+ c = Config(descr)
+ c.set(b1=False, c1='b')
+ assert not c.sub.b1
+ assert c.sub.c1 == 'b'
+ # new config, because you cannot change values once they are set
+ c = Config(descr)
+ c.set(b2=False, **{'sub.c1': 'c'})
+ assert not c.b2
+ assert c.sub.c1 == 'c'
+ py.test.raises(AmbigousOptionError, "c.set(d1=True)")
+ py.test.raises(NoMatchingOptionFound, "c.set(unknown='foo')")
+
+def test_optparse_help():
+ import cStringIO
+ descr = OptionDescription("opt", "", [
+ BoolOption("bool1", 'do bool1', default=False, cmdline='--bool1'),
+ BoolOption("bool2", 'do bool2', default=False, cmdline='--bool2', negation=False),
+ BoolOption("bool3", 'do bool3', default=True, cmdline='--bool3'),
+ ChoiceOption("choice", "choose!", ['a', 'b', 'c'], 'a', '--choice'),
+ ChoiceOption("choice2", "choose2!", ['x', 'y', 'z'], None, '--choice2'),
+ StrOption("str", 'specify xyz', default='hello', cmdline='--str'),
+ ])
+ conf = Config(descr)
+ parser = to_optparse(conf)
+ out = cStringIO.StringIO()
+ parser.print_help(out)
+ help = out.getvalue()
+ #print help
+ assert "do bool1\n" in help
+ assert "unset option set by --bool1 [default]" in help
+ assert "do bool2\n" in help
+ assert "do bool3 [default]" in help
+ assert "choose! [CHOICE=a|b|c, default: a]" in help
+ assert "choose2! [CHOICE2=x|y|z]" in help
+ assert "specify xyz [default: hello]" in help
Modified: pypy/branch/even-more-config4/pypy/config/test/test_pypyoption.py
==============================================================================
--- pypy/branch/even-more-config4/pypy/config/test/test_pypyoption.py (original)
+++ pypy/branch/even-more-config4/pypy/config/test/test_pypyoption.py Tue Oct 24 22:18:14 2006
@@ -14,8 +14,9 @@
conf.objspace.std.withsmallint = True
assert not conf.objspace.std.withprebuiltint
+ conf = Config(pypy_optiondescription)
conf.objspace.std.withprebuiltint = True
- assert not conf.objspace.std.withsmallint
+ py.test.raises(ValueError, "conf.objspace.std.withsmallint = True")
def test_objspace_incopatibilities():
conf = Config(pypy_optiondescription)
@@ -24,3 +25,9 @@
conf = Config(pypy_optiondescription)
conf.objspace.name = "logic"
assert not conf.objspace.geninterp
+
+def test_stacklessgc_required():
+ conf = Config(pypy_optiondescription)
+ conf.translation.gc = "stacklessgc"
+ assert conf.translation.stackless
+ assert conf.translation.type_system == "lltype"
Modified: pypy/branch/even-more-config4/pypy/jit/codegen/i386/test/test_genc_ts.py
==============================================================================
--- pypy/branch/even-more-config4/pypy/jit/codegen/i386/test/test_genc_ts.py (original)
+++ pypy/branch/even-more-config4/pypy/jit/codegen/i386/test/test_genc_ts.py Tue Oct 24 22:18:14 2006
@@ -95,7 +95,8 @@
annmodel.SomeInteger())
annhelper.finish()
t = self.rtyper.annotator.translator
- cbuilder = CStandaloneBuilder(t, ll_main, gcpolicy='boehm')
+ t.config.translation.gc = 'boehm'
+ cbuilder = CStandaloneBuilder(t, ll_main)
cbuilder.generate_source()
cbuilder.compile()
self.main_cbuilder= cbuilder
Modified: pypy/branch/even-more-config4/pypy/objspace/flow/flowcontext.py
==============================================================================
--- pypy/branch/even-more-config4/pypy/objspace/flow/flowcontext.py (original)
+++ pypy/branch/even-more-config4/pypy/objspace/flow/flowcontext.py Tue Oct 24 22:18:14 2006
@@ -281,7 +281,7 @@
except OperationError, e:
#print "OE", e.w_type, e.w_value
- if (self.space.do_imports_immediately and
+ if (self.space.config.translation.do_imports_immediately and
e.w_type is self.space.w_ImportError):
raise ImportError('import statement always raises %s' % (
e,))
Modified: pypy/branch/even-more-config4/pypy/objspace/flow/objspace.py
==============================================================================
--- pypy/branch/even-more-config4/pypy/objspace/flow/objspace.py (original)
+++ pypy/branch/even-more-config4/pypy/objspace/flow/objspace.py Tue Oct 24 22:18:14 2006
@@ -34,9 +34,6 @@
full_exceptions = False
- builtins_can_raise_exceptions = False
- do_imports_immediately = True
-
def initialize(self):
import __builtin__
self.concrete_mode = 1
@@ -428,7 +425,7 @@
exceptions = [Exception] # *any* exception by default
if isinstance(w_callable, Constant):
c = w_callable.value
- if not self.builtins_can_raise_exceptions:
+ if not self.config.translation.builtins_can_raise_exceptions:
if (isinstance(c, (types.BuiltinFunctionType,
types.BuiltinMethodType,
types.ClassType,
Modified: pypy/branch/even-more-config4/pypy/objspace/flow/specialcase.py
==============================================================================
--- pypy/branch/even-more-config4/pypy/objspace/flow/specialcase.py (original)
+++ pypy/branch/even-more-config4/pypy/objspace/flow/specialcase.py Tue Oct 24 22:18:14 2006
@@ -11,7 +11,7 @@
# import * in a function gives us the locals as Variable
# we always forbid it as a SyntaxError
raise SyntaxError, "RPython: import * is not allowed in functions"
- if space.do_imports_immediately:
+ if space.config.translation.do_imports_immediately:
name, glob, loc, frm = (space.unwrap(w_name), space.unwrap(w_glob),
space.unwrap(w_loc), space.unwrap(w_frm))
try:
@@ -36,7 +36,7 @@
else:
raise Exception, "should call %r with exactly %d arguments" % (
fn, Arity[opname])
- if space.builtins_can_raise_exceptions:
+ if space.config.translation.builtins_can_raise_exceptions:
# in this mode, avoid constant folding and raise an implicit Exception
w_result = space.do_operation(opname, *args_w)
space.handle_implicit_exceptions([Exception])
Modified: pypy/branch/even-more-config4/pypy/objspace/flow/test/test_objspace.py
==============================================================================
--- pypy/branch/even-more-config4/pypy/objspace/flow/test/test_objspace.py (original)
+++ pypy/branch/even-more-config4/pypy/objspace/flow/test/test_objspace.py Tue Oct 24 22:18:14 2006
@@ -713,9 +713,9 @@
class TestFlowObjSpaceDelay(Base):
- def setup_class(cls):
+ def setup_class(cls):
cls.space = FlowObjSpace()
- cls.space.do_imports_immediately = False
+ cls.space.config.translation.do_imports_immediately = False
def test_import_something(self):
def f():
Modified: pypy/branch/even-more-config4/pypy/rpython/lltypesystem/test/test_rtagged.py
==============================================================================
--- pypy/branch/even-more-config4/pypy/rpython/lltypesystem/test/test_rtagged.py (original)
+++ pypy/branch/even-more-config4/pypy/rpython/lltypesystem/test/test_rtagged.py Tue Oct 24 22:18:14 2006
@@ -182,7 +182,8 @@
interp, graph = get_interpreter(fn, [-1000])
t = interp.typer.annotator.translator
- backend_optimizations(t, constfold=True)
+ t.config.translation.backendopt.constfold = True
+ backend_optimizations(t)
if conftest.option.view:
t.view()
Modified: pypy/branch/even-more-config4/pypy/rpython/memory/gctransform/test/test_framework.py
==============================================================================
--- pypy/branch/even-more-config4/pypy/rpython/memory/gctransform/test/test_framework.py (original)
+++ pypy/branch/even-more-config4/pypy/rpython/memory/gctransform/test/test_framework.py Tue Oct 24 22:18:14 2006
@@ -26,7 +26,7 @@
from pypy.annotation.listdef import s_list_of_strings
t = rtype(entrypoint, [s_list_of_strings])
- cbuild = CStandaloneBuilder(t, entrypoint, FrameworkGcPolicy2)
+ cbuild = CStandaloneBuilder(t, entrypoint, gcpolicy=FrameworkGcPolicy2)
db = cbuild.generate_graphs_for_llinterp()
entrypointptr = cbuild.getentrypointptr()
entrygraph = entrypointptr._obj.graph
Modified: pypy/branch/even-more-config4/pypy/rpython/memory/gctransform/test/test_refcounting.py
==============================================================================
--- pypy/branch/even-more-config4/pypy/rpython/memory/gctransform/test/test_refcounting.py (original)
+++ pypy/branch/even-more-config4/pypy/rpython/memory/gctransform/test/test_refcounting.py Tue Oct 24 22:18:14 2006
@@ -14,7 +14,7 @@
from pypy.translator.c import gc
t = rtype(f, args_s)
- cbuild = CStandaloneBuilder(t, f, RefcountingGcPolicy2)
+ cbuild = CStandaloneBuilder(t, f, gcpolicy=RefcountingGcPolicy2)
db = cbuild.generate_graphs_for_llinterp()
graph = cbuild.getentrypointptr()._obj.graph
llinterp = LLInterpreter(t.rtyper)
Modified: pypy/branch/even-more-config4/pypy/rpython/memory/gctransform/test/test_stacklessframework.py
==============================================================================
--- pypy/branch/even-more-config4/pypy/rpython/memory/gctransform/test/test_stacklessframework.py (original)
+++ pypy/branch/even-more-config4/pypy/rpython/memory/gctransform/test/test_stacklessframework.py Tue Oct 24 22:18:14 2006
@@ -27,7 +27,8 @@
from pypy.annotation.listdef import s_list_of_strings
t = rtype(entrypoint, [s_list_of_strings])
- cbuild = CStandaloneBuilder(t, entrypoint, StacklessFrameworkGcPolicy2)
+ cbuild = CStandaloneBuilder(t, entrypoint,
+ gcpolicy=StacklessFrameworkGcPolicy2)
db = cbuild.generate_graphs_for_llinterp()
entrypointptr = cbuild.getentrypointptr()
entrygraph = entrypointptr._obj.graph
Modified: pypy/branch/even-more-config4/pypy/rpython/memory/test/test_transformed_gc.py
==============================================================================
--- pypy/branch/even-more-config4/pypy/rpython/memory/test/test_transformed_gc.py (original)
+++ pypy/branch/even-more-config4/pypy/rpython/memory/test/test_transformed_gc.py Tue Oct 24 22:18:14 2006
@@ -198,7 +198,7 @@
ARGS = lltype.FixedSizeArray(lltype.Signed, nbargs)
s_args = annmodel.SomePtr(lltype.Ptr(ARGS))
t = rtype(entrypoint, [s_args])
- cbuild = CStandaloneBuilder(t, entrypoint, self.gcpolicy)
+ cbuild = CStandaloneBuilder(t, entrypoint, gcpolicy=self.gcpolicy)
db = cbuild.generate_graphs_for_llinterp()
entrypointptr = cbuild.getentrypointptr()
entrygraph = entrypointptr._obj.graph
Modified: pypy/branch/even-more-config4/pypy/tool/option.py
==============================================================================
--- pypy/branch/even-more-config4/pypy/tool/option.py (original)
+++ pypy/branch/even-more-config4/pypy/tool/option.py Tue Oct 24 22:18:14 2006
@@ -26,7 +26,7 @@
def get_standard_options():
config = Config(pypy_optiondescription)
- parser = to_optparse(config)
+ parser = to_optparse(config, useoptions=["objspace.*"])
parser.add_option(
'-H', action="callback",
callback=run_tb_server,
Modified: pypy/branch/even-more-config4/pypy/translator/backendopt/all.py
==============================================================================
--- pypy/branch/even-more-config4/pypy/translator/backendopt/all.py (original)
+++ pypy/branch/even-more-config4/pypy/translator/backendopt/all.py Tue Oct 24 22:18:14 2006
@@ -12,8 +12,6 @@
from pypy.translator.backendopt.support import log
from pypy.objspace.flow.model import checkgraph
-PRINT_STATISTICS = False
-
def backend_optimizations(translator, graphs=None,
raisingop2direct_call_all=False,
inline_threshold=1,
@@ -24,10 +22,22 @@
heap2stack=False,
clever_malloc_removal=False):
+ config = translator.config.translation.backendopt
+ # ZZZ the arguments here should disappear
+ raisingop2direct_call_all = (config.raisingop2direct_call or
+ raisingop2direct_call_all)
+ mallocs = config.mallocs or mallocs
+ merge_if_blocks_to_switch = (config.merge_if_blocks or
+ merge_if_blocks_to_switch)
+ propagate = config.propagate or propagate
+ constfold = config.constfold or constfold
+ heap2stack = config.heap2stack or heap2stack
+ clever_malloc_removal = config.clever_malloc_removal or clever_malloc_removal
+
if graphs is None:
graphs = translator.graphs
- if PRINT_STATISTICS:
+ if config.print_statistics:
print "before optimizations:"
print_statistics(translator.graphs[0], translator, "per-graph.txt")
@@ -41,7 +51,7 @@
simplify.transform_dead_op_vars(graph, translator)
removenoops.remove_duplicate_casts(graph, translator)
- if PRINT_STATISTICS:
+ if config.print_statistics:
print "after no-op removal:"
print_statistics(translator.graphs[0], translator)
@@ -60,7 +70,7 @@
removenoops.remove_superfluous_keep_alive(graph)
removenoops.remove_duplicate_casts(graph, translator)
- if PRINT_STATISTICS:
+ if config.print_statistics:
print "after inlining:"
print_statistics(translator.graphs[0], translator)
@@ -77,14 +87,14 @@
tot += count
log.malloc("removed %d simple mallocs in total" % tot)
- if PRINT_STATISTICS:
+ if config.print_statistics:
print "after malloc removal:"
print_statistics(translator.graphs[0], translator)
else:
assert graphs is translator.graphs # XXX for now
clever_inlining_and_malloc_removal(translator)
- if PRINT_STATISTICS:
+ if config.print_statistics:
print "after clever inlining and malloc removal"
print_statistics(translator.graphs[0], translator)
@@ -104,7 +114,7 @@
for graph in graphs:
merge_if_blocks(graph)
- if PRINT_STATISTICS:
+ if config.print_statistics:
print "after if-to-switch:"
print_statistics(translator.graphs[0], translator)
Modified: pypy/branch/even-more-config4/pypy/translator/c/database.py
==============================================================================
--- pypy/branch/even-more-config4/pypy/translator/c/database.py (original)
+++ pypy/branch/even-more-config4/pypy/translator/c/database.py Tue Oct 24 22:18:14 2006
@@ -15,17 +15,25 @@
from pypy.translator.c.support import log
from pypy.translator.c.extfunc import do_the_getting
from pypy import conftest
+from pypy.translator.c import gc
+
# ____________________________________________________________
class LowLevelDatabase(object):
- stacklesstransformer = None
gctransformer = None
- def __init__(self, translator=None, standalone=False, gcpolicy=None, thread_enabled=False):
+ def __init__(self, translator=None, standalone=False,
+ gcpolicyclass=None,
+ stacklesstransformer=None,
+ thread_enabled=False):
self.translator = translator
self.standalone = standalone
- self.thread_enabled = thread_enabled
+ self.stacklesstransformer = stacklesstransformer
+ if gcpolicyclass is None:
+ gcpolicyclass = gc.RefcountingGcPolicy
+ self.gcpolicy = gcpolicyclass(self, thread_enabled)
+
self.structdefnodes = {}
self.pendingsetupnodes = []
self.containernodes = {}
@@ -46,31 +54,12 @@
from pypy.translator.c.pyobj import PyObjMaker
self.pyobjmaker = PyObjMaker(self.namespace, self, translator)
- gcpolicy = gcpolicy or conftest.option.gcpolicy or 'ref'
- if isinstance(gcpolicy, str):
- from pypy.translator.c import gc
- polname = gcpolicy
- if polname == 'boehm':
- gcpolicy = gc.BoehmGcPolicy
- elif polname == 'exact_boehm':
- gcpolicy = gc.MoreExactBoehmGcPolicy
- elif polname == 'ref':
- gcpolicy = gc.RefcountingGcPolicy
- elif polname == 'none':
- gcpolicy = gc.NoneGcPolicy
- elif polname == 'framework':
- gcpolicy = gc.FrameworkGcPolicy
- elif polname == 'stacklessgc':
- gcpolicy = gc.StacklessFrameworkGcPolicy
- else:
- assert False, "unknown gc policy %r"%polname
if translator is None or translator.rtyper is None:
self.exctransformer = None
else:
self.exctransformer = translator.getexceptiontransformer()
- self.gcpolicy = gcpolicy(self, thread_enabled)
if translator is not None:
- self.gctransformer = gcpolicy.transformerclass(translator)
+ self.gctransformer = self.gcpolicy.transformerclass(translator)
self.completed = False
def gettypedefnode(self, T, varlength=1):
Modified: pypy/branch/even-more-config4/pypy/translator/c/gc.py
==============================================================================
--- pypy/branch/even-more-config4/pypy/translator/c/gc.py (original)
+++ pypy/branch/even-more-config4/pypy/translator/c/gc.py Tue Oct 24 22:18:14 2006
@@ -427,3 +427,15 @@
class StacklessFrameworkGcPolicy(FrameworkGcPolicy):
transformerclass = stacklessframework.StacklessFrameworkGCTransformer
requires_stackless = True
+
+
+name_to_gcpolicy = {
+ 'boehm': BoehmGcPolicy,
+ 'exact_boehm': MoreExactBoehmGcPolicy,
+ 'ref': RefcountingGcPolicy,
+ 'none': NoneGcPolicy,
+ 'framework': FrameworkGcPolicy,
+ 'stacklessgc': StacklessFrameworkGcPolicy,
+}
+
+
Modified: pypy/branch/even-more-config4/pypy/translator/c/genc.py
==============================================================================
--- pypy/branch/even-more-config4/pypy/translator/c/genc.py (original)
+++ pypy/branch/even-more-config4/pypy/translator/c/genc.py Tue Oct 24 22:18:14 2006
@@ -14,20 +14,27 @@
from pypy.translator.locality.calltree import CallTree
from pypy.translator.c.support import log, c_string_constant
from pypy.rpython.typesystem import getfunctionptr
+from pypy.translator.c import gc
class CBuilder(object):
c_source_filename = None
_compiled = False
symboltable = None
- stackless = False
modulename = None
- def __init__(self, translator, entrypoint, gcpolicy=None, libraries=None, thread_enabled=False):
+ def __init__(self, translator, entrypoint, config=None, libraries=None,
+ gcpolicy=None):
self.translator = translator
self.entrypoint = entrypoint
self.originalentrypoint = entrypoint
self.gcpolicy = gcpolicy
- self.thread_enabled = thread_enabled
+ if config is None:
+ from pypy.config.config import Config
+ from pypy.config.pypyoption import pypy_optiondescription
+ config = Config(pypy_optiondescription)
+ if gcpolicy is not None and gcpolicy.requires_stackless:
+ config.translation.stackless = True
+ self.config = config
if libraries is None:
libraries = []
@@ -36,23 +43,25 @@
def build_database(self, exports=[], pyobj_options=None):
translator = self.translator
- db = LowLevelDatabase(translator, standalone=self.standalone,
- gcpolicy=self.gcpolicy, thread_enabled=self.thread_enabled)
- assert self.stackless in (False, 'old', True)
- if db.gcpolicy.requires_stackless:
- assert self.stackless != 'old' # incompatible
- self.stackless = True
- if self.stackless:
+ gcpolicyclass = self.get_gcpolicyclass()
+
+ if self.config.translation.stackless:
if not self.standalone:
raise Exception("stackless: only for stand-alone builds")
-
+
from pypy.translator.stackless.transform import StacklessTransformer
- db.stacklesstransformer = StacklessTransformer(translator,
- self.originalentrypoint,
- db.gcpolicy.requires_stackless)
- self.entrypoint = db.stacklesstransformer.slp_entry_point
+ stacklesstransformer = StacklessTransformer(
+ translator, self.originalentrypoint,
+ stackless_gc=gcpolicyclass.requires_stackless)
+ self.entrypoint = stacklesstransformer.slp_entry_point
+ else:
+ stacklesstransformer = None
+ db = LowLevelDatabase(translator, standalone=self.standalone,
+ gcpolicyclass=gcpolicyclass,
+ stacklesstransformer=stacklesstransformer,
+ thread_enabled=self.config.translation.thread)
# pass extra options into pyobjmaker
if pyobj_options:
for key, value in pyobj_options.items():
@@ -97,6 +106,12 @@
have___thread = None
+
+ def get_gcpolicyclass(self):
+ if self.gcpolicy is None:
+ return gc.name_to_gcpolicy[self.config.translation.gc]
+ return self.gcpolicy
+
def generate_source(self, db=None, defines={}):
assert self.c_source_filename is None
translator = self.translator
@@ -112,12 +127,14 @@
targetdir = udir.ensure(modulename, dir=1)
self.targetdir = targetdir
defines = defines.copy()
- # defines={'COUNT_OP_MALLOCS': 1}
+ if self.config.translation.countmallocs:
+ defines['COUNT_OP_MALLOCS'] = 1
if CBuilder.have___thread is None:
CBuilder.have___thread = check_under_under_thread()
if not self.standalone:
from pypy.translator.c.symboltable import SymbolTable
- self.symboltable = SymbolTable()
+ # XXX fix symboltable
+ #self.symboltable = SymbolTable()
cfile, extra = gen_source(db, modulename, targetdir,
defines = defines,
exports = self.exports,
@@ -125,9 +142,6 @@
else:
if CBuilder.have___thread:
defines['HAVE___THREAD'] = 1
- if self.stackless == 'old':
- defines['USE_STACKLESS'] = '1'
- defines['USE_OPTIMIZED_STACKLESS_UNWIND'] = '1'
cfile, extra = gen_source_standalone(db, modulename, targetdir,
entrypointname = pfname,
defines = defines)
@@ -135,7 +149,7 @@
self.extrafiles = extra
if self.standalone:
self.gen_makefile(targetdir)
- return cfile
+ return cfile
def generate_graphs_for_llinterp(self, db=None):
# prepare the graphs as when the source is generated, but without
@@ -282,7 +296,10 @@
print >> f
print >> f, 'CFLAGS =', ' '.join(compiler.compile_extra)
print >> f, 'LDFLAGS =', ' '.join(compiler.link_extra)
- print >> f, 'TFLAGS = ' + ('', '-pthread')[self.thread_enabled]
+ if self.config.translation.thread:
+ print >> f, 'TFLAGS = ' + '-pthread'
+ else:
+ print >> f, 'TFLAGS = ' + ''
print >> f, 'PROFOPT = ' + profopt
print >> f, 'CC = ' + cc
print >> f
@@ -624,10 +641,6 @@
sg.set_strategy(targetdir)
sg.gen_readable_parts_of_source(f)
- # 2bis) old-style stackless data
- if hasattr(database, 'stacklessdata'):
- database.stacklessdata.writefiles(sg)
-
# 3) start-up code
print >> f
gen_startupcode(f, database)
Modified: pypy/branch/even-more-config4/pypy/translator/c/src/g_include.h
==============================================================================
--- pypy/branch/even-more-config4/pypy/translator/c/src/g_include.h (original)
+++ pypy/branch/even-more-config4/pypy/translator/c/src/g_include.h Tue Oct 24 22:18:14 2006
@@ -40,7 +40,6 @@
# ifdef RPyExc_thread_error
# include "src/ll_thread.h"
# endif
-# include "src/ll_stackless.h"
# include "src/ll__socket.h"
#endif
Modified: pypy/branch/even-more-config4/pypy/translator/c/test/test_backendoptimized.py
==============================================================================
--- pypy/branch/even-more-config4/pypy/translator/c/test/test_backendoptimized.py (original)
+++ pypy/branch/even-more-config4/pypy/translator/c/test/test_backendoptimized.py Tue Oct 24 22:18:14 2006
@@ -15,12 +15,12 @@
t.view()
def test_remove_same_as(self):
- def f(n=bool):
+ def f(n):
if bool(bool(bool(n))):
return 123
else:
return 456
- fn = self.getcompiled(f)
+ fn = self.getcompiled(f, [bool])
assert f(True) == 123
assert f(False) == 456
@@ -39,13 +39,13 @@
def __del__(self):
b.num_deleted += 1
- def f(x=int):
+ def f(x):
a = A()
for i in range(x):
a = A()
return b.num_deleted
- fn = self.getcompiled(f)
+ fn = self.getcompiled(f, [int])
res = f(5)
assert res == 5
res = fn(5)
@@ -66,7 +66,7 @@
s.b_dels += 1
class C(A):
pass
- def f(x=int):
+ def f(x):
A()
B()
C()
@@ -77,7 +77,7 @@
return s.a_dels * 10 + s.b_dels
else:
return -1
- fn = self.getcompiled(f)
+ fn = self.getcompiled(f, [int])
res = f(1)
assert res == 42
res = fn(1)
@@ -92,7 +92,7 @@
backend_optimizations(t, merge_if_blocks_to_switch=True)
def test_int_switch(self):
- def f(x=int):
+ def f(x):
if x == 3:
return 9
elif x == 9:
@@ -101,12 +101,12 @@
return 3
return 0
codegenerator = self.CodeGenerator()
- fn = codegenerator.getcompiled(f)
+ fn = codegenerator.getcompiled(f, [int])
for x in (0,1,2,3,9,27,48, -9):
assert fn(x) == f(x)
def test_uint_switch(self):
- def f(x=r_uint):
+ def f(x):
if x == r_uint(3):
return 9
elif x == r_uint(9):
@@ -115,12 +115,12 @@
return 3
return 0
codegenerator = self.CodeGenerator()
- fn = codegenerator.getcompiled(f)
+ fn = codegenerator.getcompiled(f, [r_uint])
for x in (0,1,2,3,9,27,48):
assert fn(x) == f(x)
def test_longlong_switch(self):
- def f(x=r_longlong):
+ def f(x):
if x == r_longlong(3):
return 9
elif x == r_longlong(9):
@@ -129,12 +129,12 @@
return 3
return 0
codegenerator = self.CodeGenerator()
- fn = codegenerator.getcompiled(f)
+ fn = codegenerator.getcompiled(f, [r_longlong])
for x in (0,1,2,3,9,27,48, -9):
assert fn(x) == f(x)
def test_ulonglong_switch(self):
- def f(x=r_ulonglong):
+ def f(x):
if x == r_ulonglong(3):
return 9
elif x == r_ulonglong(9):
@@ -143,12 +143,12 @@
return 3
return 0
codegenerator = self.CodeGenerator()
- fn = codegenerator.getcompiled(f)
+ fn = codegenerator.getcompiled(f, [r_ulonglong])
for x in (0,1,2,3,9,27,48, -9):
assert fn(x) == f(x)
def test_chr_switch(self):
- def f(y=int):
+ def f(y):
x = chr(y)
if x == 'a':
return 'b'
@@ -158,13 +158,13 @@
return 'd'
return '@'
codegenerator = self.CodeGenerator()
- fn = codegenerator.getcompiled(f)
+ fn = codegenerator.getcompiled(f, [int])
for x in 'ABCabc@':
y = ord(x)
assert fn(y) == f(y)
def test_unichr_switch(self):
- def f(y=int):
+ def f(y):
x = unichr(y)
if x == u'a':
return 'b'
@@ -174,7 +174,7 @@
return 'd'
return '@'
codegenerator = self.CodeGenerator()
- fn = codegenerator.getcompiled(f)
+ fn = codegenerator.getcompiled(f, [int])
for x in u'ABCabc@':
y = ord(x)
assert fn(y) == f(y)
@@ -219,13 +219,13 @@
backend_optimizations(t, raisingop2direct_call_all=True)
def test_int_floordiv_zer(self):
- def f(x=int):
+ def f(x):
try:
y = 123 / x
except:
y = 456
return y
codegenerator = self.CodeGenerator()
- fn = codegenerator.getcompiled(f)
+ fn = codegenerator.getcompiled(f, [int])
for x in (0,1,2,3,9,27,48, -9):
assert fn(x) == f(x)
Modified: pypy/branch/even-more-config4/pypy/translator/c/test/test_boehm.py
==============================================================================
--- pypy/branch/even-more-config4/pypy/translator/c/test/test_boehm.py (original)
+++ pypy/branch/even-more-config4/pypy/translator/c/test/test_boehm.py Tue Oct 24 22:18:14 2006
@@ -3,13 +3,15 @@
from pypy.translator.tool.cbuild import check_boehm_presence
from pypy.translator.c.genc import CExtModuleBuilder
from pypy import conftest
+from pypy.config.config import Config
+from pypy.config.pypyoption import pypy_optiondescription
def setup_module(mod):
if not check_boehm_presence():
py.test.skip("Boehm GC not present")
class AbstractGCTestClass:
- from pypy.translator.c.gc import BoehmGcPolicy as gcpolicy
+ gcpolicy = "boehm"
# deal with cleanups
def setup_method(self, meth):
@@ -21,14 +23,17 @@
def getcompiled(self, func, argstypelist = [],
annotatorpolicy=None):
- t = TranslationContext(simplifying=True)
+ config = Config(pypy_optiondescription)
+ config.translation.gc = self.gcpolicy
+ config.translation.simplifying = True
+ t = TranslationContext(config=config)
self.t = t
a = t.buildannotator(policy=annotatorpolicy)
a.build_types(func, argstypelist)
t.buildrtyper().specialize()
t.checkgraphs()
def compile():
- cbuilder = CExtModuleBuilder(t, func, gcpolicy=self.gcpolicy)
+ cbuilder = CExtModuleBuilder(t, func, config=config)
c_source_filename = cbuilder.generate_source()
if conftest.option.view:
t.view()
@@ -40,6 +45,7 @@
class TestUsingBoehm(AbstractGCTestClass):
+ gcpolicy = "boehm"
def test_malloc_a_lot(self):
def malloc_a_lot():
@@ -135,7 +141,7 @@
s = State()
s.dels = 0
def g():
- a = A()
+ a = A()
def f():
s.dels = 0
for i in range(10):
@@ -173,6 +179,6 @@
class TestUsingExactBoehm(TestUsingBoehm):
- from pypy.translator.c.gc import MoreExactBoehmGcPolicy as gcpolicy
+ gcpolicy = "exact_boehm"
Modified: pypy/branch/even-more-config4/pypy/translator/c/test/test_exception.py
==============================================================================
--- pypy/branch/even-more-config4/pypy/translator/c/test/test_exception.py (original)
+++ pypy/branch/even-more-config4/pypy/translator/c/test/test_exception.py Tue Oct 24 22:18:14 2006
@@ -20,7 +20,7 @@
raise MyException()
else:
return 3
- def fn(i=int):
+ def fn(i):
try:
a = raise_(i) + 11
b = raise_(i) + 12
@@ -33,19 +33,19 @@
except:
return 22
return 66
- f = getcompiled(fn)
+ f = getcompiled(fn, [int])
assert f(0) == fn(0)
assert f(1) == fn(1)
assert f(2) == fn(2)
def test_implicit_index_error_lists():
- def fn(n=int):
+ def fn(n):
lst = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
try:
return lst[n]
except:
return 2
- f = getcompiled(fn)
+ f = getcompiled(fn, [int])
assert f(-1) == fn(-1)
assert f( 0) == fn( 0)
assert f(10) == fn(10)
@@ -64,12 +64,12 @@
assert f1() == 5
def test_raise_outside_testfn():
- def testfn(n=int):
+ def testfn(n):
if n < 0:
raise ValueError("hello")
else:
raise MyException("world")
- f1 = getcompiled(testfn)
+ f1 = getcompiled(testfn, [int])
assert py.test.raises(ValueError, f1, -1)
try:
f1(1)
@@ -99,7 +99,7 @@
s = lltype.malloc(S, n)
tag.a = 42
return s
- def testfn(n=int):
+ def testfn(n):
tag = lltype.malloc(S, 0)
try:
s = g(n, tag)
@@ -107,7 +107,7 @@
except MemoryError:
result = 1000
return result + tag.a
- f1 = getcompiled(testfn)
+ f1 = getcompiled(testfn, [int])
assert f1(10) == 42
assert f1(sys.maxint) == 1000
for i in range(20):
@@ -116,14 +116,14 @@
assert f1(sys.maxint // 2 + 16384) == 1000
def test_assert():
- def testfn(n=int):
+ def testfn(n):
assert n >= 0
# big confusion with py.test's AssertionError handling here...
# some hacks to try to disable it for the current test.
saved = no_magic()
try:
- f1 = getcompiled(testfn)
+ f1 = getcompiled(testfn, [int])
res = f1(0)
assert res is None, repr(res)
res = f1(42)
Modified: pypy/branch/even-more-config4/pypy/translator/c/test/test_exceptiontransform.py
==============================================================================
--- pypy/branch/even-more-config4/pypy/translator/c/test/test_exceptiontransform.py (original)
+++ pypy/branch/even-more-config4/pypy/translator/c/test/test_exceptiontransform.py Tue Oct 24 22:18:14 2006
@@ -4,6 +4,7 @@
from pypy.translator.c import exceptiontransform, genc, gc
from pypy.objspace.flow.model import c_last_exception
from pypy.rpython.test.test_llinterp import get_interpreter
+from pypy.translator.c.test.test_genc import compile
from pypy import conftest
import sys
@@ -39,20 +40,6 @@
_already_transformed[t] = True
return interp.eval_graph(graph, values)
-def compile_func(fn, inputtypes):
- t = TranslationContext()
- t.buildannotator().build_types(fn, inputtypes)
- t.buildrtyper().specialize()
-## etrafo = exceptiontransform.ExceptionTransformer(t)
-## etrafo.transform_completely()
- builder = genc.CExtModuleBuilder(t, fn, gcpolicy=gc.RefcountingGcPolicy)
- builder.generate_source()
- builder.compile()
- builder.import_module()
- if conftest.option.view:
- t.view()
- return builder.get_entry_point()
-
def test_simple():
def one():
return 1
@@ -65,7 +52,7 @@
assert len(list(g.iterblocks())) == 2 # graph does not change
result = interpret(foo, [])
assert result == 1
- f = compile_func(foo, [])
+ f = compile(foo, [])
assert f() == 1
def test_passthrough():
@@ -77,7 +64,7 @@
one(0)
one(1)
t, g = transform_func(foo, [])
- f = compile_func(foo, [])
+ f = compile(foo, [])
py.test.raises(ValueError, f)
def test_catches():
@@ -101,7 +88,7 @@
return 4 + x
t, g = transform_func(foo, [int])
assert len(list(g.iterblocks())) == 9
- f = compile_func(foo, [int])
+ f = compile(foo, [int])
result = interpret(foo, [6])
assert result == 2
result = f(6)
@@ -132,7 +119,7 @@
return 4 + x
t, g = transform_func(foo, [int])
assert len(list(g.iterblocks())) == 5
- f = compile_func(foo, [int])
+ f = compile(foo, [int])
result = interpret(foo, [6])
assert result == 2
result = f(6)
@@ -152,7 +139,7 @@
raise ValueError()
t, g = transform_func(foo, [int])
assert len(list(g.iterblocks())) == 3
- f = compile_func(foo, [int])
+ f = compile(foo, [int])
f(0)
py.test.raises(ValueError, f, 1)
@@ -172,7 +159,7 @@
y.z = 42
r = can_raise(n)
return r + y.z
- f = compile_func(foo, [int])
+ f = compile(foo, [int])
res = f(0)
assert res == 43
Modified: pypy/branch/even-more-config4/pypy/translator/c/test/test_genc.py
==============================================================================
--- pypy/branch/even-more-config4/pypy/translator/c/test/test_genc.py (original)
+++ pypy/branch/even-more-config4/pypy/translator/c/test/test_genc.py Tue Oct 24 22:18:14 2006
@@ -12,6 +12,7 @@
from pypy.translator.tool.cbuild import enable_fast_compilation
from pypy.translator.gensupp import uniquemodulename
from pypy.translator.backendopt.all import backend_optimizations
+from pypy.translator.interactive import Translation
from pypy import conftest
# XXX this tries to make compiling faster for full-scale testing
@@ -19,7 +20,6 @@
#from pypy.translator.tool import cbuild
#cbuild.enable_fast_compilation()
-
def compile_db(db):
enable_fast_compilation() # for testing
modulename = uniquemodulename('testing')
@@ -30,21 +30,18 @@
libraries = db.gcpolicy.gc_libraries())
return m
-def compile(fn, argtypes, view=False, gcpolicy=None, backendopt=True,
+def compile(fn, argtypes, view=False, gcpolicy="ref", backendopt=True,
annotatorpolicy=None):
- t = TranslationContext()
- a = t.buildannotator(policy=annotatorpolicy)
- a.build_types(fn, argtypes)
- t.buildrtyper().specialize()
- if backendopt:
- backend_optimizations(t)
- db = LowLevelDatabase(t, gcpolicy=gcpolicy)
- entrypoint = db.get(pyobjectptr(fn))
- db.complete()
- module = compile_db(db)
- if view or conftest.option.view:
- t.view()
- compiled_fn = getattr(module, entrypoint)
+ t = Translation(fn, argtypes, gc=gcpolicy, backend="c",
+ policy=annotatorpolicy)
+ if not backendopt:
+ t.disable(["backendopt_lltype"])
+ t.annotate()
+ # XXX fish
+ t.driver.config.translation.countmallocs = True
+ compiled_fn = t.compile_c()
+ # XXX fish fish fish some more
+ module = t.driver.cbuilder.c_ext_module
def checking_fn(*args, **kwds):
if 'expected_extra_mallocs' in kwds:
expected_extra_mallocs = kwds.pop('expected_extra_mallocs')
Modified: pypy/branch/even-more-config4/pypy/translator/c/test/test_lltyped.py
==============================================================================
--- pypy/branch/even-more-config4/pypy/translator/c/test/test_lltyped.py (original)
+++ pypy/branch/even-more-config4/pypy/translator/c/test/test_lltyped.py Tue Oct 24 22:18:14 2006
@@ -101,13 +101,13 @@
s.a1 = malloc(A, immortal=True)
s.a1[2].x = 50
s.a2[2].x = 60
- def llf(n=int):
+ def llf(n):
if n == 1:
a = s.a1
else:
a = s.a2
return a[2].x
- fn = self.getcompiled(llf)
+ fn = self.getcompiled(llf, [int])
res = fn(1)
assert res == 50
res = fn(2)
@@ -119,12 +119,12 @@
A.become(FixedSizeArray(Struct('s1', ('f', Ptr(F)), ('n', Signed)), 5))
a = malloc(A, immortal=True)
a[3].n = 42
- def llf(n=int):
+ def llf(n):
if a[n].f:
return a[n].f(a)
else:
return -1
- fn = self.getcompiled(llf)
+ fn = self.getcompiled(llf, [int])
res = fn(4)
assert res == -1
@@ -139,7 +139,7 @@
b0 = direct_arrayitems(a)
b1 = direct_ptradd(b0, 1)
b2 = direct_ptradd(b1, 1)
- def llf(n=int):
+ def llf(n):
b0 = direct_arrayitems(a)
b3 = direct_ptradd(direct_ptradd(b0, 5), -2)
saved = a[n]
@@ -148,7 +148,7 @@
return b0[0] + b3[-2] + b2[1] + b1[3]
finally:
a[n] = saved
- fn = self.getcompiled(llf)
+ fn = self.getcompiled(llf, [int])
res = fn(0)
assert res == 1000 + 10 + 30 + 40
res = fn(1)
@@ -162,13 +162,13 @@
def test_direct_fieldptr(self):
S = GcStruct('S', ('x', Signed), ('y', Signed))
- def llf(n=int):
+ def llf(n):
s = malloc(S)
a = direct_fieldptr(s, 'y')
a[0] = n
return s.y
- fn = self.getcompiled(llf)
+ fn = self.getcompiled(llf, [int])
res = fn(34)
assert res == 34
@@ -238,17 +238,18 @@
fn = self.getcompiled(llf)
res = fn()
assert res == 27
+ del self.process
def test_union(self):
U = Struct('U', ('s', Signed), ('c', Char),
hints={'union': True})
u = malloc(U, immortal=True)
- def llf(c=int):
+ def llf(c):
u.s = 0x10203040
u.c = chr(c)
return u.s
- fn = self.getcompiled(llf)
+ fn = self.getcompiled(llf, [int])
res = fn(0x33)
assert res in [0x10203033, 0x33203040]
@@ -257,12 +258,12 @@
A = Array(Void)
size1 = llmemory.sizeof(A, 1)
size2 = llmemory.sizeof(A, 14)
- def f(x=int):
+ def f(x):
if x:
return size1
else:
return size2
- fn = self.getcompiled(f)
+ fn = self.getcompiled(f, [int])
res1 = fn(1)
res2 = fn(0)
assert res1 == res2
@@ -279,11 +280,11 @@
def trailing_byte(s):
adr_s = llmemory.cast_ptr_to_adr(s)
return (adr_s + chars_offset).char[len(s)]
- def f(x=int):
+ def f(x):
r = 0
for i in range(x):
r += ord(trailing_byte(' '*(100-x*x)))
return r
- fn = self.getcompiled(f)
+ fn = self.getcompiled(f, [int])
res = fn(10)
assert res == 0
Modified: pypy/branch/even-more-config4/pypy/translator/c/test/test_newgc.py
==============================================================================
--- pypy/branch/even-more-config4/pypy/translator/c/test/test_newgc.py (original)
+++ pypy/branch/even-more-config4/pypy/translator/c/test/test_newgc.py Tue Oct 24 22:18:14 2006
@@ -9,16 +9,19 @@
from pypy.rpython.lltypesystem import lltype, llmemory
from pypy.rpython.lltypesystem.lloperation import llop
from pypy.rpython.objectmodel import cast_weakgcaddress_to_object, cast_object_to_weakgcaddress
-
+from pypy.config.config import Config
+from pypy.config.pypyoption import pypy_optiondescription
from pypy import conftest
-def compile_func(fn, inputtypes, t=None, gcpolicy=gc.RefcountingGcPolicy):
+def compile_func(fn, inputtypes, t=None, gcpolicy="ref"):
+ config = Config(pypy_optiondescription)
+ config.translation.gc = gcpolicy
if t is None:
- t = TranslationContext()
+ t = TranslationContext(config=config)
if inputtypes is not None:
t.buildannotator().build_types(fn, inputtypes)
t.buildrtyper().specialize()
- builder = genc.CExtModuleBuilder(t, fn, gcpolicy=gcpolicy)
+ builder = genc.CExtModuleBuilder(t, fn, config=config)
builder.generate_source(defines={'COUNT_OP_MALLOCS': 1})
builder.compile()
builder.import_module()
@@ -143,7 +146,7 @@
assert fn(0) == 5
def test_del_basic():
- for gcpolicy in [gc.RefcountingGcPolicy]: #, gc.FrameworkGcPolicy]:
+ for gcpolicy in ["ref"]: #, "framework"]:
S = lltype.GcStruct('S', ('x', lltype.Signed))
TRASH = lltype.GcStruct('TRASH', ('x', lltype.Signed))
lltype.attachRuntimeTypeInfo(S)
@@ -399,7 +402,7 @@
from pypy.translator.c.test.test_boehm import AbstractGCTestClass
class TestUsingFramework(AbstractGCTestClass):
- from pypy.translator.c.gc import FrameworkGcPolicy as gcpolicy
+ gcpolicy = "framework"
def test_empty_collect(self):
def f():
@@ -862,7 +865,7 @@
res = fn()
class TestUsingStacklessFramework(TestUsingFramework):
- from pypy.translator.c.gc import StacklessFrameworkGcPolicy as gcpolicy
+ gcpolicy = "stacklessgc"
def getcompiled(self, f):
# XXX quick hack
Modified: pypy/branch/even-more-config4/pypy/translator/c/test/test_stackless.py
==============================================================================
--- pypy/branch/even-more-config4/pypy/translator/c/test/test_stackless.py (original)
+++ pypy/branch/even-more-config4/pypy/translator/c/test/test_stackless.py Tue Oct 24 22:18:14 2006
@@ -5,23 +5,25 @@
from pypy.annotation.listdef import s_list_of_strings
from pypy.rpython.rstack import stack_unwind, stack_frames_depth, stack_too_big
from pypy.rpython.rstack import yield_current_frame_to_caller
+from pypy.config.config import Config
+from pypy.config.pypyoption import pypy_optiondescription
import os
class StacklessTest(object):
backendopt = False
stacklessmode = True
- gcpolicy = gc.BoehmGcPolicy
+ gcpolicy = "boehm"
def setup_class(cls):
import py
- if cls.gcpolicy in (None, gc.RefcountingGcPolicy):
+ if cls.gcpolicy in (None, "ref"):
# to re-enable this, remove the two characters 'gc' in the
# declaregcptrtype(rstack.frame_stack_top,...) call in
# rpython/extfunctable. Doing so breaks translator/stackless/.
import py
py.test.skip("stackless + refcounting doesn't work any more for now")
- elif cls.gcpolicy is gc.BoehmGcPolicy:
+ elif cls.gcpolicy is "boehm":
from pypy.translator.tool.cbuild import check_boehm_presence
if not check_boehm_presence():
py.test.skip("Boehm GC not present")
@@ -31,7 +33,10 @@
os.write(1, str(fn())+"\n")
return 0
- t = TranslationContext()
+ config = Config(pypy_optiondescription)
+ config.translation.gc = self.gcpolicy
+ config.translation.stackless = True
+ t = TranslationContext(config=config)
self.t = t
t.buildannotator().build_types(entry_point, [s_list_of_strings])
t.buildrtyper().specialize()
@@ -41,7 +46,7 @@
from pypy.translator.transform import insert_ll_stackcheck
insert_ll_stackcheck(t)
- cbuilder = CStandaloneBuilder(t, entry_point, gcpolicy=self.gcpolicy)
+ cbuilder = CStandaloneBuilder(t, entry_point, config=config)
cbuilder.stackless = self.stacklessmode
cbuilder.generate_source()
cbuilder.compile()
Modified: pypy/branch/even-more-config4/pypy/translator/c/test/test_symboltable.py
==============================================================================
--- pypy/branch/even-more-config4/pypy/translator/c/test/test_symboltable.py (original)
+++ pypy/branch/even-more-config4/pypy/translator/c/test/test_symboltable.py Tue Oct 24 22:18:14 2006
@@ -1,6 +1,8 @@
+import py
from pypy.translator.c.symboltable import getsymboltable
from pypy.translator.c.test import test_typed
+py.test.skip("XXX symboltable not supported currently")
getcompiled = test_typed.TestTypedTestCase().getcompiled
def test_simple():
Modified: pypy/branch/even-more-config4/pypy/translator/c/test/test_typed.py
==============================================================================
--- pypy/branch/even-more-config4/pypy/translator/c/test/test_typed.py (original)
+++ pypy/branch/even-more-config4/pypy/translator/c/test/test_typed.py Tue Oct 24 22:18:14 2006
@@ -5,27 +5,26 @@
from py.test import raises
from pypy import conftest
-from pypy.translator.test import snippet
+from pypy.translator.test import snippet
from pypy.translator.translator import TranslationContext
from pypy.rpython.rarithmetic import r_uint, r_ulonglong, r_longlong, intmask
+from pypy.config.config import Config
+from pypy.config.pypyoption import pypy_optiondescription
# XXX this tries to make compiling faster for full-scale testing
from pypy.translator.tool import cbuild
cbuild.enable_fast_compilation()
+
class CompilationTestCase:
def annotatefunc(self, func, argtypes=None):
- t = TranslationContext(simplifying=True)
+ config = Config(pypy_optiondescription)
+ config.translation.gc = "ref"
+ config.translation.simplifying = True
+ t = TranslationContext(config=config)
if argtypes is None:
- # builds starting-types from func_defs
- # XXX kill kill kill!
argtypes = []
- if func.func_defaults:
- for spec in func.func_defaults:
- if isinstance(spec, tuple):
- spec = spec[0] # use the first type only for the tests
- argtypes.append(spec)
a = t.buildannotator()
a.build_types(func, argtypes)
a.simplify()
@@ -33,7 +32,7 @@
def compilefunc(self, t, func):
from pypy.translator.c import genc
- builder = genc.CExtModuleBuilder(t, func)
+ builder = genc.CExtModuleBuilder(t, func, config=t.config)
builder.generate_source()
builder.compile()
builder.import_module()
@@ -65,15 +64,15 @@
assert inheritance2() == ((-12, -12), (3, "world"))
def test_factorial2(self):
- factorial2 = self.getcompiled(snippet.factorial2)
+ factorial2 = self.getcompiled(snippet.factorial2, [int])
assert factorial2(5) == 120
def test_factorial(self):
- factorial = self.getcompiled(snippet.factorial)
+ factorial = self.getcompiled(snippet.factorial, [int])
assert factorial(5) == 120
def test_simple_method(self):
- simple_method = self.getcompiled(snippet.simple_method)
+ simple_method = self.getcompiled(snippet.simple_method, [int])
assert simple_method(55) == 55
def test_sieve_of_eratosthenes(self):
@@ -81,19 +80,16 @@
assert sieve_of_eratosthenes() == 1028
def test_nested_whiles(self):
- nested_whiles = self.getcompiled(snippet.nested_whiles)
+ nested_whiles = self.getcompiled(snippet.nested_whiles, [int, int])
assert nested_whiles(5,3) == '!!!!!'
def test_call_five(self):
- call_five = self.getcompiled(snippet.call_five)
+ call_five = self.getcompiled(snippet.call_five, [int])
result = call_five()
assert result == [5]
- # -- currently result isn't a real list, but a pseudo-array
- # that can't be inspected from Python.
- #self.assertEquals(result.__class__.__name__[:8], "list of ")
def test_call_unpack_56(self):
- call_unpack_56 = self.getcompiled(snippet.call_unpack_56)
+ call_unpack_56 = self.getcompiled(snippet.call_unpack_56, [])
result = call_unpack_56()
assert result == (2, 5, 6)
@@ -108,16 +104,16 @@
assert fn() == "hello world"
def test_tuple_repr(self):
- def tuple_repr(x=int, y=object):
+ def tuple_repr(x, y):
z = x, y
while x:
x = x-1
return z
- fn = self.getcompiled(tuple_repr)
+ fn = self.getcompiled(tuple_repr, [int, str])
assert fn(6,'a') == (6,'a')
def test_classattribute(self):
- fn = self.getcompiled(snippet.classattribute)
+ fn = self.getcompiled(snippet.classattribute, [int])
assert fn(1) == 123
assert fn(2) == 456
assert fn(3) == 789
@@ -125,51 +121,41 @@
assert fn(5) == 101112
def test_get_set_del_slice(self):
- fn = self.getcompiled(snippet.get_set_del_slice)
+ fn = self.getcompiled(snippet.get_set_del_slice, [list])
l = list('abcdefghij')
result = fn(l)
assert l == [3, 'c', 8, 11, 'h', 9]
assert result == ([3, 'c'], [9], [11, 'h'])
- def test_slice_long(self):
- def slice_long(l=list, n=long):
- return l[:n]
- fn = self.getcompiled(slice_long)
- l = list('abc')
- result = fn(l, 2**32)
- assert result == list('abc')
- result = fn(l, 2**64)
- assert result == list('abc')
-
def test_type_conversion(self):
# obfuscated test case specially for typer.insert_link_conversions()
- def type_conversion(n=int):
+ def type_conversion(n):
if n > 3:
while n > 0:
n = n-1
if n == 5:
n += 3.1416
return n
- fn = self.getcompiled(type_conversion)
+ fn = self.getcompiled(type_conversion, [int])
assert fn(3) == 3
assert fn(5) == 0
assert abs(fn(7) + 0.8584) < 1E-5
def test_do_try_raise_choose(self):
- fn = self.getcompiled(snippet.try_raise_choose)
+ fn = self.getcompiled(snippet.try_raise_choose, [int])
result = []
for n in [-1,0,1,2]:
result.append(fn(n))
- assert result == [-1,0,1,2]
+ assert result == [-1,0,1,2]
def test_is_perfect_number(self):
- fn = self.getcompiled(snippet.is_perfect_number)
+ fn = self.getcompiled(snippet.is_perfect_number, [int])
for i in range(1, 33):
perfect = fn(i)
assert perfect is (i in (6,28))
def test_prime(self):
- fn = self.getcompiled(snippet.prime)
+ fn = self.getcompiled(snippet.prime, [int])
result = [fn(i) for i in range(1, 21)]
assert result == [False, True, True, False, True, False, True, False,
False, False, True, False, True, False, False, False,
@@ -178,7 +164,7 @@
def test_mutate_global(self):
class Stuff:
pass
- g1 = Stuff(); g1.value = 1
+ g1 = Stuff(); g1.value = 1
g2 = Stuff(); g2.value = 2
g3 = Stuff(); g3.value = 3
g1.next = g3
@@ -193,88 +179,88 @@
assert fn() == 1
def test_float_ops(self):
- def f(x=float):
+ def f(x):
return abs((-x) ** 3 + 1)
- fn = self.getcompiled(f)
+ fn = self.getcompiled(f, [float])
assert fn(-4.5) == 92.125
assert fn(4.5) == 90.125
def test_memoryerror(self):
- def f(i=int):
+ def f(i):
lst = [0]*i
lst[-1] = 5
return lst[0]
- fn = self.getcompiled(f)
+ fn = self.getcompiled(f, [int])
assert fn(1) == 5
assert fn(2) == 0
py.test.raises(MemoryError, fn, sys.maxint//2+1)
py.test.raises(MemoryError, fn, sys.maxint)
def test_chr(self):
- def f(x=int):
+ def f(x):
try:
return 'Yes ' + chr(x)
except ValueError:
return 'No'
- fn = self.getcompiled(f)
+ fn = self.getcompiled(f, [int])
assert fn(65) == 'Yes A'
assert fn(256) == 'No'
assert fn(-1) == 'No'
def test_unichr(self):
- def f(x=int):
+ def f(x):
try:
return ord(unichr(x))
except ValueError:
return -42
- fn = self.getcompiled(f)
+ fn = self.getcompiled(f, [int])
assert fn(65) == 65
assert fn(-12) == -42
assert fn(sys.maxint) == -42
def test_list_indexerror(self):
- def f(i=int):
+ def f(i):
lst = [123, 456]
try:
lst[i] = 789
except IndexError:
return 42
return lst[0]
- fn = self.getcompiled(f)
+ fn = self.getcompiled(f, [int])
assert fn(1) == 123
assert fn(2) == 42
assert fn(-2) == 789
assert fn(-3) == 42
def test_long_long(self):
- def f(i=r_ulonglong):
+ def f(i):
return 4*i
- fn = self.getcompiled(f, view=False)
+ fn = self.getcompiled(f, [r_ulonglong], view=False)
assert fn(sys.maxint) == 4*sys.maxint
- def g(i=r_longlong):
+ def g(i):
return 4*i
- gn = self.getcompiled(g, view=False)
+ gn = self.getcompiled(g, [r_longlong], view=False)
assert gn(sys.maxint) == 4*sys.maxint
def test_specializing_int_functions(self):
def f(i):
return i + 1
f._annspecialcase_ = "specialize:argtype(0)"
- def g(n=int):
+ def g(n):
if n > 0:
return f(r_longlong(0))
else:
return f(0)
- fn = self.getcompiled(g)
+ fn = self.getcompiled(g, [int])
assert g(0) == 1
assert g(1) == 1
def test_downcast_int(self):
- def f(i=r_longlong):
+ def f(i):
return int(i)
- fn = self.getcompiled(f)
+ fn = self.getcompiled(f, [r_longlong])
assert fn(0) == 0
def test_function_ptr(self):
@@ -282,13 +268,13 @@
return 1
def f2():
return 2
- def g(i=int):
+ def g(i):
if i:
f = f1
else:
f = f2
return f()
- fn = self.getcompiled(g)
+ fn = self.getcompiled(g, [int])
assert fn(0) == 2
assert fn(1) == 1
@@ -346,92 +332,92 @@
assert result is False
def test_str_compare(self):
- def testfn(i=int, j=int):
+ def testfn(i, j):
s1 = ['one', 'two']
s2 = ['one', 'two', 'o', 'on', 'twos', 'foobar']
return s1[i] == s2[j]
- fn = self.getcompiled(testfn)
+ fn = self.getcompiled(testfn, [int, int])
for i in range(2):
for j in range(6):
res = fn(i, j)
assert res is testfn(i, j)
- def testfn(i=int, j=int):
+ def testfn(i, j):
s1 = ['one', 'two']
s2 = ['one', 'two', 'o', 'on', 'twos', 'foobar']
return s1[i] != s2[j]
- fn = self.getcompiled(testfn)
+ fn = self.getcompiled(testfn, [int, int])
for i in range(2):
for j in range(6):
res = fn(i, j)
assert res is testfn(i, j)
- def testfn(i=int, j=int):
+ def testfn(i, j):
s1 = ['one', 'two']
s2 = ['one', 'two', 'o', 'on', 'twos', 'foobar']
return s1[i] < s2[j]
- fn = self.getcompiled(testfn)
+ fn = self.getcompiled(testfn, [int, int])
for i in range(2):
for j in range(6):
res = fn(i, j)
assert res is testfn(i, j)
- def testfn(i=int, j=int):
+ def testfn(i, j):
s1 = ['one', 'two']
s2 = ['one', 'two', 'o', 'on', 'twos', 'foobar']
return s1[i] <= s2[j]
- fn = self.getcompiled(testfn)
+ fn = self.getcompiled(testfn, [int, int])
for i in range(2):
for j in range(6):
res = fn(i, j)
assert res is testfn(i, j)
- def testfn(i=int, j=int):
+ def testfn(i, j):
s1 = ['one', 'two']
s2 = ['one', 'two', 'o', 'on', 'twos', 'foobar']
return s1[i] > s2[j]
- fn = self.getcompiled(testfn)
+ fn = self.getcompiled(testfn, [int, int])
for i in range(2):
for j in range(6):
res = fn(i, j)
assert res is testfn(i, j)
- def testfn(i=int, j=int):
+ def testfn(i, j):
s1 = ['one', 'two']
s2 = ['one', 'two', 'o', 'on', 'twos', 'foobar']
return s1[i] >= s2[j]
- fn = self.getcompiled(testfn)
+ fn = self.getcompiled(testfn, [int, int])
for i in range(2):
for j in range(6):
res = fn(i, j)
assert res is testfn(i, j)
def test_str_methods(self):
- def testfn(i=int, j=int):
+ def testfn(i, j):
s1 = ['one', 'two']
s2 = ['one', 'two', 'o', 'on', 'ne', 'e', 'twos', 'foobar', 'fortytwo']
return s1[i].startswith(s2[j])
- fn = self.getcompiled(testfn)
+ fn = self.getcompiled(testfn, [int, int])
for i in range(2):
for j in range(9):
res = fn(i, j)
assert res is testfn(i, j)
- def testfn(i=int, j=int):
+ def testfn(i, j):
s1 = ['one', 'two']
s2 = ['one', 'two', 'o', 'on', 'ne', 'e', 'twos', 'foobar', 'fortytwo']
return s1[i].endswith(s2[j])
- fn = self.getcompiled(testfn)
+ fn = self.getcompiled(testfn, [int, int])
for i in range(2):
for j in range(9):
res = fn(i, j)
assert res is testfn(i, j)
def test_str_join(self):
- def testfn(i=int, j=int):
+ def testfn(i, j):
s1 = [ '', ',', ' and ']
s2 = [ [], ['foo'], ['bar', 'baz', 'bazz']]
return s1[i].join(s2[j])
- fn = self.getcompiled(testfn)
+ fn = self.getcompiled(testfn, [int, int])
for i in range(3):
for j in range(3):
res = fn(i, j)
@@ -439,9 +425,9 @@
def test_unichr_eq(self):
l = list(u'Hello world')
- def f(i=int,j=int):
+ def f(i, j):
return l[i] == l[j]
- fn = self.getcompiled(f)
+ fn = self.getcompiled(f, [int, int])
for i in range(len(l)):
for j in range(len(l)):
res = fn(i,j)
@@ -449,9 +435,9 @@
def test_unichr_ne(self):
l = list(u'Hello world')
- def f(i=int,j=int):
+ def f(i, j):
return l[i] != l[j]
- fn = self.getcompiled(f)
+ fn = self.getcompiled(f, [int, int])
for i in range(len(l)):
for j in range(len(l)):
res = fn(i,j)
@@ -459,37 +445,34 @@
def test_unichr_ord(self):
l = list(u'Hello world')
- def f(i=int):
- return ord(l[i])
- fn = self.getcompiled(f)
+ def f(i):
+ return ord(l[i])
+ fn = self.getcompiled(f, [int])
for i in range(len(l)):
res = fn(i)
assert res == f(i)
def test_unichr_unichr(self):
l = list(u'Hello world')
- def f(i=int, j=int):
+ def f(i, j):
return l[i] == unichr(j)
- fn = self.getcompiled(f)
+ fn = self.getcompiled(f, [int, int])
for i in range(len(l)):
for j in range(len(l)):
res = fn(i, ord(l[j]))
assert res == f(i, ord(l[j]))
- def test_slice_long(self):
- "the parent's test_slice_long() makes no sense here"
-
def test_int_overflow(self):
- fn = self.getcompiled(snippet.add_func)
+ fn = self.getcompiled(snippet.add_func, [int])
raises(OverflowError, fn, sys.maxint)
def test_int_floordiv_ovf_zer(self):
- fn = self.getcompiled(snippet.div_func)
+ fn = self.getcompiled(snippet.div_func, [int])
raises(OverflowError, fn, -1)
raises(ZeroDivisionError, fn, 0)
def test_int_mul_ovf(self):
- fn = self.getcompiled(snippet.mul_func)
+ fn = self.getcompiled(snippet.mul_func, [int, int])
for y in range(-5, 5):
for x in range(-5, 5):
assert fn(x, y) == snippet.mul_func(x, y)
@@ -499,38 +482,38 @@
raises(OverflowError, fn, n, 5)
def test_int_mod_ovf_zer(self):
- fn = self.getcompiled(snippet.mod_func)
+ fn = self.getcompiled(snippet.mod_func, [int])
raises(OverflowError, fn, -1)
raises(ZeroDivisionError, fn, 0)
def test_int_rshift_val(self):
- fn = self.getcompiled(snippet.rshift_func)
+ fn = self.getcompiled(snippet.rshift_func, [int])
raises(ValueError, fn, -1)
def test_int_lshift_ovf_val(self):
- fn = self.getcompiled(snippet.lshift_func)
+ fn = self.getcompiled(snippet.lshift_func, [int])
raises(ValueError, fn, -1)
raises(OverflowError, fn, 1)
def test_int_unary_ovf(self):
- fn = self.getcompiled(snippet.unary_func)
+ fn = self.getcompiled(snippet.unary_func, [int])
for i in range(-3,3):
assert fn(i) == (-(i), abs(i-1))
raises (OverflowError, fn, -sys.maxint-1)
raises (OverflowError, fn, -sys.maxint)
# floats
- def test_float_operations(self):
+ def test_float_operations(self):
import math
- def func(x=float, y=float):
- z = x + y / 2.1 * x
+ def func(x, y):
+ z = x + y / 2.1 * x
z = math.fmod(z, 60.0)
z = pow(z, 2)
z = -z
- return int(z)
+ return int(z)
- fn = self.getcompiled(func)
- assert fn(5.0, 6.0) == func(5.0, 6.0)
+ fn = self.getcompiled(func, [float, float])
+ assert fn(5.0, 6.0) == func(5.0, 6.0)
def test_rpbc_bound_method_static_call(self):
class R:
@@ -555,39 +538,39 @@
def test_stringformatting(self):
- def fn(i=int):
+ def fn(i):
return "you said %d, you did"%i
- f = self.getcompiled(fn)
+ f = self.getcompiled(fn, [int])
assert f(1) == fn(1)
def test_int2str(self):
- def fn(i=int):
+ def fn(i):
return str(i)
- f = self.getcompiled(fn)
+ f = self.getcompiled(fn, [int])
assert f(1) == fn(1)
def test_float2str(self):
- def fn(i=float):
+ def fn(i):
return str(i)
- f = self.getcompiled(fn)
+ f = self.getcompiled(fn, [float])
res = f(1.0)
assert type(res) is str and float(res) == 1.0
def test_uint_arith(self):
- def fn(i=r_uint):
+ def fn(i):
try:
return ~(i*(i+1))/(i-1)
except ZeroDivisionError:
return r_uint(91872331)
- f = self.getcompiled(fn)
+ f = self.getcompiled(fn, [r_uint])
for value in range(15):
i = r_uint(value)
assert f(i) == fn(i)
def test_ord_returns_a_positive(self):
- def fn(i=int):
+ def fn(i):
return ord(chr(i))
- f = self.getcompiled(fn)
+ f = self.getcompiled(fn, [int])
assert f(255) == 255
def test_hash_preservation(self):
@@ -613,7 +596,7 @@
assert res[1] == intmask(hash(c)+hash(d))
def test_list_basic_ops(self):
- def list_basic_ops(i=int, j=int):
+ def list_basic_ops(i, j):
l = [1,2,3]
l.insert(0, 42)
del l[1]
@@ -624,7 +607,7 @@
l += [5,6]
l[1] = i
return l[j]
- f = self.getcompiled(list_basic_ops)
+ f = self.getcompiled(list_basic_ops, [int, int])
for i in range(6):
for j in range(6):
assert f(i,j) == list_basic_ops(i,j)
@@ -638,28 +621,28 @@
assert f() == fn()
def test_range_idx(self):
- def fn(idx=int):
+ def fn(idx):
r = range(10, 37, 4)
try:
return r[idx]
except: raise
- f = self.getcompiled(fn)
+ f = self.getcompiled(fn, [int])
assert f(0) == fn(0)
assert f(-1) == fn(-1)
raises(IndexError, f, 42)
def test_range_step(self):
- def fn(step=int):
+ def fn(step):
r = range(10, 37, step)
# we always raise on step = 0
return r[-2]
- f = self.getcompiled(fn)#, view=True)
+ f = self.getcompiled(fn, [int])
assert f(1) == fn(1)
assert f(3) == fn(3)
raises(ValueError, f, 0)
def test_range_iter(self):
- def fn(start=int, stop=int, step=int):
+ def fn(start, stop, step):
res = 0
if step == 0:
if stop >= start:
@@ -671,17 +654,17 @@
for i in r:
res = res * 51 + i
return res
- f = self.getcompiled(fn)
+ f = self.getcompiled(fn, [int, int, int])
for args in [2, 7, 0], [7, 2, 0], [10, 50, 7], [50, -10, -3]:
assert f(*args) == intmask(fn(*args))
def test_recursion_detection(self):
- def f(n=int, accum=int):
+ def f(n, accum):
if n == 0:
return accum
else:
return f(n-1, accum*n)
- fn = self.getcompiled(f)
+ fn = self.getcompiled(f, [int, int])
assert fn(7, 1) == 5040
assert fn(7, 1) == 5040 # detection must work several times, too
assert fn(7, 1) == 5040
@@ -719,13 +702,13 @@
if x:
return f(x)
return 1
- def g(x=int):
+ def g(x):
try:
f(x)
except RuntimeError:
return 42
return 1
- fn = self.getcompiled(g)
+ fn = self.getcompiled(g, [int])
assert fn(0) == 1
assert fn(1) == 42
@@ -746,7 +729,7 @@
except Exception:
return 42
return x
- fn = self.getcompiled(f)
+ fn = self.getcompiled(f)
res = fn()
assert res == 42
@@ -758,9 +741,9 @@
except TypeError:
return 42
return x
- fn = self.getcompiled(f)
+ fn = self.getcompiled(f)
res = fn()
- assert res == 42
+ assert res == 42
def f():
d1 = r_dict(eq, raising_hash)
@@ -770,6 +753,6 @@
except TypeError:
return 42
return 0
- fn = self.getcompiled(f)
+ fn = self.getcompiled(f)
res = fn()
- assert res == 42
+ assert res == 42
Modified: pypy/branch/even-more-config4/pypy/translator/cli/gencli.py
==============================================================================
--- pypy/branch/even-more-config4/pypy/translator/cli/gencli.py (original)
+++ pypy/branch/even-more-config4/pypy/translator/cli/gencli.py Tue Oct 24 22:18:14 2006
@@ -3,6 +3,8 @@
import py
from py.compat import subprocess
+from pypy.config.config import Config
+from pypy.config.pypyoption import pypy_optiondescription
from pypy.translator.cli import conftest
from pypy.translator.cli.ilgenerator import IlasmGenerator
from pypy.translator.cli.function import Function, log
@@ -28,7 +30,7 @@
class GenCli(object):
def __init__(self, tmpdir, translator, entrypoint=None, type_system_class=CTS,
opcode_dict=opcodes, name_suffix='.il', function_class=Function,
- database_class = LowLevelDatabase, pending_graphs=()):
+ database_class = LowLevelDatabase, pending_graphs=(), config=None):
self.tmpdir = tmpdir
self.translator = translator
self.entrypoint = entrypoint
@@ -46,6 +48,9 @@
self.tmpfile = tmpdir.join(self.assembly_name + name_suffix)
self.const_stat = str(tmpdir.join('const_stat'))
+ if config is None:
+ config = Config(pypy_optiondescription)
+ self.config = config
def generate_source(self , asm_class = IlasmGenerator ):
out = self.tmpfile.open('w')
@@ -53,9 +58,9 @@
out = Tee(sys.stdout, out)
if USE_STACKOPT:
- self.ilasm = StackOptGenerator(out, self.assembly_name)
+ self.ilasm = StackOptGenerator(out, self.assembly_name, self.config)
else:
- self.ilasm = asm_class(out, self.assembly_name)
+ self.ilasm = asm_class(out, self.assembly_name, self.config)
# TODO: instance methods that are also called as unbound
# methods are rendered twice, once within the class and once
Modified: pypy/branch/even-more-config4/pypy/translator/cli/ilgenerator.py
==============================================================================
--- pypy/branch/even-more-config4/pypy/translator/cli/ilgenerator.py (original)
+++ pypy/branch/even-more-config4/pypy/translator/cli/ilgenerator.py Tue Oct 24 22:18:14 2006
@@ -1,8 +1,6 @@
from pypy.rpython.lltypesystem.lltype import Signed, Unsigned, Void, Bool, Float
from pypy.rpython.lltypesystem.lltype import SignedLongLong, UnsignedLongLong
-TRACE_CALL = False
-
class CodeGenerator(object):
def __init__(self, out, indentstep = 4, startblock = '{', endblock = '}'):
self._out = out
@@ -38,8 +36,9 @@
"""
Generate IL code by writing to a file and compiling it with ilasm
"""
- def __init__(self, outfile, name):
+ def __init__(self, outfile, name, config):
self.out = outfile
+ self.config = config
self.code = CodeGenerator(self.out)
self.code.writeline('.assembly extern mscorlib {}')
self.code.writeline('.assembly extern pypylib {}')
@@ -114,8 +113,8 @@
if is_entrypoint:
self.code.writeline('.entrypoint')
self.code.writeline('.maxstack 32')
- self.stderr('start %s' % name, TRACE_CALL and name!='.ctor'
- and method_type!='runtime')
+ self.stderr('start %s' % name, self.config.translation.cli.trace_calls
+ and name!='.ctor' and method_type!='runtime')
def end_function(self):
self.flush()
Modified: pypy/branch/even-more-config4/pypy/translator/driver.py
==============================================================================
--- pypy/branch/even-more-config4/pypy/translator/driver.py (original)
+++ pypy/branch/even-more-config4/pypy/translator/driver.py Tue Oct 24 22:18:14 2006
@@ -14,26 +14,23 @@
py.log.setconsumer("translation", ansi_log)
-DEFAULT_OPTIONS = {
- 'gc': 'ref',
- 'cc': None,
- 'profopt': None,
-
- 'thread': False, # influences GC policy
-
- 'stackless': False,
- 'debug': True,
- 'insist': False,
- 'backend': 'c',
- 'type_system': None,
- 'lowmem': False,
- 'fork_before': None,
- 'raisingop2direct_call' : False,
- 'merge_if_blocks': True,
- 'debug_transform' : False,
+DEFAULTS = {
+ 'translation.gc': 'ref',
+ 'translation.cc': None,
+ 'translation.profopt': None,
+
+ 'translation.thread': False, # influences GC policy
+
+ 'translation.stackless': False,
+ 'translation.debug': True,
+ 'translation.insist': False,
+ 'translation.backend': 'c',
+ 'translation.fork_before': None,
+ 'translation.backendopt.raisingop2direct_call' : False,
+ 'translation.backendopt.merge_if_blocks': True,
+ 'translation.debug_transform' : False,
}
-_default_options = optparse.Values(defaults=DEFAULT_OPTIONS)
def taskdef(taskfunc, deps, title, new_state=None, expected_states=[], idemp=False):
taskfunc.task_deps = deps
@@ -56,15 +53,25 @@
class TranslationDriver(SimpleTaskEngine):
- def __init__(self, options=None, default_goal=None, disable=[],
- exe_name=None, extmod_name=None):
+ def __init__(self, setopts=None, default_goal=None, disable=[],
+ exe_name=None, extmod_name=None,
+ config=None, overrides=None):
SimpleTaskEngine.__init__(self)
self.log = log
- if options is None:
- options = _default_options
- self.options = options
+ if config is None:
+ from pypy.config.config import Config
+ from pypy.config.pypyoption import pypy_optiondescription
+ config = Config(pypy_optiondescription,
+ **DEFAULTS)
+ self.config = config
+ if overrides is not None:
+ self.config.override(overrides)
+
+ if setopts is not None:
+ self.config.set(**setopts)
+
self.exe_name = exe_name
self.extmod_name = extmod_name
@@ -102,7 +109,7 @@
if task in ('rtype', 'backendopt', 'llinterpret'):
if ts:
if ts == postfix:
- expose_task(task, explicit_task)
+ expose_task(task, explicit_task)
else:
expose_task(explicit_task)
elif task in ('source', 'compile', 'run'):
@@ -114,22 +121,14 @@
expose_task(explicit_task)
else:
expose_task(explicit_task)
+
+ def get_info(self): # XXX more?
+ d = {'backend': self.config.translation.backend}
+ return d
def get_backend_and_type_system(self):
- type_system = None
- backend = None
- opts = self.options
- if opts.type_system:
- type_system = opts.type_system
- if opts.backend:
- backend = opts.backend
- ts = backend_to_typesystem(backend)
- if type_system:
- if ts != type_system:
- raise ValueError, ("incosistent type-system and backend:"
- " %s and %s" % (type_system, backend))
- else:
- type_system = ts
+ type_system = self.config.translation.type_system
+ backend = self.config.translation.backend
return backend, type_system
def backend_select_goals(self, goals):
@@ -167,7 +166,7 @@
self.inputtypes = inputtypes
if policy is None:
- policy = annpolicy.AnnotatorPolicy()
+ policy = annpolicy.AnnotatorPolicy()
if standalone:
policy.allow_someobjects = False
self.policy = policy
@@ -176,10 +175,10 @@
if empty_translator:
# set verbose flags
- empty_translator.flags['verbose'] = True
+ empty_translator.config.translation.verbose = True
translator = empty_translator
else:
- translator = TranslationContext(verbose=True)
+ translator = TranslationContext(config=self.config, verbose=True)
self.entry_point = entry_point
self.translator = translator
@@ -206,12 +205,12 @@
policy = self.policy
self.log.info('with policy: %s.%s' % (policy.__class__.__module__, policy.__class__.__name__))
- annmodel.DEBUG = self.options.debug
+ annmodel.DEBUG = self.config.translation.debug
annotator = translator.buildannotator(policy=policy)
s = annotator.build_types(self.entry_point, self.inputtypes)
- if self.options.debug_transform:
+ if self.config.translation.debug_transform:
from pypy.translator.transformer.debug import DebugTransformer
dt = DebugTransformer(translator)
dt.transform_all()
@@ -249,38 +248,34 @@
def task_rtype_lltype(self):
- opt = self.options
rtyper = self.translator.buildrtyper(type_system='lltype')
+ insist = not self.config.translation.insist
rtyper.specialize(dont_simplify_again=True,
- crash_on_first_typeerror=not opt.insist)
+ crash_on_first_typeerror=insist)
#
task_rtype_lltype = taskdef(task_rtype_lltype, ['annotate'], "RTyping")
RTYPE = 'rtype_lltype'
def task_rtype_ootype(self):
# Maybe type_system should simply be an option used in task_rtype
- opt = self.options
+ insist = not self.config.translation.insist
rtyper = self.translator.buildrtyper(type_system="ootype")
rtyper.specialize(dont_simplify_again=True,
- crash_on_first_typeerror=not opt.insist)
+ crash_on_first_typeerror=insist)
#
task_rtype_ootype = taskdef(task_rtype_ootype, ['annotate'], "ootyping")
OOTYPE = 'rtype_ootype'
def task_backendopt_lltype(self):
from pypy.translator.backendopt.all import backend_optimizations
- opt = self.options
- backend_optimizations(self.translator,
- raisingop2direct_call_all=opt.raisingop2direct_call,
- merge_if_blocks_to_switch=opt.merge_if_blocks)
+ backend_optimizations(self.translator)
#
- task_backendopt_lltype = taskdef(task_backendopt_lltype,
+ task_backendopt_lltype = taskdef(task_backendopt_lltype,
[RTYPE], "lltype back-end optimisations")
BACKENDOPT = 'backendopt_lltype'
def task_backendopt_ootype(self):
from pypy.translator.backendopt.all import backend_optimizations
- opt = self.options
backend_optimizations(self.translator,
raisingop2direct_call_all=False,
inline_threshold=0,
@@ -301,14 +296,13 @@
insert_ll_stackcheck(self.translator)
task_stackcheckinsertion_lltype = taskdef(
- task_stackcheckinsertion_lltype,
- ['?'+BACKENDOPT, RTYPE, 'annotate'],
+ task_stackcheckinsertion_lltype,
+ ['?'+BACKENDOPT, RTYPE, 'annotate'],
"inserting stack checks")
STACKCHECKINSERTION = 'stackcheckinsertion_lltype'
def task_database_c(self):
translator = self.translator
- opt = self.options
if translator.annotator is not None:
translator.frozen = True
@@ -319,9 +313,8 @@
else:
from pypy.translator.c.genc import CExtModuleBuilder as CBuilder
cbuilder = CBuilder(self.translator, self.entry_point,
- gcpolicy = opt.gc,
- thread_enabled = getattr(opt, 'thread', False))
- cbuilder.stackless = opt.stackless
+ config=self.config)
+ cbuilder.stackless = self.config.translation.stackless
if not standalone: # xxx more messy
cbuilder.modulename = self.extmod_name
database = cbuilder.build_database()
@@ -329,7 +322,7 @@
self.cbuilder = cbuilder
self.database = database
#
- task_database_c = taskdef(task_database_c,
+ task_database_c = taskdef(task_database_c,
[STACKCHECKINSERTION, '?'+BACKENDOPT, RTYPE, '?annotate'],
"Creating database for generating c source")
@@ -346,7 +339,8 @@
if self.exe_name is not None:
import shutil
exename = mkexename(self.c_entryp)
- newexename = self.exe_name % self.options.__dict__
+ info = {'backend': self.config.translation.backend}
+ newexename = self.exe_name % self.get_info()
if '/' not in newexename and '\\' not in newexename:
newexename = './' + newexename
newexename = mkexename(newexename)
@@ -403,14 +397,14 @@
def task_source_llvm(self):
translator = self.translator
- opts = self.options
if translator.annotator is None:
raise ValueError, "llvm requires annotation."
from pypy.translator.llvm import genllvm
# XXX Need more options for policies/llvm-backendoptions here?
- self.llvmgen = genllvm.GenLLVM(translator, self.options.gc, self.standalone)
+ self.llvmgen = genllvm.GenLLVM(translator, self.config.translation.gc,
+ self.standalone)
llvm_filename = self.llvmgen.gen_llvm_source(self.entry_point)
self.log.info("written: %s" % (llvm_filename,))
@@ -422,7 +416,7 @@
def task_compile_llvm(self):
gen = self.llvmgen
if self.standalone:
- exe_name = (self.exe_name or 'testing') % self.options.__dict__
+ exe_name = (self.exe_name or 'testing') % self.get_info()
self.c_entryp = gen.compile_llvm_source(exe_name=exe_name)
self.create_exe()
else:
@@ -478,7 +472,8 @@
def task_source_js(self):
from pypy.translator.js.js import JS
self.gen = JS(self.translator, functions=[self.entry_point],
- stackless=self.options.stackless, use_debug=self.options.debug_transform)
+ stackless=self.config.translation.stackless,
+ use_debug=self.config.translation.debug_transform)
filename = self.gen.write_source()
self.log.info("Wrote %s" % (filename,))
task_source_js = taskdef(task_source_js,
@@ -501,7 +496,8 @@
from pypy.tool.udir import udir
entry_point_graph = self.translator.graphs[0]
- self.gen = GenCli(udir, self.translator, get_entrypoint(entry_point_graph))
+ self.gen = GenCli(udir, self.translator, get_entrypoint(entry_point_graph),
+ config=self.config)
filename = self.gen.generate_source()
self.log.info("Wrote %s" % (filename,))
task_source_cli = taskdef(task_source_cli, [OOBACKENDOPT, OOTYPE],
@@ -537,15 +533,15 @@
goals = self.backend_select_goals(goals)
return self._execute(goals, task_skip = self._maybe_skip())
- def from_targetspec(targetspec_dic, options=None, args=None, empty_translator=None,
+ def from_targetspec(targetspec_dic, config=None, args=None,
+ empty_translator=None,
disable=[],
default_goal=None):
if args is None:
args = []
- if options is None:
- options = _default_options
- driver = TranslationDriver(options, default_goal, disable)
+ driver = TranslationDriver(config=config, default_goal=default_goal,
+ disable=disable)
# patch some attributes of the os module to make sure they
# have the same value on every platform.
backend, ts = driver.get_backend_and_type_system()
@@ -580,7 +576,7 @@
# checkpointing support
def _event(self, kind, goal, func):
if kind == 'pre':
- fork_before = self.options.fork_before
+ fork_before = self.config.translation.fork_before
if fork_before:
fork_before, = self.backend_select_goals([fork_before])
if not fork_before in self.done and fork_before == goal:
Modified: pypy/branch/even-more-config4/pypy/translator/geninterplevel.py
==============================================================================
--- pypy/branch/even-more-config4/pypy/translator/geninterplevel.py (original)
+++ pypy/branch/even-more-config4/pypy/translator/geninterplevel.py Tue Oct 24 22:18:14 2006
@@ -64,13 +64,6 @@
uniquemodulename, C_IDENTIFIER, NameManager
-# list of simplifcation passes needed by geninterp
-from pypy.translator.simplify import transform_ovfcheck, all_passes as needed_passes
-
-needed_passes = needed_passes[:]
-needed_passes.remove(transform_ovfcheck)
-
-
import pypy # __path__
import py.path
from pypy.tool.ansi_print import ansi_log
@@ -1487,7 +1480,7 @@
sys.path.remove(libdir)
entrypoint = dic
- t = TranslationContext(verbose=False, simplifying=needed_passes,
+ t = TranslationContext(verbose=False, simplifying=True,
do_imports_immediately=do_imports_immediately,
builtins_can_raise_exceptions=True,
list_comprehension_operations=False)
Modified: pypy/branch/even-more-config4/pypy/translator/goal/targetlogicstandalone.py
==============================================================================
--- pypy/branch/even-more-config4/pypy/translator/goal/targetlogicstandalone.py (original)
+++ pypy/branch/even-more-config4/pypy/translator/goal/targetlogicstandalone.py Tue Oct 24 22:18:14 2006
@@ -1,106 +1,19 @@
import os, sys
-from pypy.tool.option import make_config
+from pypy.translator.goal.targetpypystandalone import PyPyTarget
-from pypy.objspace.logic import Space
-# XXX from pypy.annotation.model import *
-# since we are execfile()'ed this would pull some
-# weird objects into the globals, which we would try to pickle.
-from pypy.interpreter import gateway
-from pypy.interpreter.error import OperationError
-from pypy.translator.goal.ann_override import PyPyAnnotatorPolicy
-
-# 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.
-
-try:
- this_dir = os.path.dirname(__file__)
-except NameError:
- this_dir = os.path.dirname(sys.argv[0])
-
-def debug(msg):
- os.write(2, "debug: " + msg + '\n')
-
-# __________ Entry point __________
-
-def entry_point(argv):
- debug("entry point starting")
- for arg in argv:
- debug(" argv -> " + arg)
- try:
- w_executable = space.wrap(argv[0])
- w_argv = space.newlist([space.wrap(s) for s in argv[1:]])
- w_exitcode = space.call_function(w_entry_point, w_executable, w_argv)
- # try to pull it all in
- ## from pypy.interpreter import main, interactive, error
- ## con = interactive.PyPyConsole(space)
- ## con.interact()
- except OperationError, e:
- debug("OperationError:")
- debug(" operror-type: " + e.w_type.getname(space, '?'))
- debug(" operror-value: " + space.str_w(space.str(e.w_value)))
- return 1
- return space.int_w(w_exitcode)
# _____ Define and setup target ___
-opt_defaults = {'stackless' : True, 'debug': True}
+opt_defaults = {'translation.stackless' : True,
+ 'translation.debug': True,
+ 'objspace.name': 'logic',
+ 'objspace.usemodules._stackless': True}
-take_options = True
+class LogicPyPyTarget(PyPyTarget):
+ usage = "target logic standalone"
-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
-
- # obscure hack to stuff the translation options into the translated PyPy
- import pypy.module.sys
- wrapstr = 'space.wrap(%r)' % (options.__dict__)
- pypy.module.sys.Module.interpleveldefs['pypy_translation_info'] = wrapstr
-
- 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)
-
- # manually imports app_main.py
- filename = os.path.join(this_dir, 'app_main.py')
- w_dict = space.newdict()
- space.exec_(open(filename).read(), w_dict, w_dict)
- w_entry_point = space.getitem(w_dict, space.wrap('entry_point'))
-
- # sanity-check: call the entry point
- res = entry_point(["pypy", "app_basic_example.py"])
- assert res == 0
-
- return entry_point, None, PyPyAnnotatorPolicy()
+ def handle_config(self, config):
+ config.set(**opt_defaults)
+LogicPyPyTarget().interface(globals())
Modified: pypy/branch/even-more-config4/pypy/translator/goal/targetmultiplespaces.py
==============================================================================
--- pypy/branch/even-more-config4/pypy/translator/goal/targetmultiplespaces.py (original)
+++ pypy/branch/even-more-config4/pypy/translator/goal/targetmultiplespaces.py Tue Oct 24 22:18:14 2006
@@ -9,6 +9,7 @@
from pypy.interpreter import gateway
from pypy.interpreter.error import OperationError
from pypy.translator.goal.ann_override import PyPyAnnotatorPolicy
+from pypy.translator.goal.targetpypystandalone import PyPyTarget, debug
# WARNING: this requires the annotator.
# There is no easy way to build all caches manually,
@@ -50,89 +51,43 @@
return 1
return space.int_w(w_exitcode)
-# _____ Define and setup target ___
-# for now this will do for option handling
-
-take_options = True
-
-def opt_parser():
- import py
- defl = {'thread': False}
- parser = py.compat.optparse.OptionParser(usage="target multiple spaces",
- 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")
+class MultipleSpaceTarget(PyPyTarget):
+
+ usage = "target multiple spaces standalone"
- options.thread = tgt_options.thread
+ def handle_config(self, config):
+ config.set(**{"translation.thread": False})
- global space1, space2, w_entry_point_1, w_entry_point_2
+ def get_entry_point(self, config):
+ global space1, space2, w_entry_point_1, w_entry_point_2
+ space1 = StdObjSpace(config)
+ space2 = StdObjSpace(config)
+
+ space1.setattr(space1.getbuiltinmodule('sys'),
+ space1.wrap('pypy_space'),
+ space1.wrap(1))
+ space2.setattr(space2.getbuiltinmodule('sys'),
+ space2.wrap('pypy_space'),
+ space2.wrap(2))
+
+ # manually imports app_main.py
+ filename = os.path.join(this_dir, 'app_main.py')
+ w_dict = space1.newdict()
+ space1.exec_(open(filename).read(), w_dict, w_dict)
+ w_entry_point_1 = space1.getitem(w_dict, space1.wrap('entry_point'))
+
+ w_dict = space2.newdict()
+ space2.exec_(open(filename).read(), w_dict, w_dict)
+ w_entry_point_2 = space2.getitem(w_dict, space2.wrap('entry_point'))
+
+ # sanity-check: call the entry point
+ res = entry_point(["pypy", "app_basic_example.py"])
+ assert res == 0
+ res = entry_point(["pypy", "--space2", "app_basic_example.py"])
+ assert res == 0
- if getattr(options, "lowmem", False):
- config.objspace.geninterp = False
-
- # obscure hack to stuff the translation options into the translated PyPy
- import pypy.module.sys
- wrapstr = 'space.wrap(%r)' % (options.__dict__)
- pypy.module.sys.Module.interpleveldefs['pypy_translation_info'] = wrapstr
-
- usemodules = []
- if tgt_options.usemodules:
- for modname in tgt_options.usemodules.split(","):
- setattr(config.objspace.usemodules, modname, True)
- if tgt_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)
-
- space1.setattr(space1.getbuiltinmodule('sys'),
- space1.wrap('pypy_space'),
- space1.wrap(1))
- space2.setattr(space2.getbuiltinmodule('sys'),
- space2.wrap('pypy_space'),
- space2.wrap(2))
-
- # manually imports app_main.py
- filename = os.path.join(this_dir, 'app_main.py')
- w_dict = space1.newdict()
- space1.exec_(open(filename).read(), w_dict, w_dict)
- w_entry_point_1 = space1.getitem(w_dict, space1.wrap('entry_point'))
-
- w_dict = space2.newdict()
- space2.exec_(open(filename).read(), w_dict, w_dict)
- w_entry_point_2 = space2.getitem(w_dict, space2.wrap('entry_point'))
-
- # sanity-check: call the entry point
- res = entry_point(["pypy", "app_basic_example.py"])
- assert res == 0
- res = entry_point(["pypy", "--space2", "app_basic_example.py"])
- assert res == 0
+ return entry_point, None, PyPyAnnotatorPolicy()
- return entry_point, None, PyPyAnnotatorPolicy()
+MultipleSpaceTarget().interface(globals())
Modified: pypy/branch/even-more-config4/pypy/translator/goal/targetpypystandalone.py
==============================================================================
--- pypy/branch/even-more-config4/pypy/translator/goal/targetpypystandalone.py (original)
+++ pypy/branch/even-more-config4/pypy/translator/goal/targetpypystandalone.py Tue Oct 24 22:18:14 2006
@@ -65,86 +65,93 @@
return exitcode
return entry_point
+def call_finish(space):
+ space.finish()
+
+def call_startup(space):
+ space.startup()
+
# _____ Define and setup target ___
# for now this will do for option handling
-take_options = True
+class PyPyTarget(object):
-def opt_parser_config():
- parser = py.compat.optparse.OptionParser(usage="target PyPy standalone",
- add_help_option=False)
- parser.set_defaults(thread=False)
- parser.add_option("--thread", action="store_true", dest="thread",
- help="enable threading")
- config = Config(pypy_optiondescription)
- opt_parser = py.compat.optparse.OptionParser(usage="target PyPy standalone",
- add_help_option=False)
- to_optparse(config, parser=parser)
- return config, parser
+ usage = "taget PyPy standalone"
-def print_help():
- opt_parser_config()[1].print_help()
+ take_options = True
-def call_finish(space):
- space.finish()
+ def opt_parser(self, config):
+ parser = to_optparse(config, useoptions=["objspace.*"],
+ parserkwargs={'usage': self.usage})
+ return parser
-def call_startup(space):
- space.startup()
+ def handle_config(self, config):
+ pass
+
+ def print_help(self, config):
+ self.opt_parser(config).print_help()
+
+ def target(self, driver, args):
+ driver.exe_name = 'pypy-%(backend)s'
+
+ config = driver.config
+ parser = self.opt_parser(config)
+
+ parser.parse_args(args)
+
+ # expose the following variables to ease debugging
+ global space, entry_point
+
+ # obscure hack to stuff the translation options into the translated PyPy
+ import pypy.module.sys
+ paths = config.getpaths()
+ options = dict([(path, getattr(config, path)) for path in paths])
+ wrapstr = 'space.wrap(%r)' % (options)
+ pypy.module.sys.Module.interpleveldefs['pypy_translation_info'] = wrapstr
+
+ if config.translation.thread:
+ config.objspace.usemodules.thread = True
+ elif config.objspace.usemodules.thread:
+ config.translation.thread = True
+
+ if config.translation.stackless:
+ config.objspace.usemodules._stackless = True
+ elif config.objspace.usemodules._stackless:
+ config.translation.stackless = True
+
+ config.objspace.nofaking = True
+ config.objspace.compiler = "ast"
+ config.translating = True
+
+ import translate
+ translate.log_config(config.objspace, "PyPy config object")
+
+ return self.get_entry_point(config)
+
+ def get_entry_point(self, config):
+ space = make_objspace(config)
+
+ # disable translation of the whole of classobjinterp.py
+ StdObjSpace.setup_old_style_classes = lambda self: None
+
+
+ # manually imports app_main.py
+ filename = os.path.join(this_dir, 'app_main.py')
+ w_dict = space.newdict()
+ space.exec_(open(filename).read(), w_dict, w_dict)
+ entry_point = create_entry_point(space, w_dict)
+
+ # sanity-check: call the entry point
+ res = entry_point(["pypy", "app_basic_example.py"])
+ assert res == 0
+
+ return entry_point, None, PyPyAnnotatorPolicy(single_space = space)
+ def interface(self, ns):
+ for name in ['take_options', 'handle_config', 'print_help', 'target']:
+ ns[name] = getattr(self, name)
-def target(driver, args):
- global config, opt_parser
- driver.exe_name = 'pypy-%(backend)s'
- options = driver.options
-
- config, opt_parser = opt_parser_config()
-
- tgt_options, _ = opt_parser.parse_args(args)
-
- # expose the following variables to ease debugging
- global space, entry_point
-
- if getattr(options, "lowmem", False):
- config.objspace.geninterp = False
-
- # obscure hack to stuff the translation options into the translated PyPy
- import pypy.module.sys
- wrapstr = 'space.wrap(%r)' % (options.__dict__)
- pypy.module.sys.Module.interpleveldefs['pypy_translation_info'] = wrapstr
-
- if tgt_options.thread:
- config.objspace.usemodules.thread = True
- elif config.objspace.usemodules.thread:
- tgt_options.thread = True
-
- if options.stackless:
- config.objspace.usemodules._stackless = True
- elif config.objspace.usemodules._stackless:
- options.stackless = True
-
- config.objspace.nofaking = True
- config.objspace.compiler = "ast"
- config.translating = True
-
- translate.log_options(tgt_options, "target PyPy options in effect")
- translate.log_config(config, "PyPy config object")
-
- space = make_objspace(config)
-
- # disable translation of the whole of classobjinterp.py
- StdObjSpace.setup_old_style_classes = lambda self: None
-
-
- # manually imports app_main.py
- filename = os.path.join(this_dir, 'app_main.py')
- w_dict = space.newdict()
- space.exec_(open(filename).read(), w_dict, w_dict)
- entry_point = create_entry_point(space, w_dict)
-
- # sanity-check: call the entry point
- res = entry_point(["pypy", "app_basic_example.py"])
- assert res == 0
- return entry_point, None, PyPyAnnotatorPolicy(single_space = space)
+PyPyTarget().interface(globals())
Modified: pypy/branch/even-more-config4/pypy/translator/goal/targetvarsized.py
==============================================================================
--- pypy/branch/even-more-config4/pypy/translator/goal/targetvarsized.py (original)
+++ pypy/branch/even-more-config4/pypy/translator/goal/targetvarsized.py Tue Oct 24 22:18:14 2006
@@ -38,7 +38,7 @@
# _____ Define and setup target ___
-def target(driver, args):
+def target(driver, args, config):
global modules, functions
if len(args) == 0:
N = DEFAULT_CODE_SIZE_FACTOR
Modified: pypy/branch/even-more-config4/pypy/translator/goal/translate.py
==============================================================================
--- pypy/branch/even-more-config4/pypy/translator/goal/translate.py (original)
+++ pypy/branch/even-more-config4/pypy/translator/goal/translate.py Tue Oct 24 22:18:14 2006
@@ -8,119 +8,76 @@
import autopath
+from pypy.config.config import to_optparse, OptionDescription, BoolOption, \
+ ArbitraryOption, StrOption, IntOption, Config, \
+ ChoiceOption, OptHelpFormatter
+from pypy.config.pypyoption import pypy_optiondescription
+
+
+GOALS= [
+ ("annotate", "do type inference", "-a --annotate", ""),
+ ("rtype", "do rtyping", "-t --rtype", ""),
+ ("backendopt", "do backend optimizations", "--backendopt", ""),
+ ("source", "create source", "-s --source", ""),
+ ("compile", "compile", "-c --compile", " (default goal)"),
+ ("run", "run the resulting binary", "--run", ""),
+ ("llinterpret", "interpret the rtyped flow graphs", "--llinterpret", ""),
+ ]
+
+def goal_options():
+ result = []
+ for name, doc, cmdline, extra in GOALS:
+ yesdoc = doc[0].upper()+doc[1:]+extra
+ result.append(BoolOption(name, yesdoc, default=False, cmdline=cmdline,
+ negation=False))
+ result.append(BoolOption("no_%s" % name, "Don't "+doc, default=False,
+ cmdline="--no-"+name, negation=False))
+ return result
+
+translate_optiondescr = OptionDescription("translate", "XXX", [
+ IntOption("graphserve", """Serve analysis graphs on port number
+(see pypy/translator/tool/pygame/graphclient.py)""",
+ cmdline="--graphserve"),
+ StrOption("targetspec", "XXX", default='targetpypystandalone',
+ cmdline=None),
+ BoolOption("profile",
+ "cProfile (to debug the speed of the translation process)",
+ default=False,
+ cmdline="--profile"),
+ BoolOption("batch", "Don't run interactive helpers", default=False,
+ cmdline="--batch", negation=False),
+ IntOption("huge", "Threshold in the number of functions after which"
+ "a local call graph and not a full one is displayed",
+ default=100, cmdline="--huge"),
+ BoolOption("text", "Don't start the pygame viewer", default=False,
+ cmdline="--text", negation=False),
+ BoolOption("help", "show this help message and exit", default=False,
+ cmdline="-h --help", negation=False),
+ ArbitraryOption("goals", "XXX",
+ defaultfactory=list),
+ # xxx default goals ['annotate', 'rtype', 'backendopt', 'source', 'compile']
+ ArbitraryOption("skipped_goals", "XXX",
+ defaultfactory=lambda: ['run']),
+ OptionDescription("goal_options",
+ "Goals that should be reached during translation",
+ goal_options()),
+])
-# dict are not ordered, cheat with #_xyz keys and bunchiter
-def OPT(*args):
- return args
-
-def bunchiter(d):
- purify = lambda name: name.split('_',1)[1]
- items = d.items()
- items.sort()
- for name, val in items:
- yield purify(name), val
-
-GOAL = object()
-SKIP_GOAL = object()
-
-opts = {
-
- '0_Annotation': {
- '0_annotate': [OPT(('-a', '--annotate'), "Annotate", GOAL),
- OPT(('--no-annotate',), "Don't annotate", SKIP_GOAL)],
- '1_debug': [OPT(('-d', '--debug'), "Record annotation debug info", True)]
- },
-
- '1_RTyping': {
- '0_rtype': [OPT(('-t', '--rtype'), "RType", GOAL),
- OPT(('--no-rtype',), "Don't rtype", SKIP_GOAL)],
- '1_insist': [OPT(('--insist',), "Dont' stop on first rtyper error", True)]
- },
- '2_Backend optimisations': {
- '_backendopt': [OPT(('-o', '--backendopt'), "Do backend optimisations", GOAL),
- OPT(('--no-backendopt',), "Don't do backend optimisations", SKIP_GOAL)],
- },
-
- '3_Code generation options': {
- '0_source': [OPT(('-s', '--source'), "Generate source code", GOAL),
- OPT(('--no-source',), "Don't generate source code", SKIP_GOAL)],
-
- '1_backend': [OPT(('-b', '--backend'), "Backend", ['c', 'llvm', 'cl', 'squeak', 'js', 'cli'])],
-
- '2_gc': [OPT(('--gc',), "Garbage collector", ['boehm', 'ref', 'framework', 'none', 'exact_boehm', 'stacklessgc'])],
- '4_stackless': [OPT(('--stackless',), "Stackless code generation (graph transformer)", True)],
- '5_merge_if_blocks': [OPT(('--no-if-blocks-merge',), "Do not merge if ... elif ... chains and use a switch statement for them.", False)],
- '6_raisingop2direct_call': [OPT(('--raisingop2direct_call',), "Convert possible exception raising operations to direct calls.", True)],
- },
-
-
- '4_Compilation options':{
- '_compile': [OPT(('-c', '--compile'), "Compile generated source", GOAL),
- OPT(('--no-compile',), "Don't compile", SKIP_GOAL)],
- '2_cc': [OPT(('--cc',), "Set compiler", str)],
- '3_profopt': [OPT(('--profopt',), "Set profile based optimization script", str)],
- },
-
- '5_Run options': {
- '_run': [OPT(('-r', '--run'), "Run compiled code", GOAL),
- OPT(('--no-run',), "Don't run compiled code", SKIP_GOAL)],
- },
-
- '6_General&other options': {
- '0_batch': [OPT(('--batch',), "Don't run interactive helpers", True)],
- '1_lowmem': [OPT(('--lowmem',), "Target should try to save memory", True)],
-
- '2_huge': [OPT(('--huge',), "Threshold in the number of functions after which only a local call graph and not a full one is displayed", int)],
-
- '3_text': [OPT(('--text',), "Don't start the pygame viewer", True)],
+OVERRIDES = {
+ 'translation.debug': False,
+ 'translation.insist': False,
+
+ 'translation.gc': 'boehm',
+ 'translation.backend': 'c',
+ 'translation.stackless': False,
+ 'translation.backendopt.raisingop2direct_call' : False,
+ 'translation.backendopt.merge_if_blocks': True,
- '4_graphserve': [OPT(('--graphserve',), """Serve analysis graphs on port number
-(see pypy/translator/tool/pygame/graphclient.py)""", int)],
+ 'translation.cc': None,
+ 'translation.profopt': None,
- '5_fork_before': [OPT(('--fork-before',), """(UNIX) Create restartable checkpoint before step""",
- ['annotate', 'rtype', 'backendopt', 'database', 'source'])],
-
- '6_llinterpret': [OPT(('--llinterpret',), "Interpret the rtyped flow graphs", GOAL)],
-
- '7_profile': [OPT(('--profile',), "cProfile (to debug the speed of the translation process)", True)],
- },
-
-
-}
-
-defaults = {
- 'help': False,
-
- 'targetspec': 'targetpypystandalone',
-
- 'goals': [],
-
- 'default_goals': ['annotate', 'rtype', 'backendopt', 'source', 'compile'],
- 'skipped_goals': ['run'],
-
- 'lowmem': False,
-
- 'debug': False,
- 'insist': False,
-
- 'gc': 'boehm',
- 'backend': 'c',
- 'type_system': None,
- 'stackless': False,
- 'raisingop2direct_call' : False,
- 'merge_if_blocks': True,
-
- 'batch': False,
- 'text': False,
- 'graphserve': None,
- 'huge': 100,
- 'cc': None,
- 'profopt': None,
-
- 'fork_before': None,
- 'profile': False,
- 'debug_transform': False,
+ 'translation.debug_transform': False,
}
import py
@@ -130,45 +87,15 @@
log = py.log.Producer("translation")
py.log.setconsumer("translation", ansi_log)
-class OptHelpFormatter(optparse.IndentedHelpFormatter):
-
- def expand_default(self, option):
- assert self.parser
- dfls = self.parser.defaults
- defl = ""
- if option.action == 'callback' and option.callback == goal_cb:
- enable, goal = option.callback_args
- if enable == (goal in dfls['default_goals']):
- defl = "[default]"
- else:
- val = dfls.get(option.dest)
- if val is None:
- pass
- elif isinstance(val, bool):
- if val is True and option.action=="store_true":
- defl = "[default]"
- else:
- defl = "[default: %s]" % val
-
- return option.help.replace("%defl", defl)
-
-def goal_cb(option, opt, value, parser, enable, goal):
- if enable:
- if goal not in parser.values.ensure_value('goals', []):
- parser.values.goals = parser.values.goals + [goal]
- else:
- if goal not in parser.values.ensure_value('skipped_goals', []):
- parser.values.skipped_goals = parser.values.skipped_goals + [goal]
-
def load_target(targetspec):
log.info("Translating target as defined by %s" % targetspec)
if not targetspec.endswith('.py'):
targetspec += '.py'
thismod = sys.modules[__name__]
+ sys.modules['translate'] = thismod
targetspec_dic = {
'__name__': os.path.splitext(os.path.basename(targetspec))[0],
- '__file__': targetspec,
- 'translate': thismod}
+ '__file__': targetspec}
sys.path.insert(0, os.path.dirname(targetspec))
execfile(targetspec, targetspec_dic)
return targetspec_dic
@@ -181,83 +108,53 @@
opt_parser.disable_interspersed_args()
- for group_name, grp_opts in bunchiter(opts):
- grp = opt_parser.add_option_group(group_name)
- for dest, dest_opts in bunchiter(grp_opts):
- for names, descr, choice in dest_opts:
- opt_setup = {'action': 'store',
- 'dest': dest,
- 'help': descr+" %defl"}
- if choice in (GOAL, SKIP_GOAL):
- del opt_setup['dest']
- opt_setup['action'] = 'callback'
- opt_setup['nargs'] = 0
- opt_setup['callback'] = goal_cb
- opt_setup['callback_args'] = (choice is GOAL, dest,)
- elif isinstance(choice, list):
- opt_setup['type'] = 'choice'
- opt_setup['choices'] = choice
- opt_setup['metavar'] = "[%s]" % '|'.join(choice)
- elif isinstance(choice, bool):
- opt_setup['action'] = ['store_false', 'store_true'][choice]
- elif choice is int:
- opt_setup['type'] = 'int'
- elif choice is str:
- opt_setup['type'] = 'string'
- else:
- opt_setup['action'] = 'store_const'
- opt_setup['const'] = choice
-
- grp.add_option(*names, **opt_setup)
-
- # add help back as a flag
- opt_parser.add_option("-h", "--help",
- action="store_true", dest="help",
- help="show this help message and exit")
+ config = Config(pypy_optiondescription,
+ **OVERRIDES)
+ to_optparse(config, parser=opt_parser, useoptions=['translation.*'])
+ translateconfig = Config(translate_optiondescr)
+ to_optparse(translateconfig, parser=opt_parser)
options, args = opt_parser.parse_args()
+ # set goals and skipped_goals
+ for name, _, _, _ in GOALS:
+ if getattr(translateconfig.goal_options, name):
+ if name not in translateconfig.goals:
+ translateconfig.goals.append(name)
+ if getattr(translateconfig.goal_options, 'no_'+name):
+ if name not in translateconfig.skipped_goals:
+ translateconfig.skipped_goals.append(name)
+
if args:
arg = args[0]
args = args[1:]
if os.path.isfile(arg+'.py'):
assert not os.path.isfile(arg), (
"ambiguous file naming, please rename %s" % arg)
- options.targetspec = arg
+ translateconfig.targetspec = arg
elif os.path.isfile(arg) and arg.endswith('.py'):
- options.targetspec = arg[:-3]
+ translateconfig.targetspec = arg[:-3]
else:
args = [arg] + args
- # for help, applied later
- opt_parser.set_defaults(**defaults)
-
- targetspec = options.ensure_value('targetspec', opt_parser.defaults['targetspec'])
+ targetspec = translateconfig.targetspec
targetspec_dic = load_target(targetspec)
if args and not targetspec_dic.get('take_options', False):
log.WARNING("target specific arguments supplied but will be ignored: %s" % ' '.join(args))
- # target specific defaults taking over
- if 'opt_defaults' in targetspec_dic:
- opt_parser.set_defaults(**targetspec_dic['opt_defaults'])
+ # let the target modify or prepare itself
+ # based on the config
+ if 'handle_config' in targetspec_dic:
+ targetspec_dic['handle_config'](config)
- if options.help:
+ if translateconfig.help:
opt_parser.print_help()
if 'print_help' in targetspec_dic:
- print
- targetspec_dic['print_help']()
+ targetspec_dic['print_help'](config)
sys.exit(0)
-
- # apply defaults
- for name, val in opt_parser.defaults.iteritems():
- options.ensure_value(name, val)
-
- # tweak: default_goals into default_goal
- del options.default_goals
- options.default_goal = 'compile'
- return targetspec_dic, options, args
+ return targetspec_dic, translateconfig, config, args
def log_options(options, header="options in effect"):
# list options (xxx filter, filter for target)
@@ -273,20 +170,19 @@
log(str(config))
def main():
- targetspec_dic, options, args = parse_options_and_load_target()
+ targetspec_dic, translateconfig, config, args = parse_options_and_load_target()
from pypy.translator import translator
from pypy.translator import driver
from pypy.translator.tool.pdbplus import PdbPlusShow
- if options.profile:
+ if translateconfig.profile:
from cProfile import Profile
prof = Profile()
prof.enable()
else:
prof = None
- t = translator.TranslationContext()
- t.driver_options = options
+ t = translator.TranslationContext(config=config)
class ServerSetup:
async_server = None
@@ -296,14 +192,14 @@
return self.async_server
elif port is not None:
from pypy.translator.tool.graphserver import run_async_server
- serv_start, serv_show, serv_stop = self.async_server = run_async_server(t, options, port)
+ serv_start, serv_show, serv_stop = self.async_server = run_async_server(t, translateconfig, port)
return serv_start, serv_show, serv_stop
elif not async_only:
from pypy.translator.tool.graphserver import run_server_for_inprocess_client
- return run_server_for_inprocess_client(t, options)
+ return run_server_for_inprocess_client(t, translateconfig)
server_setup = ServerSetup()
- server_setup(options.graphserve, async_only=True)
+ server_setup(translateconfig.graphserve, async_only=True)
pdb_plus_show = PdbPlusShow(t) # need a translator to support extended commands
@@ -330,27 +226,28 @@
else:
log.event('Done.')
- if options.batch:
+ if translateconfig.batch:
log.event("batch mode, not calling interactive helpers")
return
log.event("start debugger...")
- pdb_plus_show.start(tb, server_setup, graphic=not options.text)
+ pdb_plus_show.start(tb, server_setup, graphic=not translateconfig.text)
- log_options(options)
+ log_config(translateconfig, "translate.py configuration")
try:
- drv = driver.TranslationDriver.from_targetspec(targetspec_dic, options, args,
- empty_translator=t,
- disable=options.skipped_goals,
- default_goal='compile')
+ drv = driver.TranslationDriver.from_targetspec(targetspec_dic, config, args,
+ empty_translator=t,
+ disable=translateconfig.skipped_goals,
+ default_goal='compile')
+ log_config(config.translation, "translation configuration")
pdb_plus_show.expose({'drv': drv, 'prof': prof})
if drv.exe_name is None and '__name__' in targetspec_dic:
drv.exe_name = targetspec_dic['__name__'] + '-%(backend)s'
- goals = options.goals
+ goals = translateconfig.goals
drv.proceed(goals)
except SystemExit:
Modified: pypy/branch/even-more-config4/pypy/translator/interactive.py
==============================================================================
--- pypy/branch/even-more-config4/pypy/translator/interactive.py (original)
+++ pypy/branch/even-more-config4/pypy/translator/interactive.py Tue Oct 24 22:18:14 2006
@@ -3,11 +3,13 @@
import autopath
from pypy.translator.translator import TranslationContext
from pypy.translator import driver
+from pypy.config.config import Config
+from pypy.config.pypyoption import pypy_optiondescription
-DEFAULT_OPTIONS = driver.DEFAULT_OPTIONS.copy()
-DEFAULT_OPTIONS.update({
- 'backend': None,
-})
+DEFAULTS = {
+ 'translation.backend': None,
+ 'translation.type_system': None,
+}
class Translation(object):
@@ -18,9 +20,9 @@
graph = self.context.buildflowgraph(entry_point)
self.context._prebuilt_graphs[entry_point] = graph
- self.driver = driver.TranslationDriver(
- optparse.Values(defaults=DEFAULT_OPTIONS))
-
+ self.driver = driver.TranslationDriver(overrides=DEFAULTS)
+ self.config = self.driver.config
+
# hook into driver events
driver_own_event = self.driver._event
def _event(kind, goal, func):
@@ -29,27 +31,8 @@
self.driver._event = _event
self.driver_setup = False
- self.frozen_options = {}
-
self.update_options(argtypes, kwds)
- GOAL_USES_OPTS = {
- 'annotate': ['debug'],
- 'rtype_lltype': ['insist'],
- 'rtype_ootype': ['insist'],
- 'backendopt_lltype': ['raisingop2direct_call', 'merge_if_blocks'],
- 'stackcheckinsertion_lltype': [],
- 'database_c': ['gc', 'stackless'],
- 'source_llvm': [],
- 'source_js': [],
- 'source_c': [],
- 'compile_c': [],
- 'compile_llvm': [],
- 'source_cl': [],
- 'source_cli': [],
- 'compile_cli': [],
- }
-
def view(self):
self.context.view()
@@ -61,9 +44,8 @@
#print goal
self.ensure_setup()
elif kind == 'post':
- used_opts = dict.fromkeys(self.GOAL_USES_OPTS[goal], True)
- self.frozen_options.update(used_opts)
-
+ pass
+
def ensure_setup(self, argtypes=None, policy=None, standalone=False):
if not self.driver_setup:
if standalone:
@@ -89,40 +71,31 @@
if argtypes or kwds.get('policy') or kwds.get('standalone'):
self.ensure_setup(argtypes, kwds.get('policy'),
kwds.get('standalone'))
- for optname, value in kwds.iteritems():
- if optname in ('policy', 'standalone'):
- continue
- if optname in self.frozen_options:
- if getattr(self.driver.options, optname) != value:
- raise Exception("inconsistent option supplied: %s" % optname)
- else:
- if not hasattr(self.driver.options, optname):
- raise TypeError('driver has no option %r' % (optname,))
- setattr(self.driver.options, optname, value)
- self.frozen_options[optname] = True
+ kwds.pop('policy', None)
+ kwds.pop('standalone', None)
+ self.config.translation.set(**kwds)
def ensure_opt(self, name, value=None, fallback=None):
if value is not None:
self.update_options(None, {name: value})
- elif fallback is not None and name not in self.frozen_options:
+ return value
+ val = getattr(self.config.translation, name, None)
+ if fallback is not None and val is None:
self.update_options(None, {name: fallback})
- val = getattr(self.driver.options, name)
- if val is None:
- raise Exception("the %r option should have been specified at this point" % name)
- return val
+ return fallback
+ if val is not None:
+ return val
+ raise Exception(
+ "the %r option should have been specified at this point" %name)
def ensure_type_system(self, type_system=None):
- if type_system is None:
- backend = self.driver.options.backend
- if backend is not None:
- type_system = driver.backend_to_typesystem(backend)
+ if self.config.translation.backend is not None:
+ return self.ensure_opt('type_system')
return self.ensure_opt('type_system', type_system, 'lltype')
def ensure_backend(self, backend=None):
backend = self.ensure_opt('backend', backend)
self.ensure_type_system()
- if backend == 'llvm':
- self.update_options(None, {'gc': 'boehm'})
return backend
# disable some goals (steps)
Modified: pypy/branch/even-more-config4/pypy/translator/js/main.py
==============================================================================
--- pypy/branch/even-more-config4/pypy/translator/js/main.py (original)
+++ pypy/branch/even-more-config4/pypy/translator/js/main.py Tue Oct 24 22:18:14 2006
@@ -5,7 +5,7 @@
#from pypy.translator.js.test.runtest import compile_function
#from pypy.translator.translator import TranslationContext
-from pypy.translator.driver import TranslationDriver, DEFAULT_OPTIONS
+from pypy.translator.driver import TranslationDriver
from pypy.translator.js.js import JS
from pypy.tool.error import AnnotatorError, FlowingError, debug
from pypy.rpython.nonconst import NonConstant
@@ -121,10 +121,13 @@
exec(source_ssf) in globals()
# now we gonna just cut off not needed function
# XXX: Really do that
- options = optparse.Values(defaults=DEFAULT_OPTIONS)
- options.debug_transform = opts.debug_transform
- # XXX: This makes no sense (copying options)
- driver = TranslationDriver(options=options)
+ #options = optparse.Values(defaults=DEFAULT_OPTIONS)
+ #options.debug_transform = opts.debug_transform
+ from pypy.config.config import Config
+ from pypy.config.pypyoption import pypy_optiondescription
+ config = Config(pypy_optiondescription)
+ config.translation.debug_transform = opts.debug_transform
+ driver = TranslationDriver(config=config)
try:
driver.setup(some_strange_function_which_will_never_be_called, [], policy = JsPolicy())
driver.proceed(["compile_js"])
Modified: pypy/branch/even-more-config4/pypy/translator/llvm/gc.py
==============================================================================
--- pypy/branch/even-more-config4/pypy/translator/llvm/gc.py (original)
+++ pypy/branch/even-more-config4/pypy/translator/llvm/gc.py Tue Oct 24 22:18:14 2006
@@ -1,5 +1,6 @@
import sys
from pypy.rpython.lltypesystem.rstr import STR
+from pypy.translator.c import gc
from pypy.translator.llvm.log import log
log = log.gc
@@ -110,7 +111,7 @@
raise Exception, 'GcPolicy should not be used directly'
def new(db, gcpolicy=None):
- """ factory """
+ # """ factory """
if gcpolicy == 'boehm':
# XXX would be nice to localise this sort of thing?
assert have_boehm(), 'warning: Boehm GC libary not found in /usr/lib'
Modified: pypy/branch/even-more-config4/pypy/translator/llvm/genllvm.py
==============================================================================
--- pypy/branch/even-more-config4/pypy/translator/llvm/genllvm.py (original)
+++ pypy/branch/even-more-config4/pypy/translator/llvm/genllvm.py Tue Oct 24 22:18:14 2006
@@ -25,19 +25,26 @@
function_count = {}
def __init__(self, translator, gcpolicy, standalone,
- debug=False, logging=True, stackless=False):
+ debug=False, logging=True, stackless=False, config=None):
# reset counters
LLVMNode.nodename_count = {}
if gcpolicy is None:
gcpolicy = "boehm"
-
+
self.gcpolicy = gcpolicy
+
- self.stackless = stackless
self.standalone = standalone
self.translator = translator
+
+ if config is None:
+ from pypy.config.config import Config
+ from pypy.config.pypyoption import pypy_optiondescription
+ config = Config(pypy_optiondescription)
+ self.config = config
+ self.stackless = stackless
# the debug flag is for creating comments of every operation
# that may be executed
@@ -76,7 +83,7 @@
# please dont ask!
from pypy.translator.c.genc import CStandaloneBuilder
from pypy.translator.c import gc
- cbuild = CStandaloneBuilder(self.translator, func, self.gcpolicy)
+ cbuild = CStandaloneBuilder(self.translator, func, config=self.config)
cbuild.stackless = self.stackless
c_db = cbuild.generate_graphs_for_llinterp()
Modified: pypy/branch/even-more-config4/pypy/translator/stackless/test/test_transform.py
==============================================================================
--- pypy/branch/even-more-config4/pypy/translator/stackless/test/test_transform.py (original)
+++ pypy/branch/even-more-config4/pypy/translator/stackless/test/test_transform.py Tue Oct 24 22:18:14 2006
@@ -246,6 +246,7 @@
def rtype_stackless_function(fn):
t = TranslationContext()
+ t.config.translation.stackless = True
annotator = t.buildannotator()
annotator.policy.allow_someobjects = False
@@ -269,8 +270,8 @@
t = rtype_stackless_function(entry_point)
- cbuilder = CStandaloneBuilder(t, entry_point, gcpolicy=gc.BoehmGcPolicy)
- cbuilder.stackless = True
+ cbuilder = CStandaloneBuilder(t, entry_point, config=t.config,
+ gcpolicy=gc.BoehmGcPolicy)
cbuilder.generate_source()
if conftest.option.view:
t.view()
Modified: pypy/branch/even-more-config4/pypy/translator/test/test_driver.py
==============================================================================
--- pypy/branch/even-more-config4/pypy/translator/test/test_driver.py (original)
+++ pypy/branch/even-more-config4/pypy/translator/test/test_driver.py Tue Oct 24 22:18:14 2006
@@ -1,6 +1,8 @@
import py
-from pypy.translator.driver import TranslationDriver, DEFAULT_OPTIONS
+from pypy.translator.driver import TranslationDriver
+from pypy.config.config import Config
+from pypy.config.pypyoption import pypy_optiondescription
from py.compat import optparse
def cmpl(l1, l2):
@@ -21,42 +23,40 @@
assert td.backend_select_goals(['rtype']) == ['rtype_lltype']
assert td.backend_select_goals(['rtype_lltype']) == ['rtype_lltype']
assert td.backend_select_goals(['backendopt']) == ['backendopt_lltype']
- assert td.backend_select_goals(['backendopt_lltype']) == ['backendopt_lltype']
+ assert td.backend_select_goals(['backendopt_lltype']) == [
+ 'backendopt_lltype']
- d = DEFAULT_OPTIONS.copy()
- d['backend'] = None
- td = TranslationDriver(options=optparse.Values(defaults=d))
+ td = TranslationDriver({'backend': None, 'type_system': None})
assert td.backend_select_goals(['compile_c']) == ['compile_c']
py.test.raises(Exception, td.backend_select_goals, ['compile'])
py.test.raises(Exception, td.backend_select_goals, ['rtype'])
- assert td.backend_select_goals(['rtype_lltype']) == ['rtype_lltype']
+ assert td.backend_select_goals(['rtype_lltype']) == ['rtype_lltype']
py.test.raises(Exception, td.backend_select_goals, ['backendopt'])
- assert td.backend_select_goals(['backendopt_lltype']) == ['backendopt_lltype']
-
+ assert td.backend_select_goals(['backendopt_lltype']) == [
+ 'backendopt_lltype']
assert cmpl(td.exposed,
['annotate', 'backendopt_lltype',
'backendopt_ootype',
'llinterpret_lltype',
- 'rtype_ootype', 'rtype_lltype',
- 'source_cl', 'source_js', 'source_squeak', 'source_cli', 'source_c',
- 'source_llvm', 'compile_cl', 'compile_cli', 'compile_c', 'compile_squeak',
- 'compile_llvm', 'compile_js', 'run_cl', 'run_squeak', 'run_llvm',
- 'run_c', 'run_js', 'run_cli'])
-
- d = DEFAULT_OPTIONS.copy()
- d['backend'] = None
- d['type_system'] = 'lltype'
- td = TranslationDriver(options=optparse.Values(defaults=d))
+ 'rtype_ootype', 'rtype_lltype', 'source_cl', 'source_js',
+ 'source_squeak', 'source_cli', 'source_c', 'source_llvm',
+ 'compile_cl', 'compile_cli', 'compile_c', 'compile_squeak',
+ 'compile_llvm', 'compile_js', 'run_cl', 'run_squeak',
+ 'run_llvm', 'run_c', 'run_js', 'run_cli'])
+
+ td = TranslationDriver({'backend': None, 'type_system': 'lltype'})
assert td.backend_select_goals(['compile_c']) == ['compile_c']
py.test.raises(Exception, td.backend_select_goals, ['compile'])
- assert td.backend_select_goals(['rtype_lltype']) == ['rtype_lltype']
- assert td.backend_select_goals(['rtype']) == ['rtype_lltype']
+ assert td.backend_select_goals(['rtype_lltype']) == ['rtype_lltype']
+ assert td.backend_select_goals(['rtype']) == ['rtype_lltype']
assert td.backend_select_goals(['backendopt']) == ['backendopt_lltype']
- assert td.backend_select_goals(['backendopt_lltype']) == ['backendopt_lltype']
+ assert td.backend_select_goals(['backendopt_lltype']) == [
+ 'backendopt_lltype']
assert cmpl(td.exposed,
- ['annotate', 'backendopt', 'llinterpret', 'rtype', 'source_c', 'source_llvm',
- 'compile_c', 'compile_llvm', 'run_llvm', 'run_c'])
+ ['annotate', 'backendopt', 'llinterpret', 'rtype', 'source_c',
+ 'source_llvm', 'compile_c', 'compile_llvm', 'run_llvm',
+ 'run_c'])
Modified: pypy/branch/even-more-config4/pypy/translator/test/test_interactive.py
==============================================================================
--- pypy/branch/even-more-config4/pypy/translator/test/test_interactive.py (original)
+++ pypy/branch/even-more-config4/pypy/translator/test/test_interactive.py Tue Oct 24 22:18:14 2006
@@ -41,10 +41,6 @@
assert 'rtype_lltype' in t.driver.done
- t = Translation(f, [int, int])
- t.annotate()
- py.test.raises(Exception, "t.rtype([int, int],debug=False)")
-
def test_simple_backendopt():
def f(x, y):
return x,y
Modified: pypy/branch/even-more-config4/pypy/translator/translator.py
==============================================================================
--- pypy/branch/even-more-config4/pypy/translator/translator.py (original)
+++ pypy/branch/even-more-config4/pypy/translator/translator.py Tue Oct 24 22:18:14 2006
@@ -12,9 +12,9 @@
from pypy.tool.ansi_print import ansi_log
from pypy.tool.sourcetools import nice_repr_for_func
import py
-log = py.log.Producer("flowgraph")
-py.log.setconsumer("flowgraph", ansi_log)
-
+log = py.log.Producer("flowgraph")
+py.log.setconsumer("flowgraph", ansi_log)
+
class TranslationContext(object):
FLOWING_FLAGS = {
'verbose': False,
@@ -24,11 +24,18 @@
'list_comprehension_operations': False, # True, - not super-tested
}
- def __init__(self, **flowing_flags):
- self.flags = self.FLOWING_FLAGS.copy()
- self.flags.update(flowing_flags)
- if len(self.flags) > len(self.FLOWING_FLAGS):
- raise TypeError("unexpected keyword argument")
+ def __init__(self, config=None, **flowing_flags):
+ if config is None:
+ from pypy.config.config import Config
+ from pypy.config.pypyoption import pypy_optiondescription
+ config = Config(pypy_optiondescription)
+ # ZZZ should go away in the end
+ for attr in ['verbose', 'simplifying', 'do_imports_immediately',
+ 'builtins_can_raise_exceptions',
+ 'list_comprehension_operations']:
+ if attr in flowing_flags:
+ setattr(config.translation, attr, flowing_flags[attr])
+ self.config = config
self.annotator = None
self.rtyper = None
self.exceptiontransformer = None
@@ -47,18 +54,18 @@
if func in self._prebuilt_graphs:
graph = self._prebuilt_graphs.pop(func)
else:
- if self.flags.get('verbose'):
+ if self.config.translation.verbose:
log.start(nice_repr_for_func(func))
- space = FlowObjSpace()
- space.__dict__.update(self.flags) # xxx push flags there
+ space = FlowObjSpace(self.config)
if self.annotator:
+ # ZZZ
self.annotator.policy._adjust_space_config(space)
graph = space.build_flow(func)
- if self.flags.get('simplifying'):
+ if self.config.translation.simplifying:
simplify.simplify_graph(graph)
- if self.flags.get('list_comprehension_operations'):
+ if self.config.translation.list_comprehension_operations:
simplify.detect_list_comprehension(graph)
- if self.flags.get('verbose'):
+ if self.config.translation.verbose:
log.done(func.__name__)
self.graphs.append(graph) # store the graph in our list
return graph
More information about the Pypy-commit
mailing list