[pypy-svn] r65950 - in pypy/branch/pyjitpl5/pypy: interpreter jit/tl/spli jit/tl/spli/test
benjamin at codespeak.net
benjamin at codespeak.net
Thu Jun 25 01:00:11 CEST 2009
Author: benjamin
Date: Thu Jun 25 01:00:09 2009
New Revision: 65950
Modified:
pypy/branch/pyjitpl5/pypy/interpreter/pycode.py
pypy/branch/pyjitpl5/pypy/jit/tl/spli/objects.py
pypy/branch/pyjitpl5/pypy/jit/tl/spli/pycode.py
pypy/branch/pyjitpl5/pypy/jit/tl/spli/serializer.py
pypy/branch/pyjitpl5/pypy/jit/tl/spli/test/test_jit.py
Log:
make SPLI code objects SPLIObjects
Modified: pypy/branch/pyjitpl5/pypy/interpreter/pycode.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/interpreter/pycode.py (original)
+++ pypy/branch/pyjitpl5/pypy/interpreter/pycode.py Thu Jun 25 01:00:09 2009
@@ -117,7 +117,7 @@
return self._signature
@classmethod
- def _from_code(cls, space, code, hidden_applevel=False):
+ def _from_code(cls, space, code, hidden_applevel=False, code_hook=None):
""" Initialize the code object from a real (CPython) one.
This is just a hack, until we have our own compile.
At the moment, we just fake this.
@@ -126,9 +126,11 @@
assert isinstance(code, types.CodeType)
newconsts_w = [None] * len(code.co_consts)
num = 0
+ if code_hook is None:
+ code_hook = cls._from_code
for const in code.co_consts:
if isinstance(const, types.CodeType): # from stable compiler
- const = cls._from_code(space, const, hidden_applevel=hidden_applevel)
+ const = code_hook(space, const, hidden_applevel, code_hook)
newconsts_w[num] = space.wrap(const)
num += 1
# stick the underlying CPython magic value, if the code object
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 01:00:09 2009
@@ -14,6 +14,8 @@
return spli_None
elif isinstance(x, Wrappable):
return x.__spacebind__(self)
+ elif isinstance(x, SPLIObject):
+ return x # Already done.
else:
raise NotImplementedError("Wrapping %s" % x)
Modified: pypy/branch/pyjitpl5/pypy/jit/tl/spli/pycode.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/tl/spli/pycode.py (original)
+++ pypy/branch/pyjitpl5/pypy/jit/tl/spli/pycode.py Thu Jun 25 01:00:09 2009
@@ -1,60 +1,22 @@
+from pypy.interpreter import pycode
+from pypy.jit.tl.spli import objects
-from pypy.interpreter import pycode, eval
-class Code(pycode.PyCode):
- def __init__(self, space, argcount, nlocals, stacksize, flags,
- code, consts, names, varnames, filename,
- name, firstlineno, lnotab, freevars, cellvars,
- hidden_applevel=False, magic = pycode.default_magic):
+class Code(objects.SPLIObject):
+
+ def __init__(self, argcount, nlocals, stacksize, code, consts, names):
"""Initialize a new code object from parameters given by
the pypy compiler"""
- self.space = space
- eval.Code.__init__(self, name)
self.co_argcount = argcount
self.co_nlocals = nlocals
self.co_stacksize = stacksize
- self.co_flags = flags
self.co_code = code
self.co_consts_w = consts
- self.co_names_w = [space.new_interned_str(aname) for aname in names]
- self.co_varnames = varnames
- self.co_freevars = freevars
- self.co_cellvars = cellvars
- self.co_filename = filename
- self.co_name = name
- self.co_firstlineno = firstlineno
- self.co_lnotab = lnotab
- self.hidden_applevel = hidden_applevel
- self.magic = magic
- #self._signature = cpython_code_signature(self)
- # Precompute what arguments need to be copied into cellvars
- self._args_as_cellvars = []
-
-# if self.co_cellvars:
-# argcount = self.co_argcount
-# assert argcount >= 0 # annotator hint
-# if self.co_flags & CO_VARARGS:
-# argcount += 1
-# if self.co_flags & CO_VARKEYWORDS:
-# argcount += 1
-# # Cell vars could shadow already-set arguments.
-# # astcompiler.pyassem used to be clever about the order of
-# # the variables in both co_varnames and co_cellvars, but
-# # it no longer is for the sake of simplicity. Moreover
-# # code objects loaded from CPython don't necessarily follow
-# # an order, which could lead to strange bugs if .pyc files
-# # produced by CPython are loaded by PyPy. Note that CPython
-# # contains the following bad-looking nested loops at *every*
-# # function call!
-# argvars = self.co_varnames
-# cellvars = self.co_cellvars
-# for i in range(len(cellvars)):
-# cellname = cellvars[i]
-# for j in range(argcount):
-# if cellname == argvars[j]:
-# # argument j has the same name as the cell var i
-# while len(self._args_as_cellvars) <= i:
-# self._args_as_cellvars.append(-1) # pad
-# self._args_as_cellvars[i] = j
+ self.co_names_w = names
-# self._compute_flatcall()
+ @classmethod
+ def _from_code(cls, space, code, hidden_applevel=False, code_hook=None):
+ pyco = pycode.PyCode._from_code(space, code, code_hook=cls._from_code)
+ return cls(pyco.co_argcount, pyco.co_nlocals, pyco.co_stacksize,
+ pyco.co_code, pyco.co_consts_w,
+ pyco.co_names_w)
Modified: pypy/branch/pyjitpl5/pypy/jit/tl/spli/serializer.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/tl/spli/serializer.py (original)
+++ pypy/branch/pyjitpl5/pypy/jit/tl/spli/serializer.py Thu Jun 25 01:00:09 2009
@@ -10,7 +10,7 @@
from pypy.rlib.rstruct.runpack import runpack
import struct
-FMT = 'iiiii'
+FMT = 'iiii'
int_lgt = len(struct.pack('i', 0))
header_lgt = int_lgt * len(FMT)
@@ -57,24 +57,18 @@
def serialize(code):
header = struct.pack(FMT, code.co_argcount, code.co_nlocals,
- code.co_stacksize, code.co_flags, len(code.co_code))
- constsrepr = (struct.pack('i', len(code.co_consts)) +
+ code.co_stacksize, len(code.co_code))
+ constsrepr = (struct.pack('i', len(code.co_consts)) +
"".join([serialize_const(const) for const in code.co_consts]))
return header + code.co_code + constsrepr
-def deserialize(coderepr, space=None):
- if space is None:
- space = DumbObjSpace()
+def deserialize(coderepr):
header = coderepr[:header_lgt]
- argcount, nlocals, stacksize, flags, code_len = runpack(FMT, header)
+ argcount, nlocals, stacksize, code_len = runpack(FMT, header)
assert code_len >= 0
code = coderepr[header_lgt:(code_len + header_lgt)]
consts = unserialize_consts(coderepr[code_len + header_lgt:])
- names = []
- varnames = ["a", "b", "cde"] # help annotator, nobody ever reads it
- return Code(space, argcount, nlocals, stacksize, flags, code,
- consts, names, varnames, 'file', 'code', 0,
- 0, [], [])
+ return Code(argcount, nlocals, stacksize, code, consts, [])
def main(argv):
if len(argv) != 4:
Modified: pypy/branch/pyjitpl5/pypy/jit/tl/spli/test/test_jit.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/tl/spli/test/test_jit.py (original)
+++ pypy/branch/pyjitpl5/pypy/jit/tl/spli/test/test_jit.py Thu Jun 25 01:00:09 2009
@@ -14,19 +14,17 @@
def interpret(self, f, args):
coderepr = serializer.serialize(f.func_code)
- space = objects.DumbObjSpace()
arg_params = ", ".join(['arg%d' % i for i in range(len(args))])
arg_ass = "\n ".join(['frame.locals[%d] = arg%d' % (i, i) for
i in range(len(args))])
source = py.code.Source("""
def bootstrap(%(arg_params)s):
- co = serializer.deserialize(coderepr, space)
+ co = serializer.deserialize(coderepr)
frame = interpreter.SPLIFrame(co)
%(arg_ass)s
return frame.run()
""" % locals())
d = globals().copy()
- d['space'] = space
d['coderepr'] = coderepr
exec source.compile() in d
return self.meta_interp(d['bootstrap'], args, listops=True,
More information about the Pypy-commit
mailing list