[pypy-svn] r23032 - in pypy/dist/pypy: jit jit/test rpython

pedronis at codespeak.net pedronis at codespeak.net
Sat Feb 4 22:34:24 CET 2006


Author: pedronis
Date: Sat Feb  4 22:34:20 2006
New Revision: 23032

Added:
   pypy/dist/pypy/jit/hintrconstant.py   (contents, props changed)
   pypy/dist/pypy/jit/hintrtyper.py   (contents, props changed)
   pypy/dist/pypy/jit/test/test_hint_rtyping.py
      - copied, changed from r23030, pypy/dist/pypy/jit/test/test_hint_annotation.py
Modified:
   pypy/dist/pypy/jit/hintannotator.py
   pypy/dist/pypy/rpython/rtyper.py
   pypy/dist/pypy/rpython/typesystem.py
Log:
(arigo, pedronis)

started working on rtyping hint annotated graph. Introduced hintrtyper.HintTyper,
derived from the RPythonTyper, it may need some different traversal, per graph logic.

Started a repr for fixed ll abstrac constants in hintrconstant.py



Modified: pypy/dist/pypy/jit/hintannotator.py
==============================================================================
--- pypy/dist/pypy/jit/hintannotator.py	(original)
+++ pypy/dist/pypy/jit/hintannotator.py	Sat Feb  4 22:34:20 2006
@@ -15,6 +15,9 @@
         flowgraph = desc.specialize(input_args_hs)
         return self.build_graph_types(flowgraph, input_args_hs)
 
+    def simplify(self):
+        pass
+
     def consider_op_malloc(self, hs_TYPE):
         TYPE = hs_TYPE.const
         vstructdef = self.bookkeeper.getvirtualcontainerdef(TYPE)

Added: pypy/dist/pypy/jit/hintrconstant.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/jit/hintrconstant.py	Sat Feb  4 22:34:20 2006
@@ -0,0 +1,26 @@
+from pypy.annotation.pairtype import pairtype
+from pypy.jit.hintrtyper import HintTypeSystem
+from pypy.jit.hintmodel import SomeLLAbstractConstant
+from pypy.rpython.rmodel import Repr
+
+class __extend__(pairtype(HintTypeSystem, SomeLLAbstractConstant)):
+
+    def rtyper_makerepr((ts, hs_c), rtyper):
+        if hs_c.is_fixed() or hs_c.eager_concrete:
+            return LLFixedConstantRepr(hs_c.concretetype)
+        else:
+            XXX
+
+    def rtyper_makekey((ts, hs_c), rtyper):
+        fixed = hs_c.is_fixed() or hs_c.eager_concrete
+        return hs_c.__class__, fixed, hs_c.concretetype
+
+class LLFixedConstantRepr(Repr):
+
+    def __init__(self, lowleveltype):
+        self.lowleveltype = lowleveltype
+
+#...
+#
+#    def rtype_int_add(_, hop):
+#        hop.inputargs(

Added: pypy/dist/pypy/jit/hintrtyper.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/jit/hintrtyper.py	Sat Feb  4 22:34:20 2006
@@ -0,0 +1,36 @@
+from pypy.rpython.rtyper import RPythonTyper
+from pypy.rpython.typesystem import TypeSystem
+from pypy.jit import hintmodel
+
+class HintTypeSystem(TypeSystem):
+    name = "hinttypesystem"
+
+    def perform_normalizations(self, rtyper):
+        pass   # for now
+
+HintTypeSystem.instance = HintTypeSystem()
+
+# ___________________________________________________________
+
+class HintTyper(RPythonTyper):
+    
+    def __init__(self, hannotator):
+    	RPythonTyper.__init__(self, hannotator, 
+                              type_system=HintTypeSystem.instance)
+        self._canonical_reprs = {}
+
+    def fixedrepr(self, lowleveltype):
+        key = True, lowleveltype
+        try:
+            repr =  self._canonical_reprs[key]
+        except KeyError:
+            hs = hintmodel.SomeLLAbstractConstant(lowleveltype, {})
+            hs.eager_concrete = True
+            repr = self._canonical_reprs[key] = self.getrepr(hs)
+        return repr
+
+# register operations from model
+HintTyper._registeroperations(hintmodel)
+
+# import reprs
+from pypy.jit import hintrconstant

Modified: pypy/dist/pypy/rpython/rtyper.py
==============================================================================
--- pypy/dist/pypy/rpython/rtyper.py	(original)
+++ pypy/dist/pypy/rpython/rtyper.py	Sat Feb  4 22:34:20 2006
@@ -25,11 +25,9 @@
      attachRuntimeTypeInfo, Primitive
 from pypy.rpython.ootypesystem import ootype
 from pypy.translator.unsimplify import insert_empty_block
