[pypy-commit] pypy type_system-cleanup: Remove rpython/rtyper/typesystem.py and move getfunctionptr() to lltype

rlamy noreply at buildbot.pypy.org
Fri Oct 9 05:31:23 CEST 2015


Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: type_system-cleanup
Changeset: r80071:68c2ec00cda8
Date: 2015-10-09 04:24 +0100
http://bitbucket.org/pypy/pypy/changeset/68c2ec00cda8/

Log:	Remove rpython/rtyper/typesystem.py and move getfunctionptr() to
	lltype

diff --git a/rpython/jit/codewriter/call.py b/rpython/jit/codewriter/call.py
--- a/rpython/jit/codewriter/call.py
+++ b/rpython/jit/codewriter/call.py
@@ -9,7 +9,7 @@
     QuasiImmutAnalyzer, RandomEffectsAnalyzer, effectinfo_from_writeanalyze,
     EffectInfo, CallInfoCollection)
 from rpython.rtyper.lltypesystem import lltype, llmemory
-from rpython.rtyper.typesystem import getfunctionptr
+from rpython.rtyper.lltypesystem.lltype import getfunctionptr
 from rpython.rlib import rposix
 from rpython.translator.backendopt.canraise import RaiseAnalyzer
 from rpython.translator.backendopt.writeanalyze import ReadWriteAnalyzer
diff --git a/rpython/rtyper/lltypesystem/lltype.py b/rpython/rtyper/lltypesystem/lltype.py
--- a/rpython/rtyper/lltypesystem/lltype.py
+++ b/rpython/rtyper/lltypesystem/lltype.py
@@ -2265,6 +2265,35 @@
     o = _func(TYPE, _name=name, **attrs)
     return _ptr(Ptr(TYPE), o)
 
+def _getconcretetype(v):
+    return v.concretetype
+
+def getfunctionptr(graph, getconcretetype=_getconcretetype):
+    """Return callable given a Python function."""
+    llinputs = [getconcretetype(v) for v in graph.getargs()]
+    lloutput = getconcretetype(graph.getreturnvar())
+
+    FT = 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 functionptr(FT, name, graph=graph, _callable=_callable,
+                           **fnobjattrs)
+    else:
+        return functionptr(FT, name, graph=graph)
 
 def nullptr(T):
     return Ptr(T)._defl()
@@ -2444,3 +2473,5 @@
         for item in v.items:
             for i in dissect_ll_instance(item, t.OF, memo):
                 yield i
+
+
diff --git a/rpython/rtyper/rpbc.py b/rpython/rtyper/rpbc.py
--- a/rpython/rtyper/rpbc.py
+++ b/rpython/rtyper/rpbc.py
@@ -13,11 +13,11 @@
 from rpython.rtyper.error import TyperError
 from rpython.rtyper.lltypesystem import rffi
 from rpython.rtyper.lltypesystem import llmemory
-from rpython.rtyper.lltypesystem.lltype import (typeOf, Void, ForwardReference,
-    Struct, Bool, Char, Ptr, malloc, nullptr, Array, Signed, cast_pointer)
+from rpython.rtyper.lltypesystem.lltype import (
+    typeOf, Void, ForwardReference, Struct, Bool, Char, Ptr, malloc, nullptr,
+    Array, Signed, cast_pointer, getfunctionptr)
 from rpython.rtyper.rmodel import (Repr, inputconst, CanBeNull, mangle,
     warning, impossible_repr)
-from rpython.rtyper.typesystem import getfunctionptr
 from rpython.tool.pairtype import pair, pairtype
 from rpython.translator.unsimplify import varoftype
 
diff --git a/rpython/rtyper/rtyper.py b/rpython/rtyper/rtyper.py
--- a/rpython/rtyper/rtyper.py
+++ b/rpython/rtyper/rtyper.py
@@ -23,9 +23,8 @@
 from rpython.rtyper.exceptiondata import ExceptionData
 from rpython.rtyper.lltypesystem.lltype import (Signed, Void, LowLevelType,
     Ptr, ContainerType, FuncType, functionptr, typeOf, RuntimeTypeInfo,
-    attachRuntimeTypeInfo, Primitive)
+    attachRuntimeTypeInfo, Primitive, getfunctionptr)
 from rpython.rtyper.rmodel import Repr, inputconst, BrokenReprTyperError
-from rpython.rtyper.typesystem import getfunctionptr
 from rpython.rtyper import rclass
 from rpython.rtyper.rclass import RootClassRepr
 from rpython.tool.pairtype import pair
diff --git a/rpython/rtyper/typesystem.py b/rpython/rtyper/typesystem.py
deleted file mode 100644
--- a/rpython/rtyper/typesystem.py
+++ /dev/null
@@ -1,35 +0,0 @@
-
-"""typesystem.py -- Typesystem-specific operations for RTyper."""
-
-from rpython.rtyper.lltypesystem import lltype
-
-
-def _getconcretetype(v):
-    return v.concretetype
-
-def getfunctionptr(graph, getconcretetype=_getconcretetype):
-    """Return callable given a Python function."""
-    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)
diff --git a/rpython/translator/backendopt/mallocv.py b/rpython/translator/backendopt/mallocv.py
--- a/rpython/translator/backendopt/mallocv.py
+++ b/rpython/translator/backendopt/mallocv.py
@@ -4,7 +4,7 @@
 from rpython.translator.backendopt.support import log
 from rpython.translator.simplify import join_blocks
 from rpython.translator.unsimplify import varoftype
-from rpython.rtyper.typesystem import getfunctionptr
+from rpython.rtyper.lltypesystem.lltype import getfunctionptr
 from rpython.rtyper.lltypesystem import lltype
 from rpython.rtyper.lltypesystem.lloperation import llop
 
diff --git a/rpython/translator/c/dlltool.py b/rpython/translator/c/dlltool.py
--- a/rpython/translator/c/dlltool.py
+++ b/rpython/translator/c/dlltool.py
@@ -1,6 +1,6 @@
 
 from rpython.translator.c.genc import CBuilder
-from rpython.rtyper.typesystem import getfunctionptr
+from rpython.rtyper.lltypesystem.lltype import getfunctionptr
 from rpython.translator.tool.cbuild import ExternalCompilationInfo
 
 
diff --git a/rpython/translator/c/genc.py b/rpython/translator/c/genc.py
--- a/rpython/translator/c/genc.py
+++ b/rpython/translator/c/genc.py
@@ -3,7 +3,7 @@
 import sys, os
 from rpython.rlib import exports
 from rpython.rlib.entrypoint import entrypoint
-from rpython.rtyper.typesystem import getfunctionptr
+from rpython.rtyper.lltypesystem.lltype import getfunctionptr
 from rpython.rtyper.lltypesystem import lltype, rffi
 from rpython.tool import runsubprocess
 from rpython.tool.nullpath import NullPyPathLocal
@@ -468,7 +468,7 @@
                 '$(CC) -o $*.o -c $*.vmprof.lbl.s',
                 'mv $*.gctmp $*.gcmap',
                 'rm $*.vmprof.lbl.s'])
-            
+
             # the rule to compute gcmaptable.s
             mk.rule('gcmaptable.s', '$(GCMAPFILES)',
                     [
@@ -759,7 +759,7 @@
         database, database.translator.rtyper)
     for line in preimplementationlines:
         print >> f, line
-    f.write('#endif /* _PY_PREIMPL_H */\n')    
+    f.write('#endif /* _PY_PREIMPL_H */\n')
 
 def gen_startupcode(f, database):
     # generate the start-up code and put it into a function
diff --git a/rpython/translator/c/test/test_database.py b/rpython/translator/c/test/test_database.py
--- a/rpython/translator/c/test/test_database.py
+++ b/rpython/translator/c/test/test_database.py
@@ -4,7 +4,7 @@
 from rpython.translator.c.database import LowLevelDatabase
 from rpython.flowspace.model import Constant, Variable, SpaceOperation
 from rpython.flowspace.model import Block, Link, FunctionGraph
-from rpython.rtyper.typesystem import getfunctionptr
+from rpython.rtyper.lltypesystem.lltype import getfunctionptr
 from rpython.rtyper.lltypesystem.rffi import VOIDP, INT_real, INT, CArrayPtr
 
 
@@ -43,7 +43,7 @@
 
 def test_inlined_struct():
     db = LowLevelDatabase()
-    pfx = db.namespace.global_prefix + 'g_'    
+    pfx = db.namespace.global_prefix + 'g_'
     S = GcStruct('test', ('x', Struct('subtest', ('y', Signed))))
     s = malloc(S)
     s.x.y = 42
@@ -56,7 +56,7 @@
 
 def test_complete():
     db = LowLevelDatabase()
-    pfx = db.namespace.global_prefix + 'g_'    
+    pfx = db.namespace.global_prefix + 'g_'
     T = GcStruct('subtest', ('y', Signed))
     S = GcStruct('test', ('x', Ptr(T)))
     s = malloc(S)
@@ -136,7 +136,7 @@
     block.closeblock(Link([result], graph.returnblock))
     graph.getreturnvar().concretetype = Signed
     # --------------------         end        --------------------
-    
+
     F = FuncType([Signed], Signed)
     f = functionptr(F, "f", graph=graph)
     db = LowLevelDatabase()
@@ -206,7 +206,7 @@
         s.ptr2 = ptr2
         return s.ptr1.x * s.ptr2.x
     t, graph = makegraph(ll_f, [int])
-    
+
     db = LowLevelDatabase(t)
     db.get(getfunctionptr(graph))
     db.complete()


More information about the pypy-commit mailing list