Author: David Schneider <david.schnei...@picle.org> Branch: Changeset: r61401:a57b50cb7158 Date: 2013-02-18 11:28 +0100 http://bitbucket.org/pypy/pypy/changeset/a57b50cb7158/
Log: add a helper method to translatorshell to get the compiled function from the compiled library and update the documentation diff --git a/pypy/doc/getting-started-dev.rst b/pypy/doc/getting-started-dev.rst --- a/pypy/doc/getting-started-dev.rst +++ b/pypy/doc/getting-started-dev.rst @@ -58,8 +58,7 @@ only use low level types that are available in C (e.g. int). The compiled version is now in a ``.so`` library. You can run it say using ctypes: - >>> from ctypes import CDLL - >>> f = CDLL(lib) + >>> f = get_c_function(lib, snippet.is_perfect_number) >>> f(5) 0 >>> f(6) diff --git a/rpython/bin/translatorshell.py b/rpython/bin/translatorshell.py --- a/rpython/bin/translatorshell.py +++ b/rpython/bin/translatorshell.py @@ -15,9 +15,10 @@ t.view() # graph + annotations under the mouse t.rtype() # use low level operations - f = t.compile_c() # C compilation + lib = t.compile_c() # C compilation as a library + f = get_c_function(lib, f) # get the function out of the library assert f(arg) == func(arg) # sanity check (for C) - + Some functions are provided for the benefit of interactive testing. Try dir(snippet) for list of current snippets. @@ -31,6 +32,13 @@ import py + +def get_c_function(lib, f): + from ctypes import CDLL + name = f.__name__ + return getattr(CDLL(lib.strpath), 'pypy_g_' + name) + + def setup_readline(): import readline try: _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit