[pypy-svn] r21794 - in pypy/dist/pypy/translator/js: . test

ericvrp at codespeak.net ericvrp at codespeak.net
Sat Jan 7 20:18:08 CET 2006


Author: ericvrp
Date: Sat Jan  7 20:17:51 2006
New Revision: 21794

Modified:
   pypy/dist/pypy/translator/js/codewriter.py
   pypy/dist/pypy/translator/js/funcnode.py
   pypy/dist/pypy/translator/js/test/runtest.py
Log:
Added support for block with multiple exits


Modified: pypy/dist/pypy/translator/js/codewriter.py
==============================================================================
--- pypy/dist/pypy/translator/js/codewriter.py	(original)
+++ pypy/dist/pypy/translator/js/codewriter.py	Sat Jan  7 20:17:51 2006
@@ -134,6 +134,15 @@
         self.append('}')
         self.skip_closeblock()
 
+    def switch(self, cond, defaultdest, value_labels):
+        if not defaultdest:
+            raise TypeError('switches must have a default case.') 
+        labels = ','.join(["'%s':%s" % (value, label) for value, label in value_labels])
+        #XXX for performance this Object should become global
+        self.append("if (!(block = {%s}[%s])) block = %s" % (labels, cond, defaultdest))
+        self._goto_block('block')
+        self.skip_closeblock() 
+
     def openfunc(self, decl, funcnode, blocks): 
         self.decl     = decl
         self.funcnode = funcnode

Modified: pypy/dist/pypy/translator/js/funcnode.py
==============================================================================
--- pypy/dist/pypy/translator/js/funcnode.py	(original)
+++ pypy/dist/pypy/translator/js/funcnode.py	Sat Jan  7 20:17:51 2006
@@ -83,14 +83,40 @@
     def write_block_branches(self, codewriter, block):
         if block.exitswitch == c_last_exception:
             return
+
         if len(block.exits) == 1:
             codewriter.br_uncond(self.blockindex[block.exits[0].target], block.exits[0])
-        elif len(block.exits) == 2:
-            cond = self.db.repr_arg(block.exitswitch)
+            return
+
+        cond = self.db.repr_arg(block.exitswitch)
+        if block.exitswitch.concretetype == lltype.Bool:
+            assert len(block.exits) == 2
             codewriter.br(cond,
                           self.blockindex[block.exits[0].target], block.exits[0],
                           self.blockindex[block.exits[1].target], block.exits[1])
 
+        elif block.exitswitch.concretetype in \
+            (lltype.Signed, lltype.Unsigned, lltype.SignedLongLong,
+             lltype.UnsignedLongLong, lltype.Char, lltype.UniChar):
+            defaultlink = None
+            value_labels = []
+            for link in block.exits:
+                if link.exitcase is 'default':
+                    defaultlink = link
+                    continue
+
+                exitcase = link.llexitcase
+                if block.exitswitch.concretetype in [lltype.Char, lltype.UniChar]:
+                    exitcase = ord(exitcase)
+                value_labels.append( (exitcase,
+                                      self.blockindex[link.target]) )
+
+            codewriter.switch(cond, self.blockindex[defaultlink.target], value_labels)
+
+        else:
+           raise BranchException("exitswitch type '%s' not supported" %
+                                 block.exitswitch.concretetype)  
+
     def write_block_operations(self, codewriter, block):
         opwriter = OpWriter(self.db, codewriter, self, block)
         if block.exitswitch == c_last_exception:

Modified: pypy/dist/pypy/translator/js/test/runtest.py
==============================================================================
--- pypy/dist/pypy/translator/js/test/runtest.py	(original)
+++ pypy/dist/pypy/translator/js/test/runtest.py	Sat Jan  7 20:17:51 2006
@@ -24,7 +24,7 @@
         t = Translator(function)
         a = t.annotate(annotation)
         t.specialize()
-        t.backend_optimizations(inline_threshold=0, mallocs=False, merge_if_blocks_to_switch=False)
+        t.backend_optimizations(inline_threshold=0, mallocs=False)
         #t.backend_optimizations()
         if view:
             t.view()



More information about the Pypy-commit mailing list