[pypy-commit] pypy annotator: Don't use binaryop.BINARY_OPERATIONS in annrpython.py
rlamy
noreply at buildbot.pypy.org
Sat Dec 14 12:47:52 CET 2013
Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: annotator
Changeset: r68436:b0d606986842
Date: 2013-12-14 03:08 +0100
http://bitbucket.org/pypy/pypy/changeset/b0d606986842/
Log: Don't use binaryop.BINARY_OPERATIONS in annrpython.py
diff --git a/rpython/annotator/annrpython.py b/rpython/annotator/annrpython.py
--- a/rpython/annotator/annrpython.py
+++ b/rpython/annotator/annrpython.py
@@ -9,7 +9,7 @@
from rpython.flowspace.model import (Variable, Constant, FunctionGraph,
c_last_exception, checkgraph)
from rpython.translator import simplify, transform
-from rpython.annotator import model as annmodel, signature, binaryop
+from rpython.annotator import model as annmodel, signature
from rpython.annotator.bookkeeper import Bookkeeper
import py
@@ -455,7 +455,7 @@
# occour for this specific, typed operation.
if block.exitswitch == c_last_exception:
op = block.operations[-1]
- if op.opname in binaryop.BINARY_OPERATIONS:
+ if op.dispatch == 2:
arg1 = self.binding(op.args[0])
arg2 = self.binding(op.args[1])
binop = getattr(pair(arg1, arg2), op.opname, None)
@@ -625,20 +625,6 @@
return self.bookkeeper.newdict()
-def _register_binary():
- d = {}
- for opname in binaryop.BINARY_OPERATIONS:
- fnname = 'consider_op_' + opname
- exec py.code.Source("""
-def consider_op_%s(self, arg1, arg2, *args):
- return pair(arg1,arg2).%s(*args)
-""" % (opname, opname)).compile() in globals(), d
- setattr(RPythonAnnotator, fnname, d[fnname])
-
-# register simple operations handling
-_register_binary()
-
-
class BlockedInference(Exception):
"""This exception signals the type inference engine that the situation
is currently blocked, and that it should try to progress elsewhere."""
diff --git a/rpython/flowspace/operation.py b/rpython/flowspace/operation.py
--- a/rpython/flowspace/operation.py
+++ b/rpython/flowspace/operation.py
@@ -8,6 +8,7 @@
import operator
import sys
import types
+from rpython.tool.pairtype import pair
from rpython.rlib.unroll import unrolling_iterable, _unroller
from rpython.tool.sourcetools import compile2
from rpython.flowspace.model import (Constant, WrapException, const, Variable,
@@ -138,11 +139,19 @@
impl = getattr(arg, self.opname)
return impl(*other_args)
+class DoubleDispatchMixin(object):
+ dispatch = 2
+ def consider(self, annotator, arg1, arg2, *other_args):
+ impl = getattr(pair(arg1, arg2), self.opname)
+ return impl(*other_args)
+
def add_operator(name, arity, dispatch=None, pyfunc=None, pure=False, ovf=False):
operator_func = getattr(operator, name, None)
if dispatch == 1:
bases = [SingleDispatchMixin]
+ elif dispatch == 2:
+ bases = [DoubleDispatchMixin]
else:
bases = []
if ovf:
More information about the pypy-commit
mailing list