[pypy-commit] pypy default: Removed pointless singleton

alex_gaynor noreply at buildbot.pypy.org
Sat May 24 20:26:03 CEST 2014


Author: Alex Gaynor <alex.gaynor at gmail.com>
Branch: 
Changeset: r71702:88669e5d7fe2
Date: 2014-05-24 13:25 -0500
http://bitbucket.org/pypy/pypy/changeset/88669e5d7fe2/

Log:	Removed pointless singleton

diff --git a/rpython/rtyper/rtyper.py b/rpython/rtyper/rtyper.py
--- a/rpython/rtyper/rtyper.py
+++ b/rpython/rtyper/rtyper.py
@@ -38,7 +38,7 @@
     def __init__(self, annotator):
         self.annotator = annotator
         self.lowlevel_ann_policy = LowLevelAnnotatorPolicy(self)
-        self.type_system = LowLevelTypeSystem.instance
+        self.type_system = LowLevelTypeSystem()
         self.reprs = {}
         self._reprs_must_call_setup = []
         self._seen_reprs_must_call_setup = {}
diff --git a/rpython/rtyper/typesystem.py b/rpython/rtyper/typesystem.py
--- a/rpython/rtyper/typesystem.py
+++ b/rpython/rtyper/typesystem.py
@@ -1,14 +1,11 @@
 
 """typesystem.py -- Typesystem-specific operations for RTyper."""
 
-from rpython.tool.pairtype import extendabletype
-
 from rpython.rtyper.lltypesystem import lltype
 from rpython.rtyper.error import TyperError
 
+
 class LowLevelTypeSystem(object):
-    __metaclass__ = extendabletype
-
     name = "lltypesystem"
 
     def deref(self, obj):
@@ -24,41 +21,12 @@
         return lltype.nullptr(T.TO)
 
     def getcallable(self, graph, getconcretetype=None):
-        """Return callable given a Python function."""
-        if getconcretetype is None:
-            getconcretetype = self.getconcretetype
-        llinputs = [getconcretetype(v) for v in graph.getargs()]
-        lloutput = getconcretetype(graph.getreturnvar())
-
-        FT = lltype.FuncType(llinputs, lloutput)
-        name = graph.name
-        if hasattr(graph, 'func') and callable(graph.func):
-            # the Python function object can have _llfnobjattrs_, specifying
-            # attributes that are forced upon the functionptr().  The idea
-            # for not passing these extra attributes as arguments to
-            # getcallable() itself is that multiple calls to getcallable()
-            # for the same graph should return equal functionptr() objects.
-            if hasattr(graph.func, '_llfnobjattrs_'):
-                fnobjattrs = graph.func._llfnobjattrs_.copy()
-                # can specify a '_name', but use graph.name by default
-                name = fnobjattrs.pop('_name', name)
-            else:
-                fnobjattrs = {}
-            # _callable is normally graph.func, but can be overridden:
-            # see fakeimpl in extfunc.py
-            _callable = fnobjattrs.pop('_callable', graph.func)
-            return lltype.functionptr(FT, name, graph = graph,
-                                      _callable = _callable, **fnobjattrs)
-        else:
-            return lltype.functionptr(FT, name, graph = graph)
+        return getfunctionptr(graph, getconcretetype)
 
     def getexternalcallable(self, ll_args, ll_result, name, **kwds):
         FT = lltype.FuncType(ll_args, ll_result)
         return lltype.functionptr(FT, name, **kwds)
 
-    def getconcretetype(self, v):
-        return v.concretetype
-
     def generic_is(self, robj1, robj2, hop):
         roriginal1 = robj1
         roriginal2 = robj2
@@ -78,6 +46,35 @@
         return hop.genop('ptr_eq', v_list, resulttype=lltype.Bool)
 
 
-# All typesystems are singletons
-LowLevelTypeSystem.instance = LowLevelTypeSystem()
-getfunctionptr = LowLevelTypeSystem.instance.getcallable
+def _getconcretetype(v):
+    return v.concretetype
+
+def getfunctionptr(graph, getconcretetype=None):
+    """Return callable given a Python function."""
+    if getconcretetype is None:
+        getconcretetype = _getconcretetype
+    llinputs = [getconcretetype(v) for v in graph.getargs()]
+    lloutput = getconcretetype(graph.getreturnvar())
+
+    FT = lltype.FuncType(llinputs, lloutput)
+    name = graph.name
+    if hasattr(graph, 'func') and callable(graph.func):
+        # the Python function object can have _llfnobjattrs_, specifying
+        # attributes that are forced upon the functionptr().  The idea
+        # for not passing these extra attributes as arguments to
+        # getcallable() itself is that multiple calls to getcallable()
+        # for the same graph should return equal functionptr() objects.
+        if hasattr(graph.func, '_llfnobjattrs_'):
+            fnobjattrs = graph.func._llfnobjattrs_.copy()
+            # can specify a '_name', but use graph.name by default
+            name = fnobjattrs.pop('_name', name)
+        else:
+            fnobjattrs = {}
+        # _callable is normally graph.func, but can be overridden:
+        # see fakeimpl in extfunc.py
+        _callable = fnobjattrs.pop('_callable', graph.func)
+        return lltype.functionptr(FT, name, graph = graph,
+                                  _callable = _callable, **fnobjattrs)
+    else:
+        return lltype.functionptr(FT, name, graph = graph)
+


More information about the pypy-commit mailing list