本文整理汇总了Python中pypy.translator.translator.TranslationContext.viewcg方法的典型用法代码示例。如果您正苦于以下问题:Python TranslationContext.viewcg方法的具体用法?Python TranslationContext.viewcg怎么用?Python TranslationContext.viewcg使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pypy.translator.translator.TranslationContext
的用法示例。
在下文中一共展示了TranslationContext.viewcg方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getcompiled
# 需要导入模块: from pypy.translator.translator import TranslationContext [as 别名]
# 或者: from pypy.translator.translator.TranslationContext import viewcg [as 别名]
def getcompiled(func, view=conftest.option.view, use_boehm=False):
from pypy.translator.translator import TranslationContext
from pypy.translator.backendopt.all import backend_optimizations
from pypy.translator.c import gc
from pypy.translator.c.genc import CExtModuleBuilder
global t # allow us to view later
t = TranslationContext()
t.buildannotator().build_types(func, get_annotation(func))
t.buildrtyper().specialize()
t.checkgraphs()
gcpolicy = None
if use_boehm:
gcpolicy = gc.BoehmGcPolicy
cbuilder = CExtModuleBuilder(t, func, t.config, gcpolicy=gcpolicy)
cbuilder.generate_source()
cbuilder.compile()
backend_optimizations(t)
if view:
t.viewcg()
return getattr(cbuilder.import_module(), func.__name__)
示例2: build_sqfunc
# 需要导入模块: from pypy.translator.translator import TranslationContext [as 别名]
# 或者: from pypy.translator.translator.TranslationContext import viewcg [as 别名]
def build_sqfunc(func, args=[], view=False):
try: func = func.im_func
except AttributeError: pass
t = TranslationContext()
t.buildannotator().build_types(func, args)
t.buildrtyper(type_system="ootype").specialize()
if view or conftest.option.view:
t.viewcg()
gen = GenSqueak(udir, t)
gen.gen()
示例3: rtype
# 需要导入模块: from pypy.translator.translator import TranslationContext [as 别名]
# 或者: from pypy.translator.translator.TranslationContext import viewcg [as 别名]
def rtype(func, inputtypes, specialize=True, gcname='ref', stacklessgc=False,
backendopt=False, **extraconfigopts):
from pypy.translator.translator import TranslationContext
t = TranslationContext()
# XXX XXX XXX mess
t.config.translation.gc = gcname
if stacklessgc:
t.config.translation.gcrootfinder = "stackless"
t.config.set(**extraconfigopts)
t.buildannotator().build_types(func, inputtypes)
if specialize:
t.buildrtyper().specialize()
if backendopt:
from pypy.translator.backendopt.all import backend_optimizations
backend_optimizations(t)
if conftest.option.view:
t.viewcg()
return t
示例4: rtype
# 需要导入模块: from pypy.translator.translator import TranslationContext [as 别名]
# 或者: from pypy.translator.translator.TranslationContext import viewcg [as 别名]
def rtype(func, inputtypes, specialize=True, gcname='ref',
backendopt=False, **extraconfigopts):
from pypy.translator.translator import TranslationContext
t = TranslationContext()
# XXX XXX XXX mess
t.config.translation.gc = gcname
t.config.translation.gcremovetypeptr = True
t.config.set(**extraconfigopts)
ann = t.buildannotator(policy=annpolicy.StrictAnnotatorPolicy())
ann.build_types(func, inputtypes)
if specialize:
t.buildrtyper().specialize()
if backendopt:
from pypy.translator.backendopt.all import backend_optimizations
backend_optimizations(t)
if conftest.option.view:
t.viewcg()
return t
示例5: _build
# 需要导入模块: from pypy.translator.translator import TranslationContext [as 别名]
# 或者: from pypy.translator.translator.TranslationContext import viewcg [as 别名]
def _build(self, func, annotation, graph=None):
try:
func = func.im_func
except AttributeError:
pass
t = TranslationContext()
if graph is not None:
graph.func = func
ann = t.buildannotator()
inputcells = [ann.typeannotation(a) for a in annotation]
ann.build_graph_types(graph, inputcells)
t.graphs.insert(0, graph)
else:
t.buildannotator().build_types(func, annotation)
t.buildrtyper(type_system="ootype").specialize()
self.graph = t.graphs[0]
if conftest.option.view:
t.viewcg()
gen = GenSqueak(udir, t)
gen.gen()
return gen
示例6: Translation
# 需要导入模块: from pypy.translator.translator import TranslationContext [as 别名]
# 或者: from pypy.translator.translator.TranslationContext import viewcg [as 别名]
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)
# hook into driver events
driver_own_event = self.driver._event
def _event(kind, goal, func):
self.driver_event(kind, goal, func)
driver_own_event(kind, goal, func)
self.driver._event = _event
self.driver_setup = False
self.update_options(argtypes, kwds)
# 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 driver_event(self, kind, goal, func):
if kind == 'pre':
#print goal
self.ensure_setup()
elif kind == 'post':
pass
def ensure_setup(self, argtypes=None, policy=None, standalone=False):
if not self.driver_setup:
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
self.driver_setup = True
else:
# check consistency
if standalone:
assert argtypes is None
assert self.ann_argtypes is None
elif argtypes is not None and argtypes != self.ann_argtypes:
raise Exception("inconsistent argtype supplied")
if policy is not None and policy != self.ann_policy:
raise Exception("inconsistent annotation polish supplied")
def update_options(self, argtypes, kwds):
if argtypes or kwds.get('policy') or kwds.get('standalone'):
self.ensure_setup(argtypes, kwds.get('policy'),
kwds.get('standalone'))
kwds.pop('policy', None)
kwds.pop('standalone', None)
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(None, {name: value})
return value
val = getattr(self.config.translation, name, None)
if fallback is not None and val is None:
self.update_options(None, {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)
#.........这里部分代码省略.........