Commits

Maciej Fijalkowski committed dfc78c7

Move signature back to the interpreter

Comments (0)

Files changed (12)

pypy/interpreter/gateway.py

 
 from pypy.interpreter.eval import Code
 from pypy.interpreter.argument import Arguments
-from rpython.rtyper.signature import Signature
+from pypy.interpreter.signature import Signature
 from pypy.interpreter.baseobjspace import (W_Root, ObjSpace, Wrappable,
     SpaceCache, DescrMismatch)
 from pypy.interpreter.error import OperationError

pypy/interpreter/pycode.py

 import dis, imp, struct, types, new, sys
 
 from pypy.interpreter import eval
-from rpython.rtyper.signature import Signature
+from pypy.interpreter.signature import Signature
 from pypy.interpreter.error import OperationError
 from pypy.interpreter.gateway import unwrap_spec
 from pypy.interpreter.astcompiler.consts import (

pypy/interpreter/signature.py

+from rpython.rlib import jit
+
+class Signature(object):
+    _immutable_ = True
+    _immutable_fields_ = ["argnames[*]"]
+    __slots__ = ("argnames", "varargname", "kwargname")
+
+    def __init__(self, argnames, varargname=None, kwargname=None):
+        self.argnames = argnames
+        self.varargname = varargname
+        self.kwargname = kwargname
+
+    @jit.elidable
+    def find_argname(self, name):
+        try:
+            return self.argnames.index(name)
+        except ValueError:
+            return -1
+
+    def num_argnames(self):
+        return len(self.argnames)
+
+    def has_vararg(self):
+        return self.varargname is not None
+
+    def has_kwarg(self):
+        return self.kwargname is not None
+
+    def scope_length(self):
+        scopelen = len(self.argnames)
+        scopelen += self.has_vararg()
+        scopelen += self.has_kwarg()
+        return scopelen
+
+    def getallvarnames(self):
+        argnames = self.argnames
+        if self.varargname is not None:
+            argnames = argnames + [self.varargname]
+        if self.kwargname is not None:
+            argnames = argnames + [self.kwargname]
+        return argnames
+
+    def __repr__(self):
+        return "Signature(%r, %r, %r)" % (
+                self.argnames, self.varargname, self.kwargname)
+
+    def __eq__(self, other):
+        if not isinstance(other, Signature):
+            return NotImplemented
+        return (self.argnames == other.argnames and
+                self.varargname == other.varargname and
+                self.kwargname == other.kwargname)
+
+    def __ne__(self, other):
+        if not isinstance(other, Signature):
+            return NotImplemented
+        return not self == other
+
+
+    # make it look tuply for its use in the annotator
+
+    def __len__(self):
+        return 3
+
+    def __getitem__(self, i):
+        if i == 0:
+            return self.argnames
+        if i == 1:
+            return self.varargname
+        if i == 2:
+            return self.kwargname
+        raise IndexError

pypy/interpreter/test/test_argument.py

 import py
 from pypy.interpreter.argument import (Arguments, ArgErr, ArgErrUnknownKwds,
         ArgErrMultipleValues, ArgErrCount)
-from rpython.rtyper.signature import Signature
+from pypy.interpreter.signature import Signature
 from pypy.interpreter.error import OperationError
 
 

pypy/interpreter/test/test_gateway.py

 
 from pypy.interpreter import gateway, argument
 from pypy.interpreter.gateway import ObjSpace, W_Root, WrappedDefault
-from rpython.rtyper.signature import Signature
+from pypy.interpreter.signature import Signature
 import py
 import sys
 

pypy/module/oracle/interp_pool.py

 from pypy.interpreter.typedef import TypeDef, GetSetProperty
 from pypy.interpreter.typedef import interp_attrproperty, interp_attrproperty_w
 from pypy.interpreter.error import OperationError
+from pypy.interpreter.signature import Signature
 from rpython.rtyper.lltypesystem import rffi, lltype
-from rpython.rtyper.signature import Signature
 
 from pypy.module.oracle import roci, config
 from pypy.module.oracle import interp_error, interp_environ

pypy/objspace/std/bytearrayobject.py

 from pypy.objspace.std import slicetype
 from pypy.interpreter import gateway
 from pypy.interpreter.buffer import RWBuffer
+from pypy.interpreter.signature import Signature
 from pypy.objspace.std.bytearraytype import (
     makebytearraydata_w, getbytevalue,
     new_bytearray
 )
 from rpython.tool.sourcetools import func_with_new_name
-from rpython.rtyper.signature import Signature
 
 
 class W_BytearrayObject(W_Object):

pypy/objspace/std/dictmultiobject.py

 from pypy.objspace.std.register_all import register_all
 from pypy.objspace.std.settype import set_typedef as settypedef
 from pypy.objspace.std.frozensettype import frozenset_typedef as frozensettypedef
-from pypy.interpreter import gateway
 from pypy.interpreter.error import OperationError, operationerrfmt
+from pypy.interpreter.signature import Signature
 
-from rpython.rlib.objectmodel import r_dict, we_are_translated, specialize,\
-     newlist_hint
+from rpython.rlib.objectmodel import r_dict, specialize, newlist_hint
 from rpython.rlib.debug import mark_dict_non_null
 from rpython.tool.sourcetools import func_with_new_name
-from rpython.rtyper.signature import Signature
 
 from rpython.rlib import rerased
 from rpython.rlib import jit

pypy/objspace/std/listobject.py

 from pypy.objspace.std.sliceobject import W_SliceObject, normalize_simple_slice
 from pypy.objspace.std import slicetype
 from pypy.interpreter import gateway, baseobjspace
+from pypy.interpreter.signature import Signature
 from rpython.rlib.objectmodel import (instantiate, newlist_hint, specialize,
                                    resizelist_hint)
 from rpython.rlib.listsort import make_timsort_class
 from rpython.rlib import rerased, jit, debug
-from rpython.rtyper.signature import Signature
 from rpython.tool.sourcetools import func_with_new_name
 
 UNROLL_CUTOFF = 5

pypy/objspace/std/setobject.py

 from pypy.objspace.std.model import registerimplementation, W_Object
 from pypy.objspace.std.register_all import register_all
-from rpython.rlib.objectmodel import r_dict
-from rpython.rlib.rarithmetic import intmask, r_uint
 from pypy.interpreter.error import OperationError
 from pypy.interpreter import gateway
 from pypy.objspace.std.settype import set_typedef as settypedef
 from pypy.objspace.std.frozensettype import frozenset_typedef as frozensettypedef
-from rpython.rlib import rerased
-from rpython.rlib.objectmodel import instantiate
-from rpython.rtyper.signature import Signature
+from pypy.interpreter.signature import Signature
 from pypy.interpreter.generator import GeneratorIterator
 from pypy.objspace.std.listobject import W_ListObject
 from pypy.objspace.std.intobject import W_IntObject
 from pypy.objspace.std.stringobject import W_StringObject
 from pypy.objspace.std.unicodeobject import W_UnicodeObject
 
+from rpython.rlib.objectmodel import r_dict
+from rpython.rlib.rarithmetic import intmask, r_uint
+from rpython.rlib import rerased
+
 class W_BaseSetObject(W_Object):
     typedef = None
 

rpython/rtyper/normalizecalls.py

 from rpython.annotator import model as annmodel, description
-from rpython.rtyper.signature import Signature
+from rpython.flowspace.argument import Signature
 from rpython.flowspace.model import (Variable, Constant, Block, Link,
     checkgraph, FunctionGraph, SpaceOperation)
 from rpython.rlib.objectmodel import ComputedIntSymbolic

rpython/rtyper/signature.py

-from rpython.rlib import jit
-
-class Signature(object):
-    _immutable_ = True
-    _immutable_fields_ = ["argnames[*]"]
-    __slots__ = ("argnames", "varargname", "kwargname")
-
-    def __init__(self, argnames, varargname=None, kwargname=None):
-        self.argnames = argnames
-        self.varargname = varargname
-        self.kwargname = kwargname
-
-    @jit.elidable
-    def find_argname(self, name):
-        try:
-            return self.argnames.index(name)
-        except ValueError:
-            return -1
-
-    def num_argnames(self):
-        return len(self.argnames)
-
-    def has_vararg(self):
-        return self.varargname is not None
-
-    def has_kwarg(self):
-        return self.kwargname is not None
-
-    def scope_length(self):
-        scopelen = len(self.argnames)
-        scopelen += self.has_vararg()
-        scopelen += self.has_kwarg()
-        return scopelen
-
-    def getallvarnames(self):
-        argnames = self.argnames
-        if self.varargname is not None:
-            argnames = argnames + [self.varargname]
-        if self.kwargname is not None:
-            argnames = argnames + [self.kwargname]
-        return argnames
-
-    def __repr__(self):
-        return "Signature(%r, %r, %r)" % (
-                self.argnames, self.varargname, self.kwargname)
-
-    def __eq__(self, other):
-        if not isinstance(other, Signature):
-            return NotImplemented
-        return (self.argnames == other.argnames and
-                self.varargname == other.varargname and
-                self.kwargname == other.kwargname)
-
-    def __ne__(self, other):
-        if not isinstance(other, Signature):
-            return NotImplemented
-        return not self == other
-
-
-    # make it look tuply for its use in the annotator
-
-    def __len__(self):
-        return 3
-
-    def __getitem__(self, i):
-        if i == 0:
-            return self.argnames
-        if i == 1:
-            return self.varargname
-        if i == 2:
-            return self.kwargname
-        raise IndexError