Commits

Amaury Forgeot d'Arc committed 85f0de7

re-import a full copy of rpython/flowspace from default branch.

Comments (0)

Files changed (7)

rpython/flowspace/argument.py

         elif num_args > co_argcount:
             raise ArgErrCount(num_args, num_kwds, signature, defaults_w, 0)
 
-        # if a **kwargs argument is needed, create the dict
-        w_kwds = None
+        # if a **kwargs argument is needed, explode
         if signature.has_kwarg():
-            w_kwds = self.space.newdict(kwargs=True)
-            scope_w[co_argcount + signature.has_vararg()] = w_kwds
+            raise TypeError("Keyword arguments as **kwargs is not supported by RPython")
 
         # handle keyword arguments
         num_remainingkwds = 0
                     num_remainingkwds -= 1
 
             if num_remainingkwds:
-                if w_kwds is not None:
-                    # collect extra keyword arguments into the **kwarg
-                    limit = len(keywords)
-                    if self.keyword_names_w is not None:
-                        limit -= len(self.keyword_names_w)
-                    for i in range(len(keywords)):
-                        if i in kwds_mapping:
-                            continue
-                        if i < limit:
-                            w_key = self.space.wrap(keywords[i])
-                        else:
-                            w_key = self.keyword_names_w[i - limit]
-                        self.space.setitem(w_kwds, w_key, keywords_w[i])
-                else:
-                    if co_argcount == 0:
-                        raise ArgErrCount(num_args, num_kwds, signature, defaults_w, 0)
-                    raise ArgErrUnknownKwds(self.space, num_remainingkwds, keywords,
-                                            kwds_mapping, self.keyword_names_w)
+                if co_argcount == 0:
+                    raise ArgErrCount(num_args, num_kwds, signature, defaults_w, 0)
+                raise ArgErrUnknownKwds(self.space, num_remainingkwds, keywords,
+                                        kwds_mapping, self.keyword_names_w)
 
         # check for missing arguments and fill them from the kwds,
         # or with defaults, if available

rpython/flowspace/bytecode.py

     """
     opnames = host_bytecode_spec.method_names
 
-    def __init__(self, argcount, kwonlyargcount, nlocals, stacksize, flags,
+    def __init__(self, argcount, nlocals, stacksize, flags,
                      code, consts, names, varnames, filename,
                      name, firstlineno, lnotab, freevars):
         """Initialize a new code object"""
         self.co_name = name
         assert nlocals >= 0
         self.co_argcount = argcount
-        # note that this is ignored, as HostCode represents a python2 bytecode
-        self.co_kwonlyargcount = kwonlyargcount
         self.co_nlocals = nlocals
         self.co_stacksize = stacksize
         self.co_flags = flags
         """Initialize the code object from a real (CPython) one.
         """
         return cls(code.co_argcount,
-                   getattr(code, 'co_kwonlyargcount', 0),
                       code.co_nlocals,
                       code.co_stacksize,
                       code.co_flags,

rpython/flowspace/flowcontext.py

                 self.last_exception = operr
                 raise operr
             else:
-                raise FSException(space.w_RuntimeError,
-                    space.wrap("No active exception to reraise"))
+                raise FSException(space.w_TypeError,
+                    space.wrap("raise: no active exception to re-raise"))
 
         w_value = w_traceback = space.w_None
         if nbargs >= 3:
     LOAD_CLOSURE = BAD_OPCODE
     MAKE_CLOSURE = BAD_OPCODE
 
-    # opcodes removed or heavily changed in python 3
-
-    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):
-        return ArgumentsForTranslation(self.space, *args)
-
 ### Frame blocks ###
 
 class SuspendedUnroller(object):

rpython/flowspace/objspace.py

         clsname = exc.__name__
         locals()['w_' + clsname] = Constant(exc)
 
-    py3k = False # the RPython bytecode is still python2
     # the following exceptions should not show up
     # during flow graph construction
     w_NameError = 'NameError'
             return val
         return self.unwrap(w_obj)
 
-    identifier_w = str_w # RPython interprets Python2, where identifier_w is
-                         # equivalent to str_w
-
-    def unicode_w(self, w_obj):
-        if isinstance(w_obj, Constant):
-            val = w_obj.value
-            if type(val) is str:
-                return val.decode('ascii')
-            elif type(val) is unicode:
-                return val
-            else:
-                raise TypeError("expected unicode: " + repr(w_obj))
-        return self.unwrap(w_obj)                                
-
     def float_w(self, w_obj):
         if isinstance(w_obj, Constant):
             val = w_obj.value

rpython/flowspace/operation.py

 _add_exceptions("""pow""",
                 OverflowError) # for the float case
 del _add_exceptions, _add_except_ovf
-
-def make_op(fs, name, symbol, arity, specialnames):
-    if getattr(fs, name, None) is not None:
-        return
-
-    op = None
-    skip = False
-    arithmetic = False
-
-    if (name.startswith('del') or
-        name.startswith('set') or
-        name.startswith('inplace_')):
-        # skip potential mutators
-        skip = True
-    elif name in ('id', 'hash', 'iter', 'userdel'):
-        # skip potential runtime context dependecies
-        skip = True
-    elif name in ('repr', 'str'):
-        rep = getattr(__builtin__, name)
-        def op(obj):
-            s = rep(obj)
-            if "at 0x" in s:
-                print >>sys.stderr, "Warning: captured address may be awkward"
-            return s
-    else:
-        op = FunctionByName[name]
-        arithmetic = (name + '_ovf') in FunctionByName
-
-    if not op and not skip:
-        raise ValueError("XXX missing operator: %s" % (name,))
-
-    def generic_operator(self, *args_w):
-        assert len(args_w) == arity, name + " got the wrong number of arguments"
-        if op:
-            args = []
-            for w_arg in args_w:
-                try:
-                    arg = self.unwrap_for_computation(w_arg)
-                except model.UnwrapException:
-                    break
-                else:
-                    args.append(arg)
-            else:
-                # All arguments are constants: call the operator now
-                try:
-                    result = op(*args)
-                except Exception, e:
-                    etype = e.__class__
-                    msg = "generated by a constant operation:\n\t%s%r" % (
-                        name, tuple(args))
-                    raise OperationThatShouldNotBePropagatedError(
-                        self.wrap(etype), self.wrap(msg))
-                else:
-                    # don't try to constant-fold operations giving a 'long'
-                    # result.  The result is probably meant to be sent to
-                    # an intmask(), but the 'long' constant confuses the
-                    # annotator a lot.
-                    if arithmetic and type(result) is long:
-                        pass
-                    # don't constant-fold getslice on lists, either
-                    elif name == 'getslice' and type(result) is list:
-                        pass
-                    # otherwise, fine
-                    else:
-                        try:
-                            return self.wrap(result)
-                        except model.WrapException:
-                            # type cannot sanely appear in flow graph,
-                            # store operation with variable result instead
-                            pass
-        w_result = self.do_operation_with_implicit_exceptions(name, *args_w)
-        return w_result
-
-    setattr(fs, name, generic_operator)
-
-

rpython/flowspace/test/test_argument.py

     def str_w(self, s):
         return str(s)
 
-    def unicode_w(self, s):
-        return unicode(s)
-
-    def identifier_w(self, s):
-        return self.unicode_w(s).encode('utf-8')
-
     def len(self, x):
         return len(x)
 

rpython/flowspace/test/test_objspace.py

             for op in block.operations:
                 assert not op.opname == "call_args"
 
-    def test_keyword_arguments(self):
-        def g(a, b):
-            pass
-        def f():
-            return g(a=1, b=2)
-        self.codetest(f)
-
     def test_catch_importerror_1(self):
         def f():
             try: