| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
"""RPython Translator Frontend |
| 5 |
|
| 6 |
Glue script putting together the various pieces of the translator. |
| 7 |
Can be used for interactive testing of the translator. |
| 8 |
|
| 9 |
Example: |
| 10 |
|
| 11 |
t = Translation(func, [int]) # pass the list of args types |
| 12 |
t.view() # control flow graph |
| 13 |
|
| 14 |
t.annotate() |
| 15 |
t.view() # graph + annotations under the mouse |
| 16 |
|
| 17 |
t.rtype() # use low level operations |
| 18 |
lib = t.compile_c() # C compilation as a library |
| 19 |
f = get_c_function(lib, func) # get the function out of the library |
| 20 |
assert f(arg) == func(arg) # sanity check (for C) |
| 21 |
|
| 22 |
|
| 23 |
Some functions are provided for the benefit of interactive testing. |
| 24 |
Try dir(snippet) for list of current snippets. |
| 25 |
""" |
| 26 |
from __future__ import print_function |
| 27 |
|
| 28 |
import os |
| 29 |
import sys |
| 30 |
sys.path.insert(0, os.path.dirname(os.path.dirname( |
| 31 |
os.path.dirname(os.path.realpath(__file__))))) |
| 32 |
|
| 33 |
from rpython.translator.interactive import Translation |
| 34 |
from rpython.rtyper.rtyper import * |
| 35 |
from rpython.rlib.rarithmetic import * |
| 36 |
|
| 37 |
|
| 38 |
def get_c_function(lib, f): |
| 39 |
from ctypes import CDLL |
| 40 |
name = f.__name__ |
| 41 |
return getattr(CDLL(lib.strpath), 'pypy_g_' + name) |
| 42 |
|
| 43 |
|
| 44 |
def setup_readline(): |
| 45 |
import readline |
| 46 |
try: |
| 47 |
import rlcompleter2 |
| 48 |
rlcompleter2.setup() |
| 49 |
except ImportError: |
| 50 |
import rlcompleter |
| 51 |
readline.parse_and_bind("tab: complete") |
| 52 |
import os |
| 53 |
histfile = os.path.join(os.environ["HOME"], ".pypytrhist") |
| 54 |
try: |
| 55 |
getattr(readline, "clear_history", lambda: None)() |
| 56 |
readline.read_history_file(histfile) |
| 57 |
except IOError: |
| 58 |
pass |
| 59 |
import atexit |
| 60 |
atexit.register(readline.write_history_file, histfile) |
| 61 |
|
| 62 |
if __name__ == '__main__': |
| 63 |
try: |
| 64 |
setup_readline() |
| 65 |
except ImportError as err: |
| 66 |
print("Disabling readline support (%s)" % err) |
| 67 |
from rpython.translator.test import snippet |
| 68 |
from rpython.rtyper.rtyper import RPythonTyper |
| 69 |
|
| 70 |
if (os.getcwd() not in sys.path and |
| 71 |
os.path.curdir not in sys.path): |
| 72 |
sys.path.insert(0, os.getcwd()) |
| 73 |
|
| 74 |
print(__doc__) |
| 75 |
|
| 76 |
import os |
| 77 |
os.putenv("PYTHONINSPECT", "1") |