本文整理汇总了Python中pypy.translator.interactive.Translation类的典型用法代码示例。如果您正苦于以下问题:Python Translation类的具体用法?Python Translation怎么用?Python Translation使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Translation类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: main
def main():
import_benchmarks()
benchmarks = []
for name, thing in globals().iteritems():
if getattr(thing, 'benchmark', False):
benchmarks.append((name, thing))
benchmarks.sort()
def entry_point(argv):
for name, func in benchmarks:
print name, ':', func()
return 0
t = Translation(entry_point, standalone=True, backend='c')
c_exe = t.compile()
t = Translation(entry_point, standalone=True, backend='cli')
cli_exe = t.compile()
c_res = run_benchmark(c_exe)
cli_res = run_benchmark(cli_exe)
print 'benchmark genc gencli ratio'
print
for name, _ in benchmarks:
c_time = c_res[name]
cli_time = cli_res[name]
if c_time == 0:
ratio = '%10s' % '---'
else:
ratio = '%10.2f' % (cli_time/c_time)
print '%-32s %10.2f %10.2f %s' % (name, c_time, cli_time, ratio)
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:31,代码来源:microbench.py
示例2: _makefunc_str_int
def _makefunc_str_int(cls, f):
def main(argv):
arg0 = argv[1]
arg1 = int(argv[2])
try:
res = f(arg0, arg1)
except MemoryError:
print "MEMORY-ERROR"
else:
print res
return 0
t = Translation(main, standalone=True, gc=cls.gcpolicy,
policy=annpolicy.StrictAnnotatorPolicy(),
taggedpointers=cls.taggedpointers,
gcremovetypeptr=cls.removetypeptr)
t.disable(['backendopt'])
t.set_backend_extra_options(c_debug_defines=True)
t.rtype()
if conftest.option.view:
t.viewcg()
exename = t.compile()
def run(s, i):
data = py.process.cmdexec("%s %s %d" % (exename, s, i))
data = data.strip()
if data == 'MEMORY-ERROR':
raise MemoryError
return data
return run
开发者ID:pombredanne,项目名称:pypy,代码行数:31,代码来源:test_newgc.py
示例3: test_lib
def test_lib():
def entry_point(argv):
fd = os.open("/tmp/foobar", os.O_RDONLY, 0777)
assert fd == 77
res = os.read(fd, 123)
assert res == "he\x00llo"
count = os.write(fd, "world\x00!\x00")
assert count == 42
for arg in argv:
count = os.write(fd, arg)
assert count == 61
os.close(fd)
return 0
t = Translation(entry_point, backend='c', standalone=True, sandbox=True)
exe = t.compile()
proc = MySandboxedProc([exe, 'x1', 'y2'], expected = [
("open", ("/tmp/foobar", os.O_RDONLY, 0777), 77),
("read", (77, 123), "he\x00llo"),
("write", (77, "world\x00!\x00"), 42),
("write", (77, exe), 61),
("write", (77, "x1"), 61),
("write", (77, "y2"), 61),
("close", (77,), None),
])
proc.handle_forever()
assert proc.seen == len(proc.expected)
开发者ID:antoine1fr,项目名称:pygirl,代码行数:27,代码来源:test_sandlib.py
示例4: test_annotator_folding
def test_annotator_folding():
from pypy.translator.interactive import Translation
gcoption = ChoiceOption('name', 'GC name', ['ref', 'framework'], 'ref')
gcgroup = OptionDescription('gc', '', [gcoption])
descr = OptionDescription('pypy', '', [gcgroup])
config = Config(descr)
def f(x):
if config.gc.name == 'ref':
return x + 1
else:
return 'foo'
t = Translation(f)
t.rtype([int])
block = t.context.graphs[0].startblock
assert len(block.exits[0].target.operations) == 0
assert len(block.operations) == 1
assert len(block.exits) == 1
assert block.operations[0].opname == 'int_add'
assert config._freeze_()
# does not raise, since it does not change the attribute
config.gc.name = "ref"
py.test.raises(TypeError, 'config.gc.name = "framework"')
开发者ID:AishwaryaKM,项目名称:python-tutorial,代码行数:27,代码来源:test_config.py
示例5: run
def run(self, entry_point, args, expected):
t = Translation(entry_point, backend='c', standalone=True,
sandbox=True)
exe = t.compile()
from pypy.translator.sandbox.sandlib import SimpleIOSandboxedProc
proc = SimpleIOSandboxedProc([exe] + args)
output, error = proc.communicate()
assert error == ''
assert output == expected
开发者ID:antoine1fr,项目名称:pygirl,代码行数:9,代码来源:test_sandbox.py
示例6: test_translate
def test_translate():
from pypy.translator.interactive import Translation
def f(x, y):
rnd = Random(x)
rnd.init_by_array([x, y])
rnd.jumpahead(y)
return rnd.genrand32(), rnd.random()
t = Translation(f)
fc = t.compile_c([int, int])
assert fc(1, 2) == f(1, 2)
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:10,代码来源:test_rrandom.py
示例7: build_adi
def build_adi(function, types):
t = Translation(function)
t.rtype(types)
if conftest.option.view:
t.view()
adi = AbstractDataFlowInterpreter(t.context)
graph = graphof(t.context, function)
adi.schedule_function(graph)
adi.complete()
return t.context, adi, graph
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:10,代码来源:test_escape.py
示例8: test_tagged_boehm
def test_tagged_boehm():
t = Translation(entry_point, standalone=True, gc='boehm', taggedpointers=True)
try:
exename = str(t.compile_c())
finally:
if conftest.option.view:
t.view()
g = os.popen(exename, 'r')
data = g.read()
g.close()
assert data.rstrip().endswith('ALL OK')
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:11,代码来源:test_rtagged.py
示例9: test_tagged_boehm
def test_tagged_boehm():
py.test.skip("broken as test need rffi")
t = Translation(entry_point, standalone=True, gc='boehm')
try:
exename = t.compile_llvm()
finally:
if conftest.option.view:
t.view()
g = os.popen(exename, 'r')
data = g.read()
g.close()
assert data.rstrip().endswith('ALL OK')
开发者ID:antoine1fr,项目名称:pygirl,代码行数:12,代码来源:test_rtagged.py
示例10: test_enforced_args
def test_enforced_args():
from pypy.annotation.model import s_None
from pypy.rpython.annlowlevel import MixLevelHelperAnnotator
from pypy.translator.interactive import Translation
def f1():
str2charp("hello")
def f2():
str2charp("world")
t = Translation(f1, [])
t.rtype()
mixann = MixLevelHelperAnnotator(t.context.rtyper)
mixann.getgraph(f2, [], s_None)
mixann.finish()
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:13,代码来源:test_rffi.py
示例11: test_tagged_boehm
def test_tagged_boehm():
runtest.llvm_test()
runtest.gcc3_test()
t = Translation(entry_point, standalone=True, gc='boehm')
try:
exename = t.compile_llvm()
finally:
if conftest.option.view:
t.view()
g = os.popen(exename, 'r')
data = g.read()
g.close()
assert data.rstrip().endswith('ALL OK')
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:13,代码来源:test_rtagged.py
示例12: test_prof_inline
def test_prof_inline():
if sys.platform == 'win32':
py.test.skip("instrumentation support is unix only for now")
def add(a,b):
return a + b - b + b - b + b - b + b - b + b - b + b - b + b
def entry_point(argv):
tot = 0
x = int(argv[1])
while x > 0:
tot = add(tot, x)
x -= 1
os.write(1, str(tot))
return 0
from pypy.translator.interactive import Translation
t = Translation(entry_point, backend='c', standalone=True)
# no counters
t.backendopt(inline_threshold=100, profile_based_inline="500")
exe = t.compile()
out = py.process.cmdexec("%s 500" % exe)
assert int(out) == 500*501/2
t = Translation(entry_point, backend='c', standalone=True)
# counters
t.backendopt(inline_threshold=all.INLINE_THRESHOLD_FOR_TEST*0.5,
profile_based_inline="500")
exe = t.compile()
out = py.process.cmdexec("%s 500" % exe)
assert int(out) == 500*501/2
开发者ID:antoine1fr,项目名称:pygirl,代码行数:28,代码来源:test_standalone.py
示例13: test_translate_compiled_parser
def test_translate_compiled_parser():
r0 = Rule("expression", [["additive", "EOF"]])
r1 = Rule("additive", [["multitive", "+", "additive"], ["multitive"]])
r2 = Rule("multitive", [["primary", "*", "multitive"], ["primary"]])
r3 = Rule("primary", [["(", "additive", ")"], ["decimal"]])
r4 = Rule("decimal", [[symb] for symb in "0123456789"])
p = PackratParser([r0, r1, r2, r3, r4], "expression")
compiler = ParserCompiler(p)
kls = compiler.compile()
p = kls()
tree = p.parse([Token(c, i, SourcePos(i, 0, i))
for i, c in enumerate(list("2*(3+4)") + ["EOF"])])
data = [Token(c, i, SourcePos(i, 0, i))
for i, c in enumerate(list("2*(3+4)") + ["EOF"])]
print tree
p = kls()
def parse(choose):
tree = p.parse(data)
return tree.symbol + " " + "-%-".join([c.symbol for c in tree.children])
t = Translation(parse)
t.annotate([bool])
t.backendopt()
t.rtype()
func = t.compile_c()
res1 = parse(True)
res2 = func(True)
assert res1 == res2
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:27,代码来源:test_translate.py
示例14: test_profopt
def test_profopt(self):
def add(a,b):
return a + b - b + b - b + b - b + b - b + b - b + b - b + b
def entry_point(argv):
tot = 0
x = int(argv[1])
while x > 0:
tot = add(tot, x)
x -= 1
os.write(1, str(tot))
return 0
from pypy.translator.interactive import Translation
# XXX this is mostly a "does not crash option"
t = Translation(entry_point, backend='c', standalone=True, profopt="100")
# no counters
t.backendopt()
exe = t.compile()
out = py.process.cmdexec("%s 500" % exe)
assert int(out) == 500*501/2
t = Translation(entry_point, backend='c', standalone=True, profopt="100",
noprofopt=True)
# no counters
t.backendopt()
exe = t.compile()
out = py.process.cmdexec("%s 500" % exe)
assert int(out) == 500*501/2
开发者ID:ieure,项目名称:pypy,代码行数:26,代码来源:test_standalone.py
示例15: compile
def compile(fn, argtypes, view=False, gcpolicy="ref", backendopt=True,
annotatorpolicy=None):
t = Translation(fn, argtypes, gc=gcpolicy, backend="c",
policy=annotatorpolicy)
if not backendopt:
t.disable(["backendopt_lltype"])
t.annotate()
# XXX fish
t.driver.config.translation.countmallocs = True
compiled_fn = t.compile_c()
if getattr(py.test.config.option, 'view', False):
t.view()
malloc_counters = t.driver.cbuilder.get_malloc_counters()
def checking_fn(*args, **kwds):
if 'expected_extra_mallocs' in kwds:
expected_extra_mallocs = kwds.pop('expected_extra_mallocs')
else:
expected_extra_mallocs = 0
res = compiled_fn(*args, **kwds)
mallocs, frees = malloc_counters()
if isinstance(expected_extra_mallocs, int):
assert mallocs - frees == expected_extra_mallocs
else:
assert mallocs - frees in expected_extra_mallocs
return res
return checking_fn
开发者ID:alkorzt,项目名称:pypy,代码行数:26,代码来源:test_genc.py
示例16: test_profopt
def test_profopt():
if sys.platform == 'win32':
py.test.skip("instrumentation support is unix only for now")
def add(a,b):
return a + b - b + b - b + b - b + b - b + b - b + b - b + b
def entry_point(argv):
tot = 0
x = int(argv[1])
while x > 0:
tot = add(tot, x)
x -= 1
os.write(1, str(tot))
return 0
from pypy.translator.interactive import Translation
# XXX this is mostly a "does not crash option"
t = Translation(entry_point, backend='c', standalone=True, profopt="")
# no counters
t.backendopt()
exe = t.compile()
out = py.process.cmdexec("%s 500" % exe)
assert int(out) == 500*501/2
t = Translation(entry_point, backend='c', standalone=True, profopt="",
noprofopt=True)
# no counters
t.backendopt()
exe = t.compile()
out = py.process.cmdexec("%s 500" % exe)
assert int(out) == 500*501/2
开发者ID:antoine1fr,项目名称:pygirl,代码行数:28,代码来源:test_standalone.py
示例17: compile
def compile(fn, argtypes, view=False, gcpolicy="ref", backendopt=True,
annotatorpolicy=None):
if argtypes is not None and "__pypy__" in sys.builtin_module_names:
py.test.skip("requires building cpython extension modules")
t = Translation(fn, argtypes, gc=gcpolicy, backend="c",
policy=annotatorpolicy)
if not backendopt:
t.disable(["backendopt_lltype"])
t.annotate()
# XXX fish
t.driver.config.translation.countmallocs = True
compiled_fn = t.compile_c()
try:
if py.test.config.option.view:
t.view()
except AttributeError:
pass
malloc_counters = t.driver.cbuilder.get_malloc_counters()
def checking_fn(*args, **kwds):
if 'expected_extra_mallocs' in kwds:
expected_extra_mallocs = kwds.pop('expected_extra_mallocs')
else:
expected_extra_mallocs = 0
res = compiled_fn(*args, **kwds)
mallocs, frees = malloc_counters()
if isinstance(expected_extra_mallocs, int):
assert mallocs - frees == expected_extra_mallocs
else:
assert mallocs - frees in expected_extra_mallocs
return res
return checking_fn
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:31,代码来源:test_genc.py
示例18: test_dup2_access
def test_dup2_access():
def entry_point(argv):
os.dup2(34, 56)
y = os.access("spam", 77)
return 1 - y
t = Translation(entry_point, backend='c', standalone=True, sandbox=True)
exe = t.compile()
g, f = os.popen2(exe, "t", 0)
expect(f, g, "ll_os.ll_os_dup2", (34, 56), None)
expect(f, g, "ll_os.ll_os_access", ("spam", 77), True)
g.close()
tail = f.read()
f.close()
assert tail == ""
开发者ID:antoine1fr,项目名称:pygirl,代码行数:15,代码来源:test_sandbox.py
示例19: test_time
def test_time():
def entry_point(argv):
t = time.time()
os.dup(int(t*1000))
return 0
t = Translation(entry_point, backend='c', standalone=True, sandbox=True)
exe = t.compile()
g, f = os.popen2(exe, "t", 0)
expect(f, g, "ll_time.ll_time_time", (), 3.141592)
expect(f, g, "ll_os.ll_os_dup", (3141,), 3)
g.close()
tail = f.read()
f.close()
assert tail == ""
开发者ID:antoine1fr,项目名称:pygirl,代码行数:15,代码来源:test_sandbox.py
示例20: test_foobar
def test_foobar():
py.test.skip("to be updated")
foobar = rffi.llexternal("foobar", [rffi.CCHARP], rffi.LONG)
def entry_point(argv):
s = rffi.str2charp(argv[1]); n = foobar(s); rffi.free_charp(s)
s = rffi.str2charp(argv[n]); n = foobar(s); rffi.free_charp(s)
return n
t = Translation(entry_point, backend='c', standalone=True, sandbox=True)
exe = t.compile()
proc = MySandboxedProc([exe, 'spam', 'egg'], expected = [
("foobar", ("spam",), 2),
("foobar", ("egg",), 0),
])
proc.handle_forever()
assert proc.seen == len(proc.expected)
开发者ID:antoine1fr,项目名称:pygirl,代码行数:16,代码来源:test_sandlib.py
注:本文中的pypy.translator.interactive.Translation类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论