-from pypy.translator.transform import insert_stackcheck
 from pypy.rpython.error import TyperError
 from pypy.rpython.rmodel import Repr, inputconst, BrokenReprTyperError
 from pypy.rpython.rmodel import warning, HalfConcreteWrapper
-from pypy.rpython.normalizecalls import perform_normalizations
 from pypy.rpython.annlowlevel import annotate_lowlevel_helper
 from pypy.rpython.rmodel import log
 from pypy.rpython.typesystem import LowLevelTypeSystem,\
@@ -41,12 +39,15 @@
     def __init__(self, annotator, type_system="lltype"):
         self.annotator = annotator
 
-        if type_system == "lltype":
-            self.type_system = LowLevelTypeSystem.instance
-        elif type_system == "ootype":
-            self.type_system = ObjectOrientedTypeSystem.instance
+        if isinstance(type_system, str):
+            if type_system == "lltype":
+                self.type_system = LowLevelTypeSystem.instance
+            elif type_system == "ootype":
+                self.type_system = ObjectOrientedTypeSystem.instance
+            else:
+                raise TyperError("Unknown type system %r!" % type_system)
         else:
-            raise TyperError("Unknown type system %r!" % type_system)
+            self.type_system = type_system
         self.type_system_deref = self.type_system.deref
         self.reprs = {}
         self._reprs_must_call_setup = []
@@ -132,13 +133,12 @@
         """Main entry point: specialize all annotated blocks of the program."""
         self.crash_on_first_typeerror = crash_on_first_typeerror
         # specialize depends on annotator simplifications
-        insert_stackcheck(self.annotator)
         if not dont_simplify_again:
             self.annotator.simplify()
             
         # first make sure that all functions called in a group have exactly
         # the same signature, by hacking their flow graphs if needed
-        perform_normalizations(self)
+        self.type_system.perform_normalizations(self)
         # new blocks can be created as a result of specialize_block(), so
         # we need to be careful about the loop here.
         self.already_seen = {}
@@ -474,25 +474,24 @@
 
     # __________ regular operations __________
 
-    def _registeroperations(loc):
+    def _registeroperations(cls, model):
+        ns = cls.__dict__
         # All unary operations
-        for opname in annmodel.UNARY_OPERATIONS:
+        for opname in model.UNARY_OPERATIONS:
             exec py.code.compile("""
                 def translate_op_%s(self, hop):
                     r_arg1 = hop.args_r[0]
                     return r_arg1.rtype_%s(hop)
-                """ % (opname, opname)) in globals(), loc
+                """ % (opname, opname)) in globals(), ns
         # All binary operations
-        for opname in annmodel.BINARY_OPERATIONS:
+        for opname in model.BINARY_OPERATIONS:
             exec py.code.compile("""
                 def translate_op_%s(self, hop):
                     r_arg1 = hop.args_r[0]
                     r_arg2 = hop.args_r[1]
                     return pair(r_arg1, r_arg2).rtype_%s(hop)
-                """ % (opname, opname)) in globals(), loc
-
-    _registeroperations(locals())
-    del _registeroperations
+                """ % (opname, opname)) in globals(), ns
+    _registeroperations = classmethod(_registeroperations)
 
     # this one is not in BINARY_OPERATIONS
     def translate_op_contains(self, hop):
@@ -579,6 +578,9 @@
         funcptr = self.getcallable(graph)
         attachRuntimeTypeInfo(GCSTRUCT, funcptr, destrptr)
 
+# register operations from annotation model
+RPythonTyper._registeroperations(annmodel)
+
 # ____________________________________________________________
 
 

Modified: pypy/dist/pypy/rpython/typesystem.py
==============================================================================
--- pypy/dist/pypy/rpython/typesystem.py	(original)
+++ pypy/dist/pypy/rpython/typesystem.py	Sat Feb  4 22:34:20 2006
@@ -58,6 +58,16 @@
 in a graph."""
         raise NotImplementedError()
 
+    def perform_normalizations(self, rtyper):
+        """Prepare the annotator's internal data structures for rtyping
+        with the specified type system.
+        """
+        # default implementation
+        from pypy.translator.transform import insert_stackcheck
+        from pypy.rpython.normalizecalls import perform_normalizations
+        insert_stackcheck(rtyper.annotator)
+        perform_normalizations(rtyper)
+
 class LowLevelTypeSystem(TypeSystem):
     name = "lltypesystem"
     callable_trait = (lltype.FuncType, lltype.functionptr)



More information about the Pypy-commit mailing list