[pypy-commit] pypy py3k: In flow object space, restore opcodes and operations removed in the base

amauryfa noreply at buildbot.pypy.org
Mon Oct 17 19:57:40 CEST 2011


Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch: py3k
Changeset: r48152:211a8e36ea40
Date: 2011-10-17 19:50 +0200
http://bitbucket.org/pypy/pypy/changeset/211a8e36ea40/

Log:	In flow object space, restore opcodes and operations removed in the
	base objectspace

diff --git a/pypy/objspace/flow/flowcontext.py b/pypy/objspace/flow/flowcontext.py
--- a/pypy/objspace/flow/flowcontext.py
+++ b/pypy/objspace/flow/flowcontext.py
@@ -425,6 +425,100 @@
     def MAP_ADD(self, oparg, next_instr):
         raise NotImplementedError("MAP_ADD")
 
+    # opcodes removed or heavily changed in python 3
+
+    @jit.unroll_safe
+    def RAISE_VARARGS(self, nbargs, next_instr):
+        space = self.space
+        if nbargs == 0:
+            frame = self
+            ec = self.space.getexecutioncontext()
+            while frame:
+                if frame.last_exception is not None:
+                    operror = ec._convert_exc(frame.last_exception)
+                    break
+                frame = frame.f_backref()
+            else:
+                raise OperationError(space.w_TypeError,
+                    space.wrap("raise: no active exception to re-raise"))
+            # re-raise, no new traceback obj will be attached
+            self.last_exception = operror
+            from pypy.interpreter.pyopcode import Reraise
+            raise Reraise
+
+        w_value = w_traceback = space.w_None
+        if nbargs >= 3:
+            w_traceback = self.popvalue()
+        if nbargs >= 2:
+            w_value = self.popvalue()
+        if 1:
+            w_type = self.popvalue()
+        operror = OperationError(w_type, w_value)
+        operror.normalize_exception(space)
+        raise operror
+
+    def slice(self, w_start, w_end):
+        w_obj = self.popvalue()
+        w_result = self.space.getslice(w_obj, w_start, w_end)
+        self.pushvalue(w_result)
+
+    def SLICE_0(self, oparg, next_instr):
+        self.slice(self.space.w_None, self.space.w_None)
+
+    def SLICE_1(self, oparg, next_instr):
+        w_start = self.popvalue()
+        self.slice(w_start, self.space.w_None)
+
+    def SLICE_2(self, oparg, next_instr):
+        w_end = self.popvalue()
+        self.slice(self.space.w_None, w_end)
+
+    def SLICE_3(self, oparg, next_instr):
+        w_end = self.popvalue()
+        w_start = self.popvalue()
+        self.slice(w_start, w_end)
+
+    def storeslice(self, w_start, w_end):
+        w_obj = self.popvalue()
+        w_newvalue = self.popvalue()
+        self.space.setslice(w_obj, w_start, w_end, w_newvalue)
+
+    def STORE_SLICE_0(self, oparg, next_instr):
+        self.storeslice(self.space.w_None, self.space.w_None)
+
+    def STORE_SLICE_1(self, oparg, next_instr):
+        w_start = self.popvalue()
+        self.storeslice(w_start, self.space.w_None)
+
+    def STORE_SLICE_2(self, oparg, next_instr):
+        w_end = self.popvalue()
+        self.storeslice(self.space.w_None, w_end)
+
+    def STORE_SLICE_3(self, oparg, next_instr):
+        w_end = self.popvalue()
+        w_start = self.popvalue()
+        self.storeslice(w_start, w_end)
+
+    def deleteslice(self, w_start, w_end):
+        w_obj = self.popvalue()
+        self.space.delslice(w_obj, w_start, w_end)
+
+    def DELETE_SLICE_0(self, oparg, next_instr):
+        self.deleteslice(self.space.w_None, self.space.w_None)
+
+    def DELETE_SLICE_1(self, oparg, next_instr):
+        w_start = self.popvalue()
+        self.deleteslice(w_start, self.space.w_None)
+
+    def DELETE_SLICE_2(self, oparg, next_instr):
+        w_end = self.popvalue()
+        self.deleteslice(self.space.w_None, w_end)
+
+    def DELETE_SLICE_3(self, oparg, next_instr):
+        w_end = self.popvalue()
+        w_start = self.popvalue()
+        self.deleteslice(w_start, w_end)
+
     def make_arguments(self, nargs):
         return ArgumentsForTranslation(self.space, self.peekvalues(nargs))
     def argument_factory(self, *args):
diff --git a/pypy/objspace/flow/operation.py b/pypy/objspace/flow/operation.py
--- a/pypy/objspace/flow/operation.py
+++ b/pypy/objspace/flow/operation.py
@@ -14,6 +14,13 @@
 from pypy.rlib.rarithmetic import ovfcheck, ovfcheck_lshift
 from pypy.objspace.flow import model
 
+MethodTable = ObjSpace.MethodTable[:]
+MethodTable.extend([
+    ('getslice',        'getslice',  3, ['__getslice__']),
+    ('setslice',        'setslice',  4, ['__setslice__']),
+    ('delslice',        'delslice',  3, ['__delslice__']),
+])
+
 
 class OperationThatShouldNotBePropagatedError(OperationError):
     pass
@@ -235,7 +242,7 @@
 
 def setup():
     # insert all operators
-    for line in ObjSpace.MethodTable:
+    for line in MethodTable:
         name = line[0]
         if hasattr(operator, name):
             Table.append((name, getattr(operator, name)))
@@ -246,7 +253,7 @@
         if func not in OperationName:
             OperationName[func] = name
     # check that the result is complete
-    for line in ObjSpace.MethodTable:
+    for line in MethodTable:
         name = line[0]
         Arity[name] = line[2]
         assert name in FunctionByName
@@ -428,6 +435,6 @@
 
 def add_operations(fs):
     """Add function operations to the flow space."""
-    for line in ObjSpace.MethodTable:
+    for line in MethodTable:
         make_op(fs, *line)
     special_overrides(fs)


More information about the pypy-commit mailing list