Commits

Anonymous committed 4134223

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.

  • Participants
  • Parent commits 40580ce

Comments (0)

Files changed (7)

File pypy/annotation/annrpython.py

 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")
         # 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'
         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):
 """ % (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):
     _registeroperations = classmethod(_registeroperations)
 
 # register simple operations handling
-RPythonAnnotator._registeroperations(annmodel)
+RPythonAnnotator._registeroperations(unaryop.UNARY_OPERATIONS, binaryop.BINARY_OPERATIONS)
 
 
 class BlockedInference(Exception):

File pypy/annotation/model.py

     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

File pypy/rpython/rmodel.py

 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 \
                                         "'%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

File pypy/rpython/rtyper.py

 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
 
     # __________ 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):
                 """ % (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):
         attachRuntimeTypeInfo(GCSTRUCT, funcptr, destrptr, None)
 
 # register operations from annotation model
-RPythonTyper._registeroperations(annmodel)
+RPythonTyper._registeroperations(unaryop.UNARY_OPERATIONS, binaryop.BINARY_OPERATIONS)
 
 # ____________________________________________________________
 

File pypy/rpython/test/test_rbool.py

 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
 
 
     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):

File pypy/rpython/test/test_rfloat.py

 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 (
 
     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):

File pypy/rpython/test/test_rint.py

 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
 
     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