[pypy-svn] r32579 - pypy/dist/pypy/jit/timeshifter
arigo at codespeak.net
arigo at codespeak.net
Fri Sep 22 15:14:30 CEST 2006
Author: arigo
Date: Fri Sep 22 15:14:28 2006
New Revision: 32579
Modified:
pypy/dist/pypy/jit/timeshifter/oop.py
pypy/dist/pypy/jit/timeshifter/rcontainer.py
pypy/dist/pypy/jit/timeshifter/rtyper.py
pypy/dist/pypy/jit/timeshifter/rvalue.py
pypy/dist/pypy/jit/timeshifter/transform.py
pypy/dist/pypy/jit/timeshifter/vlist.py
Log:
(arre, arigo)
Type-safety, with __slots__ to check that attributes are not moved up unexpectedly.
Lots of isinstance() fixes...
Modified: pypy/dist/pypy/jit/timeshifter/oop.py
==============================================================================
--- pypy/dist/pypy/jit/timeshifter/oop.py (original)
+++ pypy/dist/pypy/jit/timeshifter/oop.py Fri Sep 22 15:14:28 2006
@@ -52,15 +52,19 @@
self.sigtoken = RGenOp.sigToken(FUNCTYPE)
if operation_name == 'newlist':
- from pypy.jit.timeshifter.vlist import ListTypeDesc, oop_newlist
- self.typedesc = ListTypeDesc(hrtyper, FUNCTYPE.RESULT.TO)
- self.ll_handler = oop_newlist
+ typename, method = 'list', 'oop_newlist'
+ SELFTYPE = FUNCTYPE.RESULT.TO
+ self.is_method = False
else:
typename, method = operation_name.split('.')
method = 'oop_%s_%s' % (typename, method)
- vmodule = __import__('pypy.jit.timeshifter.v%s' % (typename,),
- None, None, [method])
- self.ll_handler = getattr(vmodule, method)
+ SELFTYPE = FUNCTYPE.ARGS[self.argpositions[0]].TO
+ self.is_method = True
+
+ vmodule = __import__('pypy.jit.timeshifter.v%s' % (typename,),
+ None, None, [method])
+ self.typedesc = vmodule.TypeDesc(hrtyper, SELFTYPE)
+ self.ll_handler = getattr(vmodule, method)
# exception handling
graph = fnobj.graph
Modified: pypy/dist/pypy/jit/timeshifter/rcontainer.py
==============================================================================
--- pypy/dist/pypy/jit/timeshifter/rcontainer.py (original)
+++ pypy/dist/pypy/jit/timeshifter/rcontainer.py Fri Sep 22 15:14:28 2006
@@ -3,6 +3,7 @@
from pypy.jit.timeshifter import rvalue
class AbstractContainer(object):
+ __slots__ = []
def op_getfield(self, jitstate, fielddesc):
raise NotImplementedError
Modified: pypy/dist/pypy/jit/timeshifter/rtyper.py
==============================================================================
--- pypy/dist/pypy/jit/timeshifter/rtyper.py (original)
+++ pypy/dist/pypy/jit/timeshifter/rtyper.py Fri Sep 22 15:14:28 2006
@@ -61,6 +61,8 @@
self.r_JITState) = self.s_r_instanceof(rtimeshift.JITState)
(self.s_RedBox,
self.r_RedBox) = self.s_r_instanceof(rvalue.RedBox)
+ (self.s_PtrRedBox,
+ self.r_PtrRedBox) = self.s_r_instanceof(rvalue.PtrRedBox)
(self.s_OopSpecDesc,
self.r_OopSpecDesc) = self.s_r_instanceof(oop.OopSpecDesc)
(self.s_ConstOrVar,
@@ -819,6 +821,10 @@
args_v.extend([hop.llops.genconst(ll_None)] * missing_args)
args_s = [ts.s_RedBox] * len(args_v)
+ if oopspecdesc.is_method:
+ args_s[0] = ts.s_PtrRedBox # for more precise annotations
+ args_v[0] = hop.llops.genop('cast_pointer', [args_v[0]],
+ resulttype = ts.r_PtrRedBox.lowleveltype)
RESULT = originalconcretetype(hop.s_result)
if RESULT is lltype.Void:
s_result = annmodel.s_None
Modified: pypy/dist/pypy/jit/timeshifter/rvalue.py
==============================================================================
--- pypy/dist/pypy/jit/timeshifter/rvalue.py (original)
+++ pypy/dist/pypy/jit/timeshifter/rvalue.py Fri Sep 22 15:14:28 2006
@@ -21,6 +21,7 @@
class RedBox(object):
+ __slots__ = ['kind', 'genvar']
def __init__(self, kind, genvar=None):
self.kind = kind
@@ -177,23 +178,26 @@
def copy(self, memo):
boxmemo = memo.boxes
try:
- return boxmemo[self]
+ result = boxmemo[self]
except KeyError:
result = PtrRedBox(self.kind, self.genvar)
boxmemo[self] = result
if self.content:
result.content = self.content.copy(memo)
- return result
+ assert isinstance(result, PtrRedBox)
+ return result
def replace(self, memo):
boxmemo = memo.boxes
try:
- return boxmemo[self]
+ result = boxmemo[self]
except KeyError:
boxmemo[self] = self
if self.content:
self.content.replace(memo)
- return self
+ result = self
+ assert isinstance(result, PtrRedBox)
+ return result
def freeze(self, memo):
boxmemo = memo.boxes
Modified: pypy/dist/pypy/jit/timeshifter/transform.py
==============================================================================
--- pypy/dist/pypy/jit/timeshifter/transform.py (original)
+++ pypy/dist/pypy/jit/timeshifter/transform.py Fri Sep 22 15:14:28 2006
@@ -72,12 +72,12 @@
# __________ helpers __________
- def genop(self, block, opname, args, result_type=None, result_like=None):
- # 'result_type' can be a LowLevelType (for green returns)
- # or a template variable whose hintannotation is copied
- if result_type is not None:
- v_res = varoftype(result_type)
- hs = hintmodel.SomeLLAbstractConstant(result_type, {})
+ def genop(self, block, opname, args, resulttype=None, result_like=None):
+ # 'result_like' can be a template variable whose hintannotation is
+ # copied
+ if resulttype is not None:
+ v_res = varoftype(resulttype)
+ hs = hintmodel.SomeLLAbstractConstant(resulttype, {})
self.hannotator.setbinding(v_res, hs)
elif result_like is not None:
v_res = copyvar(self.hannotator, result_like)
@@ -182,13 +182,13 @@
nonconstant_block = Block([])
v_flag = self.genop(block, 'is_constant', [v_redswitch],
- result_type = lltype.Bool)
+ resulttype = lltype.Bool)
self.genswitch(block, v_flag, true = constant_block,
false = nonconstant_block)
v_greenswitch = self.genop(constant_block, 'revealconst',
[v_redswitch],
- result_type = lltype.Bool)
+ resulttype = lltype.Bool)
constant_block.exitswitch = v_greenswitch
constant_block.closeblock(link_f, link_t)
@@ -248,7 +248,7 @@
c_mp = inputconst(lltype.Void, mp)
v_finished_flag = self.genop(block, 'merge_point',
[self.c_mpfamily, c_mp] + greens,
- result_type = lltype.Bool)
+ resulttype = lltype.Bool)
block.exitswitch = v_finished_flag
[link_f] = block.exits
link_t = Link([self.c_dummy], self.graph.returnblock)
@@ -273,7 +273,7 @@
if self.resumepoints:
block = self.before_return_block()
v_switchcase = self.genop(block, 'dispatch_next', [],
- result_type = lltype.Signed)
+ resulttype = lltype.Signed)
block.exitswitch = v_switchcase
defaultlink = block.exits[0]
defaultlink.exitcase = 'default'
@@ -376,7 +376,7 @@
if not hs_func.is_green():
# XXX for now, assume that it will be a constant red box
v_greenfunc = self.genop(block, 'revealconst', [args_v[0]],
- result_type = originalconcretetype(hs_func))
+ resulttype = originalconcretetype(hs_func))
args_v[0] = v_greenfunc
self.genop(block, 'indirect_%s_call' % (color,), args_v)
Modified: pypy/dist/pypy/jit/timeshifter/vlist.py
==============================================================================
--- pypy/dist/pypy/jit/timeshifter/vlist.py (original)
+++ pypy/dist/pypy/jit/timeshifter/vlist.py Fri Sep 22 15:14:28 2006
@@ -33,6 +33,8 @@
vlist.ownbox = box
return box
+TypeDesc = ListTypeDesc
+
class FrozenVirtualList(AbstractContainer):
@@ -137,101 +139,116 @@
return oopspecdesc.residual_call(jitstate, [lengthbox, itembox])
def oop_list_copy(jitstate, oopspecdesc, selfbox):
- if isinstance(selfbox.content, VirtualList):
+ content = selfbox.content
+ if isinstance(content, VirtualList):
copybox = oopspecdesc.typedesc.factory(0, None)
- copybox.content.item_boxes.extend(selfbox.content.item_boxes)
+ copycontent = copybox.content
+ assert isinstance(copycontent, VirtualList)
+ copycontent.item_boxes.extend(content.item_boxes)
return copybox
else:
return oopspecdesc.residual_call(jitstate, [selfbox])
def oop_list_len(jitstate, oopspecdesc, selfbox):
- if isinstance(selfbox.content, VirtualList):
- return rvalue.ll_fromvalue(jitstate, len(selfbox.content.item_boxes))
+ content = selfbox.content
+ if isinstance(content, VirtualList):
+ return rvalue.ll_fromvalue(jitstate, len(content.item_boxes))
else:
return oopspecdesc.residual_call(jitstate, [selfbox])
def oop_list_nonzero(jitstate, oopspecdesc, selfbox):
- if isinstance(selfbox.content, VirtualList):
- return rvalue.ll_fromvalue(jitstate, bool(selfbox.content.item_boxes))
+ content = selfbox.content
+ if isinstance(content, VirtualList):
+ return rvalue.ll_fromvalue(jitstate, bool(content.item_boxes))
else:
return oopspecdesc.residual_call(jitstate, [selfbox])
def oop_list_append(jitstate, oopspecdesc, selfbox, itembox):
- if isinstance(selfbox.content, VirtualList):
- selfbox.content.item_boxes.append(itembox)
+ content = selfbox.content
+ if isinstance(content, VirtualList):
+ content.item_boxes.append(itembox)
else:
oopspecdesc.residual_call(jitstate, [selfbox, itembox])
def oop_list_insert(jitstate, oopspecdesc, selfbox, indexbox, itembox):
- if isinstance(selfbox.content, VirtualList) and indexbox.is_constant():
+ content = selfbox.content
+ if isinstance(content, VirtualList) and indexbox.is_constant():
index = rvalue.ll_getvalue(indexbox, lltype.Signed)
# XXX what if the assert fails?
- assert 0 <= index <= len(selfbox.content.item_boxes)
- selfbox.content.item_boxes.insert(index, itembox)
+ assert 0 <= index <= len(content.item_boxes)
+ content.item_boxes.insert(index, itembox)
else:
oopspecdesc.residual_call(jitstate, [selfbox, indexbox, itembox])
def oop_list_concat(jitstate, oopspecdesc, selfbox, otherbox):
- if isinstance(selfbox.content, VirtualList):
+ content = selfbox.content
+ if isinstance(content, VirtualList):
assert isinstance(otherbox, rvalue.PtrRedBox)
- if (otherbox.content is not None and
- isinstance(otherbox.content, VirtualList)):
+ othercontent = otherbox.content
+ if othercontent is not None and isinstance(othercontent, VirtualList):
newbox = oopspecdesc.typedesc.factory(0, None)
- newbox.content.item_boxes.extend(selfbox.content.item_boxes)
- newbox.content.item_boxes.extend(otherbox.content.item_boxes)
+ newcontent = newbox.content
+ assert isinstance(newcontent, VirtualList)
+ newcontent.item_boxes.extend(content.item_boxes)
+ newcontent.item_boxes.extend(othercontent.item_boxes)
return newbox
return oopspecdesc.residual_call(jitstate, [selfbox, otherbox])
def oop_list_pop(jitstate, oopspecdesc, selfbox, indexbox=None):
+ content = selfbox.content
if indexbox is None:
- if isinstance(selfbox.content, VirtualList):
+ if isinstance(content, VirtualList):
try:
- return selfbox.content.item_boxes.pop()
+ return content.item_boxes.pop()
except IndexError:
return oopspecdesc.residual_exception(jitstate, IndexError)
else:
return oopspecdesc.residual_call(jitstate, [selfbox])
- if (isinstance(selfbox.content, VirtualList) and
+ if (isinstance(content, VirtualList) and
indexbox.is_constant()):
index = rvalue.ll_getvalue(indexbox, lltype.Signed)
try:
- return selfbox.content.item_boxes.pop(index)
+ return content.item_boxes.pop(index)
except IndexError:
return oopspecdesc.residual_exception(jitstate, IndexError)
return oopspecdesc.residual_call(jitstate, [selfbox, indexbox])
def oop_list_reverse(jitstate, oopspecdesc, selfbox):
- if isinstance(selfbox.content, VirtualList):
- selfbox.content.item_boxes.reverse()
+ content = selfbox.content
+ if isinstance(content, VirtualList):
+ content.item_boxes.reverse()
else:
oopspecdesc.residual_call(jitstate, [selfbox])
def oop_list_getitem(jitstate, oopspecdesc, selfbox, indexbox):
- if isinstance(selfbox.content, VirtualList) and indexbox.is_constant():
+ content = selfbox.content
+ if isinstance(content, VirtualList) and indexbox.is_constant():
index = rvalue.ll_getvalue(indexbox, lltype.Signed)
try:
- return selfbox.content.item_boxes[index]
+ return content.item_boxes[index]
except IndexError:
return oopspecdesc.residual_exception(jitstate, IndexError)
else:
return oopspecdesc.residual_call(jitstate, [selfbox, indexbox])
def oop_list_setitem(jitstate, oopspecdesc, selfbox, indexbox, itembox):
- if isinstance(selfbox.content, VirtualList) and indexbox.is_constant():
+ content = selfbox.content
+ if isinstance(content, VirtualList) and indexbox.is_constant():
index = rvalue.ll_getvalue(indexbox, lltype.Signed)
try:
- selfbox.content.item_boxes[index] = itembox
+ content.item_boxes[index] = itembox
except IndexError:
oopspecdesc.residual_exception(jitstate, IndexError)
else:
oopspecdesc.residual_call(jitstate, [selfbox, indexbox, itembox])
def oop_list_delitem(jitstate, oopspecdesc, selfbox, indexbox):
- if isinstance(selfbox.content, VirtualList) and indexbox.is_constant():
+ content = selfbox.content
+ if isinstance(content, VirtualList) and indexbox.is_constant():
index = rvalue.ll_getvalue(indexbox, lltype.Signed)
try:
- del selfbox.content.item_boxes[index]
+ del content.item_boxes[index]
except IndexError:
oopspecdesc.residual_exception(jitstate, IndexError)
else:
More information about the Pypy-commit
mailing list