Author: Tim Felgentreff <[email protected]>
Branch:
Changeset: r62313:6432b66e69bb
Date: 2013-03-12 14:44 +0100
http://bitbucket.org/pypy/pypy/changeset/6432b66e69bb/
Log: (cfbolz, timfel) refactor hack to find operation that is currently
being annotated, into a semi-official method on bookkeeper
diff --git a/rpython/annotator/binaryop.py b/rpython/annotator/binaryop.py
--- a/rpython/annotator/binaryop.py
+++ b/rpython/annotator/binaryop.py
@@ -143,13 +143,9 @@
# XXX HACK HACK HACK
bk = getbookkeeper()
if bk is not None: # for testing
+ op = bk._find_current_op("is_", 2)
knowntypedata = {}
- fn, block, i = bk.position_key
-
annotator = bk.annotator
- op = block.operations[i]
- assert op.opname == "is_"
- assert len(op.args) == 2
def bind(src_obj, tgt_obj, tgt_arg):
if hasattr(tgt_obj, 'is_type_of') and src_obj.is_constant():
@@ -319,11 +315,7 @@
rarithmetic.signedtype(int2.knowntype)):
return r
knowntypedata = {}
- # XXX HACK HACK HACK
- fn, block, i = getbookkeeper().position_key
- op = block.operations[i]
- assert op.opname == opname
- assert len(op.args) == 2
+ op = getbookkeeper()._find_current_op(opname=opname, arity=2)
def tointtype(int0):
if int0.knowntype is bool:
return int
diff --git a/rpython/annotator/bookkeeper.py b/rpython/annotator/bookkeeper.py
--- a/rpython/annotator/bookkeeper.py
+++ b/rpython/annotator/bookkeeper.py
@@ -693,6 +693,20 @@
if emulate_enter:
self.leave()
+ def _find_current_op(self, opname=None, arity=None, pos=None, s_type=None):
+ """ Find operation that is currently being annotated. Do some
+ sanity checks to see whether the correct op was found."""
+ # XXX XXX HACK HACK HACK
+ fn, block, i = self.position_key
+ op = block.operations[i]
+ if opname is not None:
+ assert op.opname == opname or op.opname in opname
+ if arity is not None:
+ assert len(op.args) == arity
+ if pos is not None:
+ assert self.annotator.binding(op.args[pos]) == s_type
+ return op
+
def build_args(self, op, args_s):
space = RPythonCallsSpace()
if op == "simple_call":
diff --git a/rpython/annotator/builtin.py b/rpython/annotator/builtin.py
--- a/rpython/annotator/builtin.py
+++ b/rpython/annotator/builtin.py
@@ -178,15 +178,9 @@
# from bool to int, notice
that isinstance( , bool|int)
# is quite border case for
RPython
r.const = False
- # XXX HACK HACK HACK
- # XXX HACK HACK HACK
- # XXX HACK HACK HACK
bk = getbookkeeper()
if variables is None:
- fn, block, i = bk.position_key
- op = block.operations[i]
- assert op.opname == "simple_call"
- assert len(op.args) == 3
+ op = bk._find_current_op("simple_call", 3)
assert op.args[0] == Constant(isinstance)
variables = [op.args[1]]
for variable in variables:
diff --git a/rpython/annotator/unaryop.py b/rpython/annotator/unaryop.py
--- a/rpython/annotator/unaryop.py
+++ b/rpython/annotator/unaryop.py
@@ -43,12 +43,7 @@
raise Exception, 'type() called with more than one argument'
r = SomeType()
bk = getbookkeeper()
- fn, block, i = bk.position_key
- annotator = bk.annotator
- op = block.operations[i]
- assert op.opname == "type"
- assert len(op.args) == 1
- assert annotator.binding(op.args[0]) == obj
+ op = bk._find_current_op(opname="type", arity=1, pos=0, s_type=obj)
r.is_type_of = [op.args[0]]
return r
@@ -79,10 +74,7 @@
bk = getbookkeeper()
knowntypedata = {}
- fn, block, i = bk.position_key
- op = block.operations[i]
- assert op.opname == "is_true" or op.opname == "nonzero"
- assert len(op.args) == 1
+ op = bk._find_current_op(opname=("is_true", "nonzero"), arity=1)
arg = op.args[0]
s_nonnone_obj = s_obj
if s_obj.can_be_none():
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit