[pypy-commit] pypy default: merge
fijal
noreply at buildbot.pypy.org
Thu Jan 30 11:39:07 CET 2014
Author: Maciej Fijalkowski <fijall at gmail.com>
Branch:
Changeset: r69015:203f1a18b7ce
Date: 2014-01-30 11:38 +0100
http://bitbucket.org/pypy/pypy/changeset/203f1a18b7ce/
Log: merge
diff too long, truncating to 2000 out of 3269 lines
diff --git a/pypy/doc/faq.rst b/pypy/doc/faq.rst
--- a/pypy/doc/faq.rst
+++ b/pypy/doc/faq.rst
@@ -426,25 +426,12 @@
Could we use LLVM?
------------------
-In theory yes. But we tried to use it 5 or 6 times already, as a
-translation backend or as a JIT backend --- and failed each time.
+There is a (static) translation backend using LLVM in the branch
+``llvm-translation-backend``. It can translate PyPy with or without the JIT on
+Linux.
-In more details: using LLVM as a (static) translation backend is
-pointless nowadays because you can generate C code and compile it with
-clang. (Note that compiling PyPy with clang gives a result that is not
-faster than compiling it with gcc.) We might in theory get extra
-benefits from LLVM's GC integration, but this requires more work on the
-LLVM side before it would be remotely useful. Anyway, it could be
-interfaced via a custom primitive in the C code.
-
-On the other hand, using LLVM as our JIT backend looks interesting as
-well --- but again we made an attempt, and it failed: LLVM has no way to
-patch the generated machine code.
-
-So the position of the core PyPy developers is that if anyone wants to
-make an N+1'th attempt with LLVM, they are welcome, and will be happy to
-provide help in the IRC channel, but they are left with the burden of proof
-that (a) it works and (b) it gives important benefits.
+Using LLVM as our JIT backend looks interesting as well -- we made an attempt,
+but it failed: LLVM has no way to patch the generated machine code.
----------------------
How do I compile PyPy?
diff --git a/pypy/interpreter/error.py b/pypy/interpreter/error.py
--- a/pypy/interpreter/error.py
+++ b/pypy/interpreter/error.py
@@ -6,7 +6,7 @@
from errno import EINTR
from rpython.rlib import jit
-from rpython.rlib.objectmodel import we_are_translated
+from rpython.rlib.objectmodel import we_are_translated, specialize
from pypy.interpreter import debug
@@ -40,12 +40,11 @@
self.debug_excs = []
def clear(self, space):
- # for sys.exc_clear()
- self.w_type = space.w_None
- self._w_value = space.w_None
- self._application_traceback = None
- if not we_are_translated():
- del self.debug_excs[:]
+ # XXX remove this method. The point is that we cannot always
+ # hack at 'self' to clear w_type and _w_value, because in some
+ # corner cases the OperationError will be used again: see
+ # test_interpreter.py:test_with_statement_and_sys_clear.
+ pass
def match(self, space, w_check_class):
"Check if this application-level exception matches 'w_check_class'."
@@ -300,6 +299,10 @@
"""
self._application_traceback = traceback
+ at specialize.memo()
+def get_cleared_operation_error(space):
+ return OperationError(space.w_None, space.w_None)
+
# ____________________________________________________________
# optimization only: avoid the slowest operation -- the string
# formatting with '%' -- in the common case were we don't
@@ -371,8 +374,8 @@
class OpErrFmtNoArgs(OperationError):
def __init__(self, w_type, value):
+ self._value = value
self.setup(w_type)
- self._value = value
def get_w_value(self, space):
w_value = self._w_value
diff --git a/pypy/interpreter/executioncontext.py b/pypy/interpreter/executioncontext.py
--- a/pypy/interpreter/executioncontext.py
+++ b/pypy/interpreter/executioncontext.py
@@ -1,5 +1,5 @@
import sys
-from pypy.interpreter.error import OperationError
+from pypy.interpreter.error import OperationError, get_cleared_operation_error
from rpython.rlib.unroll import unrolling_iterable
from rpython.rlib import jit
@@ -217,6 +217,17 @@
if frame: # else, the exception goes nowhere and is lost
frame.last_exception = operror
+ def clear_sys_exc_info(self):
+ # Find the frame out of which sys_exc_info() would return its result,
+ # and hack this frame's last_exception to become the cleared
+ # OperationError (which is different from None!).
+ frame = self.gettopframe_nohidden()
+ while frame:
+ if frame.last_exception is not None:
+ frame.last_exception = get_cleared_operation_error(self.space)
+ break
+ frame = self.getnextframe_nohidden(frame)
+
@jit.dont_look_inside
def settrace(self, w_func):
"""Set the global trace function."""
diff --git a/pypy/interpreter/pyopcode.py b/pypy/interpreter/pyopcode.py
--- a/pypy/interpreter/pyopcode.py
+++ b/pypy/interpreter/pyopcode.py
@@ -744,6 +744,9 @@
else:
raise OperationError(space.w_TypeError,
space.wrap("raise: no active exception to re-raise"))
+ if operror.w_type is space.w_None:
+ raise OperationError(space.w_TypeError,
+ space.wrap("raise: the exception to re-raise was cleared"))
# re-raise, no new traceback obj will be attached
self.last_exception = operror
raise RaiseWithExplicitTraceback(operror)
diff --git a/pypy/interpreter/test/test_interpreter.py b/pypy/interpreter/test/test_interpreter.py
--- a/pypy/interpreter/test/test_interpreter.py
+++ b/pypy/interpreter/test/test_interpreter.py
@@ -311,3 +311,73 @@
assert str(e) == "maximum recursion depth exceeded"
else:
assert 0, "should have raised!"
+
+ def test_with_statement_and_sys_clear(self):
+ import sys
+ class CM(object):
+ def __enter__(self):
+ return self
+ def __exit__(self, exc_type, exc_value, tb):
+ sys.exc_clear()
+ try:
+ with CM():
+ 1 / 0
+ raise AssertionError("should not be reached")
+ except ZeroDivisionError:
+ pass
+
+ def test_sys_clear_while_handling_exception(self):
+ import sys
+ def f():
+ try:
+ some_missing_name
+ except NameError:
+ g()
+ assert sys.exc_info()[0] is NameError
+ def g():
+ assert sys.exc_info()[0] is NameError
+ try:
+ 1 / 0
+ except ZeroDivisionError:
+ assert sys.exc_info()[0] is ZeroDivisionError
+ sys.exc_clear()
+ assert sys.exc_info()[0] is None
+ h()
+ assert sys.exc_info()[0] is None
+ def h():
+ assert sys.exc_info()[0] is None
+ f()
+
+ def test_sys_clear_while_handling_exception_nested(self):
+ import sys
+ def f():
+ try:
+ some_missing_name
+ except NameError:
+ g()
+ assert sys.exc_info()[0] is NameError
+ def g():
+ assert sys.exc_info()[0] is NameError
+ try:
+ 1 / 0
+ except ZeroDivisionError:
+ assert sys.exc_info()[0] is ZeroDivisionError
+ h1()
+ assert sys.exc_info()[0] is None
+ h()
+ assert sys.exc_info()[0] is None
+ def h():
+ assert sys.exc_info()[0] is None
+ def h1():
+ sys.exc_clear()
+ f()
+
+ def test_sys_clear_reraise(self):
+ import sys
+ def f():
+ try:
+ 1 / 0
+ except ZeroDivisionError:
+ sys.exc_clear()
+ raise
+ raises(TypeError, f)
diff --git a/pypy/module/cpyext/include/pyconfig.h b/pypy/module/cpyext/include/pyconfig.h
--- a/pypy/module/cpyext/include/pyconfig.h
+++ b/pypy/module/cpyext/include/pyconfig.h
@@ -15,6 +15,8 @@
#define HAVE_UNICODE
#define WITHOUT_COMPLEX
#define HAVE_WCHAR_H 1
+#define HAVE_SYS_TYPES_H 1
+#define HAVE_SYS_STAT_H 1
/* PyPy supposes Py_UNICODE == wchar_t */
#define HAVE_USABLE_WCHAR_T 1
diff --git a/pypy/module/cpyext/include/pyport.h b/pypy/module/cpyext/include/pyport.h
--- a/pypy/module/cpyext/include/pyport.h
+++ b/pypy/module/cpyext/include/pyport.h
@@ -64,4 +64,45 @@
# error "Python needs a typedef for Py_uintptr_t in pyport.h."
#endif /* HAVE_UINTPTR_T */
+/*******************************
+ * stat() and fstat() fiddling *
+ *******************************/
+
+/* We expect that stat and fstat exist on most systems.
+ * It's confirmed on Unix, Mac and Windows.
+ * If you don't have them, add
+ * #define DONT_HAVE_STAT
+ * and/or
+ * #define DONT_HAVE_FSTAT
+ * to your pyconfig.h. Python code beyond this should check HAVE_STAT and
+ * HAVE_FSTAT instead.
+ * Also
+ * #define HAVE_SYS_STAT_H
+ * if <sys/stat.h> exists on your platform, and
+ * #define HAVE_STAT_H
+ * if <stat.h> does.
+ */
+#ifndef DONT_HAVE_STAT
+#define HAVE_STAT
+#endif
+
+#ifndef DONT_HAVE_FSTAT
+#define HAVE_FSTAT
+#endif
+
+#ifdef RISCOS
+#include <sys/types.h>
+#include "unixstuff.h"
+#endif
+
+#ifdef HAVE_SYS_STAT_H
+#if defined(PYOS_OS2) && defined(PYCC_GCC)
+#include <sys/types.h>
+#endif
+#include <sys/stat.h>
+#elif defined(HAVE_STAT_H)
+#include <stat.h>
+#else
+#endif
+
#endif /* Py_PYPORT_H */
diff --git a/pypy/module/micronumpy/arrayimpl/concrete.py b/pypy/module/micronumpy/arrayimpl/concrete.py
--- a/pypy/module/micronumpy/arrayimpl/concrete.py
+++ b/pypy/module/micronumpy/arrayimpl/concrete.py
@@ -367,6 +367,9 @@
return SliceArray(0, strides, backstrides, new_shape, self,
orig_array)
+ def set_dtype(self, space, dtype):
+ self.dtype = dtype
+
def argsort(self, space, w_axis):
from pypy.module.micronumpy.arrayimpl.sort import argsort_array
return argsort_array(self, space, w_axis)
diff --git a/pypy/module/micronumpy/arrayimpl/scalar.py b/pypy/module/micronumpy/arrayimpl/scalar.py
--- a/pypy/module/micronumpy/arrayimpl/scalar.py
+++ b/pypy/module/micronumpy/arrayimpl/scalar.py
@@ -173,6 +173,10 @@
raise OperationError(space.w_ValueError, space.wrap(
"total size of the array must be unchanged"))
+ def set_dtype(self, space, dtype):
+ self.value = self.value.convert_to(space, dtype)
+ self.dtype = dtype
+
def reshape(self, space, orig_array, new_shape):
return self.set_shape(space, orig_array, new_shape)
diff --git a/pypy/module/micronumpy/interp_dtype.py b/pypy/module/micronumpy/interp_dtype.py
--- a/pypy/module/micronumpy/interp_dtype.py
+++ b/pypy/module/micronumpy/interp_dtype.py
@@ -207,7 +207,7 @@
space.wrap(offset)]))
return w_d
- def set_fields(self, space, w_fields):
+ def descr_set_fields(self, space, w_fields):
if w_fields == space.w_None:
self.fields = None
else:
@@ -233,19 +233,26 @@
return space.w_None
return space.newtuple([space.wrap(name) for name in self.fieldnames])
- def set_names(self, space, w_names):
- self.fieldnames = []
- if w_names == space.w_None:
- return
- else:
+ def descr_set_names(self, space, w_names):
+ fieldnames = []
+ if w_names != space.w_None:
iter = space.iter(w_names)
while True:
try:
- self.fieldnames.append(space.str_w(space.next(iter)))
+ name = space.str_w(space.next(iter))
except OperationError, e:
if not e.match(space, space.w_StopIteration):
raise
break
+ if name in fieldnames:
+ raise OperationError(space.w_ValueError, space.wrap(
+ "Duplicate field names given."))
+ fieldnames.append(name)
+ self.fieldnames = fieldnames
+
+ def descr_del_names(self, space):
+ raise OperationError(space.w_AttributeError, space.wrap(
+ "Cannot delete dtype names attribute"))
def descr_get_hasobject(self, space):
return space.w_False
@@ -321,10 +328,10 @@
self.byteorder = endian
fieldnames = space.getitem(w_data, space.wrap(3))
- self.set_names(space, fieldnames)
+ self.descr_set_names(space, fieldnames)
fields = space.getitem(w_data, space.wrap(4))
- self.set_fields(space, fields)
+ self.descr_set_fields(space, fields)
@unwrap_spec(new_order=str)
def descr_newbyteorder(self, space, new_order=NPY_SWAP):
@@ -468,7 +475,9 @@
shape = GetSetProperty(W_Dtype.descr_get_shape),
isnative = GetSetProperty(W_Dtype.descr_get_isnative),
fields = GetSetProperty(W_Dtype.descr_get_fields),
- names = GetSetProperty(W_Dtype.descr_get_names),
+ names = GetSetProperty(W_Dtype.descr_get_names,
+ W_Dtype.descr_set_names,
+ W_Dtype.descr_del_names),
hasobject = GetSetProperty(W_Dtype.descr_get_hasobject),
descr = GetSetProperty(W_Dtype.descr_get_descr),
)
diff --git a/pypy/module/micronumpy/interp_numarray.py b/pypy/module/micronumpy/interp_numarray.py
--- a/pypy/module/micronumpy/interp_numarray.py
+++ b/pypy/module/micronumpy/interp_numarray.py
@@ -84,6 +84,19 @@
def descr_get_dtype(self, space):
return self.implementation.dtype
+ def descr_set_dtype(self, space, w_dtype):
+ dtype = space.interp_w(interp_dtype.W_Dtype,
+ space.call_function(space.gettypefor(interp_dtype.W_Dtype), w_dtype))
+ if (dtype.get_size() != self.get_dtype().get_size() or
+ dtype.is_flexible_type() or self.get_dtype().is_flexible_type()):
+ raise OperationError(space.w_ValueError, space.wrap(
+ "new type not compatible with array."))
+ self.implementation.set_dtype(space, dtype)
+
+ def descr_del_dtype(self, space):
+ raise OperationError(space.w_AttributeError, space.wrap(
+ "Cannot delete array dtype"))
+
def descr_get_ndim(self, space):
return space.wrap(len(self.get_shape()))
@@ -489,6 +502,15 @@
raise OperationError(space.w_NotImplementedError, space.wrap(
"non-int arg not supported"))
+ def descr_itemset(self, space, args_w):
+ if len(args_w) == 0:
+ raise OperationError(space.w_ValueError, space.wrap(
+ "itemset must have at least one argument"))
+ if len(args_w) != len(self.get_shape()) + 1:
+ raise OperationError(space.w_ValueError, space.wrap(
+ "incorrect number of indices for array"))
+ self.descr_setitem(space, space.newtuple(args_w[:-1]), args_w[-1])
+
def descr___array__(self, space, w_dtype=None):
if not space.is_none(w_dtype):
raise OperationError(space.w_NotImplementedError, space.wrap(
@@ -629,10 +651,6 @@
raise OperationError(space.w_NotImplementedError, space.wrap(
"getfield not implemented yet"))
- def descr_itemset(self, space, w_arg):
- raise OperationError(space.w_NotImplementedError, space.wrap(
- "itemset not implemented yet"))
-
@unwrap_spec(new_order=str)
def descr_newbyteorder(self, space, new_order=NPY_SWAP):
return self.descr_view(space,
@@ -903,8 +921,8 @@
w_res = self.descr_mul(space, other)
assert isinstance(w_res, W_NDimArray)
return w_res.descr_sum(space, space.wrap(-1), out)
- dtype = interp_ufuncs.find_binop_result_dtype(space,
- self.get_dtype(), other.get_dtype())
+ dtype = interp_ufuncs.find_binop_result_dtype(space, self.get_dtype(),
+ other.get_dtype())
if self.get_size() < 1 and other.get_size() < 1:
# numpy compatability
return W_NDimArray.new_scalar(space, dtype, space.wrap(0))
@@ -912,25 +930,27 @@
out_shape, other_critical_dim = _match_dot_shapes(space, self, other)
if out:
matches = True
- if len(out.get_shape()) != len(out_shape):
+ if dtype != out.get_dtype():
+ matches = False
+ elif not out.implementation.order == "C":
+ matches = False
+ elif len(out.get_shape()) != len(out_shape):
matches = False
else:
for i in range(len(out_shape)):
if out.get_shape()[i] != out_shape[i]:
matches = False
break
- if dtype != out.get_dtype():
- matches = False
- if not out.implementation.order == "C":
- matches = False
if not matches:
raise OperationError(space.w_ValueError, space.wrap(
- 'output array is not acceptable (must have the right type, nr dimensions, and be a C-Array)'))
+ 'output array is not acceptable (must have the right type, '
+ 'nr dimensions, and be a C-Array)'))
w_res = out
+ w_res.fill(space, self.get_dtype().coerce(space, None))
else:
w_res = W_NDimArray.from_shape(space, out_shape, dtype, w_instance=self)
# This is the place to add fpypy and blas
- return loop.multidim_dot(space, self, other, w_res, dtype,
+ return loop.multidim_dot(space, self, other, w_res, dtype,
other_critical_dim)
def descr_mean(self, space, __args__):
@@ -946,7 +966,8 @@
def _reduce_ufunc_impl(ufunc_name, promote_to_largest=False,
cumulative=False):
- def impl(self, space, w_axis=None, w_dtype=None, w_out=None):
+ @unwrap_spec(keepdims=bool)
+ def impl(self, space, w_axis=None, w_dtype=None, w_out=None, keepdims=False):
if space.is_none(w_out):
out = None
elif not isinstance(w_out, W_NDimArray):
@@ -956,7 +977,7 @@
out = w_out
return getattr(interp_ufuncs.get(space), ufunc_name).reduce(
space, self, promote_to_largest, w_axis,
- False, out, w_dtype, cumulative=cumulative)
+ keepdims, out, w_dtype, cumulative=cumulative)
return func_with_new_name(impl, "reduce_%s_impl_%d_%d" % (ufunc_name,
promote_to_largest, cumulative))
@@ -1288,7 +1309,9 @@
__gt__ = interp2app(W_NDimArray.descr_gt),
__ge__ = interp2app(W_NDimArray.descr_ge),
- dtype = GetSetProperty(W_NDimArray.descr_get_dtype),
+ dtype = GetSetProperty(W_NDimArray.descr_get_dtype,
+ W_NDimArray.descr_set_dtype,
+ W_NDimArray.descr_del_dtype),
shape = GetSetProperty(W_NDimArray.descr_get_shape,
W_NDimArray.descr_set_shape),
strides = GetSetProperty(W_NDimArray.descr_get_strides),
@@ -1336,6 +1359,7 @@
flat = GetSetProperty(W_NDimArray.descr_get_flatiter,
W_NDimArray.descr_set_flatiter),
item = interp2app(W_NDimArray.descr_item),
+ itemset = interp2app(W_NDimArray.descr_itemset),
real = GetSetProperty(W_NDimArray.descr_get_real,
W_NDimArray.descr_set_real),
imag = GetSetProperty(W_NDimArray.descr_get_imag,
diff --git a/pypy/module/micronumpy/interp_ufuncs.py b/pypy/module/micronumpy/interp_ufuncs.py
--- a/pypy/module/micronumpy/interp_ufuncs.py
+++ b/pypy/module/micronumpy/interp_ufuncs.py
@@ -252,8 +252,20 @@
if out:
out.set_scalar_value(res)
return out
+ if keepdims:
+ shape = [1] * len(obj_shape)
+ out = W_NDimArray.from_shape(space, [1] * len(obj_shape), dtype, w_instance=obj)
+ out.implementation.setitem(0, res)
+ return out
return res
+ def descr_outer(self, space, __args__):
+ return self._outer(space, __args__)
+
+ def _outer(self, space, __args__):
+ raise OperationError(space.w_ValueError,
+ space.wrap("outer product only supported for binary functions"))
+
class W_Ufunc1(W_Ufunc):
_immutable_fields_ = ["func", "bool_result"]
argcount = 1
@@ -432,6 +444,7 @@
nin = interp_attrproperty("argcount", cls=W_Ufunc),
reduce = interp2app(W_Ufunc.descr_reduce),
+ outer = interp2app(W_Ufunc.descr_outer),
)
diff --git a/pypy/module/micronumpy/loop.py b/pypy/module/micronumpy/loop.py
--- a/pypy/module/micronumpy/loop.py
+++ b/pypy/module/micronumpy/loop.py
@@ -146,8 +146,7 @@
while not obj_iter.done():
reduce_driver.jit_merge_point(shapelen=shapelen, func=func,
done_func=done_func,
- calc_dtype=calc_dtype,
- )
+ calc_dtype=calc_dtype)
rval = obj_iter.getitem().convert_to(space, calc_dtype)
if done_func is not None and done_func(calc_dtype, rval):
return rval
@@ -172,8 +171,7 @@
shapelen = len(obj.get_shape())
while not obj_iter.done():
reduce_cum_driver.jit_merge_point(shapelen=shapelen, func=func,
- dtype=calc_dtype,
- )
+ dtype=calc_dtype)
rval = obj_iter.getitem().convert_to(space, calc_dtype)
cur_value = func(calc_dtype, cur_value, rval)
out_iter.setitem(cur_value)
@@ -271,8 +269,7 @@
iter.next()
shapelen = len(arr.get_shape())
while not iter.done():
- arg_driver.jit_merge_point(shapelen=shapelen, dtype=dtype,
- )
+ arg_driver.jit_merge_point(shapelen=shapelen, dtype=dtype)
w_val = iter.getitem()
new_best = getattr(dtype.itemtype, op_name)(cur_best, w_val)
if dtype.itemtype.ne(new_best, cur_best):
@@ -311,6 +308,7 @@
if i != right_critical_dim]
right_skip = range(len(left_shape) - 1)
result_skip = [len(result.get_shape()) - (len(right_shape) > 1)]
+ assert result.get_dtype() == dtype
outi = result.create_dot_iter(broadcast_shape, result_skip)
lefti = left.create_dot_iter(broadcast_shape, left_skip)
righti = right.create_dot_iter(broadcast_shape, right_skip)
@@ -318,10 +316,10 @@
dot_driver.jit_merge_point(dtype=dtype)
lval = lefti.getitem().convert_to(space, dtype)
rval = righti.getitem().convert_to(space, dtype)
- outval = outi.getitem().convert_to(space, dtype)
+ outval = outi.getitem()
v = dtype.itemtype.mul(lval, rval)
- value = dtype.itemtype.add(v, outval).convert_to(space, dtype)
- outi.setitem(value)
+ v = dtype.itemtype.add(v, outval)
+ outi.setitem(v)
outi.next()
righti.next()
lefti.next()
@@ -652,8 +650,8 @@
out_iter = out.create_iter(shape)
while not arr_iter.done():
round_driver.jit_merge_point(shapelen=shapelen, dtype=dtype)
- w_v = dtype.itemtype.round(arr_iter.getitem().convert_to(space, dtype),
- decimals)
+ w_v = arr_iter.getitem().convert_to(space, dtype)
+ w_v = dtype.itemtype.round(w_v, decimals)
out_iter.setitem(w_v)
arr_iter.next()
out_iter.next()
diff --git a/pypy/module/micronumpy/strides.py b/pypy/module/micronumpy/strides.py
--- a/pypy/module/micronumpy/strides.py
+++ b/pypy/module/micronumpy/strides.py
@@ -72,6 +72,8 @@
is_rec_type = dtype is not None and dtype.is_record_type()
if is_rec_type and is_single_elem(space, w_iterable, is_rec_type):
return [], [w_iterable]
+ if isinstance(w_iterable, W_NDimArray) and w_iterable.is_scalar():
+ return [], [w_iterable]
shape = [space.len_w(w_iterable)]
batch = space.listview(w_iterable)
while True:
diff --git a/pypy/module/micronumpy/test/test_arrayops.py b/pypy/module/micronumpy/test/test_arrayops.py
--- a/pypy/module/micronumpy/test/test_arrayops.py
+++ b/pypy/module/micronumpy/test/test_arrayops.py
@@ -56,6 +56,10 @@
b = arange(12).reshape(4, 3)
c = a.dot(b)
assert (c == [[ 42, 48, 54], [114, 136, 158], [186, 224, 262]]).all()
+ c = a.dot(b.astype(float))
+ assert (c == [[ 42, 48, 54], [114, 136, 158], [186, 224, 262]]).all()
+ c = a.astype(float).dot(b)
+ assert (c == [[ 42, 48, 54], [114, 136, 158], [186, 224, 262]]).all()
a = arange(24).reshape(2, 3, 4)
raises(ValueError, "a.dot(a)")
@@ -91,9 +95,11 @@
out = arange(9).reshape(3, 3)
c = dot(a, b, out=out)
assert (c == out).all()
- out = arange(9,dtype=float).reshape(3, 3)
+ assert (c == [[42, 48, 54], [114, 136, 158], [186, 224, 262]]).all()
+ out = arange(9, dtype=float).reshape(3, 3)
exc = raises(ValueError, dot, a, b, out)
- assert exc.value[0].find('not acceptable') > 0
+ assert exc.value[0] == ('output array is not acceptable (must have the '
+ 'right type, nr dimensions, and be a C-Array)')
def test_choose_basic(self):
from numpypy import array
diff --git a/pypy/module/micronumpy/test/test_dtypes.py b/pypy/module/micronumpy/test/test_dtypes.py
--- a/pypy/module/micronumpy/test/test_dtypes.py
+++ b/pypy/module/micronumpy/test/test_dtypes.py
@@ -204,6 +204,9 @@
assert array([256], 'B')[0] == 0
assert array([32768], 'h')[0] == -32768
assert array([65536], 'H')[0] == 0
+ a = array([65520], dtype='float64')
+ b = array(a, dtype='float16')
+ assert b == float('inf')
if dtype('l').itemsize == 4: # 32-bit
raises(OverflowError, "array([2**32/2], 'i')")
raises(OverflowError, "array([2**32], 'I')")
@@ -948,6 +951,13 @@
assert d.type is void
assert d.char == 'V'
assert d.names == ("x", "y", "z", "value")
+ d.names = ('a', 'b', 'c', 'd')
+ assert d.names == ('a', 'b', 'c', 'd')
+ exc = raises(ValueError, "d.names = ('a', 'b', 'c', 'c')")
+ assert exc.value[0] == "Duplicate field names given."
+ exc = raises(AttributeError, 'del d.names')
+ assert exc.value[0] == "Cannot delete dtype names attribute"
+ assert d.names == ('a', 'b', 'c', 'd')
raises(KeyError, 'd["xyz"]')
raises(KeyError, 'd.fields["xyz"]')
diff --git a/pypy/module/micronumpy/test/test_numarray.py b/pypy/module/micronumpy/test/test_numarray.py
--- a/pypy/module/micronumpy/test/test_numarray.py
+++ b/pypy/module/micronumpy/test/test_numarray.py
@@ -291,7 +291,6 @@
def test_noop_ndmin(self):
from numpypy import array
-
arr = array([1], ndmin=3)
assert arr.shape == (1, 1, 1)
@@ -320,6 +319,26 @@
d = c.reshape(3, 4, 0)
e = d.repeat(3, 0)
assert e.shape == (9, 4, 0)
+ a = array(123)
+ b = array(a, dtype=float)
+ assert b == 123.0
+
+ def test_dtype_attribute(self):
+ import numpy as np
+ a = np.array(40000, dtype='uint16')
+ assert a.dtype == np.uint16
+ a.dtype = np.int16
+ assert a == -25536
+ a = np.array([1, 2, 3, 4, 40000], dtype='uint16')
+ assert a.dtype == np.uint16
+ a.dtype = np.int16
+ assert a[4] == -25536
+ exc = raises(ValueError, 'a.dtype = None')
+ assert exc.value[0] == 'new type not compatible with array.'
+ exc = raises(ValueError, 'a.dtype = np.int32')
+ assert exc.value[0] == 'new type not compatible with array.'
+ exc = raises(AttributeError, 'del a.dtype')
+ assert exc.value[0] == 'Cannot delete array dtype'
def test_buffer(self):
import numpy as np
@@ -397,10 +416,6 @@
assert ten == 10
def test_empty(self):
- """
- Test that empty() works.
- """
-
from numpypy import empty
a = empty(2)
a[1] = 1.0
@@ -1383,6 +1398,8 @@
from numpypy import arange, array
a = arange(15).reshape(5, 3)
assert a.sum() == 105
+ assert a.sum(keepdims=True) == 105
+ assert a.sum(keepdims=True).shape == (1, 1)
assert a.max() == 14
assert array([]).sum() == 0.0
assert array([]).reshape(0, 2).sum() == 0.
@@ -1415,6 +1432,8 @@
from numpypy import array, dtype
a = array(range(1, 6))
assert a.prod() == 120.0
+ assert a.prod(keepdims=True) == 120.0
+ assert a.prod(keepdims=True).shape == (1,)
assert a[:4].prod() == 24.0
for dt in ['bool', 'int8', 'uint8', 'int16', 'uint16']:
a = array([True, False], dtype=dt)
@@ -1429,6 +1448,8 @@
from numpypy import array, zeros
a = array([-1.2, 3.4, 5.7, -3.0, 2.7])
assert a.max() == 5.7
+ assert a.max(keepdims=True) == 5.7
+ assert a.max(keepdims=True).shape == (1,)
b = array([])
raises(ValueError, "b.max()")
assert list(zeros((0, 2)).max(axis=1)) == []
@@ -1442,6 +1463,8 @@
from numpypy import array, zeros
a = array([-1.2, 3.4, 5.7, -3.0, 2.7])
assert a.min() == -3.0
+ assert a.min(keepdims=True) == -3.0
+ assert a.min(keepdims=True).shape == (1,)
b = array([])
raises(ValueError, "b.min()")
assert list(zeros((0, 2)).min(axis=1)) == []
@@ -1492,6 +1515,8 @@
assert a.all() == False
a[0] = 3.0
assert a.all() == True
+ assert a.all(keepdims=True) == True
+ assert a.all(keepdims=True).shape == (1,)
b = array([])
assert b.all() == True
@@ -1499,6 +1524,8 @@
from numpypy import array, zeros
a = array(range(5))
assert a.any() == True
+ assert a.any(keepdims=True) == True
+ assert a.any(keepdims=True).shape == (1,)
b = zeros(5)
assert b.any() == False
c = array([])
@@ -2795,6 +2822,19 @@
assert b[0] == 1
assert b[1] == 'ab'
+ def test_itemset(self):
+ import numpy as np
+ a = np.array(range(5))
+ exc = raises(ValueError, a.itemset)
+ assert exc.value[0] == 'itemset must have at least one argument'
+ exc = raises(ValueError, a.itemset, 1, 2, 3)
+ assert exc.value[0] == 'incorrect number of indices for array'
+ a.itemset(1, 5)
+ assert a[1] == 5
+ a = np.array(range(6)).reshape(2, 3)
+ a.itemset(1, 2, 100)
+ assert a[1, 2] == 100
+
def test_index(self):
import numpy as np
a = np.array([1], np.uint16)
diff --git a/pypy/module/micronumpy/test/test_ufuncs.py b/pypy/module/micronumpy/test/test_ufuncs.py
--- a/pypy/module/micronumpy/test/test_ufuncs.py
+++ b/pypy/module/micronumpy/test/test_ufuncs.py
@@ -1052,3 +1052,9 @@
np.array([0, -1, -3, -6, -10])).all()
assert (np.divide.accumulate(todivide) ==
np.array([2., 4., 16.])).all()
+
+ def test_outer(self):
+ import numpy as np
+ from numpypy import absolute
+ exc = raises(ValueError, np.absolute.outer, [-1, -2])
+ assert exc.value[0] == 'outer product only supported for binary functions'
diff --git a/pypy/module/micronumpy/types.py b/pypy/module/micronumpy/types.py
--- a/pypy/module/micronumpy/types.py
+++ b/pypy/module/micronumpy/types.py
@@ -404,6 +404,7 @@
if w_item is None:
return self.box(0)
return self.box(space.int_w(space.call_function(space.w_int, w_item)))
+
def _coerce(self, space, w_item):
return self._base_coerce(space, w_item)
@@ -979,7 +980,7 @@
def byteswap(self, w_v):
value = self.unbox(w_v)
- hbits = float_pack(value,2)
+ hbits = float_pack(value, 2)
swapped = byteswap(rffi.cast(self._STORAGE_T, hbits))
return self.box(float_unpack(r_ulonglong(swapped), 2))
@@ -990,11 +991,14 @@
return float_unpack(r_ulonglong(hbits), 2)
def _write(self, storage, i, offset, value):
- hbits = rffi.cast(self._STORAGE_T, float_pack(value, 2))
+ try:
+ hbits = float_pack(value, 2)
+ except OverflowError:
+ hbits = float_pack(rfloat.INFINITY, 2)
+ hbits = rffi.cast(self._STORAGE_T, hbits)
if not self.native:
hbits = byteswap(hbits)
- raw_storage_setitem(storage, i + offset,
- rffi.cast(self._STORAGE_T, hbits))
+ raw_storage_setitem(storage, i + offset, hbits)
class Float32(BaseType, Float):
T = rffi.FLOAT
diff --git a/pypy/module/struct/formatiterator.py b/pypy/module/struct/formatiterator.py
--- a/pypy/module/struct/formatiterator.py
+++ b/pypy/module/struct/formatiterator.py
@@ -3,7 +3,7 @@
from rpython.rlib.rstring import StringBuilder
from rpython.rlib.rstruct.error import StructError
from rpython.rlib.rstruct.formatiterator import FormatIterator
-from rpython.rlib.rstruct.standardfmttable import PACK_ACCEPTS_BROKEN_INPUT
+
from pypy.interpreter.error import OperationError
@@ -45,69 +45,47 @@
self.args_index += 1
return w_obj
- if PACK_ACCEPTS_BROKEN_INPUT:
- # permissive version - accepts float arguments too
+ def accept_int_arg(self):
+ return self._accept_integral("int_w")
- def accept_int_arg(self):
- return self._accept_integral("int_w")
+ def accept_uint_arg(self):
+ return self._accept_integral("uint_w")
- def accept_uint_arg(self):
- return self._accept_integral("uint_w")
+ def accept_longlong_arg(self):
+ return self._accept_integral("r_longlong_w")
- def accept_longlong_arg(self):
- return self._accept_integral("r_longlong_w")
+ def accept_ulonglong_arg(self):
+ return self._accept_integral("r_ulonglong_w")
- def accept_ulonglong_arg(self):
- return self._accept_integral("r_ulonglong_w")
+ @specialize.arg(1)
+ def _accept_integral(self, meth):
+ space = self.space
+ w_obj = self.accept_obj_arg()
+ if (space.isinstance_w(w_obj, space.w_int) or
+ space.isinstance_w(w_obj, space.w_long)):
+ w_index = w_obj
+ else:
+ w_index = None
+ w_index_method = space.lookup(w_obj, "__index__")
+ if w_index_method is not None:
+ try:
+ w_index = space.index(w_obj)
+ except OperationError, e:
+ if not e.match(space, space.w_TypeError):
+ raise
+ pass
+ if w_index is None:
+ w_index = self._maybe_float(w_obj)
+ return getattr(space, meth)(w_index)
- @specialize.arg(1)
- def _accept_integral(self, meth):
- space = self.space
- w_obj = self.accept_obj_arg()
- if (space.isinstance_w(w_obj, space.w_int) or
- space.isinstance_w(w_obj, space.w_long)):
- w_index = w_obj
- else:
- w_index = None
- w_index_method = space.lookup(w_obj, "__index__")
- if w_index_method is not None:
- try:
- w_index = space.index(w_obj)
- except OperationError, e:
- if not e.match(space, space.w_TypeError):
- raise
- pass
- if w_index is None:
- w_index = self._maybe_float(w_obj)
- return getattr(space, meth)(w_index)
-
- def _maybe_float(self, w_obj):
- space = self.space
- if space.isinstance_w(w_obj, space.w_float):
- msg = "struct: integer argument expected, got float"
- else:
- msg = "integer argument expected, got non-integer"
- space.warn(space.wrap(msg), space.w_DeprecationWarning)
- return space.int(w_obj) # wrapped float -> wrapped int or long
-
- else:
- # strict version
-
- def accept_int_arg(self):
- w_obj = self.accept_obj_arg()
- return self.space.int_w(w_obj)
-
- def accept_uint_arg(self):
- w_obj = self.accept_obj_arg()
- return self.space.uint_w(w_obj)
-
- def accept_longlong_arg(self):
- w_obj = self.accept_obj_arg()
- return self.space.r_longlong_w(w_obj)
-
- def accept_ulonglong_arg(self):
- w_obj = self.accept_obj_arg()
- return self.space.r_ulonglong_w(w_obj)
+ def _maybe_float(self, w_obj):
+ space = self.space
+ if space.isinstance_w(w_obj, space.w_float):
+ msg = "struct: integer argument expected, got float"
+ else:
+ msg = "integer argument expected, got non-integer"
+ space.warn(space.wrap(msg), space.w_DeprecationWarning)
+ return space.int(w_obj) # wrapped float -> wrapped int or long
def accept_bool_arg(self):
w_obj = self.accept_obj_arg()
diff --git a/pypy/module/sys/vm.py b/pypy/module/sys/vm.py
--- a/pypy/module/sys/vm.py
+++ b/pypy/module/sys/vm.py
@@ -155,9 +155,7 @@
to exc_info() will return (None,None,None) until another exception is
raised and caught in the current thread or the execution stack returns to a
frame where another exception is being handled."""
- operror = space.getexecutioncontext().sys_exc_info()
- if operror is not None:
- operror.clear(space)
+ space.getexecutioncontext().clear_sys_exc_info()
def settrace(space, w_func):
"""Set the global debug tracing function. It will be called on each
diff --git a/rpython/annotator/binaryop.py b/rpython/annotator/binaryop.py
--- a/rpython/annotator/binaryop.py
+++ b/rpython/annotator/binaryop.py
@@ -10,7 +10,7 @@
SomeDict, SomeOrderedDict, SomeUnicodeCodePoint, SomeUnicodeString,
SomeTuple, SomeImpossibleValue, s_ImpossibleValue, SomeInstance,
SomeBuiltin, SomeIterator, SomePBC, SomeFloat, s_None, SomeByteArray,
- SomeWeakRef, SomeAddress, SomeTypedAddressAccess, SomeSingleFloat,
+ SomeWeakRef, SomeSingleFloat,
SomeLongFloat, SomeType, SomeConstantType, unionof, UnionError,
read_can_only_throw, add_knowntypedata,
merge_knowntypedata,)
@@ -826,50 +826,6 @@
raise AnnotatorError('add on %r' % pbc)
return s_ImpossibleValue
-# ____________________________________________________________
-# annotation of low-level types
-from rpython.annotator.model import SomePtr
-from rpython.annotator.model import ll_to_annotation, annotation_to_lltype
-
-class __extend__(pairtype(SomePtr, SomePtr)):
- def union((p1, p2)):
- assert p1.ll_ptrtype == p2.ll_ptrtype,("mixing of incompatible pointer types: %r, %r" %
- (p1.ll_ptrtype, p2.ll_ptrtype))
- return SomePtr(p1.ll_ptrtype)
-
-class __extend__(pairtype(SomePtr, SomeInteger)):
-
- def getitem((p, int1)):
- example = p.ll_ptrtype._example()
- try:
- v = example[0]
- except IndexError:
- return None # impossible value, e.g. FixedSizeArray(0)
- return ll_to_annotation(v)
- getitem.can_only_throw = []
-
- def setitem((p, int1), s_value): # just doing checking
- example = p.ll_ptrtype._example()
- if example[0] is not None: # ignore Void s_value
- v_lltype = annotation_to_lltype(s_value)
- example[0] = v_lltype._defl()
- setitem.can_only_throw = []
-
-class __extend__(pairtype(SomePtr, SomeObject)):
- def union((p, obj)):
- assert False, ("mixing pointer type %r with something else %r" % (p.ll_ptrtype, obj))
-
- def getitem((p, obj)):
- assert False,"ptr %r getitem index not an int: %r" % (p.ll_ptrtype, obj)
-
- def setitem((p, obj), s_value):
- assert False,"ptr %r setitem index not an int: %r" % (p.ll_ptrtype, obj)
-
-class __extend__(pairtype(SomeObject, SomePtr)):
- def union((obj, p2)):
- return pair(p2, obj).union()
-
-
#_________________________________________
# weakrefs
@@ -884,62 +840,3 @@
if basedef is None: # no common base class! complain...
return SomeObject()
return SomeWeakRef(basedef)
-
-#_________________________________________
-# memory addresses
-
-class __extend__(pairtype(SomeAddress, SomeAddress)):
- def union((s_addr1, s_addr2)):
- return SomeAddress()
-
- def sub((s_addr1, s_addr2)):
- if s_addr1.is_null_address() and s_addr2.is_null_address():
- return getbookkeeper().immutablevalue(0)
- return SomeInteger()
-
- def is_((s_addr1, s_addr2)):
- assert False, "comparisons with is not supported by addresses"
-
-class __extend__(pairtype(SomeTypedAddressAccess, SomeTypedAddressAccess)):
- def union((s_taa1, s_taa2)):
- assert s_taa1.type == s_taa2.type
- return s_taa1
-
-class __extend__(pairtype(SomeTypedAddressAccess, SomeInteger)):
- def getitem((s_taa, s_int)):
- from rpython.annotator.model import lltype_to_annotation
- return lltype_to_annotation(s_taa.type)
- getitem.can_only_throw = []
-
- def setitem((s_taa, s_int), s_value):
- from rpython.annotator.model import annotation_to_lltype
- assert annotation_to_lltype(s_value) is s_taa.type
- setitem.can_only_throw = []
-
-
-class __extend__(pairtype(SomeAddress, SomeInteger)):
- def add((s_addr, s_int)):
- return SomeAddress()
-
- def sub((s_addr, s_int)):
- return SomeAddress()
-
-class __extend__(pairtype(SomeAddress, SomeImpossibleValue)):
- # need to override this specifically to hide the 'raise UnionError'
- # of pairtype(SomeAddress, SomeObject).
- def union((s_addr, s_imp)):
- return s_addr
-
-class __extend__(pairtype(SomeImpossibleValue, SomeAddress)):
- # need to override this specifically to hide the 'raise UnionError'
- # of pairtype(SomeObject, SomeAddress).
- def union((s_imp, s_addr)):
- return s_addr
-
-class __extend__(pairtype(SomeAddress, SomeObject)):
- def union((s_addr, s_obj)):
- raise UnionError(s_addr, s_obj)
-
-class __extend__(pairtype(SomeObject, SomeAddress)):
- def union((s_obj, s_addr)):
- raise UnionError(s_obj, s_addr)
diff --git a/rpython/annotator/bookkeeper.py b/rpython/annotator/bookkeeper.py
--- a/rpython/annotator/bookkeeper.py
+++ b/rpython/annotator/bookkeeper.py
@@ -8,11 +8,13 @@
from rpython.flowspace.model import Constant
from rpython.annotator.model import (SomeOrderedDict,
- SomeString, SomeChar, SomeFloat, SomePtr, unionof, SomeInstance, SomeDict,
- SomeBuiltin, SomePBC, SomeInteger, TLS, SomeAddress, SomeUnicodeCodePoint,
- s_None, s_ImpossibleValue, SomeLLADTMeth, SomeBool, SomeTuple,
+ SomeString, SomeChar, SomeFloat, unionof, SomeInstance, SomeDict,
+ SomeBuiltin, SomePBC, SomeInteger, TLS, SomeUnicodeCodePoint,
+ s_None, s_ImpossibleValue, SomeBool, SomeTuple,
SomeImpossibleValue, SomeUnicodeString, SomeList, HarmlesslyBlocked,
- SomeWeakRef, lltype_to_annotation, SomeType, SomeByteArray, SomeConstantType)
+ SomeWeakRef, SomeByteArray, SomeConstantType)
+from rpython.rtyper.llannotation import (
+ SomeAddress, SomePtr, SomeLLADTMeth, lltype_to_annotation)
from rpython.annotator.classdef import InstanceSource, ClassDef
from rpython.annotator.listdef import ListDef, ListItem
from rpython.annotator.dictdef import DictDef
diff --git a/rpython/annotator/builtin.py b/rpython/annotator/builtin.py
--- a/rpython/annotator/builtin.py
+++ b/rpython/annotator/builtin.py
@@ -4,12 +4,12 @@
import sys
from rpython.annotator.model import (
- SomeInteger, SomeObject, SomeChar, SomeBool, SomeString, SomeTuple, s_Bool,
- SomeUnicodeCodePoint, SomeAddress, SomeFloat, unionof, SomeUnicodeString,
+ SomeInteger, SomeObject, SomeChar, SomeBool, SomeString, SomeTuple,
+ SomeUnicodeCodePoint, SomeFloat, unionof, SomeUnicodeString,
SomePBC, SomeInstance, SomeDict, SomeList, SomeWeakRef, SomeIterator,
- SomeOrderedDict,
- SomeByteArray, annotation_to_lltype, lltype_to_annotation,
- ll_to_annotation, add_knowntypedata, s_ImpossibleValue,)
+ SomeOrderedDict, SomeByteArray, add_knowntypedata, s_ImpossibleValue,)
+from rpython.rtyper.llannotation import (
+ SomeAddress, annotation_to_lltype, lltype_to_annotation, ll_to_annotation)
from rpython.annotator.bookkeeper import getbookkeeper
from rpython.annotator import description
from rpython.flowspace.model import Constant
@@ -356,7 +356,7 @@
@analyzer_for(rpython.rtyper.lltypesystem.llmemory.cast_ptr_to_adr)
def llmemory_cast_ptr_to_adr(s):
- from rpython.annotator.model import SomeInteriorPtr
+ from rpython.rtyper.llannotation import SomeInteriorPtr
assert not isinstance(s, SomeInteriorPtr)
return SomeAddress()
@@ -389,7 +389,7 @@
# annotation of low-level types
-from rpython.annotator.model import SomePtr
+from rpython.rtyper.llannotation import SomePtr
from rpython.rtyper.lltypesystem import lltype
@analyzer_for(lltype.malloc)
diff --git a/rpython/annotator/description.py b/rpython/annotator/description.py
--- a/rpython/annotator/description.py
+++ b/rpython/annotator/description.py
@@ -624,7 +624,7 @@
except ValueError:
pass
else:
- from rpython.annotator.model import SomePtr
+ from rpython.rtyper.llannotation import SomePtr
assert not isinstance(s_arg, SomePtr)
else:
# call the constructor
diff --git a/rpython/annotator/model.py b/rpython/annotator/model.py
--- a/rpython/annotator/model.py
+++ b/rpython/annotator/model.py
@@ -569,139 +569,6 @@
self.classdef = classdef
# ____________________________________________________________
-# memory addresses
-
-from rpython.rtyper.lltypesystem import llmemory
-
-
-class SomeAddress(SomeObject):
- immutable = True
-
- def can_be_none(self):
- return False
-
- def is_null_address(self):
- return self.is_immutable_constant() and not self.const
-
-
-# The following class is used to annotate the intermediate value that
-# appears in expressions of the form:
-# addr.signed[offset] and addr.signed[offset] = value
-
-class SomeTypedAddressAccess(SomeObject):
- def __init__(self, type):
- self.type = type
-
- def can_be_none(self):
- return False
-
-#____________________________________________________________
-# annotation of low-level types
-
-from rpython.rtyper.lltypesystem import lltype
-
-
-class SomePtr(SomeObject):
- knowntype = lltype._ptr
- immutable = True
-
- def __init__(self, ll_ptrtype):
- assert isinstance(ll_ptrtype, lltype.Ptr)
- self.ll_ptrtype = ll_ptrtype
-
- def can_be_none(self):
- return False
-
-
-class SomeInteriorPtr(SomePtr):
- def __init__(self, ll_ptrtype):
- assert isinstance(ll_ptrtype, lltype.InteriorPtr)
- self.ll_ptrtype = ll_ptrtype
-
-
-class SomeLLADTMeth(SomeObject):
- immutable = True
-
- def __init__(self, ll_ptrtype, func):
- self.ll_ptrtype = ll_ptrtype
- self.func = func
-
- def can_be_none(self):
- return False
-
-
-
-annotation_to_ll_map = [
- (SomeSingleFloat(), lltype.SingleFloat),
- (s_None, lltype.Void), # also matches SomeImpossibleValue()
- (s_Bool, lltype.Bool),
- (SomeFloat(), lltype.Float),
- (SomeLongFloat(), lltype.LongFloat),
- (SomeChar(), lltype.Char),
- (SomeUnicodeCodePoint(), lltype.UniChar),
- (SomeAddress(), llmemory.Address),
-]
-
-
-def annotation_to_lltype(s_val, info=None):
- if isinstance(s_val, SomeInteriorPtr):
- p = s_val.ll_ptrtype
- if 0 in p.offsets:
- assert list(p.offsets).count(0) == 1
- return lltype.Ptr(lltype.Ptr(p.PARENTTYPE)._interior_ptr_type_with_index(p.TO))
- else:
- return lltype.Ptr(p.PARENTTYPE)
- if isinstance(s_val, SomePtr):
- return s_val.ll_ptrtype
- if type(s_val) is SomeInteger:
- return lltype.build_number(None, s_val.knowntype)
-
- for witness, T in annotation_to_ll_map:
- if witness.contains(s_val):
- return T
- if info is None:
- info = ''
- else:
- info = '%s: ' % info
- raise ValueError("%sshould return a low-level type,\ngot instead %r" % (
- info, s_val))
-
-ll_to_annotation_map = dict([(ll, ann) for ann, ll in annotation_to_ll_map])
-
-
-def lltype_to_annotation(T):
- try:
- s = ll_to_annotation_map.get(T)
- except TypeError:
- s = None # unhashable T, e.g. a Ptr(GcForwardReference())
- if s is None:
- if isinstance(T, lltype.Typedef):
- return lltype_to_annotation(T.OF)
- if isinstance(T, lltype.Number):
- return SomeInteger(knowntype=T._type)
- elif isinstance(T, lltype.InteriorPtr):
- return SomeInteriorPtr(T)
- else:
- return SomePtr(T)
- else:
- return s
-
-
-def ll_to_annotation(v):
- if v is None:
- # i think we can only get here in the case of void-returning
- # functions
- return s_None
- if isinstance(v, lltype._interior_ptr):
- ob = v._parent
- if ob is None:
- raise RuntimeError
- T = lltype.InteriorPtr(lltype.typeOf(ob), v._T, v._offsets)
- return SomeInteriorPtr(T)
- return lltype_to_annotation(lltype.typeOf(v))
-
-
-# ____________________________________________________________
class AnnotatorError(Exception):
diff --git a/rpython/annotator/signature.py b/rpython/annotator/signature.py
--- a/rpython/annotator/signature.py
+++ b/rpython/annotator/signature.py
@@ -2,10 +2,11 @@
from __future__ import absolute_import
import types
-from rpython.annotator.model import SomeBool, SomeInteger, SomeString,\
- SomeFloat, SomeList, SomeDict, s_None, \
- SomeObject, SomeInstance, SomeTuple, lltype_to_annotation,\
- unionof, SomeUnicodeString, SomeType, AnnotatorError
+from rpython.annotator.model import (
+ SomeBool, SomeInteger, SomeString, SomeFloat, SomeList, SomeDict, s_None,
+ SomeObject, SomeInstance, SomeTuple, unionof, SomeUnicodeString, SomeType,
+ AnnotatorError)
+from rpython.rtyper.llannotation import lltype_to_annotation
from rpython.annotator.listdef import ListDef
from rpython.annotator.dictdef import DictDef
diff --git a/rpython/annotator/test/test_model.py b/rpython/annotator/test/test_model.py
--- a/rpython/annotator/test/test_model.py
+++ b/rpython/annotator/test/test_model.py
@@ -99,73 +99,6 @@
assert not s1.contains(s2)
assert s1 != s2
-def test_ll_to_annotation():
- s_z = ll_to_annotation(lltype.Signed._defl())
- s_s = SomeInteger()
- s_u = SomeInteger(nonneg=True, unsigned=True)
- assert s_z.contains(s_s)
- assert not s_z.contains(s_u)
- s_uz = ll_to_annotation(lltype.Unsigned._defl())
- assert s_uz.contains(s_u)
- assert ll_to_annotation(lltype.Bool._defl()).contains(SomeBool())
- assert ll_to_annotation(lltype.Char._defl()).contains(SomeChar())
- S = lltype.GcStruct('s')
- A = lltype.GcArray()
- s_p = ll_to_annotation(lltype.malloc(S))
- assert isinstance(s_p, SomePtr) and s_p.ll_ptrtype == lltype.Ptr(S)
- s_p = ll_to_annotation(lltype.malloc(A, 0))
- assert isinstance(s_p, SomePtr) and s_p.ll_ptrtype == lltype.Ptr(A)
-
-def test_annotation_to_lltype():
- from rpython.rlib.rarithmetic import r_uint, r_singlefloat
- s_i = SomeInteger()
- s_pos = SomeInteger(nonneg=True)
- s_1 = SomeInteger(nonneg=True); s_1.const = 1
- s_m1 = SomeInteger(nonneg=False); s_m1.const = -1
- s_u = SomeInteger(nonneg=True, unsigned=True);
- s_u1 = SomeInteger(nonneg=True, unsigned=True);
- s_u1.const = r_uint(1)
- assert annotation_to_lltype(s_i) == lltype.Signed
- assert annotation_to_lltype(s_pos) == lltype.Signed
- assert annotation_to_lltype(s_1) == lltype.Signed
- assert annotation_to_lltype(s_m1) == lltype.Signed
- assert annotation_to_lltype(s_u) == lltype.Unsigned
- assert annotation_to_lltype(s_u1) == lltype.Unsigned
- assert annotation_to_lltype(SomeBool()) == lltype.Bool
- assert annotation_to_lltype(SomeChar()) == lltype.Char
- PS = lltype.Ptr(lltype.GcStruct('s'))
- s_p = SomePtr(ll_ptrtype=PS)
- assert annotation_to_lltype(s_p) == PS
- py.test.raises(ValueError, "annotation_to_lltype(si0)")
- s_singlefloat = SomeSingleFloat()
- s_singlefloat.const = r_singlefloat(0.0)
- assert annotation_to_lltype(s_singlefloat) == lltype.SingleFloat
-
-def test_ll_union():
- PS1 = lltype.Ptr(lltype.GcStruct('s'))
- PS2 = lltype.Ptr(lltype.GcStruct('s'))
- PS3 = lltype.Ptr(lltype.GcStruct('s3'))
- PA1 = lltype.Ptr(lltype.GcArray())
- PA2 = lltype.Ptr(lltype.GcArray())
-
- assert unionof(SomePtr(PS1),SomePtr(PS1)) == SomePtr(PS1)
- assert unionof(SomePtr(PS1),SomePtr(PS2)) == SomePtr(PS2)
- assert unionof(SomePtr(PS1),SomePtr(PS2)) == SomePtr(PS1)
-
- assert unionof(SomePtr(PA1),SomePtr(PA1)) == SomePtr(PA1)
- assert unionof(SomePtr(PA1),SomePtr(PA2)) == SomePtr(PA2)
- assert unionof(SomePtr(PA1),SomePtr(PA2)) == SomePtr(PA1)
-
- assert unionof(SomePtr(PS1),SomeImpossibleValue()) == SomePtr(PS1)
- assert unionof(SomeImpossibleValue(), SomePtr(PS1)) == SomePtr(PS1)
-
- py.test.raises(AssertionError, "unionof(SomePtr(PA1), SomePtr(PS1))")
- py.test.raises(AssertionError, "unionof(SomePtr(PS1), SomePtr(PS3))")
- py.test.raises(AssertionError, "unionof(SomePtr(PS1), SomeInteger())")
- py.test.raises(AssertionError, "unionof(SomePtr(PS1), SomeObject())")
- py.test.raises(AssertionError, "unionof(SomeInteger(), SomePtr(PS1))")
- py.test.raises(AssertionError, "unionof(SomeObject(), SomePtr(PS1))")
-
def test_nan():
f1 = SomeFloat()
f1.const = float("nan")
diff --git a/rpython/annotator/unaryop.py b/rpython/annotator/unaryop.py
--- a/rpython/annotator/unaryop.py
+++ b/rpython/annotator/unaryop.py
@@ -9,7 +9,7 @@
from rpython.annotator.model import (SomeObject, SomeInteger, SomeBool,
SomeString, SomeChar, SomeList, SomeDict, SomeTuple, SomeImpossibleValue,
SomeUnicodeCodePoint, SomeInstance, SomeBuiltin, SomeFloat, SomeIterator,
- SomePBC, SomeTypedAddressAccess, SomeAddress, SomeType, s_ImpossibleValue,
+ SomePBC, SomeType, s_ImpossibleValue,
s_Bool, s_None, unionof, add_knowntypedata,
HarmlesslyBlocked, SomeWeakRef, SomeUnicodeString, SomeByteArray)
from rpython.annotator.bookkeeper import getbookkeeper
@@ -758,8 +758,9 @@
raise AnnotatorError("Cannot call len on a pbc")
# annotation of low-level types
-from rpython.annotator.model import SomePtr, SomeLLADTMeth
-from rpython.annotator.model import ll_to_annotation, lltype_to_annotation, annotation_to_lltype
+from rpython.rtyper.llannotation import (
+ SomePtr, SomeLLADTMeth, ll_to_annotation, lltype_to_annotation,
+ annotation_to_lltype)
class __extend__(SomePtr):
@@ -822,20 +823,3 @@
return s_None # known to be a dead weakref
else:
return SomeInstance(self.classdef, can_be_None=True)
-
-#_________________________________________
-# memory addresses
-
-from rpython.rtyper.lltypesystem import llmemory
-
-class __extend__(SomeAddress):
- def getattr(self, s_attr):
- assert s_attr.is_constant()
- assert isinstance(s_attr, SomeString)
- assert s_attr.const in llmemory.supported_access_types
- return SomeTypedAddressAccess(
- llmemory.supported_access_types[s_attr.const])
- getattr.can_only_throw = []
-
- def bool(self):
- return s_Bool
diff --git a/rpython/jit/backend/llsupport/llmodel.py b/rpython/jit/backend/llsupport/llmodel.py
--- a/rpython/jit/backend/llsupport/llmodel.py
+++ b/rpython/jit/backend/llsupport/llmodel.py
@@ -2,6 +2,7 @@
from rpython.rtyper.lltypesystem.lloperation import llop
from rpython.rtyper.llinterp import LLInterpreter
from rpython.rtyper.annlowlevel import llhelper, MixLevelHelperAnnotator
+from rpython.rtyper.llannotation import lltype_to_annotation
from rpython.rlib.objectmodel import we_are_translated, specialize
from rpython.jit.metainterp import history
from rpython.jit.codewriter import heaptracker, longlong
@@ -14,7 +15,6 @@
FieldDescr, ArrayDescr, CallDescr, InteriorFieldDescr,
FLAG_POINTER, FLAG_FLOAT)
from rpython.jit.backend.llsupport.asmmemmgr import AsmMemoryManager
-from rpython.annotator import model as annmodel
from rpython.rlib.unroll import unrolling_iterable
@@ -111,8 +111,8 @@
fptr = llhelper(FUNC_TP, realloc_frame)
else:
FUNC = FUNC_TP.TO
- args_s = [annmodel.lltype_to_annotation(ARG) for ARG in FUNC.ARGS]
- s_result = annmodel.lltype_to_annotation(FUNC.RESULT)
+ args_s = [lltype_to_annotation(ARG) for ARG in FUNC.ARGS]
+ s_result = lltype_to_annotation(FUNC.RESULT)
mixlevelann = MixLevelHelperAnnotator(self.rtyper)
graph = mixlevelann.getgraph(realloc_frame, args_s, s_result)
fptr = mixlevelann.graph2delayed(graph, FUNC)
@@ -123,8 +123,8 @@
fptr = llhelper(FUNC_TP, realloc_frame_crash)
else:
FUNC = FUNC_TP.TO
- args_s = [annmodel.lltype_to_annotation(ARG) for ARG in FUNC.ARGS]
- s_result = annmodel.lltype_to_annotation(FUNC.RESULT)
+ args_s = [lltype_to_annotation(ARG) for ARG in FUNC.ARGS]
+ s_result = lltype_to_annotation(FUNC.RESULT)
mixlevelann = MixLevelHelperAnnotator(self.rtyper)
graph = mixlevelann.getgraph(realloc_frame_crash, args_s, s_result)
fptr = mixlevelann.graph2delayed(graph, FUNC)
diff --git a/rpython/jit/codewriter/support.py b/rpython/jit/codewriter/support.py
--- a/rpython/jit/codewriter/support.py
+++ b/rpython/jit/codewriter/support.py
@@ -1,6 +1,7 @@
import sys
from rpython.annotator import model as annmodel
+from rpython.rtyper.llannotation import lltype_to_annotation
from rpython.annotator.policy import AnnotatorPolicy
from rpython.flowspace.model import Variable, Constant
from rpython.jit.metainterp.typesystem import deref
@@ -32,7 +33,7 @@
if T == lltype.Ptr(ll_rstr.STR):
t = str
else:
- t = annmodel.lltype_to_annotation(T)
+ t = lltype_to_annotation(T)
return a.typeannotation(t)
def annotate(func, values, inline=None, backendoptimize=True,
@@ -814,12 +815,12 @@
return rtyper._builtin_func_for_spec_cache[key]
except (KeyError, AttributeError):
pass
- args_s = [annmodel.lltype_to_annotation(v) for v in ll_args]
+ args_s = [lltype_to_annotation(v) for v in ll_args]
if '.' not in oopspec_name: # 'newxxx' operations
LIST_OR_DICT = ll_res
else:
LIST_OR_DICT = ll_args[0]
- s_result = annmodel.lltype_to_annotation(ll_res)
+ s_result = lltype_to_annotation(ll_res)
impl = setup_extra_builtin(rtyper, oopspec_name, len(args_s), extra)
if getattr(impl, 'need_result_type', False):
bk = rtyper.annotator.bookkeeper
diff --git a/rpython/jit/metainterp/test/test_virtualizable.py b/rpython/jit/metainterp/test/test_virtualizable.py
--- a/rpython/jit/metainterp/test/test_virtualizable.py
+++ b/rpython/jit/metainterp/test/test_virtualizable.py
@@ -9,6 +9,7 @@
from rpython.rlib.jit import JitDriver, hint, dont_look_inside, promote, virtual_ref
from rpython.rlib.rarithmetic import intmask
from rpython.rtyper.annlowlevel import hlstr
+from rpython.rtyper.llannotation import lltype_to_annotation
from rpython.rtyper.extregistry import ExtRegistryEntry
from rpython.rtyper.lltypesystem import lltype, lloperation, rclass, llmemory
from rpython.rtyper.rclass import IR_IMMUTABLE, IR_IMMUTABLE_ARRAY, FieldListAccessor
@@ -23,7 +24,6 @@
_about_ = promote_virtualizable
def compute_result_annotation(self, *args):
- from rpython.annotator.model import lltype_to_annotation
return lltype_to_annotation(lltype.Void)
def specialize_call(self, hop):
diff --git a/rpython/jit/metainterp/warmspot.py b/rpython/jit/metainterp/warmspot.py
--- a/rpython/jit/metainterp/warmspot.py
+++ b/rpython/jit/metainterp/warmspot.py
@@ -4,6 +4,7 @@
from rpython.rtyper.lltypesystem import lltype, llmemory
from rpython.rtyper.annlowlevel import (llhelper, MixLevelHelperAnnotator,
cast_base_ptr_to_instance, hlstr)
+from rpython.rtyper.llannotation import lltype_to_annotation
from rpython.annotator import model as annmodel
from rpython.rtyper.llinterp import LLException
from rpython.rtyper.test.test_llinterp import get_interpreter, clear_tcache
@@ -662,8 +663,8 @@
if not self.cpu.translate_support_code:
return llhelper(FUNCPTR, func)
FUNC = FUNCPTR.TO
- args_s = [annmodel.lltype_to_annotation(ARG) for ARG in FUNC.ARGS]
- s_result = annmodel.lltype_to_annotation(FUNC.RESULT)
+ args_s = [lltype_to_annotation(ARG) for ARG in FUNC.ARGS]
+ s_result = lltype_to_annotation(FUNC.RESULT)
graph = self.annhelper.getgraph(func, args_s, s_result)
return self.annhelper.graph2delayed(graph, FUNC)
diff --git a/rpython/memory/gctransform/asmgcroot.py b/rpython/memory/gctransform/asmgcroot.py
--- a/rpython/memory/gctransform/asmgcroot.py
+++ b/rpython/memory/gctransform/asmgcroot.py
@@ -7,6 +7,7 @@
from rpython.rtyper.lltypesystem.lloperation import llop
from rpython.memory.gctransform.framework import (
BaseFrameworkGCTransformer, BaseRootWalker)
+from rpython.rtyper.llannotation import SomeAddress
from rpython.rtyper.rbuiltin import gen_cast
from rpython.translator.unsimplify import copyvar, varoftype
from rpython.translator.tool.cbuild import ExternalCompilationInfo
@@ -215,7 +216,7 @@
# update the global stack counter
rffi.stackcounter.stacks_counter += 1
#
- s_addr = annmodel.SomeAddress()
+ s_addr = SomeAddress()
s_None = annmodel.s_None
self.gc_detach_callback_pieces_ptr = getfn(gc_detach_callback_pieces,
[], s_addr)
@@ -327,10 +328,10 @@
inline=True)
self.thread_die_ptr = getfn(thread_die, [], annmodel.s_None)
self.thread_before_fork_ptr = getfn(thread_before_fork, [],
- annmodel.SomeAddress())
+ SomeAddress())
self.thread_after_fork_ptr = getfn(thread_after_fork,
[annmodel.SomeInteger(),
- annmodel.SomeAddress()],
+ SomeAddress()],
annmodel.s_None)
#
# check that the order of the need_*() is correct for us: if we
@@ -496,7 +497,7 @@
# location -- but we check for consistency that ebp points
# to a JITFRAME object.
from rpython.jit.backend.llsupport.jitframe import STACK_DEPTH_OFS
-
+
tid = self.gc.get_possibly_forwarded_type_id(ebp_in_caller)
ll_assert(rffi.cast(lltype.Signed, tid) ==
rffi.cast(lltype.Signed, self.frame_tid),
diff --git a/rpython/memory/gctransform/framework.py b/rpython/memory/gctransform/framework.py
--- a/rpython/memory/gctransform/framework.py
+++ b/rpython/memory/gctransform/framework.py
@@ -1,4 +1,5 @@
from rpython.annotator import model as annmodel
+from rpython.rtyper.llannotation import SomeAddress, SomePtr
from rpython.rlib import rgc
from rpython.rtyper import rmodel, annlowlevel
from rpython.rtyper.lltypesystem import lltype, llmemory, rffi, llgroup
@@ -195,21 +196,11 @@
# the point of this little dance is to not annotate
# self.gcdata.static_root_xyz as constants. XXX is it still needed??
data_classdef = bk.getuniqueclassdef(gctypelayout.GCData)
- data_classdef.generalize_attr(
- 'static_root_start',
- annmodel.SomeAddress())
- data_classdef.generalize_attr(
- 'static_root_nongcend',
- annmodel.SomeAddress())
- data_classdef.generalize_attr(
- 'static_root_end',
- annmodel.SomeAddress())
- data_classdef.generalize_attr(
- 'max_type_id',
- annmodel.SomeInteger())
- data_classdef.generalize_attr(
- 'typeids_z',
- annmodel.SomeAddress())
+ data_classdef.generalize_attr('static_root_start', SomeAddress())
+ data_classdef.generalize_attr('static_root_nongcend', SomeAddress())
+ data_classdef.generalize_attr('static_root_end', SomeAddress())
+ data_classdef.generalize_attr('max_type_id', annmodel.SomeInteger())
+ data_classdef.generalize_attr('typeids_z', SomeAddress())
annhelper = annlowlevel.MixLevelHelperAnnotator(self.translator.rtyper)
@@ -277,7 +268,7 @@
from rpython.memory.gc.base import ARRAY_TYPEID_MAP
from rpython.memory.gc import inspector
- s_gcref = annmodel.SomePtr(llmemory.GCREF)
+ s_gcref = SomePtr(llmemory.GCREF)
gcdata = self.gcdata
translator = self.translator
@@ -310,20 +301,20 @@
self.collect_ptr = getfn(GCClass.collect.im_func,
[s_gc, annmodel.SomeInteger()], annmodel.s_None)
self.can_move_ptr = getfn(GCClass.can_move.im_func,
- [s_gc, annmodel.SomeAddress()],
+ [s_gc, SomeAddress()],
annmodel.SomeBool())
if hasattr(GCClass, 'shrink_array'):
self.shrink_array_ptr = getfn(
GCClass.shrink_array.im_func,
- [s_gc, annmodel.SomeAddress(),
+ [s_gc, SomeAddress(),
annmodel.SomeInteger(nonneg=True)], annmodel.s_Bool)
else:
self.shrink_array_ptr = None
if hasattr(GCClass, 'heap_stats'):
self.heap_stats_ptr = getfn(GCClass.heap_stats.im_func,
- [s_gc], annmodel.SomePtr(lltype.Ptr(ARRAY_TYPEID_MAP)),
+ [s_gc], SomePtr(lltype.Ptr(ARRAY_TYPEID_MAP)),
minimal_transform=False)
self.get_member_index_ptr = getfn(
GCClass.get_member_index.im_func,
@@ -333,7 +324,7 @@
if hasattr(GCClass, 'writebarrier_before_copy'):
self.wb_before_copy_ptr = \
getfn(GCClass.writebarrier_before_copy.im_func,
- [s_gc] + [annmodel.SomeAddress()] * 2 +
+ [s_gc] + [SomeAddress()] * 2 +
[annmodel.SomeInteger()] * 3, annmodel.SomeBool())
elif GCClass.needs_write_barrier:
raise NotImplementedError("GC needs write barrier, but does not provide writebarrier_before_copy functionality")
@@ -421,7 +412,7 @@
if getattr(GCClass, 'obtain_free_space', False):
self.obtainfreespace_ptr = getfn(GCClass.obtain_free_space.im_func,
[s_gc, annmodel.SomeInteger()],
- annmodel.SomeAddress())
+ SomeAddress())
if GCClass.moving_gc:
self.id_ptr = getfn(GCClass.id.im_func,
@@ -457,8 +448,7 @@
minimal_transform=False)
self.get_typeids_z_ptr = getfn(inspector.get_typeids_z,
[s_gc],
- annmodel.SomePtr(
- lltype.Ptr(rgc.ARRAY_OF_CHAR)),
+ SomePtr(lltype.Ptr(rgc.ARRAY_OF_CHAR)),
minimal_transform=False)
self.set_max_heap_size_ptr = getfn(GCClass.set_max_heap_size.im_func,
@@ -470,8 +460,7 @@
self.write_barrier_from_array_ptr = None
if GCClass.needs_write_barrier:
self.write_barrier_ptr = getfn(GCClass.write_barrier.im_func,
- [s_gc,
- annmodel.SomeAddress()],
+ [s_gc, SomeAddress()],
annmodel.s_None,
inline=True)
func = getattr(gcdata.gc, 'remember_young_pointer', None)
@@ -479,13 +468,12 @@
# func should not be a bound method, but a real function
assert isinstance(func, types.FunctionType)
self.write_barrier_failing_case_ptr = getfn(func,
- [annmodel.SomeAddress()],
+ [SomeAddress()],
annmodel.s_None)
func = getattr(GCClass, 'write_barrier_from_array', None)
if func is not None:
self.write_barrier_from_array_ptr = getfn(func.im_func,
- [s_gc,
- annmodel.SomeAddress(),
+ [s_gc, SomeAddress(),
annmodel.SomeInteger()],
annmodel.s_None,
inline=True)
@@ -497,7 +485,7 @@
assert isinstance(func, types.FunctionType)
self.write_barrier_from_array_failing_case_ptr = \
getfn(func,
- [annmodel.SomeAddress()],
+ [SomeAddress()],
annmodel.s_None)
diff --git a/rpython/memory/gctransform/shadowstack.py b/rpython/memory/gctransform/shadowstack.py
--- a/rpython/memory/gctransform/shadowstack.py
+++ b/rpython/memory/gctransform/shadowstack.py
@@ -1,10 +1,12 @@
from rpython.annotator import model as annmodel
+from rpython.rtyper.llannotation import SomePtr
from rpython.rlib.debug import ll_assert
from rpython.rlib.nonconst import NonConstant
from rpython.rlib import rgc
from rpython.rtyper import rmodel
from rpython.rtyper.annlowlevel import llhelper
from rpython.rtyper.lltypesystem import lltype, llmemory
+from rpython.rtyper.llannotation import SomeAddress
from rpython.memory.gctransform.framework import (
BaseFrameworkGCTransformer, BaseRootWalker, sizeofaddr)
from rpython.rtyper.rbuiltin import gen_cast
@@ -14,11 +16,11 @@
def annotate_walker_functions(self, getfn):
self.incr_stack_ptr = getfn(self.root_walker.incr_stack,
[annmodel.SomeInteger()],
- annmodel.SomeAddress(),
+ SomeAddress(),
inline = True)
self.decr_stack_ptr = getfn(self.root_walker.decr_stack,
[annmodel.SomeInteger()],
- annmodel.SomeAddress(),
+ SomeAddress(),
inline = True)
def build_root_walker(self):
@@ -211,7 +213,7 @@
# no thread_before_fork_ptr here
self.thread_after_fork_ptr = getfn(thread_after_fork,
[annmodel.SomeInteger(),
- annmodel.SomeAddress()],
+ SomeAddress()],
annmodel.s_None,
minimal_transform=False)
@@ -241,8 +243,8 @@
def gc_start_fresh_new_state():
shadow_stack_pool.start_fresh_new_state()
- s_gcref = annmodel.SomePtr(llmemory.GCREF)
- s_addr = annmodel.SomeAddress()
+ s_gcref = SomePtr(llmemory.GCREF)
+ s_addr = SomeAddress()
self.gc_shadowstackref_new_ptr = getfn(gc_shadowstackref_new,
[], s_gcref,
minimal_transform=False)
diff --git a/rpython/memory/gctransform/transform.py b/rpython/memory/gctransform/transform.py
--- a/rpython/memory/gctransform/transform.py
+++ b/rpython/memory/gctransform/transform.py
@@ -9,7 +9,7 @@
from rpython.translator.backendopt.canraise import RaiseAnalyzer
from rpython.translator.backendopt.ssa import DataFlowFamilyBuilder
from rpython.translator.backendopt.constfold import constant_fold_graph
-from rpython.annotator import model as annmodel
+from rpython.rtyper.llannotation import lltype_to_annotation
from rpython.rtyper import rmodel
from rpython.rtyper.annlowlevel import MixLevelHelperAnnotator
from rpython.rtyper.rtyper import LowLevelOpList
@@ -259,8 +259,8 @@
def annotate_helper(self, ll_helper, ll_args, ll_result, inline=False):
assert not self.finished_helpers
- args_s = map(annmodel.lltype_to_annotation, ll_args)
- s_result = annmodel.lltype_to_annotation(ll_result)
+ args_s = map(lltype_to_annotation, ll_args)
+ s_result = lltype_to_annotation(ll_result)
graph = self.mixlevelannotator.getgraph(ll_helper, args_s, s_result)
# the produced graphs does not need to be fully transformed
self.need_minimal_transform(graph)
diff --git a/rpython/memory/test/test_transformed_gc.py b/rpython/memory/test/test_transformed_gc.py
--- a/rpython/memory/test/test_transformed_gc.py
+++ b/rpython/memory/test/test_transformed_gc.py
@@ -3,6 +3,7 @@
from rpython.translator.c import gc
from rpython.annotator import model as annmodel
+from rpython.rtyper.llannotation import SomePtr
from rpython.rtyper.lltypesystem import lltype, llmemory, rffi, llgroup
from rpython.memory.gctransform import framework, shadowstack
from rpython.rtyper.lltypesystem.lloperation import llop, void
@@ -98,7 +99,7 @@
from rpython.translator.c.genc import CStandaloneBuilder
- s_args = annmodel.SomePtr(lltype.Ptr(ARGS))
+ s_args = SomePtr(lltype.Ptr(ARGS))
t = rtype(entrypoint, [s_args], gcname=cls.gcname,
taggedpointers=cls.taggedpointers)
@@ -827,7 +828,7 @@
from rpython.translator.translator import graphof
from rpython.flowspace.model import Constant
from rpython.rtyper.lltypesystem import rffi
- layoutbuilder = cls.ensure_layoutbuilder(translator)
+ layoutbuilder = cls.ensure_layoutbuilder(translator)
type_id = layoutbuilder.get_type_id(P)
#
# now fix the do_malloc_fixedsize_clear in the graph of g
@@ -1116,7 +1117,7 @@
def test_adr_of_nursery(self):
run = self.runner("adr_of_nursery")
- res = run([])
+ res = run([])
class TestGenerationalNoFullCollectGC(GCTest):
# test that nursery is doing its job and that no full collection
diff --git a/rpython/rlib/_stacklet_asmgcc.py b/rpython/rlib/_stacklet_asmgcc.py
--- a/rpython/rlib/_stacklet_asmgcc.py
+++ b/rpython/rlib/_stacklet_asmgcc.py
@@ -3,6 +3,7 @@
from rpython.rtyper.lltypesystem.lloperation import llop
from rpython.rtyper.annlowlevel import llhelper, MixLevelHelperAnnotator
from rpython.annotator import model as annmodel
+from rpython.rtyper.llannotation import lltype_to_annotation
from rpython.rlib import _rffi_stacklet as _c
@@ -145,7 +146,7 @@
def complete_destrptr(gctransformer):
translator = gctransformer.translator
mixlevelannotator = MixLevelHelperAnnotator(translator.rtyper)
- args_s = [annmodel.lltype_to_annotation(lltype.Ptr(SUSPSTACK))]
+ args_s = [lltype_to_annotation(lltype.Ptr(SUSPSTACK))]
s_result = annmodel.s_None
destrptr = mixlevelannotator.delayedfunction(suspstack_destructor,
args_s, s_result)
diff --git a/rpython/rlib/debug.py b/rpython/rlib/debug.py
--- a/rpython/rlib/debug.py
+++ b/rpython/rlib/debug.py
@@ -229,12 +229,13 @@
def compute_result_annotation(self, s_RESTYPE, s_pythonfunction, *args_s):
from rpython.annotator import model as annmodel
+ from rpython.rtyper.llannotation import lltype_to_annotation
from rpython.rtyper.lltypesystem import lltype
assert s_RESTYPE.is_constant()
assert s_pythonfunction.is_constant()
s_result = s_RESTYPE.const
if isinstance(s_result, lltype.LowLevelType):
- s_result = annmodel.lltype_to_annotation(s_result)
+ s_result = lltype_to_annotation(s_result)
assert isinstance(s_result, annmodel.SomeObject)
return s_result
diff --git a/rpython/rlib/jit_hooks.py b/rpython/rlib/jit_hooks.py
--- a/rpython/rlib/jit_hooks.py
+++ b/rpython/rlib/jit_hooks.py
@@ -1,4 +1,5 @@
from rpython.annotator import model as annmodel
+from rpython.rtyper.llannotation import SomePtr, lltype_to_annotation
from rpython.rlib.objectmodel import specialize
from rpython.rtyper.annlowlevel import (cast_instance_to_base_ptr,
cast_base_ptr_to_instance, llstr)
@@ -15,7 +16,7 @@
if (isinstance(s_result, annmodel.SomeObject) or
s_result is None):
return s_result
- return annmodel.lltype_to_annotation(s_result)
+ return lltype_to_annotation(s_result)
def specialize_call(self, hop):
from rpython.rtyper.lltypesystem import lltype
@@ -50,7 +51,7 @@
def emptyval():
return lltype.nullptr(llmemory.GCREF.TO)
- at register_helper(annmodel.SomePtr(llmemory.GCREF))
+ at register_helper(SomePtr(llmemory.GCREF))
def resop_new(no, llargs, llres):
from rpython.jit.metainterp.history import ResOperation
@@ -61,7 +62,7 @@
res = None
return _cast_to_gcref(ResOperation(no, args, res))
- at register_helper(annmodel.SomePtr(llmemory.GCREF))
+ at register_helper(SomePtr(llmemory.GCREF))
def boxint_new(no):
from rpython.jit.metainterp.history import BoxInt
return _cast_to_gcref(BoxInt(no))
@@ -74,7 +75,7 @@
def resop_getopname(llop):
return llstr(_cast_to_resop(llop).getopname())
- at register_helper(annmodel.SomePtr(llmemory.GCREF))
+ at register_helper(SomePtr(llmemory.GCREF))
def resop_getarg(llop, no):
return _cast_to_gcref(_cast_to_resop(llop).getarg(no))
@@ -82,7 +83,7 @@
def resop_setarg(llop, no, llbox):
_cast_to_resop(llop).setarg(no, _cast_to_box(llbox))
- at register_helper(annmodel.SomePtr(llmemory.GCREF))
+ at register_helper(SomePtr(llmemory.GCREF))
def resop_getresult(llop):
return _cast_to_gcref(_cast_to_resop(llop).result)
@@ -94,15 +95,15 @@
def box_getint(llbox):
return _cast_to_box(llbox).getint()
- at register_helper(annmodel.SomePtr(llmemory.GCREF))
+ at register_helper(SomePtr(llmemory.GCREF))
def box_clone(llbox):
return _cast_to_gcref(_cast_to_box(llbox).clonebox())
- at register_helper(annmodel.SomePtr(llmemory.GCREF))
+ at register_helper(SomePtr(llmemory.GCREF))
def box_constbox(llbox):
return _cast_to_gcref(_cast_to_box(llbox).constbox())
- at register_helper(annmodel.SomePtr(llmemory.GCREF))
+ at register_helper(SomePtr(llmemory.GCREF))
def box_nonconstbox(llbox):
return _cast_to_gcref(_cast_to_box(llbox).nonconstbox())
diff --git a/rpython/rlib/rawstorage.py b/rpython/rlib/rawstorage.py
--- a/rpython/rlib/rawstorage.py
+++ b/rpython/rlib/rawstorage.py
@@ -2,6 +2,7 @@
from rpython.rtyper.extregistry import ExtRegistryEntry
from rpython.rtyper.lltypesystem import lltype, rffi, llmemory
from rpython.annotator import model as annmodel
+from rpython.rtyper.llannotation import lltype_to_annotation
from rpython.rlib.rgc import lltype_is_gc
from rpython.rlib.objectmodel import specialize
@@ -33,7 +34,7 @@
def compute_result_annotation(self, s_TP, s_storage, s_index):
assert s_TP.is_constant()
- return annmodel.lltype_to_annotation(s_TP.const)
+ return lltype_to_annotation(s_TP.const)
def specialize_call(self, hop):
assert hop.args_r[1].lowleveltype == RAW_STORAGE_PTR
diff --git a/rpython/rlib/rgc.py b/rpython/rlib/rgc.py
--- a/rpython/rlib/rgc.py
+++ b/rpython/rlib/rgc.py
@@ -94,9 +94,9 @@
_about_ = _heap_stats
def compute_result_annotation(self):
- from rpython.annotator import model as annmodel
+ from rpython.rtyper.llannotation import SomePtr
from rpython.memory.gc.base import ARRAY_TYPEID_MAP
- return annmodel.SomePtr(lltype.Ptr(ARRAY_TYPEID_MAP))
+ return SomePtr(lltype.Ptr(ARRAY_TYPEID_MAP))
def specialize_call(self, hop):
hop.exception_is_here()
@@ -114,8 +114,8 @@
def compute_result_annotation(self, s_TP, s_n=None, s_zero=None):
# basically return the same as malloc
- from rpython.annotator.builtin import malloc
More information about the pypy-commit
mailing list