Author: Greg Price <[email protected]>
Branch: 
Changeset: r59501:4134223a7aa3
Date: 2012-12-12 21:33 -0800
http://bitbucket.org/pypy/pypy/changeset/4134223a7aa3/

Log:    cut dependency annotation.model -> unaryop, binaryop

        This makes annotation.model very lean on dependencies, which keeps
        rlib.types lean, which will be very helpful in importing the latter
        all over for signatures without creating cyclic dependencies.

diff --git a/pypy/annotation/annrpython.py b/pypy/annotation/annrpython.py
--- a/pypy/annotation/annrpython.py
+++ b/pypy/annotation/annrpython.py
@@ -8,7 +8,7 @@
 from pypy.objspace.flow.model import (Variable, Constant, FunctionGraph,
                                       c_last_exception, checkgraph)
 from pypy.translator import simplify, transform
-from pypy.annotation import model as annmodel, signature
+from pypy.annotation import model as annmodel, signature, unaryop, binaryop
 from pypy.annotation.bookkeeper import Bookkeeper
 import py
 log = py.log.Producer("annrpython")
@@ -453,12 +453,12 @@
         # occour for this specific, typed operation.
         if block.exitswitch == c_last_exception:
             op = block.operations[-1]
-            if op.opname in annmodel.BINARY_OPERATIONS:
+            if op.opname in binaryop.BINARY_OPERATIONS:
                 arg1 = self.binding(op.args[0])
                 arg2 = self.binding(op.args[1])
                 binop = getattr(pair(arg1, arg2), op.opname, None)
                 can_only_throw = annmodel.read_can_only_throw(binop, arg1, 
arg2)
-            elif op.opname in annmodel.UNARY_OPERATIONS:
+            elif op.opname in unaryop.UNARY_OPERATIONS:
                 arg1 = self.binding(op.args[0])
                 opname = op.opname
                 if opname == 'contains': opname = 'op_contains'
@@ -629,10 +629,10 @@
         return self.bookkeeper.newdict()
 
 
-    def _registeroperations(cls, model):
+    def _registeroperations(cls, unary_ops, binary_ops):
         # All unary operations
         d = {}
-        for opname in model.UNARY_OPERATIONS:
+        for opname in unary_ops:
             fnname = 'consider_op_' + opname
             exec py.code.Source("""
 def consider_op_%s(self, arg, *args):
@@ -640,7 +640,7 @@
 """ % (opname, opname)).compile() in globals(), d
             setattr(cls, fnname, d[fnname])
         # All binary operations
