本文整理汇总了Python中pypy.translator.translator.TranslationContext.buildrtyper方法的典型用法代码示例。如果您正苦于以下问题:Python TranslationContext.buildrtyper方法的具体用法?Python TranslationContext.buildrtyper怎么用?Python TranslationContext.buildrtyper使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pypy.translator.translator.TranslationContext
的用法示例。
在下文中一共展示了TranslationContext.buildrtyper方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _build_gen
# 需要导入模块: from pypy.translator.translator import TranslationContext [as 别名]
# 或者: from pypy.translator.translator.TranslationContext import buildrtyper [as 别名]
def _build_gen(func, annotation, graph=None, backendopt=True, exctrans=False,
annotatorpolicy=None, nowrap=False):
try:
func = func.im_func
except AttributeError:
pass
t = TranslationContext()
if graph is not None:
graph.func = func
ann = t.buildannotator(policy=annotatorpolicy)
inputcells = [ann.typeannotation(a) for a in annotation]
ann.build_graph_types(graph, inputcells)
t.graphs.insert(0, graph)
else:
ann = t.buildannotator(policy=annotatorpolicy)
ann.build_types(func, annotation)
if getoption('view'):
t.view()
t.buildrtyper(type_system="ootype").specialize()
if backendopt:
check_virtual_methods(ootype.ROOT)
backend_optimizations(t)
main_graph = t.graphs[0]
if getoption('view'):
t.view()
return _build_gen_from_graph(main_graph, t, exctrans, nowrap)
示例2: test_remove_same_as_nonconst
# 需要导入模块: from pypy.translator.translator import TranslationContext [as 别名]
# 或者: from pypy.translator.translator.TranslationContext import buildrtyper [as 别名]
def test_remove_same_as_nonconst():
from pypy.rlib.nonconst import NonConstant
from pypy.rpython.lltypesystem.lloperation import llop
from pypy.rpython.lltypesystem import lltype
def f():
if NonConstant(False):
x = llop.same_as(lltype.Signed, 666)
return 42
t = TranslationContext()
t.buildannotator().build_types(f, [])
t.buildrtyper().specialize()
f_graph = graphof(t, f)
#simple_inline_function(t, nothing, f_graph)
# here, the graph looks like v21=same_as(True); exitswitch: v21
remove_same_as(f_graph)
t.checkgraphs()
# only one path should be left
for block in f_graph.iterblocks():
assert len(block.exits) <= 1
for block in t.annotator.annotated:
assert None not in block.operations
interp = LLInterpreter(t.rtyper)
result = interp.eval_graph(f_graph, [])
assert result == 42
示例3: test_dont_remove_with__del__
# 需要导入模块: from pypy.translator.translator import TranslationContext [as 别名]
# 或者: from pypy.translator.translator.TranslationContext import buildrtyper [as 别名]
def test_dont_remove_with__del__(self):
import os
delcalls = [0]
class A(object):
nextid = 0
def __init__(self):
self.id = self.nextid
self.nextid += 1
def __del__(self):
delcalls[0] += 1
os.write(1, "__del__\n")
def f(x=int):
a = A()
i = 0
while i < x:
a = A()
os.write(1, str(delcalls[0]) + "\n")
i += 1
return 1
t = TranslationContext()
t.buildannotator().build_types(f, [int])
t.buildrtyper().specialize()
graph = graphof(t, f)
backend_optimizations(t)
op = graph.startblock.exits[0].target.exits[1].target.operations[0]
assert op.opname == "malloc"
示例4: _build_gen
# 需要导入模块: from pypy.translator.translator import TranslationContext [as 别名]
# 或者: from pypy.translator.translator.TranslationContext import buildrtyper [as 别名]
def _build_gen(func, annotation, graph=None, backendopt=True):
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:
ann = t.buildannotator()
ann.build_types(func, annotation)
if getoption('view'):
t.view()
t.buildrtyper(type_system="ootype").specialize()
if backendopt:
check_virtual_methods(ootype.ROOT)
backend_optimizations(t)
main_graph = t.graphs[0]
if getoption('view'):
t.view()
if getoption('wd'):
tmpdir = py.path.local('.')
else:
tmpdir = udir
return GenCli(tmpdir, t, TestEntryPoint(main_graph, True))
示例5: compile
# 需要导入模块: from pypy.translator.translator import TranslationContext [as 别名]
# 或者: from pypy.translator.translator.TranslationContext import buildrtyper [as 别名]
def compile(f, gc, enable_opts='', **kwds):
from pypy.annotation.listdef import s_list_of_strings
from pypy.translator.translator import TranslationContext
from pypy.jit.metainterp.warmspot import apply_jit
from pypy.translator.c import genc
#
t = TranslationContext()
t.config.translation.gc = gc
if gc != 'boehm':
t.config.translation.gcremovetypeptr = True
for name, value in kwds.items():
setattr(t.config.translation, name, value)
ann = t.buildannotator(policy=annpolicy.StrictAnnotatorPolicy())
ann.build_types(f, [s_list_of_strings], main_entry_point=True)
t.buildrtyper().specialize()
if kwds['jit']:
patch = get_functions_to_patch()
old_value = {}
try:
for (obj, attr), value in patch.items():
old_value[obj, attr] = getattr(obj, attr)
setattr(obj, attr, value)
#
apply_jit(t, enable_opts=enable_opts)
#
finally:
for (obj, attr), oldvalue in old_value.items():
setattr(obj, attr, oldvalue)
cbuilder = genc.CStandaloneBuilder(t, f, t.config)
cbuilder.generate_source(defines=cbuilder.DEBUG_DEFINES)
cbuilder.compile()
return cbuilder
示例6: test_lookup_graphs_abstract
# 需要导入模块: from pypy.translator.translator import TranslationContext [as 别名]
# 或者: from pypy.translator.translator.TranslationContext import buildrtyper [as 别名]
def test_lookup_graphs_abstract():
from pypy.translator.translator import TranslationContext, graphof
class A:
pass
class B(A):
def foo(self):
pass
class C(A):
def foo(self):
pass
def fn(flag):
obj = flag and B() or C()
obj.foo()
return obj
t = TranslationContext()
t.buildannotator().build_types(fn, [int])
t.buildrtyper(type_system='ootype').specialize()
graph = graphof(t, fn)
TYPE_A = graph.getreturnvar().concretetype
TYPE_B = TYPE_A._subclasses[0]
TYPE_C = TYPE_A._subclasses[1]
assert len(TYPE_A._lookup_graphs('ofoo')) == 2
assert len(TYPE_B._lookup_graphs('ofoo')) == 1
assert len(TYPE_C._lookup_graphs('ofoo')) == 1
示例7: test_counters
# 需要导入模块: from pypy.translator.translator import TranslationContext [as 别名]
# 或者: from pypy.translator.translator.TranslationContext import buildrtyper [as 别名]
def test_counters(self):
from pypy.rpython.lltypesystem import lltype
from pypy.rpython.lltypesystem.lloperation import llop
def entry_point(argv):
llop.instrument_count(lltype.Void, 'test', 2)
llop.instrument_count(lltype.Void, 'test', 1)
llop.instrument_count(lltype.Void, 'test', 1)
llop.instrument_count(lltype.Void, 'test', 2)
llop.instrument_count(lltype.Void, 'test', 1)
return 0
t = TranslationContext(self.config)
t.config.translation.instrument = True
t.buildannotator().build_types(entry_point, [s_list_of_strings])
t.buildrtyper().specialize()
cbuilder = CStandaloneBuilder(t, entry_point, config=t.config) # xxx
cbuilder.generate_source()
cbuilder.compile()
counters_fname = udir.join("_counters_")
os.putenv('_INSTRUMENT_COUNTERS', str(counters_fname))
try:
data = cbuilder.cmdexec()
finally:
os.unsetenv('_INSTRUMENT_COUNTERS')
f = counters_fname.open('rb')
counters_data = f.read()
f.close()
import struct
counters = struct.unpack("LLL", counters_data)
assert counters == (0,3,2)
示例8: wrap_stackless_function
# 需要导入模块: from pypy.translator.translator import TranslationContext [as 别名]
# 或者: from pypy.translator.translator.TranslationContext import buildrtyper [as 别名]
def wrap_stackless_function(self, fn):
def entry_point(argv):
os.write(1, str(fn())+"\n")
return 0
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=True)
config.translation.gc = self.gcpolicy
config.translation.stackless = True
if self.stacklessgc:
config.translation.gcrootfinder = "stackless"
t = TranslationContext(config=config)
self.t = t
t.buildannotator().build_types(entry_point, [s_list_of_strings])
t.buildrtyper().specialize()
if self.backendopt:
backend_optimizations(t)
from pypy.translator.transform import insert_ll_stackcheck
insert_ll_stackcheck(t)
cbuilder = CStandaloneBuilder(t, entry_point, config=config)
cbuilder.stackless = True
cbuilder.generate_source()
cbuilder.compile()
res = cbuilder.cmdexec('')
return int(res.strip())
示例9: __init__
# 需要导入模块: from pypy.translator.translator import TranslationContext [as 别名]
# 或者: from pypy.translator.translator.TranslationContext import buildrtyper [as 别名]
def __init__(self, function, annotations, stackless=False, view=False, html=None, is_interactive=False, root = None, run_browser = True, policy = None):
if not use_browsertest and not _CLI_is_on_path():
py.test.skip('Javascript CLI (js) not found')
self.html = html
self.is_interactive = is_interactive
t = TranslationContext()
if policy is None:
from pypy.annotation.policy import AnnotatorPolicy
policy = AnnotatorPolicy()
policy.allow_someobjects = False
ann = t.buildannotator(policy=policy)
ann.build_types(function, annotations)
if view or option.view:
t.view()
t.buildrtyper(type_system="ootype").specialize()
if view or option.view:
t.view()
#self.js = JS(t, [function, callback_function], stackless)
self.js = JS(t, function, stackless)
self.js.write_source()
if root is None and use_tg:
from pypy.translator.js.demo.jsdemo.controllers import Root
self.root = Root
else:
self.root = root
self.run_browser = run_browser
self.function_calls = []
示例10: check
# 需要导入模块: from pypy.translator.translator import TranslationContext [as 别名]
# 或者: from pypy.translator.translator.TranslationContext import buildrtyper [as 别名]
def check(self, fn, signature, args, expected_result, must_be_removed=True,
inline=None):
remover = self.MallocRemover()
t = TranslationContext()
t.buildannotator().build_types(fn, signature)
t.buildrtyper(type_system=self.type_system).specialize()
graph = graphof(t, fn)
if inline is not None:
from pypy.translator.backendopt.inline import auto_inline_graphs
auto_inline_graphs(t, t.graphs, inline)
if option.view:
t.view()
# to detect missing keepalives and broken intermediate graphs,
# we do the loop ourselves instead of calling remove_simple_mallocs()
while True:
progress = remover.remove_mallocs_once(graph)
simplify.transform_dead_op_vars_in_blocks(list(graph.iterblocks()))
if progress and option.view:
t.view()
if expected_result is not Ellipsis:
interp = LLInterpreter(t.rtyper)
res = interp.eval_graph(graph, args)
assert res == expected_result
if not progress:
break
if must_be_removed:
self.check_malloc_removed(graph)
return graph
示例11: makegraph
# 需要导入模块: from pypy.translator.translator import TranslationContext [as 别名]
# 或者: from pypy.translator.translator.TranslationContext import buildrtyper [as 别名]
def makegraph(func, argtypes):
t = TranslationContext()
t.buildannotator().build_types(func, [int])
t.buildrtyper().specialize()
bk = t.annotator.bookkeeper
graph = bk.getdesc(func).getuniquegraph()
return t, graph
示例12: translate
# 需要导入模块: from pypy.translator.translator import TranslationContext [as 别名]
# 或者: from pypy.translator.translator.TranslationContext import buildrtyper [as 别名]
def translate(func, argtypes, backend_optimize=True):
t = TranslationContext()
t.buildannotator().build_types(func, argtypes)
t.buildrtyper().specialize()
if backend_optimize:
backend_optimizations(t)
return graphof(t, func), t
示例13: getcompiled
# 需要导入模块: from pypy.translator.translator import TranslationContext [as 别名]
# 或者: from pypy.translator.translator.TranslationContext import buildrtyper [as 别名]
def getcompiled(self, func, argstypelist = [],
annotatorpolicy=None):
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=True)
config.translation.gc = self.gcpolicy
config.translation.thread = self.use_threads
if self.stacklessgc:
config.translation.gcrootfinder = "stackless"
config.translation.simplifying = True
t = TranslationContext(config=config)
self.t = t
a = t.buildannotator(policy=annotatorpolicy)
a.build_types(func, argstypelist)
t.buildrtyper().specialize()
t.checkgraphs()
def compile():
cbuilder = CExtModuleBuilder(t, func, config=config)
c_source_filename = cbuilder.generate_source(
defines = cbuilder.DEBUG_DEFINES)
if conftest.option.view:
t.view()
cbuilder.compile()
self._cleanups.append(cbuilder.cleanup) # schedule cleanup after test
return cbuilder.get_entry_point(isolated=True)
return compile()
示例14: getcompiled
# 需要导入模块: from pypy.translator.translator import TranslationContext [as 别名]
# 或者: from pypy.translator.translator.TranslationContext import buildrtyper [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__)
示例15: translates
# 需要导入模块: from pypy.translator.translator import TranslationContext [as 别名]
# 或者: from pypy.translator.translator.TranslationContext import buildrtyper [as 别名]
def translates(self, func=None, argtypes=None, **kwds):
config = make_config(None, **kwds)
if func is not None:
if argtypes is None:
nb_args = func.func_code.co_argcount
argtypes = [W_Root] * nb_args
#
t = TranslationContext(config=config)
self.t = t # for debugging
ann = t.buildannotator()
ann.policy.allow_someobjects = False
if func is not None:
ann.build_types(func, argtypes, complete_now=False)
#
# annotate all _seen_extras, knowing that annotating some may
# grow the list
done = 0
while done < len(self._seen_extras):
#print self._seen_extras
ann.build_types(self._seen_extras[done], [],
complete_now=False)
done += 1
ann.complete()
#t.viewcg()
t.buildrtyper().specialize()
t.checkgraphs()