[pypy-svn] r33414 - pypy/branch/even-more-config3/pypy/translator/goal
cfbolz at codespeak.net
cfbolz at codespeak.net
Wed Oct 18 19:04:51 CEST 2006
Author: cfbolz
Date: Wed Oct 18 19:04:50 2006
New Revision: 33414
Modified:
pypy/branch/even-more-config3/pypy/translator/goal/targetdemomodule.py
pypy/branch/even-more-config3/pypy/translator/goal/targetlogicstandalone.py
pypy/branch/even-more-config3/pypy/translator/goal/targetmultiplespaces.py
pypy/branch/even-more-config3/pypy/translator/goal/targetpypystandalone.py
pypy/branch/even-more-config3/pypy/translator/goal/targetvarsized.py
pypy/branch/even-more-config3/pypy/translator/goal/translate.py
Log:
(pedronis, cfbolz): refactored translate.py and the various targets to be able
to use configs everywhere. especially fix the three remaining pypy targets to
share more code.
Modified: pypy/branch/even-more-config3/pypy/translator/goal/targetdemomodule.py
==============================================================================
--- pypy/branch/even-more-config3/pypy/translator/goal/targetdemomodule.py (original)
+++ pypy/branch/even-more-config3/pypy/translator/goal/targetdemomodule.py Wed Oct 18 19:04:50 2006
@@ -45,7 +45,7 @@
# _____ Define and setup target ___
-def target(driver, args):
+def target(driver, args, config):
driver.extmod_name = '_demo'
return __init__, [object], CPyAnnotatorPolicy(space)
Modified: pypy/branch/even-more-config3/pypy/translator/goal/targetlogicstandalone.py
==============================================================================
--- pypy/branch/even-more-config3/pypy/translator/goal/targetlogicstandalone.py (original)
+++ pypy/branch/even-more-config3/pypy/translator/goal/targetlogicstandalone.py Wed Oct 18 19:04:50 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-config3/pypy/translator/goal/targetmultiplespaces.py
==============================================================================
--- pypy/branch/even-more-config3/pypy/translator/goal/targetmultiplespaces.py (original)
+++ pypy/branch/even-more-config3/pypy/translator/goal/targetmultiplespaces.py Wed Oct 18 19:04:50 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-config3/pypy/translator/goal/targetpypystandalone.py
==============================================================================
--- pypy/branch/even-more-config3/pypy/translator/goal/targetpypystandalone.py (original)
+++ pypy/branch/even-more-config3/pypy/translator/goal/targetpypystandalone.py Wed Oct 18 19:04:50 2006
@@ -65,86 +65,92 @@
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, useoptions=["objspace.*"], 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
+ # XXX fix this
+ #import pypy.module.sys
+ #wrapstr = 'space.wrap(%r)' % (options.__dict__)
+ #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-config3/pypy/translator/goal/targetvarsized.py
==============================================================================
--- pypy/branch/even-more-config3/pypy/translator/goal/targetvarsized.py (original)
+++ pypy/branch/even-more-config3/pypy/translator/goal/targetvarsized.py Wed Oct 18 19:04:50 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-config3/pypy/translator/goal/translate.py
==============================================================================
--- pypy/branch/even-more-config3/pypy/translator/goal/translate.py (original)
+++ pypy/branch/even-more-config3/pypy/translator/goal/translate.py Wed Oct 18 19:04:50 2006
@@ -92,10 +92,10 @@
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
@@ -143,17 +143,15 @@
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
- # xxx change this interface
- if 'opt_defaults' in targetspec_dic:
- config.translation.override(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 translateconfig.help:
- # xxx change interface
opt_parser.print_help()
if 'print_help' in targetspec_dic:
- print
- targetspec_dic['print_help']()
+ targetspec_dic['print_help'](config)
sys.exit(0)
return targetspec_dic, translateconfig, config, args
@@ -236,14 +234,14 @@
pdb_plus_show.start(tb, server_setup, graphic=not translateconfig.text)
- log_config(translateconfig)
- log_config(config)
+ log_config(translateconfig, "translate.py configuration")
try:
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:
More information about the Pypy-commit
mailing list