[pypy-svn] r74051 - in pypy/branch/blackhole-improvement/pypy/jit: codewriter metainterp

arigo at codespeak.net arigo at codespeak.net
Sun Apr 25 11:50:11 CEST 2010


Author: arigo
Date: Sun Apr 25 11:50:09 2010
New Revision: 74051

Modified:
   pypy/branch/blackhole-improvement/pypy/jit/codewriter/assembler.py
   pypy/branch/blackhole-improvement/pypy/jit/metainterp/blackhole.py
Log:
Passes test_switch_dict in test_basic.


Modified: pypy/branch/blackhole-improvement/pypy/jit/codewriter/assembler.py
==============================================================================
--- pypy/branch/blackhole-improvement/pypy/jit/codewriter/assembler.py	(original)
+++ pypy/branch/blackhole-improvement/pypy/jit/codewriter/assembler.py	Sun Apr 25 11:50:09 2010
@@ -1,6 +1,6 @@
 from pypy.jit.metainterp.history import AbstractValue, AbstractDescr, getkind
 from pypy.jit.codewriter.flatten import Register, Label, TLabel, KINDS
-from pypy.jit.codewriter.flatten import ListOfKind
+from pypy.jit.codewriter.flatten import ListOfKind, SwitchDictDescr
 from pypy.objspace.flow.model import Constant
 from pypy.rpython.lltypesystem import lltype, llmemory
 
@@ -49,6 +49,7 @@
         self.constants_f = []
         self.label_positions = {}
         self.tlabel_positions = []
+        self.switchdictdescrs = []
         self.highest_regs = dict.fromkeys(KINDS, 0)
 
     def emit_reg(self, reg):
@@ -133,6 +134,8 @@
                 if x not in self._descr_dict:
                     self._descr_dict[x] = len(self.descrs)
                     self.descrs.append(x)
+                if isinstance(x, SwitchDictDescr):
+                    self.switchdictdescrs.append(x)
                 num = self._descr_dict[x]
                 assert 0 <= num <= 0xFFFF, "too many AbstractDescrs!"
                 self.code.append(chr(num & 0xFF))
@@ -153,6 +156,11 @@
             assert 0 <= target <= 0xFFFF
             self.code[pos  ] = chr(target & 0xFF)
             self.code[pos+1] = chr(target >> 8)
+        for descr in self.switchdictdescrs:
+            descr.dict = {}
+            for key, switchlabel in descr._labels:
+                target = self.label_positions[switchlabel.name]
+                descr.dict[key] = target
 
     def check_result(self):
         # Limitation of the number of registers, from the single-byte encoding

Modified: pypy/branch/blackhole-improvement/pypy/jit/metainterp/blackhole.py
==============================================================================
--- pypy/branch/blackhole-improvement/pypy/jit/metainterp/blackhole.py	(original)
+++ pypy/branch/blackhole-improvement/pypy/jit/metainterp/blackhole.py	Sun Apr 25 11:50:09 2010
@@ -4,6 +4,7 @@
 from pypy.tool.sourcetools import func_with_new_name
 from pypy.rpython.lltypesystem import lltype, llmemory
 from pypy.rpython.lltypesystem.lloperation import llop
+from pypy.jit.codewriter.flatten import SwitchDictDescr
 
 
 def arguments(*argtypes, **kwds):
@@ -294,6 +295,14 @@
     def opimpl_goto(self, target):
         return target
 
+    @arguments("i", "d", "pc", returns="L")
+    def opimpl_switch(self, switchvalue, switchdict, pc):
+        assert isinstance(switchdict, SwitchDictDescr)
+        try:
+            return switchdict.dict[switchvalue]
+        except KeyError:
+            return pc
+
     # ----------
     # the following operations are directly implemented by the backend
 



More information about the Pypy-commit mailing list