Source

pypy / pypy / translator / cli / prebuiltnodes.py

from pypy.translator.cli.function import Function

try:
    set
except NameError:
    from sets import Set as set

class Helper(Function):
    def render(self, ilasm):
        ilasm.begin_namespace('pypy.runtime')
        ilasm.begin_class('Helpers')
        Function.render(self, ilasm)
        ilasm.end_class()
        ilasm.end_namespace()

def raise_RuntimeError():
    raise RuntimeError

def raise_OverflowError():
    raise OverflowError

def raise_ValueError():
    raise ValueError

def raise_ZeroDivisionError():
    raise ZeroDivisionError

def raise_UnicodeDecodeError():
    raise UnicodeDecodeError

HELPERS = [(raise_RuntimeError, []),
           (raise_OverflowError, []),
           (raise_ValueError, []),
           (raise_ZeroDivisionError, []),
           (raise_UnicodeDecodeError, []),
           ]

def _build_helpers(translator, db):
    functions = set()
    for fn, annotation in HELPERS:
        functions.add(fn)
        translator.annotator.build_types(fn, annotation)
    translator.rtyper.specialize_more_blocks()

    res = []
    for graph in translator.graphs:
        func = getattr(graph, 'func', None)
        if func in functions:
            res.append(Helper(db, graph, func.func_name))
    return res


def get_prebuilt_nodes(translator, db):
    prebuilt_nodes = _build_helpers(translator, db)
    raise_OSError_graph = translator.rtyper.exceptiondata.fn_raise_OSError.graph
    prebuilt_nodes.append(Helper(db, raise_OSError_graph, 'raise_OSError'))

    try:
        etrafo = db.exceptiontransformer
    except AttributeError:
        pass
    else:
        for name in ('rpyexc_clear',
                     'rpyexc_fetch_type',
                     'rpyexc_fetch_value',
                     'rpyexc_occured',
                     'rpyexc_raise'):
            sm = getattr(etrafo, name+'_ptr').value
            prebuilt_nodes.append(Function(db, sm.graph, name))
    return prebuilt_nodes
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.