-        for opname in model.BINARY_OPERATIONS:
+        for opname in binary_ops:
             fnname = 'consider_op_' + opname
             exec py.code.Source("""
 def consider_op_%s(self, arg1, arg2, *args):
@@ -650,7 +650,7 @@
     _registeroperations = classmethod(_registeroperations)
 
 # register simple operations handling
-RPythonAnnotator._registeroperations(annmodel)
+RPythonAnnotator._registeroperations(unaryop.UNARY_OPERATIONS, 
binaryop.BINARY_OPERATIONS)
 
 
 class BlockedInference(Exception):
diff --git a/pypy/annotation/model.py b/pypy/annotation/model.py
--- a/pypy/annotation/model.py
+++ b/pypy/annotation/model.py
@@ -773,7 +773,3 @@
     else:
         raise RuntimeError("The annotator relies on 'assert' statements from 
the\n"
                      "\tannotated program: you cannot run it with 'python 
-O'.")
-
-# this has the side-effect of registering the unary and binary operations
-from pypy.annotation.unaryop  import UNARY_OPERATIONS
-from pypy.annotation.binaryop import BINARY_OPERATIONS
diff --git a/pypy/rpython/rmodel.py b/pypy/rpython/rmodel.py
--- a/pypy/rpython/rmodel.py
+++ b/pypy/rpython/rmodel.py
@@ -1,5 +1,5 @@
 from pypy.tool.pairtype import pairtype, extendabletype, pair
-from pypy.annotation import model as annmodel
+from pypy.annotation import model as annmodel, unaryop, binaryop
 from pypy.annotation import description
 from pypy.objspace.flow.model import Constant
 from pypy.rpython.lltypesystem.lltype import \
@@ -310,10 +310,10 @@
                                         "'%s' on %r" % (opname, self))
         setattr(rcls, attr, missing_rtype_operation)
 
-for opname in annmodel.UNARY_OPERATIONS:
+for opname in unaryop.UNARY_OPERATIONS:
     make_missing_op(Repr, opname)
 
-for opname in annmodel.BINARY_OPERATIONS:
+for opname in binaryop.BINARY_OPERATIONS:
     make_missing_op(pairtype(Repr, Repr), opname)
 
 # not in BINARY_OPERATIONS
diff --git a/pypy/rpython/rtyper.py b/pypy/rpython/rtyper.py
--- a/pypy/rpython/rtyper.py
+++ b/pypy/rpython/rtyper.py
@@ -14,7 +14,7 @@
 import os
 import py
 from pypy.tool.pairtype import pair
-from pypy.annotation import model as annmodel
+from pypy.annotation import model as annmodel, unaryop, binaryop
 from pypy.annotation.annrpython import FAIL
 from pypy.objspace.flow.model import Variable, Constant
 from pypy.objspace.flow.model import SpaceOperation, c_last_exception
@@ -592,10 +592,10 @@
 
     # __________ regular operations __________
 
-    def _registeroperations(cls, model):
+    def _registeroperations(cls, unary_ops, binary_ops):
         d = {}
         # All unary operations
-        for opname in model.UNARY_OPERATIONS:
+        for opname in unary_ops:
             fnname = 'translate_op_' + opname
             exec py.code.compile("""
                 def translate_op_%s(self, hop):
@@ -604,7 +604,7 @@
                 """ % (opname, opname)) in globals(), d
             setattr(cls, fnname, d[fnname])
         # All binary operations
-        for opname in model.BINARY_OPERATIONS:
+        for opname in binary_ops:
             fnname = 'translate_op_' + opname
             exec py.code.compile("""
                 def translate_op_%s(self, hop):
@@ -714,7 +714,7 @@
         attachRuntimeTypeInfo(GCSTRUCT, funcptr, destrptr, None)
 
 # register operations from annotation model
-RPythonTyper._registeroperations(annmodel)
+RPythonTyper._registeroperations(unaryop.UNARY_OPERATIONS, 
binaryop.BINARY_OPERATIONS)
 
 # ____________________________________________________________
 
diff --git a/pypy/rpython/test/test_rbool.py b/pypy/rpython/test/test_rbool.py
--- a/pypy/rpython/test/test_rbool.py
+++ b/pypy/rpython/test/test_rbool.py
@@ -1,5 +1,5 @@
 from pypy.translator.translator import TranslationContext
-from pypy.annotation import model as annmodel
+from pypy.annotation import unaryop, binaryop
 from pypy.rpython.test import snippet
 from pypy.rpython.test.tool import BaseRtypingTest, LLRtypeMixin, OORtypeMixin
 
@@ -25,12 +25,12 @@
 
     def DONTtest_unary_operations(self):
         # XXX TODO test if all unary operations are implemented
-        for opname in annmodel.UNARY_OPERATIONS:
+        for opname in unaryop.UNARY_OPERATIONS:
             print 'UNARY_OPERATIONS:', opname
 
     def DONTtest_binary_operations(self):
         # XXX TODO test if all binary operations are implemented
-        for opname in annmodel.BINARY_OPERATIONS:
+        for opname in binaryop.BINARY_OPERATIONS:
             print 'BINARY_OPERATIONS:', opname
 
 class BaseTestRbool(BaseRtypingTest):
diff --git a/pypy/rpython/test/test_rfloat.py b/pypy/rpython/test/test_rfloat.py
--- a/pypy/rpython/test/test_rfloat.py
+++ b/pypy/rpython/test/test_rfloat.py
@@ -1,5 +1,6 @@
 import sys
 from pypy.translator.translator import TranslationContext
+from pypy.annotation import unaryop, binaryop
 from pypy.rpython.test import snippet
 from pypy.rpython.test.tool import BaseRtypingTest, LLRtypeMixin, OORtypeMixin
 from pypy.rlib.rarithmetic import (
@@ -28,12 +29,12 @@
 
     def DONTtest_unary_operations(self):
         # XXX TODO test if all unary operations are implemented
-        for opname in annmodel.UNARY_OPERATIONS:
+        for opname in unaryop.UNARY_OPERATIONS:
             print 'UNARY_OPERATIONS:', opname
 
     def DONTtest_binary_operations(self):
         # XXX TODO test if all binary operations are implemented
-        for opname in annmodel.BINARY_OPERATIONS:
+        for opname in binaryop.BINARY_OPERATIONS:
             print 'BINARY_OPERATIONS:', opname
 
 class BaseTestRfloat(BaseRtypingTest):
diff --git a/pypy/rpython/test/test_rint.py b/pypy/rpython/test/test_rint.py
--- a/pypy/rpython/test/test_rint.py
+++ b/pypy/rpython/test/test_rint.py
@@ -1,7 +1,7 @@
 import py
 import sys, operator
 from pypy.translator.translator import TranslationContext
-from pypy.annotation import model as annmodel
+from pypy.annotation import unaryop, binaryop
 from pypy.rpython.test import snippet
 from pypy.rlib.rarithmetic import r_int, r_uint, r_longlong, r_ulonglong
 from pypy.rlib.rarithmetic import ovfcheck, r_int64, intmask, int_between
@@ -34,12 +34,12 @@
 
     def DONTtest_unary_operations(self):
         # XXX TODO test if all unary operations are implemented
-        for opname in annmodel.UNARY_OPERATIONS:
+        for opname in unaryop.UNARY_OPERATIONS:
             print 'UNARY_OPERATIONS:', opname
 
     def DONTtest_binary_operations(self):
         # XXX TODO test if all binary operations are implemented
-        for opname in annmodel.BINARY_OPERATIONS:
+        for opname in binaryop.BINARY_OPERATIONS:
             print 'BINARY_OPERATIONS:', opname
 
 
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to