[pypy-svn] r13395 - in pypy/dist/pypy: rpython translator/c

arigo at codespeak.net arigo at codespeak.net
Tue Jun 14 19:13:49 CEST 2005


Author: arigo
Date: Tue Jun 14 19:13:47 2005
New Revision: 13395

Modified:
   pypy/dist/pypy/rpython/exceptiondata.py
   pypy/dist/pypy/rpython/rtyper.py
   pypy/dist/pypy/translator/c/g_exception.h
Log:
Force the except blocks to receive a standardized exception type and value.
This allows the code generators to assume they know the low-level type of the
data coming in, to do the 'raise'.



Modified: pypy/dist/pypy/rpython/exceptiondata.py
==============================================================================
--- pypy/dist/pypy/rpython/exceptiondata.py	(original)
+++ pypy/dist/pypy/rpython/exceptiondata.py	Tue Jun 14 19:13:47 2005
@@ -18,9 +18,13 @@
         r_instance = rclass.getinstancerepr(rtyper, None)
         r_type.setup()
         r_instance.setup()
+        self.r_exception_type  = r_type
+        self.r_exception_value = r_instance
         self.lltype_of_exception_type  = r_type.lowleveltype
         self.lltype_of_exception_value = r_instance.lowleveltype
 
+
+    def make_helpers(self, rtyper):
         # create helper functions
         self.ll_exception_match  = self.make_exception_matcher(rtyper)
         self.ll_type_of_exc_inst = self.make_type_of_exc_inst(rtyper)

Modified: pypy/dist/pypy/rpython/rtyper.py
==============================================================================
--- pypy/dist/pypy/rpython/rtyper.py	(original)
+++ pypy/dist/pypy/rpython/rtyper.py	Tue Jun 14 19:13:47 2005
@@ -36,6 +36,7 @@
         for s_primitive, lltype in annmodel.annotation_to_ll_map:
             r = self.getrepr(s_primitive)
             self.primitive_to_repr[r.lowleveltype] = r
+        self.exceptiondata = ExceptionData(self)
 
     def getexceptiondata(self):
         return self.exceptiondata    # built at the end of specialize()
@@ -89,8 +90,8 @@
                 self.call_all_setups()
 
         specialize_more_blocks()
-        self.exceptiondata = ExceptionData(self)
-        specialize_more_blocks()
+        self.exceptiondata.make_helpers(self)
+        specialize_more_blocks()   # for the helpers just made
 
         if self.typererror:
             exc, value, tb = self.typererror
@@ -111,10 +112,39 @@
         assert isinstance(v, Variable)
         v.concretetype = self.bindingrepr(v).lowleveltype
 
+    def typedconstant(self, c, using_repr=None):
+        """Make a copy of the Constant 'c' and give it a concretetype."""
+        assert isinstance(c, Constant)
+        if using_repr is None:
+            using_repr = self.bindingrepr(c)
+        if not hasattr(c, 'concretetype'):
+            c = inputconst(using_repr, c.value)
+        else:
+            if c.concretetype != Void:
+                assert typeOf(c.value) == using_repr.lowleveltype
+        return c
+
+    def setup_block_entry(self, block):
+        if block.operations == () and len(block.inputargs) == 2:
+            # special case for exception blocks: force them to return an
+            # exception type and value in a standardized format
+            v1, v2 = block.inputargs
+            v1.concretetype = self.exceptiondata.lltype_of_exception_type
+            v2.concretetype = self.exceptiondata.lltype_of_exception_value
+            return [self.exceptiondata.r_exception_type,
+                    self.exceptiondata.r_exception_value]
+        else:
+            # normal path
+            result = []
+            for a in block.inputargs:
+                r = self.bindingrepr(a)
+                a.concretetype = r.lowleveltype
+                result.append(r)
+            return result
+
     def specialize_block(self, block):
         # give the best possible types to the input args
-        for a in block.inputargs:
-            self.setconcretetype(a)
+        self.setup_block_entry(block)
 
         # specialize all the operations, as far as possible
         if block.operations == ():   # return or except block
@@ -147,15 +177,20 @@
                     assert block.exitswitch == Constant(last_exception)
                     r_case = rclass.get_type_repr(self)
                 link.llexitcase = r_case.convert_const(link.exitcase)
-            for a in [link.last_exception, link.last_exc_value]:
+
+            for attr in ('last_exception', 'last_exc_value'):
+                a = getattr(link, attr)
                 if isinstance(a, Variable):
                     self.setconcretetype(a)
+                elif isinstance(a, Constant):
+                    setattr(link, attr, self.typedconstant(a))
+
+            inputargs_reprs = self.setup_block_entry(link.target)
             for i in range(len(link.args)):
                 a1 = link.args[i]
-                a2 = link.target.inputargs[i]
-                r_a2 = self.bindingrepr(a2)
+                r_a2 = inputargs_reprs[i]
                 if isinstance(a1, Constant):
-                    link.args[i] = inputconst(r_a2, a1.value)
+                    link.args[i] = self.typedconstant(a1, using_repr=r_a2)
                     continue   # the Constant was typed, done
                 r_a1 = self.bindingrepr(a1)
                 if r_a1 == r_a2:

Modified: pypy/dist/pypy/translator/c/g_exception.h
==============================================================================
--- pypy/dist/pypy/translator/c/g_exception.h	(original)
+++ pypy/dist/pypy/translator/c/g_exception.h	Tue Jun 14 19:13:47 2005
@@ -14,10 +14,10 @@
 
 #define ExceptionOccurred()	(rpython_exc_type != NULL)
 
-#define RaiseException(etype, evalue)					\
-		assert(!ExceptionOccurred());				\
-		rpython_exc_type = (RPYTHON_EXCEPTION_VTABLE)(etype);	\
-		rpython_exc_value = (RPYTHON_EXCEPTION)(evalue)
+#define RaiseException(etype, evalue)		\
+		assert(!ExceptionOccurred());	\
+		rpython_exc_type = etype;	\
+		rpython_exc_value = evalue
 
 #define FetchException(etypevar, evaluevar, type_of_evaluevar)		\
 		etypevar = rpython_exc_type;				\



More information about the Pypy-commit mailing list