[pypy-svn] r65967 - in pypy/branch/pyjitpl5/pypy/jit/tl/spli: . test
benjamin at codespeak.net
benjamin at codespeak.net
Thu Jun 25 20:55:03 CEST 2009
Author: benjamin
Date: Thu Jun 25 20:55:02 2009
New Revision: 65967
Added:
pypy/branch/pyjitpl5/pypy/jit/tl/spli/execution.py (contents, props changed)
Modified:
pypy/branch/pyjitpl5/pypy/jit/tl/spli/interpreter.py
pypy/branch/pyjitpl5/pypy/jit/tl/spli/objects.py
pypy/branch/pyjitpl5/pypy/jit/tl/spli/targetspli.py
pypy/branch/pyjitpl5/pypy/jit/tl/spli/test/test_interpreter.py
pypy/branch/pyjitpl5/pypy/jit/tl/spli/test/test_serializer.py
pypy/branch/pyjitpl5/pypy/jit/tl/spli/test/test_translated.py
Log:
add an execution context with a framestack
Added: pypy/branch/pyjitpl5/pypy/jit/tl/spli/execution.py
==============================================================================
--- (empty file)
+++ pypy/branch/pyjitpl5/pypy/jit/tl/spli/execution.py Thu Jun 25 20:55:02 2009
@@ -0,0 +1,50 @@
+import dis
+
+from pypy.jit.tl.spli import interpreter, objects, pycode
+
+
+def run_from_cpython_code(co, args=[], locs=None, globs=None):
+ space = objects.DumbObjSpace()
+ pyco = pycode.Code._from_code(space, co)
+ print dis.dis(co)
+ return run(pyco, [space.wrap(arg) for arg in args], locs, globs)
+
+def run(pyco, args, locs=None, globs=None):
+ frame = interpreter.SPLIFrame(pyco, locs, globs)
+ frame.set_args(args)
+ return get_ec().execute_frame(frame)
+
+
+def get_ec():
+ ec = state.get()
+ if ec is None:
+ ec = ExecutionContext()
+ state.set(ec)
+ return ec
+
+
+class State(object):
+
+ def __init__(self):
+ self.value = None
+
+ def get(self):
+ return self.value
+
+ def set(self, new):
+ self.value = new
+
+state = State()
+
+
+class ExecutionContext(object):
+
+ def __init__(self):
+ self.framestack = []
+
+ def execute_frame(self, frame):
+ self.framestack.append(frame)
+ try:
+ return frame.run()
+ finally:
+ self.framestack.pop()
Modified: pypy/branch/pyjitpl5/pypy/jit/tl/spli/interpreter.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/tl/spli/interpreter.py (original)
+++ pypy/branch/pyjitpl5/pypy/jit/tl/spli/interpreter.py Thu Jun 25 20:55:02 2009
@@ -1,5 +1,4 @@
from pypy.tool import stdlib_opcode as opcode
-from pypy.jit.tl.spli.pycode import Code
from pypy.jit.tl.spli import objects
from pypy.tool.stdlib_opcode import unrolling_opcode_descs
from pypy.tool.stdlib_opcode import opcode_method_names
@@ -7,7 +6,6 @@
from pypy.rlib.jit import JitDriver, hint
from pypy.rlib.objectmodel import we_are_translated
-import dis
compare_ops = [
"cmp_lt", # "<"
@@ -29,18 +27,6 @@
reds = ['frame'],
virtualizables = ['frame'])
-def spli_run_from_cpython_code(co, args=[], locs=None, globs=None):
- space = objects.DumbObjSpace()
- pyco = Code._from_code(space, co)
- print dis.dis(co)
- return run(pyco, args, locs, globs, space)
-
-def run(pyco, args, locs=None, globs=None, space=None):
- if space is None:
- space = objects.DumbObjSpace()
- frame = SPLIFrame(pyco, locs, globs)
- frame.set_args([space.wrap(arg) for arg in args])
- return frame.run()
class BlockUnroller(Exception):
pass
Modified: pypy/branch/pyjitpl5/pypy/jit/tl/spli/objects.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/tl/spli/objects.py (original)
+++ pypy/branch/pyjitpl5/pypy/jit/tl/spli/objects.py Thu Jun 25 20:55:02 2009
@@ -126,7 +126,5 @@
self.globs = globs
def call(self, args):
- from pypy.jit.tl.spli import interpreter
- frame = interpreter.SPLIFrame(self.code, None, self.globs)
- frame.set_args(args)
- return frame.run()
+ from pypy.jit.tl.spli import execution
+ return execution.run(self.code, args, None, self.globs)
Modified: pypy/branch/pyjitpl5/pypy/jit/tl/spli/targetspli.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/tl/spli/targetspli.py (original)
+++ pypy/branch/pyjitpl5/pypy/jit/tl/spli/targetspli.py Thu Jun 25 20:55:02 2009
@@ -3,10 +3,9 @@
"""
import sys, autopath, os
-from pypy.jit.tl.spli import objects, interpreter, serializer
+from pypy.jit.tl.spli import execution, serializer
from pypy.rlib.streamio import open_file_as_stream
-space = objects.DumbObjSpace()
def unwrap_arg(arg):
if arg.startswith('s:'):
@@ -23,10 +22,8 @@
args = argv[2:]
stream = open_file_as_stream(argv[1])
co = serializer.deserialize(stream.readall())
- frame = interpreter.SPLIFrame(co)
- for n in range(len(args)):
- frame.locals[n] = unwrap_arg(args[n])
- res = frame.run()
+ w_args = [unwrap_arg(args[n]) for i in range(len(args))]
+ res = execution.run(co, w_args)
print res.repr()
return 0
Modified: pypy/branch/pyjitpl5/pypy/jit/tl/spli/test/test_interpreter.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/tl/spli/test/test_interpreter.py (original)
+++ pypy/branch/pyjitpl5/pypy/jit/tl/spli/test/test_interpreter.py Thu Jun 25 20:55:02 2009
@@ -1,10 +1,10 @@
import py
-from pypy.jit.tl.spli import interpreter, objects
+from pypy.jit.tl.spli import execution, objects
class TestSPLIInterpreter:
def eval(self, func, args=[]):
- return interpreter.spli_run_from_cpython_code(func.func_code, args)
+ return execution.run_from_cpython_code(func.func_code, args)
def test_int_add(self):
def f():
@@ -64,7 +64,7 @@
return g() + 3
res = f()""", "<string>", "exec")
globs = {}
- mod_res = interpreter.spli_run_from_cpython_code(code, [], globs, globs)
+ mod_res = execution.run_from_cpython_code(code, [], globs, globs)
assert mod_res is objects.spli_None
assert len(globs) == 3
assert globs["res"].as_int() == 7
Modified: pypy/branch/pyjitpl5/pypy/jit/tl/spli/test/test_serializer.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/tl/spli/test/test_serializer.py (original)
+++ pypy/branch/pyjitpl5/pypy/jit/tl/spli/test/test_serializer.py Thu Jun 25 20:55:02 2009
@@ -1,11 +1,11 @@
from pypy.jit.tl.spli.serializer import serialize, deserialize
-from pypy.jit.tl.spli import interpreter
+from pypy.jit.tl.spli import execution
class TestSerializer(object):
def eval(self, code, args=[]):
- return interpreter.run(code, args)
+ return execution.run(code, args)
def test_basic(self):
def f():
Modified: pypy/branch/pyjitpl5/pypy/jit/tl/spli/test/test_translated.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/tl/spli/test/test_translated.py (original)
+++ pypy/branch/pyjitpl5/pypy/jit/tl/spli/test/test_translated.py Thu Jun 25 20:55:02 2009
@@ -1,6 +1,6 @@
from pypy.rpython.test.test_llinterp import interpret
-from pypy.jit.tl.spli import interpreter, objects
+from pypy.jit.tl.spli import execution, objects
from pypy.jit.tl.spli.serializer import serialize, deserialize
class TestSPLITranslated(object):
@@ -12,10 +12,10 @@
space = objects.DumbObjSpace()
def run(a, b):
co = deserialize(data)
- frame = interpreter.SPLIFrame(co)
- frame.locals[0] = space.wrap(a)
- frame.locals[1] = space.wrap(b)
- w_res = frame.run()
+ args = []
+ args.append(space.wrap(a))
+ args.append(space.wrap(b))
+ w_res = execution.run(co, args)
assert isinstance(w_res, objects.Int)
return w_res.value
More information about the Pypy-commit
mailing list