[pypy-commit] pypy jit-settrace: merged default in
alex_gaynor
noreply at buildbot.pypy.org
Fri Oct 25 21:08:51 CEST 2013
Author: Alex Gaynor <alex.gaynor at gmail.com>
Branch: jit-settrace
Changeset: r67612:10d4f8c79311
Date: 2013-10-25 12:06 -0700
http://bitbucket.org/pypy/pypy/changeset/10d4f8c79311/
Log: merged default in
diff --git a/pypy/doc/faq.rst b/pypy/doc/faq.rst
--- a/pypy/doc/faq.rst
+++ b/pypy/doc/faq.rst
@@ -266,6 +266,7 @@
You cannot use most existing standard library modules from RPython. The
exceptions are
some functions in ``os``, ``math`` and ``time`` that have native support.
+We have our own "RPython standard library" in ``rpython.rlib.*``.
To read more about the RPython limitations read the `RPython description`_.
diff --git a/pypy/interpreter/eval.py b/pypy/interpreter/eval.py
--- a/pypy/interpreter/eval.py
+++ b/pypy/interpreter/eval.py
@@ -2,9 +2,7 @@
This module defines the abstract base classes that support execution:
Code and Frame.
"""
-from rpython.rlib import jit
-from pypy.interpreter.error import OperationError
from pypy.interpreter.baseobjspace import W_Root
@@ -53,76 +51,3 @@
def funcrun_obj(self, func, w_obj, args):
return self.funcrun(func, args.prepend(w_obj))
-
-
-class Frame(W_Root):
- """A frame is an environment supporting the execution of a code object.
- Abstract base class."""
-
- def __init__(self, space, w_globals=None):
- self.space = space
- self.w_globals = w_globals # wrapped dict of globals
- self.w_locals = None # wrapped dict of locals
-
- def run(self):
- "Abstract method to override. Runs the frame"
- raise TypeError("abstract")
-
- def getdictscope(self):
- "Get the locals as a dictionary."
- self.fast2locals()
- return self.w_locals
-
- def getcode(self):
- return None
-
- def fget_code(self, space):
- return space.wrap(self.getcode())
-
- def fget_getdictscope(self, space):
- return self.getdictscope()
-
- def setdictscope(self, w_locals):
- "Initialize the locals from a dictionary."
- self.w_locals = w_locals
- self.locals2fast()
-
- @jit.unroll_safe
- def fast2locals(self):
- # Copy values from the fastlocals to self.w_locals
- if self.w_locals is None:
- self.w_locals = self.space.newdict()
- varnames = self.getcode().getvarnames()
- for i in range(min(len(varnames), self.getcode().co_nlocals)):
- name = varnames[i]
- w_value = self.locals_stack_w[i]
- w_name = self.space.wrap(name)
- if w_value is not None:
- self.space.setitem(self.w_locals, w_name, w_value)
- else:
- try:
- self.space.delitem(self.w_locals, w_name)
- except OperationError as e:
- if not e.match(self.space, self.space.w_KeyError):
- raise
-
- @jit.unroll_safe
- def locals2fast(self):
- # Copy values from self.w_locals to the fastlocals
- assert self.w_locals is not None
- varnames = self.getcode().getvarnames()
- numlocals = self.getcode().co_nlocals
-
- new_fastlocals_w = [None] * numlocals
-
- for i in range(min(len(varnames), numlocals)):
- w_name = self.space.wrap(varnames[i])
- try:
- w_value = self.space.getitem(self.w_locals, w_name)
- except OperationError, e:
- if not e.match(self.space, self.space.w_KeyError):
- raise
- else:
- new_fastlocals_w[i] = w_value
-
- self.setfastscope(new_fastlocals_w)
diff --git a/pypy/interpreter/pyframe.py b/pypy/interpreter/pyframe.py
--- a/pypy/interpreter/pyframe.py
+++ b/pypy/interpreter/pyframe.py
@@ -1,19 +1,19 @@
""" PyFrame class implementation with the interpreter main loop.
"""
+from rpython.rlib import jit
+from rpython.rlib.debug import make_sure_not_resized, check_nonneg
+from rpython.rlib.jit import hint
+from rpython.rlib.objectmodel import we_are_translated, instantiate
+from rpython.rlib.rarithmetic import intmask, r_uint
from rpython.tool.pairtype import extendabletype
-from pypy.interpreter import eval, pycode
+
+from pypy.interpreter import eval, pycode, pytraceback
from pypy.interpreter.argument import Arguments
+from pypy.interpreter.baseobjspace import W_Root
from pypy.interpreter.error import OperationError, operationerrfmt
from pypy.interpreter.executioncontext import ExecutionContext
-from pypy.interpreter import pytraceback
-from rpython.rlib.objectmodel import we_are_translated, instantiate
-from rpython.rlib.jit import hint
-from rpython.rlib.debug import make_sure_not_resized, check_nonneg
-from rpython.rlib.rarithmetic import intmask, r_uint
-from rpython.rlib import jit
from pypy.tool import stdlib_opcode
-from rpython.tool.stdlib_opcode import host_bytecode_spec
# Define some opcodes used
for op in '''DUP_TOP POP_TOP SETUP_LOOP SETUP_EXCEPT SETUP_FINALLY
@@ -21,7 +21,8 @@
globals()[op] = stdlib_opcode.opmap[op]
HAVE_ARGUMENT = stdlib_opcode.HAVE_ARGUMENT
-class PyFrame(eval.Frame):
+
+class PyFrame(W_Root):
"""Represents a frame for a regular Python function
that needs to be interpreted.
@@ -56,8 +57,10 @@
"use space.FrameClass(), not directly PyFrame()")
self = hint(self, access_directly=True, fresh_virtualizable=True)
assert isinstance(code, pycode.PyCode)
+ self.space = space
+ self.w_globals = w_globals
+ self.w_locals = None
self.pycode = code
- eval.Frame.__init__(self, space, w_globals)
self.locals_stack_w = [None] * (code.co_nlocals + code.co_stacksize)
self.valuestackdepth = code.co_nlocals
self.lastblock = None
@@ -453,6 +456,59 @@
self.locals_stack_w[i] = scope_w[i]
self.init_cells()
+ def getdictscope(self):
+ """
+ Get the locals as a dictionary
+ """
+ self.fast2locals()
+ return self.w_locals
+
+ def setdictscope(self, w_locals):
+ """
+ Initialize the locals from a dictionary.
+ """
+ self.w_locals = w_locals
+ self.locals2fast()
+
+ def fast2locals(self):
+ # Copy values from the fastlocals to self.w_locals
+ if self.w_locals is None:
+ self.w_locals = self.space.newdict()
+ varnames = self.getcode().getvarnames()
+ fastscope_w = self.getfastscope()
+ for i in range(min(len(varnames), self.getfastscopelength())):
+ name = varnames[i]
+ w_value = fastscope_w[i]
+ w_name = self.space.wrap(name)
+ if w_value is not None:
+ self.space.setitem(self.w_locals, w_name, w_value)
+ else:
+ try:
+ self.space.delitem(self.w_locals, w_name)
+ except OperationError as e:
+ if not e.match(self.space, self.space.w_KeyError):
+ raise
+
+ def locals2fast(self):
+ # Copy values from self.w_locals to the fastlocals
+ assert self.w_locals is not None
+ varnames = self.getcode().getvarnames()
+ numlocals = self.getfastscopelength()
+
+ new_fastlocals_w = [None] * numlocals
+
+ for i in range(min(len(varnames), numlocals)):
+ w_name = self.space.wrap(varnames[i])
+ try:
+ w_value = self.space.getitem(self.w_locals, w_name)
+ except OperationError, e:
+ if not e.match(self.space, self.space.w_KeyError):
+ raise
+ else:
+ new_fastlocals_w[i] = w_value
+
+ self.setfastscope(new_fastlocals_w)
+
def init_cells(self):
"""Initialize cellvars from self.locals_stack_w.
This is overridden in nestedscope.py"""
@@ -467,6 +523,12 @@
def _setcellvars(self, cellvars):
pass
+ def fget_code(self, space):
+ return space.wrap(self.getcode())
+
+ def fget_getdictscope(self, space):
+ return self.getdictscope()
+
### line numbers ###
def fget_f_lineno(self, space):
@@ -480,7 +542,7 @@
"Returns the line number of the instruction currently being executed."
try:
new_lineno = space.int_w(w_new_lineno)
- except OperationError, e:
+ except OperationError:
raise OperationError(space.w_ValueError,
space.wrap("lineno must be an integer"))
diff --git a/pypy/interpreter/test/test_eval.py b/pypy/interpreter/test/test_eval.py
deleted file mode 100644
--- a/pypy/interpreter/test/test_eval.py
+++ /dev/null
@@ -1,64 +0,0 @@
-
-from pypy.interpreter.eval import Frame
-from pypy.interpreter.pycode import PyCode
-
-
-class TestFrame:
- def setup_method(self, method):
- def c(x, y, *args):
- pass
- code = PyCode._from_code(self.space, c.func_code)
-
- class ConcreteFastscopeFrame(Frame):
- def __init__(self, space, code, numlocals):
- self.code = code
- self.code.co_nlocals = numlocals
- Frame.__init__(self, space)
- self.locals_stack_w = [None] * numlocals
-
- def getcode(self):
- return self.code
-
- def setfastscope(self, scope_w):
- self.locals_stack_w = scope_w
-
- def getfastscope(self):
- return self.locals_stack_w
-
- self.f = ConcreteFastscopeFrame(self.space, code, numlocals=5)
-
- def test_fast2locals(self):
- space = self.space
- w = space.wrap
- self.f.fast2locals()
- assert space.eq_w(self.f.w_locals, self.space.wrap({}))
-
- self.f.locals_stack_w[0] = w(5)
- self.f.fast2locals()
- assert space.eq_w(self.f.w_locals, self.space.wrap({'x': 5}))
-
- self.f.locals_stack_w[2] = w(7)
- self.f.fast2locals()
- assert space.eq_w(self.f.w_locals, self.space.wrap({'x': 5, 'args': 7}))
-
- def sameList(self, l1, l2):
- assert len(l1) == len(l2)
- for w_1, w_2 in zip(l1, l2):
- assert (w_1 is None) == (w_2 is None)
- if w_1 is not None:
- assert self.space.eq_w(w_1, w_2)
-
- def test_locals2fast(self):
- w = self.space.wrap
- self.f.w_locals = self.space.wrap({})
- self.f.locals2fast()
- self.sameList(self.f.locals_stack_w, [None] * 5)
-
- self.f.w_locals = self.space.wrap({'x': 5})
- self.f.locals2fast()
- self.sameList(self.f.locals_stack_w, [w(5)] + [None] * 4)
-
- self.f.w_locals = self.space.wrap({'x': 5, 'args': 7})
- self.f.locals2fast()
- self.sameList(self.f.locals_stack_w, [w(5), None, w(7),
- None, None])
diff --git a/pypy/interpreter/typedef.py b/pypy/interpreter/typedef.py
--- a/pypy/interpreter/typedef.py
+++ b/pypy/interpreter/typedef.py
@@ -605,7 +605,7 @@
#
# Definition of the type's descriptors for all the internal types
-from pypy.interpreter.eval import Code, Frame
+from pypy.interpreter.eval import Code
from pypy.interpreter.pycode import PyCode, CO_VARARGS, CO_VARKEYWORDS
from pypy.interpreter.pyframe import PyFrame
from pypy.interpreter.pyopcode import SuspendedUnroller
@@ -711,13 +711,6 @@
BuiltinCode.typedef.acceptable_as_base_class = False
-Frame.typedef = TypeDef('internal-frame',
- f_code = GetSetProperty(Frame.fget_code),
- f_locals = GetSetProperty(Frame.fget_getdictscope),
- f_globals = interp_attrproperty_w('w_globals', cls=Frame),
- )
-Frame.typedef.acceptable_as_base_class = False
-
PyCode.typedef = TypeDef('code',
__new__ = interp2app(PyCode.descr_code__new__.im_func),
__eq__ = interp2app(PyCode.descr_code__eq__),
@@ -756,7 +749,10 @@
f_exc_value = GetSetProperty(PyFrame.fget_f_exc_value),
f_exc_traceback = GetSetProperty(PyFrame.fget_f_exc_traceback),
f_restricted = GetSetProperty(PyFrame.fget_f_restricted),
- **Frame.typedef.rawdict)
+ f_code = GetSetProperty(PyFrame.fget_code),
+ f_locals = GetSetProperty(PyFrame.fget_getdictscope),
+ f_globals = interp_attrproperty_w('w_globals', cls=PyFrame),
+)
PyFrame.typedef.acceptable_as_base_class = False
Module.typedef = TypeDef("module",
diff --git a/pypy/module/_cffi_backend/ctypeprim.py b/pypy/module/_cffi_backend/ctypeprim.py
--- a/pypy/module/_cffi_backend/ctypeprim.py
+++ b/pypy/module/_cffi_backend/ctypeprim.py
@@ -207,7 +207,7 @@
def unpack_list_of_int_items(self, w_cdata):
if self.size == rffi.sizeof(rffi.LONG):
- from rpython.rlib.rarray import populate_list_from_raw_array
+ from rpython.rlib.rrawarray import populate_list_from_raw_array
res = []
buf = rffi.cast(rffi.LONGP, w_cdata._cdata)
length = w_cdata.get_array_length()
@@ -223,7 +223,7 @@
int_list = self.space.listview_int(w_ob)
if int_list is not None:
if self.size == rffi.sizeof(rffi.LONG): # fastest path
- from rpython.rlib.rarray import copy_list_to_raw_array
+ from rpython.rlib.rrawarray import copy_list_to_raw_array
cdata = rffi.cast(rffi.LONGP, cdata)
copy_list_to_raw_array(int_list, cdata)
else:
@@ -367,7 +367,7 @@
def unpack_list_of_float_items(self, w_cdata):
if self.size == rffi.sizeof(rffi.DOUBLE):
- from rpython.rlib.rarray import populate_list_from_raw_array
+ from rpython.rlib.rrawarray import populate_list_from_raw_array
res = []
buf = rffi.cast(rffi.DOUBLEP, w_cdata._cdata)
length = w_cdata.get_array_length()
@@ -383,7 +383,7 @@
float_list = self.space.listview_float(w_ob)
if float_list is not None:
if self.size == rffi.sizeof(rffi.DOUBLE): # fastest path
- from rpython.rlib.rarray import copy_list_to_raw_array
+ from rpython.rlib.rrawarray import copy_list_to_raw_array
cdata = rffi.cast(rffi.DOUBLEP, cdata)
copy_list_to_raw_array(float_list, cdata)
return True
diff --git a/pypy/module/_cffi_backend/test/test_fastpath.py b/pypy/module/_cffi_backend/test/test_fastpath.py
--- a/pypy/module/_cffi_backend/test/test_fastpath.py
+++ b/pypy/module/_cffi_backend/test/test_fastpath.py
@@ -136,19 +136,19 @@
def setup_method(self, meth):
from pypy.interpreter import gateway
- from rpython.rlib import rarray
+ from rpython.rlib import rrawarray
#
self.count = 0
def get_count(*args):
return self.space.wrap(self.count)
self.w_get_count = self.space.wrap(gateway.interp2app(get_count))
#
- original = rarray.populate_list_from_raw_array
+ original = rrawarray.populate_list_from_raw_array
def populate_list_from_raw_array(*args):
self.count += 1
return original(*args)
self._original = original
- rarray.populate_list_from_raw_array = populate_list_from_raw_array
+ rrawarray.populate_list_from_raw_array = populate_list_from_raw_array
#
original2 = misc.unpack_list_from_raw_array
def unpack_list_from_raw_array(*args):
@@ -177,8 +177,8 @@
def teardown_method(self, meth):
- from rpython.rlib import rarray
- rarray.populate_list_from_raw_array = self._original
+ from rpython.rlib import rrawarray
+ rrawarray.populate_list_from_raw_array = self._original
misc.unpack_list_from_raw_array = self._original2
misc.unpack_cfloat_list_from_raw_array = self._original3
misc.unpack_unsigned_list_from_raw_array = self._original4
diff --git a/pypy/module/pypyjit/test_pypy_c/test_call.py b/pypy/module/pypyjit/test_pypy_c/test_call.py
--- a/pypy/module/pypyjit/test_pypy_c/test_call.py
+++ b/pypy/module/pypyjit/test_pypy_c/test_call.py
@@ -431,7 +431,6 @@
i15 = getfield_gc_pure(p8, descr=<FieldS pypy.objspace.std.intobject.W_IntObject.inst_intval .*>)
i17 = int_lt(i15, 5000)
guard_true(i17, descr=...)
- p18 = getfield_gc(p0, descr=<FieldP pypy.interpreter.eval.Frame.inst_w_globals .*>)
guard_value(p18, ConstPtr(ptr19), descr=...)
p20 = getfield_gc(p18, descr=<FieldP pypy.objspace.std.dictmultiobject.W_DictMultiObject.inst_strategy .*>)
guard_value(p20, ConstPtr(ptr21), descr=...)
diff --git a/pypy/module/pypyjit/test_pypy_c/test_globals.py b/pypy/module/pypyjit/test_pypy_c/test_globals.py
--- a/pypy/module/pypyjit/test_pypy_c/test_globals.py
+++ b/pypy/module/pypyjit/test_pypy_c/test_globals.py
@@ -16,8 +16,6 @@
assert log.result == 500
loop, = log.loops_by_filename(self.filepath)
assert loop.match_by_id("loadglobal", """
- p10 = getfield_gc(p0, descr=<FieldP .*Frame.inst_w_globals .*>)
- guard_value(p10, ConstPtr(ptr11), descr=...)
p12 = getfield_gc(p10, descr=<FieldP .*W_DictMultiObject.inst_strategy .*>)
guard_value(p12, ConstPtr(ptr13), descr=...)
guard_not_invalidated(descr=...)
diff --git a/rpython/rlib/rarray.py b/rpython/rlib/rrawarray.py
rename from rpython/rlib/rarray.py
rename to rpython/rlib/rrawarray.py
--- a/rpython/rlib/rarray.py
+++ b/rpython/rlib/rrawarray.py
@@ -1,5 +1,4 @@
from rpython.annotator import model as annmodel
-from rpython.annotator.listdef import ListDef
from rpython.rlib.objectmodel import specialize
from rpython.rlib import jit
from rpython.rtyper.lltypesystem import lltype, llmemory
diff --git a/rpython/rlib/test/test_rarray.py b/rpython/rlib/test/test_rrawarray.py
rename from rpython/rlib/test/test_rarray.py
rename to rpython/rlib/test/test_rrawarray.py
--- a/rpython/rlib/test/test_rarray.py
+++ b/rpython/rlib/test/test_rrawarray.py
@@ -1,4 +1,5 @@
-from rpython.rlib.rarray import copy_list_to_raw_array, populate_list_from_raw_array
+from rpython.rlib.rrawarray import copy_list_to_raw_array, \
+ populate_list_from_raw_array
from rpython.rtyper.lltypesystem import lltype, rffi
from rpython.rtyper.test.tool import BaseRtypingTest
More information about the pypy-commit
mailing list