Source

pypy / pypy / translator / interactive.py

Armin Rigo 2b4ff06 
Samuele Pedroni 402c7b0 
Armin Rigo 2b4ff06 
Alex Gaynor 0425059 
Carl Friedrich B… e820a54 


Samuele Pedroni 47ebd36 
Carl Friedrich B… e820a54 
Armin Rigo 2b4ff06 



Samuele Pedroni 054038a 


Armin Rigo 2b4ff06 
Samuele Pedroni 054038a 
Armin Rigo 2b4ff06 
Maciej Fijalkows… f0d6e8d 
Maciej Fijalkows… f81dc99 
Maciej Fijalkows… f0d6e8d 
Samuele Pedroni 6e9574e 


Armin Rigo 2b4ff06 
Samuele Pedroni 86f5fe9 





Maciej Fijalkows… 37013e4 

Maciej Fijalkows… f81dc99 

Armin Rigo 2b4ff06 
Maciej Fijalkows… f81dc99 





Armin Rigo 2b4ff06 
Maciej Fijalkows… f81dc99 
Armin Rigo 164717a 
Alex Gaynor a21178a 

Carl Friedrich B… e820a54 
Armin Rigo 2b4ff06 
Samuele Pedroni acc3486 

Maciej Fijalkows… f81dc99 
Carl Friedrich B… e820a54 


Maciej Fijalkows… f81dc99 
Carl Friedrich B… e820a54 



Alex Gaynor a21178a 
Samuele Pedroni acc3486 

Carl Friedrich B… e820a54 

Samuele Pedroni acc3486 
Alex Gaynor a21178a 
Samuele Pedroni 84f3be0 
Samuele Pedroni acc3486 

Samuele Pedroni 8c0401d 
Samuele Pedroni 84f3be0 
Samuele Pedroni 846ed04 



Samuele Pedroni b2d9f53 





Samuele Pedroni 7002c60 

Maciej Fijalkows… f81dc99 

Armin Rigo 2b4ff06 

Samuele Pedroni acc3486 

Maciej Fijalkows… f81dc99 

Samuele Pedroni acc3486 
Alex Gaynor a21178a 
Samuele Pedroni 7002c60 
Maciej Fijalkows… f81dc99 

Samuele Pedroni acc3486 
Alex Gaynor a21178a 

Samuele Pedroni acc3486 
Samuele Pedroni 84f3be0 
Maciej Fijalkows… f81dc99 

Armin Rigo 2b4ff06 
Alex Gaynor a21178a 

Maciej Fijalkows… f81dc99 

Armin Rigo 2b4ff06 

Samuele Pedroni 84f3be0 
Maciej Fijalkows… f81dc99 

Valentino Volong… e8ac32e 


Maciej Fijalkows… f81dc99 

Samuele Pedroni 846ed04 
Alex Gaynor a21178a 
Samuele Pedroni 846ed04 
Alex Gaynor a21178a 
Maciej Fijalkows… f81dc99 

Samuele Pedroni 846ed04 


Alex Gaynor a21178a 
Maciej Fijalkows… f81dc99 

Antonio Cuni eed0696 



Maciej Fijalkows… f81dc99 

Antonio Cuni eed0696 

nikomatsakis 7bab53b 
Maciej Fijalkows… f81dc99 

nikomatsakis 7bab53b 



Maciej Fijalkows… f81dc99 

nikomatsakis 7bab53b 
from pypy.translator.translator import TranslationContext
from pypy.translator import driver


DEFAULTS = {
  'translation.backend': None,
  'translation.type_system': None,
  'translation.verbose': True,
}

class Translation(object):

    def __init__(self, entry_point, argtypes=None, **kwds):
        self.driver = driver.TranslationDriver(overrides=DEFAULTS)
        self.config = self.driver.config

        self.entry_point = entry_point
        self.context = TranslationContext(config=self.config)

        policy = kwds.pop('policy', None)
        self.update_options(kwds)
        self.ensure_setup(argtypes, policy)
        # for t.view() to work just after construction
        graph = self.context.buildflowgraph(entry_point)
        self.context._prebuilt_graphs[entry_point] = graph

    def view(self):
        self.context.view()

    def viewcg(self):
        self.context.viewcg()

    def ensure_setup(self, argtypes=None, policy=None):
        standalone = argtypes is None
        if standalone:
            assert argtypes is None
        else:
            if argtypes is None:
                argtypes = []
        self.driver.setup(self.entry_point, argtypes, policy,
                          empty_translator=self.context)
        self.ann_argtypes = argtypes
        self.ann_policy = policy

    def update_options(self, kwds):
        gc = kwds.pop('gc', None)
        if gc:
            self.config.translation.gc = gc
        self.config.translation.set(**kwds)

    def ensure_opt(self, name, value=None, fallback=None):
        if value is not None:
            self.update_options({name: value})
            return value
        val = getattr(self.config.translation, name, None)
        if fallback is not None and val is None:
            self.update_options({name: fallback})
            return fallback
        if val is not None:
            return val
        raise Exception(
                    "the %r option should have been specified at this point" % name)

    def ensure_type_system(self, type_system=None):
        if self.config.translation.backend is not None:
            return self.ensure_opt('type_system')
        return self.ensure_opt('type_system', type_system, 'lltype')

    def ensure_backend(self, backend=None):
        backend = self.ensure_opt('backend', backend)
        self.ensure_type_system()
        return backend

    # disable some goals (steps)
    def disable(self, to_disable):
        self.driver.disable(to_disable)

    def set_backend_extra_options(self, **extra_options):
        for name in extra_options:
            backend, option = name.split('_', 1)
            self.ensure_backend(backend)
        self.driver.set_backend_extra_options(extra_options)

    # backend independent

    def annotate(self, **kwds):
        self.update_options(kwds)
        return self.driver.annotate()

    # type system dependent

    def rtype(self, **kwds):
        self.update_options(kwds)
        ts = self.ensure_type_system()
        return getattr(self.driver, 'rtype_' + ts)()

    def backendopt(self, **kwds):
        self.update_options(kwds)
        ts = self.ensure_type_system('lltype')
        return getattr(self.driver, 'backendopt_' + ts)()

    # backend depedent

    def source(self, **kwds):
        self.update_options(kwds)
        backend = self.ensure_backend()
        getattr(self.driver, 'source_' + backend)()

    def source_c(self, **kwds):
        self.update_options(kwds)
        self.ensure_backend('c')
        self.driver.source_c()

    def source_cl(self, **kwds):
        self.update_options(kwds)
        self.ensure_backend('cl')
        self.driver.source_cl()

    def compile(self, **kwds):
        self.update_options(kwds)
        backend = self.ensure_backend()
        getattr(self.driver, 'compile_' + backend)()
        return self.driver.c_entryp

    def compile_c(self, **kwds):
        self.update_options(kwds)
        self.ensure_backend('c')
        self.driver.compile_c()
        return self.driver.c_entryp

    def compile_cli(self, **kwds):
        self.update_options(kwds)
        self.ensure_backend('cli')
        self.driver.compile_cli()
        return self.driver.c_entryp

    def source_cli(self, **kwds):
        self.update_options(kwds)
        self.ensure_backend('cli')
        self.driver.source_cli()

    def compile_jvm(self, **kwds):
        self.update_options(kwds)
        self.ensure_backend('jvm')
        self.driver.compile_jvm()
        return self.driver.c_entryp

    def source_jvm(self, **kwds):
        self.update_options(kwds)
        self.ensure_backend('jvm')
        self.driver.source_jvm()