[pypy-svn] r28325 - in pypy/dist/pypy: bin interpreter translator/goal
ac at codespeak.net
ac at codespeak.net
Mon Jun 5 13:17:26 CEST 2006
Author: ac
Date: Mon Jun 5 13:17:26 2006
New Revision: 28325
Modified:
pypy/dist/pypy/bin/py.py
pypy/dist/pypy/interpreter/baseobjspace.py
pypy/dist/pypy/translator/goal/targetpypystandalone.py
Log:
(cfbolz, arre)
Add the methods setup and finish to objectspaces.
Modified: pypy/dist/pypy/bin/py.py
==============================================================================
--- pypy/dist/pypy/bin/py.py (original)
+++ pypy/dist/pypy/bin/py.py Mon Jun 5 13:17:26 2006
@@ -111,26 +111,27 @@
banner = None
try:
- # compile and run it
- if not main.run_toplevel(space, doit, verbose=Options.verbose):
- exit_status = 1
+ def do_start():
+ space.startup()
+ if main.run_toplevel(space, do_start, verbose=Options.verbose):
+ # compile and run it
+ if not main.run_toplevel(space, doit, verbose=Options.verbose):
+ exit_status = 1
- # start the interactive console
- if go_interactive:
- con = interactive.PyPyConsole(space, verbose=Options.verbose,
- completer=Options.completer)
- if banner == '':
- banner = '%s / %s'%(con.__class__.__name__,
- repr(space))
- con.interact(banner)
- exit_status = 0
+ # start the interactive console
+ if go_interactive:
+ con = interactive.PyPyConsole(
+ space, verbose=Options.verbose,
+ completer=Options.completer)
+ if banner == '':
+ banner = '%s / %s'%(con.__class__.__name__,
+ repr(space))
+ con.interact(banner)
+ exit_status = 0
finally:
- # call the sys.exitfunc()
- w_exitfunc = space.sys.getdictvalue_w(space, 'exitfunc')
- if w_exitfunc is not None:
- def doit():
- space.call_function(w_exitfunc)
- main.run_toplevel(space, doit, verbose=Options.verbose)
+ def doit():
+ space.finish()
+ main.run_toplevel(space, doit, verbose=Options.verbose)
return exit_status
Modified: pypy/dist/pypy/interpreter/baseobjspace.py
==============================================================================
--- pypy/dist/pypy/interpreter/baseobjspace.py (original)
+++ pypy/dist/pypy/interpreter/baseobjspace.py Mon Jun 5 13:17:26 2006
@@ -158,6 +158,15 @@
# override this in subclasses for extra-options
pass
+ def startup(self):
+ # To be called before using the space
+ pass
+
+ def finish(self):
+ w_exitfunc = self.sys.getdictvalue_w(self, 'exitfunc')
+ if w_exitfunc is not None:
+ self.call_function(w_exitfunc)
+
def __repr__(self):
try:
return self._this_space_repr_
Modified: pypy/dist/pypy/translator/goal/targetpypystandalone.py
==============================================================================
--- pypy/dist/pypy/translator/goal/targetpypystandalone.py (original)
+++ pypy/dist/pypy/translator/goal/targetpypystandalone.py Mon Jun 5 13:17:26 2006
@@ -30,19 +30,30 @@
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)
+ try:
+ space.call_function(w_run_toplevel, w_call_startup)
+ 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)
+ exitcode = space.int_w(w_exitcode)
+ # 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
+ finally:
+ try:
+ space.call_function(w_run_toplevel, w_call_finish)
+ 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 exitcode
# _____ Define and setup target ___
@@ -64,6 +75,18 @@
opt_parser().print_help()
+def call_finish(space):
+ space.finish()
+
+w_call_finish = gateway.interp2app(call_finish)
+
+def call_startup(space):
+ space.startup()
+
+w_call_startup = gateway.interp2app(call_startup)
+
+
+
def target(driver, args):
driver.exe_name = 'pypy-%(backend)s'
options = driver.options
@@ -72,7 +95,7 @@
translate.log_options(tgt_options, "target PyPy options in effect")
- global space, w_entry_point
+ global space, w_entry_point, w_run_toplevel
geninterp = not getattr(options, 'lowmem', False)
@@ -103,6 +126,7 @@
w_dict = space.newdict([])
space.exec_(open(filename).read(), w_dict, w_dict)
w_entry_point = space.getitem(w_dict, space.wrap('entry_point'))
+ w_run_toplevel = space.getitem(w_dict, space.wrap('run_toplevel'))
# sanity-check: call the entry point
res = entry_point(["pypy", "app_basic_example.py"])
More information about the Pypy-commit
mailing list