[pypy-svn] r52204 - pypy/branch/jit-refactoring/pypy/jit/timeshifter
arigo at codespeak.net
arigo at codespeak.net
Wed Mar 5 23:39:23 CET 2008
Author: arigo
Date: Wed Mar 5 23:39:22 2008
New Revision: 52204
Modified:
pypy/branch/jit-refactoring/pypy/jit/timeshifter/oop.py
pypy/branch/jit-refactoring/pypy/jit/timeshifter/vdict.py
pypy/branch/jit-refactoring/pypy/jit/timeshifter/vlist.py
Log:
Try to move all the assert isinstance() inside the generic ll_handler().
I hope I'm not breaking translation of larger examples again...
Modified: pypy/branch/jit-refactoring/pypy/jit/timeshifter/oop.py
==============================================================================
--- pypy/branch/jit-refactoring/pypy/jit/timeshifter/oop.py (original)
+++ pypy/branch/jit-refactoring/pypy/jit/timeshifter/oop.py Wed Mar 5 23:39:22 2008
@@ -74,16 +74,22 @@
if operation_name == 'newlist':
typename, method = 'list', 'oop_newlist'
SELFTYPE = FUNCTYPE.RESULT.TO
- self.is_method = False
+ is_method = False
elif operation_name == 'newdict':
typename, method = 'dict', 'oop_newdict'
SELFTYPE = FUNCTYPE.RESULT.TO
- self.is_method = False
+ is_method = False
else:
typename, method = operation_name.split('.')
method = 'oop_%s_%s' % (typename, method)
SELFTYPE = FUNCTYPE.ARGS[self.argtuple[0].n].TO
- self.is_method = True
+ is_method = True
+ self.is_method = is_method
+
+ # hack! to avoid confusion between the .typedesc attribute
+ # of oopspecdescs of different types (lists, dicts, etc.)
+ # let's use different subclasses for the oopspecdesc too.
+ self.__class__ = myrealclass = globals()['OopSpecDesc_%s' % typename]
vmodule = __import__('pypy.jit.timeshifter.v%s' % (typename,),
None, None, [method])
@@ -93,20 +99,27 @@
argcount_max = handler.func_code.co_argcount
argcount_min = argcount_max - len(handler.func_defaults or ())
- def ll_handler(*args):
+ def ll_handler(jitstate, oopspecdesc, deepfrozen, *args):
# an indirection to support the fact that the handler() can
# take default arguments. This is an RPython trick to let
# a family of ll_handler()s be called with a constant number
# of arguments. If we tried to call directly the handler()s
# in a family, the fact that some have extra default arguments
# and others not causes trouble in normalizecalls.py.
- assert argcount_min <= len(args) <= argcount_max
+ assert argcount_min <= 3 + len(args) <= argcount_max
# ^^^ 'assert' is because each call family contains all
# oopspecs with the rainbow interpreter. The number of
# arguments is wrong for many of the oopspecs in the
# call family, though, so the assert prevents the actual
# call below from being seen.
- return handler(*args)
+ assert isinstance(oopspecdesc, myrealclass)
+ if is_method:
+ selfbox = args[0]
+ assert isinstance(selfbox, rvalue.PtrRedBox)
+ return handler(jitstate, oopspecdesc, deepfrozen, selfbox,
+ *args[1:])
+ else:
+ return handler(jitstate, oopspecdesc, deepfrozen, *args)
self.ll_handler = ll_handler
self.couldfold = getattr(handler, 'couldfold', False)
@@ -145,11 +158,6 @@
self.do_call = do_call
- # hack! to avoid confusion between the .typedesc attribute
- # of oopspecdescs of different types (lists, dicts, etc.)
- # let's use different subclasses for the oopspecdesc too.
- self.__class__ = globals()['OopSpecDesc_%s' % typename]
-
def residual_call(self, jitstate, argboxes, deepfrozen=False):
builder = jitstate.curbuilder
args_gv = []
Modified: pypy/branch/jit-refactoring/pypy/jit/timeshifter/vdict.py
==============================================================================
--- pypy/branch/jit-refactoring/pypy/jit/timeshifter/vdict.py (original)
+++ pypy/branch/jit-refactoring/pypy/jit/timeshifter/vdict.py Wed Mar 5 23:39:22 2008
@@ -265,12 +265,9 @@
def oop_newdict(jitstate, oopspecdesc, deepfrozen):
- assert isinstance(oopspecdesc, oop.OopSpecDesc_dict)
return oopspecdesc.typedesc.factory()
def oop_dict_setitem(jitstate, oopspecdesc, deepfrozen, selfbox, keybox, valuebox):
- assert isinstance(oopspecdesc, oop.OopSpecDesc_dict)
- assert isinstance(selfbox, rvalue.PtrRedBox)
content = selfbox.content
if isinstance(content, AbstractVirtualDict) and keybox.is_constant():
content.setitem(keybox, valuebox)
@@ -278,8 +275,6 @@
oopspecdesc.residual_call(jitstate, [selfbox, keybox, valuebox])
def oop_dict_getitem(jitstate, oopspecdesc, deepfrozen, selfbox, keybox):
- assert isinstance(oopspecdesc, oop.OopSpecDesc_dict)
- assert isinstance(selfbox, rvalue.PtrRedBox)
content = selfbox.content
if isinstance(content, AbstractVirtualDict) and keybox.is_constant():
try:
@@ -292,8 +287,6 @@
oop_dict_getitem.couldfold = True
def oop_dict_contains(jitstate, oopspecdesc, deepfrozen, selfbox, keybox):
- assert isinstance(oopspecdesc, oop.OopSpecDesc_dict)
- assert isinstance(selfbox, rvalue.PtrRedBox)
content = selfbox.content
if isinstance(content, AbstractVirtualDict) and keybox.is_constant():
try:
Modified: pypy/branch/jit-refactoring/pypy/jit/timeshifter/vlist.py
==============================================================================
--- pypy/branch/jit-refactoring/pypy/jit/timeshifter/vlist.py (original)
+++ pypy/branch/jit-refactoring/pypy/jit/timeshifter/vlist.py Wed Mar 5 23:39:22 2008
@@ -268,15 +268,12 @@
def oop_newlist(jitstate, oopspecdesc, deepfrozen, lengthbox, itembox=None):
- assert isinstance(oopspecdesc, oop.OopSpecDesc_list)
if lengthbox.is_constant():
length = rvalue.ll_getvalue(lengthbox, lltype.Signed)
return oopspecdesc.typedesc.factory(length, itembox)
return oopspecdesc.residual_call(jitstate, [lengthbox, itembox])
def oop_list_copy(jitstate, oopspecdesc, deepfrozen, selfbox):
- assert isinstance(oopspecdesc, oop.OopSpecDesc_list)
- assert isinstance(selfbox, rvalue.PtrRedBox)
content = selfbox.content
if isinstance(content, VirtualList):
copybox = oopspecdesc.typedesc.factory(0, None)
@@ -288,8 +285,6 @@
return oopspecdesc.residual_call(jitstate, [selfbox])
def oop_list_len(jitstate, oopspecdesc, deepfrozen, selfbox):
- assert isinstance(oopspecdesc, oop.OopSpecDesc_list)
- assert isinstance(selfbox, rvalue.PtrRedBox)
content = selfbox.content
if isinstance(content, VirtualList):
return rvalue.ll_fromvalue(jitstate, len(content.item_boxes))
@@ -299,8 +294,6 @@
oop_list_len.couldfold = True
def oop_list_nonzero(jitstate, oopspecdesc, deepfrozen, selfbox):
- assert isinstance(oopspecdesc, oop.OopSpecDesc_list)
- assert isinstance(selfbox, rvalue.PtrRedBox)
content = selfbox.content
if isinstance(content, VirtualList):
return rvalue.ll_fromvalue(jitstate, bool(content.item_boxes))
@@ -310,8 +303,6 @@
oop_list_nonzero.couldfold = True
def oop_list_append(jitstate, oopspecdesc, deepfrozen, selfbox, itembox):
- assert isinstance(oopspecdesc, oop.OopSpecDesc_list)
- assert isinstance(selfbox, rvalue.PtrRedBox)
content = selfbox.content
if isinstance(content, VirtualList):
content.item_boxes.append(itembox)
@@ -319,8 +310,6 @@
oopspecdesc.residual_call(jitstate, [selfbox, itembox])
def oop_list_insert(jitstate, oopspecdesc, deepfrozen, selfbox, indexbox, itembox):
- assert isinstance(oopspecdesc, oop.OopSpecDesc_list)
- assert isinstance(selfbox, rvalue.PtrRedBox)
content = selfbox.content
if isinstance(content, VirtualList) and indexbox.is_constant():
index = rvalue.ll_getvalue(indexbox, lltype.Signed)
@@ -331,8 +320,6 @@
oopspecdesc.residual_call(jitstate, [selfbox, indexbox, itembox])
def oop_list_concat(jitstate, oopspecdesc, deepfrozen, selfbox, otherbox):
- assert isinstance(oopspecdesc, oop.OopSpecDesc_list)
- assert isinstance(selfbox, rvalue.PtrRedBox)
content = selfbox.content
if isinstance(content, VirtualList):
assert isinstance(otherbox, rvalue.PtrRedBox)
@@ -347,8 +334,6 @@
return oopspecdesc.residual_call(jitstate, [selfbox, otherbox])
def oop_list_pop(jitstate, oopspecdesc, deepfrozen, selfbox, indexbox=None):
- assert isinstance(oopspecdesc, oop.OopSpecDesc_list)
- assert isinstance(selfbox, rvalue.PtrRedBox)
content = selfbox.content
if indexbox is None:
if isinstance(content, VirtualList):
@@ -369,8 +354,6 @@
return oopspecdesc.residual_call(jitstate, [selfbox, indexbox])
def oop_list_reverse(jitstate, oopspecdesc, deepfrozen, selfbox):
- assert isinstance(oopspecdesc, oop.OopSpecDesc_list)
- assert isinstance(selfbox, rvalue.PtrRedBox)
content = selfbox.content
if isinstance(content, VirtualList):
content.item_boxes.reverse()
@@ -378,8 +361,6 @@
oopspecdesc.residual_call(jitstate, [selfbox])
def oop_list_getitem(jitstate, oopspecdesc, deepfrozen, selfbox, indexbox):
- assert isinstance(oopspecdesc, oop.OopSpecDesc_list)
- assert isinstance(selfbox, rvalue.PtrRedBox)
content = selfbox.content
if isinstance(content, VirtualList) and indexbox.is_constant():
index = rvalue.ll_getvalue(indexbox, lltype.Signed)
@@ -393,8 +374,6 @@
oop_list_getitem.couldfold = True
def oop_list_setitem(jitstate, oopspecdesc, deepfrozen, selfbox, indexbox, itembox):
- assert isinstance(oopspecdesc, oop.OopSpecDesc_list)
- assert isinstance(selfbox, rvalue.PtrRedBox)
content = selfbox.content
if isinstance(content, VirtualList) and indexbox.is_constant():
index = rvalue.ll_getvalue(indexbox, lltype.Signed)
@@ -406,8 +385,6 @@
oopspecdesc.residual_call(jitstate, [selfbox, indexbox, itembox])
def oop_list_delitem(jitstate, oopspecdesc, deepfrozen, selfbox, indexbox):
- assert isinstance(oopspecdesc, oop.OopSpecDesc_list)
- assert isinstance(selfbox, rvalue.PtrRedBox)
content = selfbox.content
if isinstance(content, VirtualList) and indexbox.is_constant():
index = rvalue.ll_getvalue(indexbox, lltype.Signed)
More information about the Pypy-commit
mailing list