Source

pypy / pypy / module / sys / vm.py

Diff from to

pypy/module/sys/vm.py

     #       BINARY_SUBSCR
     # or:
     #       CALL_FUNCTION/CALL_METHOD
+    #       LOAD_CONST any integer or None
     #       LOAD_CONST <=2
-    #       SLICE_2
-    # or:
-    #       CALL_FUNCTION/CALL_METHOD
-    #       LOAD_CONST any integer
-    #       LOAD_CONST <=2
-    #       SLICE_3
+    #       BUILD_SLICE 2
+    #       BINARY_SUBSCR
     need_all_three_args = True
     co = frame.getcode().co_code
     p = frame.last_instr
             lo = ord(co[p+4])
             hi = ord(co[p+5])
             w_constant = frame.getconstant_w((hi * 256) | lo)
-            if space.isinstance_w(w_constant, space.w_int):
-                constant = space.int_w(w_constant)
-                if ord(co[p+6]) == stdlib_opcode.BINARY_SUBSCR:
+            if ord(co[p+6]) == stdlib_opcode.BINARY_SUBSCR:
+                if space.isinstance_w(w_constant, space.w_int):
+                    constant = space.int_w(w_constant)
                     if -3 <= constant <= 1 and constant != -1:
                         need_all_three_args = False
-                elif ord(co[p+6]) == stdlib_opcode.SLICE+2:
-                    if constant <= 2:
-                        need_all_three_args = False
-                elif (ord(co[p+6]) == stdlib_opcode.LOAD_CONST and
-                      ord(co[p+9]) == stdlib_opcode.SLICE+3):
+            elif (ord(co[p+6]) == stdlib_opcode.LOAD_CONST and
+                  ord(co[p+9]) == stdlib_opcode.BUILD_SLICE and
+                  ord(co[p+12]) == stdlib_opcode.BINARY_SUBSCR):
+                if (space.is_w(w_constant, space.w_None) or
+                    space.isinstance_w(w_constant, space.w_int)):
                     lo = ord(co[p+7])
                     hi = ord(co[p+8])
                     w_constant = frame.getconstant_w((hi * 256) | lo)
 "NOT_RPYTHON"
 from _structseq import structseqtype, structseqfield
 
-class windows_version_info:
-    __metaclass__ = structseqtype
+class windows_version_info(metaclass=structseqtype):
 
     name = "sys.getwindowsversion"
 
         raise OperationError(space.w_TypeError,
             space.wrap("sys.getsizeof() not implemented on PyPy"))
     return w_default
+
+def intern(space, w_str):
+    """``Intern'' the given string.  This enters the string in the (global)
+table of interned strings whose purpose is to speed up dictionary lookups.
+Return the string itself or the previously interned string object with the
+same value."""
+    if space.is_w(space.type(w_str), space.w_unicode):
+        return space.new_interned_w_str(w_str)
+    raise OperationError(space.w_TypeError, space.wrap("intern() argument must be string."))
+