本文整理汇总了Python中pypy.translator.interactive.Translation.backendopt方法的典型用法代码示例。如果您正苦于以下问题:Python Translation.backendopt方法的具体用法?Python Translation.backendopt怎么用?Python Translation.backendopt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pypy.translator.interactive.Translation
的用法示例。
在下文中一共展示了Translation.backendopt方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_profopt
# 需要导入模块: from pypy.translator.interactive import Translation [as 别名]
# 或者: from pypy.translator.interactive.Translation import backendopt [as 别名]
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
示例2: test_prof_inline
# 需要导入模块: from pypy.translator.interactive import Translation [as 别名]
# 或者: from pypy.translator.interactive.Translation import backendopt [as 别名]
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
示例3: test_profopt
# 需要导入模块: from pypy.translator.interactive import Translation [as 别名]
# 或者: from pypy.translator.interactive.Translation import backendopt [as 别名]
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
示例4: test_translate_compiled_parser
# 需要导入模块: from pypy.translator.interactive import Translation [as 别名]
# 或者: from pypy.translator.interactive.Translation import backendopt [as 别名]
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
示例5: test_simple_backendopt
# 需要导入模块: from pypy.translator.interactive import Translation [as 别名]
# 或者: from pypy.translator.interactive.Translation import backendopt [as 别名]
def test_simple_backendopt():
def f(x, y):
return x,y
t = Translation(f, [int, int], backend='c')
t.backendopt()
assert 'backendopt_lltype' in t.driver.done
t = Translation(f, [int, int])
t.backendopt()
assert 'backendopt_lltype' in t.driver.done
示例6: compile_rex
# 需要导入模块: from pypy.translator.interactive import Translation [as 别名]
# 或者: from pypy.translator.interactive.Translation import backendopt [as 别名]
def compile_rex(rex):
try:
from pypy.translator.interactive import Translation
except ImportError:
py.test.skip("pypy not found")
fda = rex.make_automaton().make_deterministic()
fda.optimize()
fn = fda.make_code()
t = Translation(fn)
t.backendopt([str], backend="c")
if py.test.config.option.view:
t.view()
return t.compile_c()
示例7: test_parser
# 需要导入模块: from pypy.translator.interactive import Translation [as 别名]
# 或者: from pypy.translator.interactive.Translation import backendopt [as 别名]
def test_parser():
def f(x):
if x:
s = "a(X, Y, Z)."
else:
s = "f(a, X, _, _, X, f(X, 2.455))."
term = parsing.parse_file(s)
assert isinstance(term, parsing.Nonterminal)
return term.symbol
assert f(True) == "file"
assert f(True) == "file"
t = Translation(f)
t.annotate([bool])
t.rtype()
t.backendopt()
func = t.compile_c()
assert func(True) == "file"
assert func(False) == "file"
示例8: test_compile_recognizer
# 需要导入模块: from pypy.translator.interactive import Translation [as 别名]
# 或者: from pypy.translator.interactive.Translation import backendopt [as 别名]
def test_compile_recognizer():
try:
from pypy.translator.interactive import Translation
except ImportError:
py.test.skip("pypy not found on path")
a = DFA()
s0 = a.add_state("start")
s1 = a.add_state()
s2 = a.add_state(final=True)
a[s0, "a"] = s0
a[s0, "c"] = s1
a[s0, "b"] = s2
a[s1, "b"] = s2
recognize = a.make_code()
t = Translation(recognize)
t.backendopt([str], backend="c")
cfn = t.compile_c()
assert cfn("aaaaaaaaaab")
assert cfn("b")
assert cfn("aaaacb")
示例9: test_profopt_mac_osx_bug
# 需要导入模块: from pypy.translator.interactive import Translation [as 别名]
# 或者: from pypy.translator.interactive.Translation import backendopt [as 别名]
def test_profopt_mac_osx_bug(self):
if sys.platform == 'win32':
py.test.skip("no profopt on win32")
def entry_point(argv):
import os
pid = os.fork()
if pid:
os.waitpid(pid, 0)
else:
os._exit(0)
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()
#py.process.cmdexec(exe)
t = Translation(entry_point, backend='c', standalone=True, profopt="",
noprofopt=True)
# no counters
t.backendopt()
exe = t.compile()
示例10: test_translate_ast_visitor
# 需要导入模块: from pypy.translator.interactive import Translation [as 别名]
# 或者: from pypy.translator.interactive.Translation import backendopt [as 别名]
def test_translate_ast_visitor():
from pypy.rlib.parsing.ebnfparse import parse_ebnf, make_parse_function
regexs, rules, ToAST = parse_ebnf("""
DECIMAL: "0|[1-9][0-9]*";
IGNORE: " ";
additive: multitive ["+!"] additive | <multitive>;
multitive: primary ["*!"] multitive | <primary>; #nonsense!
primary: "(" <additive> ")" | <DECIMAL>;
""")
parse = make_parse_function(regexs, rules)
def f():
tree = parse("(0 +! 10) *! (999 +! 10) +! 1")
tree = ToAST().visit_additive(tree)
assert len(tree) == 1
tree = tree[0]
return tree.symbol + " " + "-&-".join([c.symbol for c in tree.children])
res1 = f()
t = Translation(f)
t.annotate()
t.rtype()
t.backendopt()
func = t.compile_c()
res2 = func()
assert res1 == res2
示例11: test_translate_pypackrat_regex
# 需要导入模块: from pypy.translator.interactive import Translation [as 别名]
# 或者: from pypy.translator.interactive.Translation import backendopt [as 别名]
def test_translate_pypackrat_regex():
from pypy.rlib.parsing.pypackrat import PackratParser
class parser(PackratParser):
"""
num:
`([1-9][0-9]*)|0`;
"""
print parser._code
def parse(s):
p = parser(s)
return p.num()
res = parse("1234")
assert res == '1234'
t = Translation(parse)
t.annotate([str])
t.rtype()
t.backendopt()
if option.view:
t.view()
func = t.compile_c()
res = func("12345")
assert res == '12345'
res = func("0")
assert res == '0'
示例12: test_translate_pypackrat
# 需要导入模块: from pypy.translator.interactive import Translation [as 别名]
# 或者: from pypy.translator.interactive.Translation import backendopt [as 别名]
def test_translate_pypackrat():
from pypy.rlib.parsing.pypackrat import PackratParser
class parser(PackratParser):
"""
expr:
additive;
additive:
a = additive
'-'
b = multitive
return {'(%s - %s)' % (a, b)}
| multitive;
multitive:
a = multitive
'*'
b = simple
return {'(%s * %s)' % (a, b)}
| simple;
simple:
('0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9');
"""
print parser._code
def parse(s):
p = parser(s)
return p.expr()
res = parse("5-5-5")
assert res == '((5 - 5) - 5)'
t = Translation(parse)
t.annotate([str])
t.rtype()
t.backendopt()
if option.view:
t.view()
func = t.compile_c()
res = func("5-5-5")
assert res == '((5 - 5) - 5)'