[pypy-svn] r11929 - pypy/dist/goal
arigo at codespeak.net
arigo at codespeak.net
Wed May 4 13:28:38 CEST 2005
Author: arigo
Date: Wed May 4 13:28:38 2005
New Revision: 11929
Added:
pypy/dist/goal/app_example.py (contents, props changed)
pypy/dist/goal/app_main.py (contents, props changed)
pypy/dist/goal/targetpypymain.py
- copied, changed from r11921, pypy/dist/goal/targetpypy.py
Log:
Trying to annotate PyPy starting from a py.py equivalent (written at app-level
for simplicity). Crashes so far, will investigate...
Added: pypy/dist/goal/app_example.py
==============================================================================
--- (empty file)
+++ pypy/dist/goal/app_example.py Wed May 4 13:28:38 2005
@@ -0,0 +1,3 @@
+print '--- beginning of app_example.py ---'
+print 6*7
+print '--- end of app_example.py ---'
Added: pypy/dist/goal/app_main.py
==============================================================================
--- (empty file)
+++ pypy/dist/goal/app_main.py Wed May 4 13:28:38 2005
@@ -0,0 +1,24 @@
+# App-level version of py.py.
+# XXX very incomplete! Blindly runs the file named as first argument.
+# No option checking, no interactive console, no fancy hooks.
+
+def entry_point(argv):
+ import sys
+ sys.executable = argv[0]
+ sys.argv = argv[1:]
+
+ mainmodule = type(sys)('__main__')
+ sys.modules['__main__'] = mainmodule
+
+ try:
+ execfile(sys.argv[0], mainmodule.__dict__)
+ except:
+ sys.excepthook(*sys.exc_info())
+ return 1
+ else:
+ return 0
+
+if __name__ == '__main__':
+ # debugging only
+ import sys
+ sys.exit(entry_point(sys.argv))
Copied: pypy/dist/goal/targetpypymain.py (from r11921, pypy/dist/goal/targetpypy.py)
==============================================================================
--- pypy/dist/goal/targetpypy.py (original)
+++ pypy/dist/goal/targetpypymain.py Wed May 4 13:28:38 2005
@@ -1,32 +1,40 @@
-import buildcache2
-from pypy.objspace.std.objspace import StdObjSpace, W_Object
-from pypy.objspace.std.intobject import W_IntObject
+import os, sys
+from pypy.objspace.std.objspace import StdObjSpace
+from pypy.annotation.model import *
+from pypy.annotation.listdef import ListDef
+
+# 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.
+
+this_dir = os.path.dirname(sys.argv[0])
# __________ Entry point __________
-def entry_point():
- w_a = W_IntObject(space, -6)
- w_b = W_IntObject(space, -7)
- return space.mul(w_a, w_b)
+def entry_point(argv):
+ w_argv = space.newlist([space.wrap(s) for s in argv])
+ w_exitcode = space.call(w_entry_point, w_argv)
+ return space.int_w(w_exitcode)
# _____ Define and setup target ___
def target():
- global space
+ global space, w_entry_point
# disable translation of the whole of classobjinterp.py
StdObjSpace.setup_old_style_classes = lambda self: None
space = StdObjSpace()
- # call cache filling code
- buildcache2.buildcache(space)
- # further call the entry_point once to trigger building remaining
- # caches (as far as analyzing the entry_point is concerned)
- entry_point()
- return entry_point, []
+ # 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'))
+
+ s_list_of_strings = SomeList(ListDef(None, SomeString()))
+ return entry_point, [s_list_of_strings]
# _____ Run translated _____
def run(c_entry_point):
- w_result = c_entry_point()
- print w_result
- print w_result.intval
- assert w_result.intval == 42
+ argv = [os.path.join(this_dir, 'app_example.py')]
+ exitcode = c_entry_point(argv)
+ assert exitcode == 0
More information about the Pypy-commit
mailing list