Author: Alex Gaynor <[email protected]>
Branch: numpy-dtype-alt
Changeset: r46698:53b1543a926c
Date: 2011-08-22 01:04 -0500
http://bitbucket.org/pypy/pypy/changeset/53b1543a926c/
Log: fix test translation.
diff --git a/pypy/module/micronumpy/compile.py
b/pypy/module/micronumpy/compile.py
--- a/pypy/module/micronumpy/compile.py
+++ b/pypy/module/micronumpy/compile.py
@@ -3,9 +3,10 @@
It should not be imported by the module itself
"""
-from pypy.interpreter.baseobjspace import InternalSpaceCache
+from pypy.interpreter.baseobjspace import InternalSpaceCache, W_Root
from pypy.module.micronumpy.interp_dtype import W_Float64Dtype
from pypy.module.micronumpy.interp_numarray import Scalar, SingleDimArray,
BaseArray
+from pypy.rlib.objectmodel import specialize
class BogusBytecode(Exception):
@@ -17,27 +18,50 @@
dtype.setitem(a.storage, i, dtype.box(float(i % 10)))
return a
-class TrivialSpace(object):
+class FakeSpace(object):
+ w_ValueError = None
+
def __init__(self):
- "NOT_RPYTHON"
+ """NOT_RPYTHON"""
self.fromcache = InternalSpaceCache(self).getorbuild
- def _freeze_(self):
+ def issequence_w(self, w_obj):
return True
- def wrap(self, x):
- return x
+ @specialize.argtype(1)
+ def wrap(self, obj):
+ if isinstance(obj, float):
+ return FloatObject(obj)
+ elif isinstance(obj, bool):
+ return BoolObject(obj)
+ elif isinstance(obj, int):
+ return IntObject(obj)
+ raise Exception
- def issequence_w(self, w_obj):
- # Completely wrong in the general case, but good enough for this.
- return isinstance(w_obj, BaseArray)
+ def float(self, w_obj):
+ assert isinstance(w_obj, FloatObject)
+ return w_obj
def float_w(self, w_obj):
- assert isinstance(w_obj, float)
- return w_obj
+ return w_obj.floatval
+
+
+class FloatObject(W_Root):
+ def __init__(self, floatval):
+ self.floatval = floatval
+
+class BoolObject(W_Root):
+ def __init__(self, boolval):
+ self.boolval = boolval
+
+class IntObject(W_Root):
+ def __init__(self, intval):
+ self.intval = intval
+
+
+space = FakeSpace()
def numpy_compile(bytecode, array_size):
- space = TrivialSpace()
stack = []
i = 0
dtype = space.fromcache(W_Float64Dtype)
@@ -49,21 +73,33 @@
stack.append(Scalar(dtype, dtype.box(1.2)))
elif b == '+':
right = stack.pop()
- stack.append(stack.pop().descr_add(space, right))
+ res = stack.pop().descr_add(space, right)
+ assert isinstance(res, BaseArray)
+ stack.append(res)
elif b == '-':
right = stack.pop()
- stack.append(stack.pop().descr_sub(space, right))
+ res = stack.pop().descr_sub(space, right)
+ assert isinstance(res, BaseArray)
+ stack.append(res)
elif b == '*':
right = stack.pop()
- stack.append(stack.pop().descr_mul(space, right))
+ res = stack.pop().descr_mul(space, right)
+ assert isinstance(res, BaseArray)
+ stack.append(res)
elif b == '/':
right = stack.pop()
- stack.append(stack.pop().descr_div(space, right))
+ res = stack.pop().descr_div(space, right)
+ assert isinstance(res, BaseArray)
+ stack.append(res)
elif b == '%':
right = stack.pop()
- stack.append(stack.pop().descr_mod(space, right))
+ res = stack.pop().descr_mod(space, right)
+ assert isinstance(res, BaseArray)
+ stack.append(res)
elif b == '|':
- stack.append(stack.pop().descr_abs(space))
+ res = stack.pop().descr_abs(space)
+ assert isinstance(res, BaseArray)
+ stack.append(res)
else:
print "Unknown opcode: %s" % b
raise BogusBytecode()
diff --git a/pypy/module/micronumpy/test/test_zjit.py
b/pypy/module/micronumpy/test/test_zjit.py
--- a/pypy/module/micronumpy/test/test_zjit.py
+++ b/pypy/module/micronumpy/test/test_zjit.py
@@ -1,55 +1,16 @@
from pypy.interpreter.baseobjspace import InternalSpaceCache, W_Root
from pypy.jit.metainterp.test.support import LLJitMixin
from pypy.module.micronumpy import interp_ufuncs, signature
-from pypy.module.micronumpy.compile import numpy_compile
+from pypy.module.micronumpy.compile import (numpy_compile, FakeSpace,
+ FloatObject, IntObject, BoolObject)
from pypy.module.micronumpy.interp_dtype import W_Float64Dtype
from pypy.module.micronumpy.interp_numarray import (BaseArray, SingleDimArray,
SingleDimSlice, scalar_w)
from pypy.rlib.nonconst import NonConstant
-from pypy.rlib.objectmodel import specialize
from pypy.rpython.annlowlevel import llstr
from pypy.rpython.test.test_llinterp import interpret
-class FakeSpace(object):
- w_ValueError = None
-
- def __init__(self):
- self.fromcache = InternalSpaceCache(self).getorbuild
-
- def issequence_w(self, w_obj):
- return True
-
- @specialize.argtype(1)
- def wrap(self, obj):
- if isinstance(obj, float):
- return FloatObject(obj)
- elif isinstance(obj, bool):
- return BoolObject(obj)
- elif isinstance(obj, int):
- return IntObject(obj)
- raise Exception
-
- def float(self, w_obj):
- assert isinstance(w_obj, FloatObject)
- return w_obj
-
- def float_w(self, w_obj):
- return w_obj.floatval
-
-
-class FloatObject(W_Root):
- def __init__(self, floatval):
- self.floatval = floatval
-
-class BoolObject(W_Root):
- def __init__(self, boolval):
- self.boolval = boolval
-
-class IntObject(W_Root):
- def __init__(self, intval):
- self.intval = intval
-
class TestNumpyJIt(LLJitMixin):
def setup_class(cls):
cls.space = FakeSpace()
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit