File: translatorshell.py

package info (click to toggle)
pypy 5.6.0%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 97,040 kB
  • ctags: 185,069
  • sloc: python: 1,147,862; ansic: 49,642; cpp: 5,245; asm: 5,169; makefile: 529; sh: 481; xml: 232; lisp: 45
file content (76 lines) | stat: -rwxr-xr-x 2,167 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/env python


"""RPython Translator Frontend

Glue script putting together the various pieces of the translator.
Can be used for interactive testing of the translator.

Example:

    t = Translation(func, [int])       # pass the list of args types
    t.view()                           # control flow graph

    t.annotate()
    t.view()                           # graph + annotations under the mouse

    t.rtype()                          # use low level operations
    lib = t.compile_c()                # C compilation as a library
    f = get_c_function(lib, func)      # 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.
"""

import os
import sys
sys.path.insert(0, os.path.dirname(os.path.dirname(
                       os.path.dirname(os.path.realpath(__file__)))))

from rpython.translator.interactive import Translation
from rpython.rtyper.rtyper import *
from rpython.rlib.rarithmetic import *


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:
        import rlcompleter2
        rlcompleter2.setup()
    except ImportError:
        import rlcompleter
        readline.parse_and_bind("tab: complete")
    import os
    histfile = os.path.join(os.environ["HOME"], ".pypytrhist")
    try:
        getattr(readline, "clear_history", lambda: None)()
        readline.read_history_file(histfile)
    except IOError:
        pass
    import atexit
    atexit.register(readline.write_history_file, histfile)

if __name__ == '__main__':
    try:
        setup_readline()
    except ImportError as err:
        print "Disabling readline support (%s)" % err
    from rpython.translator.test import snippet
    from rpython.rtyper.rtyper import RPythonTyper

    if (os.getcwd() not in sys.path and
        os.path.curdir not in sys.path):
        sys.path.insert(0, os.getcwd())

    print __doc__

    import os
    os.putenv("PYTHONINSPECT", "1")