[pypy-svn] r65036 - in pypy/branch/pyjitpl5/pypy/jit/backend: cli/test test
antocuni at codespeak.net
antocuni at codespeak.net
Mon May 4 23:03:37 CEST 2009
Author: antocuni
Date: Mon May 4 23:03:36 2009
New Revision: 65036
Modified:
pypy/branch/pyjitpl5/pypy/jit/backend/cli/test/test_runner.py
pypy/branch/pyjitpl5/pypy/jit/backend/test/runner.py
Log:
port test_{passing,failing}_guard_class to ootype
Modified: pypy/branch/pyjitpl5/pypy/jit/backend/cli/test/test_runner.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/backend/cli/test/test_runner.py (original)
+++ pypy/branch/pyjitpl5/pypy/jit/backend/cli/test/test_runner.py Mon May 4 23:03:36 2009
@@ -18,12 +18,10 @@
def setup_class(cls):
cls.cpu = cls.CPUClass(rtyper=None, stats=FakeStats())
- def _skip(self):
- py.test.skip("not supported in non-translated version")
-
- test_passing_guard_class = _skip # GUARD_CLASS
- test_failing_guard_class = _skip # GUARD_CLASS
-
class TestRunner(CliJitMixin, OOtypeBackendTest):
- pass
+ def skip(self):
+ py.test.skip("not supported in non-translated version")
+
+ test_passing_guard_class = skip # GUARD_CLASS
+ test_failing_guard_class = skip # GUARD_CLASS
Modified: pypy/branch/pyjitpl5/pypy/jit/backend/test/runner.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/backend/test/runner.py (original)
+++ pypy/branch/pyjitpl5/pypy/jit/backend/test/runner.py Mon May 4 23:03:36 2009
@@ -1,7 +1,8 @@
import sys
from pypy.jit.metainterp.history import (BoxInt, Box, BoxPtr, TreeLoop,
- ConstInt, ConstPtr, BoxObj)
+ ConstInt, ConstPtr, BoxObj,
+ ConstObj)
from pypy.jit.metainterp.resoperation import ResOperation, rop
from pypy.jit.metainterp.typesystem import deref
from pypy.rpython.lltypesystem import lltype, llmemory, rstr, rffi, rclass
@@ -249,17 +250,10 @@
assert self.execute_operation(opname, args, 'void') == None
assert not self.guard_failed
+
def test_passing_guard_class(self):
- T = self.T
- vtable_for_T = lltype.malloc(self.MY_VTABLE, immortal=True)
- vtable_for_T_addr = llmemory.cast_ptr_to_adr(vtable_for_T)
- cpu = self.cpu
- cpu._cache_gcstruct2vtable = {T: vtable_for_T}
- t = lltype.malloc(T)
- t.parent.parent.typeptr = vtable_for_T
- t_box = BoxPtr(lltype.cast_opaque_ptr(llmemory.GCREF, t))
- T_box = ConstInt(cpu.cast_adr_to_int(vtable_for_T_addr))
- null_box = ConstPtr(lltype.cast_opaque_ptr(llmemory.GCREF, lltype.nullptr(T)))
+ t_box, T_box = self.alloc_instance(self.T)
+ #null_box = ConstPtr(lltype.cast_opaque_ptr(llmemory.GCREF, lltype.nullptr(T)))
self.execute_operation(rop.GUARD_CLASS, [t_box, T_box], 'void')
assert not self.guard_failed
#self.execute_operation(rop.GUARD_CLASS_INVERSE, [t_box, null_box],
@@ -274,23 +268,9 @@
assert self.guard_failed
def test_failing_guard_class(self):
- T = self.T
- U = self.U
- vtable_for_T = lltype.malloc(self.MY_VTABLE, immortal=True)
- vtable_for_T_addr = llmemory.cast_ptr_to_adr(vtable_for_T)
- vtable_for_U = lltype.malloc(self.MY_VTABLE, immortal=True)
- vtable_for_U_addr = llmemory.cast_ptr_to_adr(vtable_for_U)
- cpu = self.cpu
- cpu._cache_gcstruct2vtable = {T: vtable_for_T, U: vtable_for_U}
- t = lltype.malloc(T)
- t.parent.parent.typeptr = vtable_for_T
- t_box = BoxPtr(lltype.cast_opaque_ptr(llmemory.GCREF, t))
- T_box = ConstInt(self.cpu.cast_adr_to_int(vtable_for_T_addr))
- u = lltype.malloc(U)
- u.parent.parent.parent.typeptr = vtable_for_U
- u_box = BoxPtr(lltype.cast_opaque_ptr(llmemory.GCREF, u))
- U_box = ConstInt(self.cpu.cast_adr_to_int(vtable_for_U_addr))
- null_box = ConstPtr(lltype.cast_opaque_ptr(llmemory.GCREF, lltype.nullptr(T)))
+ t_box, T_box = self.alloc_instance(self.T)
+ u_box, U_box = self.alloc_instance(self.U)
+ #null_box = ConstPtr(lltype.cast_opaque_ptr(llmemory.GCREF, lltype.nullptr(T)))
for opname, args in [(rop.GUARD_CLASS, [t_box, U_box]),
(rop.GUARD_CLASS, [u_box, T_box]),
#(rop.GUARD_VALUE_INVERSE, [BoxInt(10), BoxInt(10)]),
@@ -324,6 +304,24 @@
U = lltype.GcStruct('U', ('parent', T),
('next', lltype.Ptr(S)))
+
+ def alloc_instance(self, T):
+ vtable_for_T = lltype.malloc(self.MY_VTABLE, immortal=True)
+ vtable_for_T_addr = llmemory.cast_ptr_to_adr(vtable_for_T)
+ cpu = self.cpu
+ if not hasattr(cpu, '_cache_gcstruct2vtable'):
+ cpu._cache_gcstruct2vtable = {}
+ cpu._cache_gcstruct2vtable.update({T: vtable_for_T})
+ t = lltype.malloc(T)
+ if T == self.T:
+ t.parent.parent.typeptr = vtable_for_T
+ elif T == self.U:
+ t.parent.parent.parent.typeptr = vtable_for_T
+ t_box = BoxPtr(lltype.cast_opaque_ptr(llmemory.GCREF, t))
+ T_box = ConstInt(self.cpu.cast_adr_to_int(vtable_for_T_addr))
+ return t_box, T_box
+
+
def test_casts(self):
from pypy.rpython.lltypesystem import lltype, llmemory
TP = lltype.GcStruct('x')
@@ -360,3 +358,15 @@
@classmethod
def get_funcbox(cls, cpu, func_ptr):
return BoxObj(ootype.cast_to_object(func_ptr))
+
+ S = ootype.Instance('S', ootype.ROOT, {'value': ootype.Signed})
+ S._add_fields({'next': S})
+ T = ootype.Instance('T', S)
+ U = ootype.Instance('U', T)
+
+ def alloc_instance(self, T):
+ t = ootype.new(T)
+ cls = ootype.classof(t)
+ t_box = BoxObj(ootype.cast_to_object(t))
+ T_box = ConstObj(ootype.cast_to_object(cls))
+ return t_box, T_box
More information about the Pypy-commit
mailing list