本文整理汇总了Python中pypy.translator.c.genc.CStandaloneBuilder.generate_source方法的典型用法代码示例。如果您正苦于以下问题:Python CStandaloneBuilder.generate_source方法的具体用法?Python CStandaloneBuilder.generate_source怎么用?Python CStandaloneBuilder.generate_source使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pypy.translator.c.genc.CStandaloneBuilder
的用法示例。
在下文中一共展示了CStandaloneBuilder.generate_source方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_counters
# 需要导入模块: from pypy.translator.c.genc import CStandaloneBuilder [as 别名]
# 或者: from pypy.translator.c.genc.CStandaloneBuilder import generate_source [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)
示例2: wrap_stackless_function
# 需要导入模块: from pypy.translator.c.genc import CStandaloneBuilder [as 别名]
# 或者: from pypy.translator.c.genc.CStandaloneBuilder import generate_source [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())
示例3: test_os_setpgrp
# 需要导入模块: from pypy.translator.c.genc import CStandaloneBuilder [as 别名]
# 或者: from pypy.translator.c.genc.CStandaloneBuilder import generate_source [as 别名]
def test_os_setpgrp(self):
def entry_point(argv):
os.setpgrp()
return 0
t = TranslationContext(self.config)
t.buildannotator().build_types(entry_point, [s_list_of_strings])
t.buildrtyper().specialize()
cbuilder = CStandaloneBuilder(t, entry_point, t.config)
cbuilder.generate_source()
cbuilder.compile()
示例4: _compile_and_run
# 需要导入模块: from pypy.translator.c.genc import CStandaloneBuilder [as 别名]
# 或者: from pypy.translator.c.genc.CStandaloneBuilder import generate_source [as 别名]
def _compile_and_run(self, t, entry_point, entry_point_graph, args):
from pypy.translator.c.genc import CStandaloneBuilder as CBuilder
# XXX patch exceptions
cbuilder = CBuilder(t, entry_point, config=t.config)
cbuilder.generate_source()
exe_name = cbuilder.compile()
log("---------- Test starting ----------")
stdout = cbuilder.cmdexec(" ".join([str(arg) for arg in args]))
res = int(stdout)
log("---------- Test done (%d) ----------" % (res,))
return res
示例5: compile
# 需要导入模块: from pypy.translator.c.genc import CStandaloneBuilder [as 别名]
# 或者: from pypy.translator.c.genc.CStandaloneBuilder import generate_source [as 别名]
def compile(self, entry_point):
t = TranslationContext(self.config)
t.config.translation.gc = "semispace"
t.config.translation.gcrootfinder = self.gcrootfinder
t.config.translation.thread = True
t.buildannotator().build_types(entry_point, [s_list_of_strings])
t.buildrtyper().specialize()
#
cbuilder = CStandaloneBuilder(t, entry_point, t.config)
cbuilder.generate_source(defines=cbuilder.DEBUG_DEFINES)
cbuilder.compile()
#
return t, cbuilder
示例6: compile
# 需要导入模块: from pypy.translator.c.genc import CStandaloneBuilder [as 别名]
# 或者: from pypy.translator.c.genc.CStandaloneBuilder import generate_source [as 别名]
def compile(self, entry_point, debug=True):
t = TranslationContext(self.config)
t.buildannotator().build_types(entry_point, [s_list_of_strings])
t.buildrtyper().specialize()
cbuilder = CStandaloneBuilder(t, entry_point, t.config)
if debug:
cbuilder.generate_source(defines=cbuilder.DEBUG_DEFINES)
else:
cbuilder.generate_source()
cbuilder.compile()
if option.view:
t.view()
return t, cbuilder
示例7: run_stackless_function
# 需要导入模块: from pypy.translator.c.genc import CStandaloneBuilder [as 别名]
# 或者: from pypy.translator.c.genc.CStandaloneBuilder import generate_source [as 别名]
def run_stackless_function(fn):
def entry_point(argv):
r = fn()
os.write(1, str(r) + "\n")
return 0
t = rtype_stackless_function(entry_point)
cbuilder = CStandaloneBuilder(t, entry_point, config=t.config, gcpolicy=gc.BoehmGcPolicy)
cbuilder.generate_source()
if conftest.option.view:
t.view()
cbuilder.compile()
res = cbuilder.cmdexec("")
return int(res.strip())
示例8: test_build
# 需要导入模块: from pypy.translator.c.genc import CStandaloneBuilder [as 别名]
# 或者: from pypy.translator.c.genc.CStandaloneBuilder import generate_source [as 别名]
def test_build():
def entry_point(argv):
res = interp_pyexpat.XML_ErrorString(3)
os.write(1, rffi.charp2str(res))
return 0
t = TranslationContext()
t.buildannotator().build_types(entry_point, [s_list_of_strings])
t.buildrtyper().specialize()
builder = CStandaloneBuilder(t, entry_point, t.config)
builder.generate_source()
builder.compile()
data = builder.cmdexec()
assert data == pyexpat.ErrorString(3)
示例9: test_frexp
# 需要导入模块: from pypy.translator.c.genc import CStandaloneBuilder [as 别名]
# 或者: from pypy.translator.c.genc.CStandaloneBuilder import generate_source [as 别名]
def test_frexp():
import math
def entry_point(argv):
m, e = math.frexp(0)
x, y = math.frexp(0)
print m, x
return 0
t = TranslationContext()
t.buildannotator().build_types(entry_point, [s_list_of_strings])
t.buildrtyper().specialize()
cbuilder = CStandaloneBuilder(t, entry_point, t.config)
cbuilder.generate_source()
cbuilder.compile()
data = cbuilder.cmdexec('hi there')
assert map(float, data.split()) == [0.0, 0.0]
示例10: test_hello_world
# 需要导入模块: from pypy.translator.c.genc import CStandaloneBuilder [as 别名]
# 或者: from pypy.translator.c.genc.CStandaloneBuilder import generate_source [as 别名]
def test_hello_world():
def entry_point(argv):
os.write(1, "hello world\n")
argv = argv[1:]
os.write(1, "argument count: " + str(len(argv)) + "\n")
for s in argv:
os.write(1, " '" + str(s) + "'\n")
return 0
t = TranslationContext()
t.buildannotator().build_types(entry_point, [s_list_of_strings])
t.buildrtyper().specialize()
cbuilder = CStandaloneBuilder(t, entry_point, t.config)
cbuilder.generate_source()
cbuilder.compile()
data = cbuilder.cmdexec('hi there')
assert data.startswith('''hello world\nargument count: 2\n 'hi'\n 'there'\n''')
示例11: _makefunc_str_int
# 需要导入模块: from pypy.translator.c.genc import CStandaloneBuilder [as 别名]
# 或者: from pypy.translator.c.genc.CStandaloneBuilder import generate_source [as 别名]
def _makefunc_str_int(cls, func):
def main(argv):
arg0 = argv[1]
arg1 = int(argv[2])
try:
res = func(arg0, arg1)
except MemoryError:
print 'Result: MemoryError'
else:
print 'Result: "%s"' % (res,)
return 0
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=True)
config.translation.gc = cls.gcpolicy
config.translation.gcrootfinder = "asmgcc"
if sys.platform == 'win32':
config.translation.cc = 'mingw32'
t = TranslationContext(config=config)
a = t.buildannotator()
a.build_types(main, [s_list_of_strings])
t.buildrtyper().specialize()
t.checkgraphs()
cbuilder = CStandaloneBuilder(t, main, config=config)
c_source_filename = cbuilder.generate_source(
defines = cbuilder.DEBUG_DEFINES)
cls._patch_makefile(cbuilder.targetdir)
if conftest.option.view:
t.view()
exe_name = cbuilder.compile()
def run(arg0, arg1):
lines = []
print >> sys.stderr, 'RUN: starting', exe_name
if sys.platform == 'win32':
redirect = ' 2> NUL'
else:
redirect = ''
g = os.popen('"%s" %s %d%s' % (exe_name, arg0, arg1, redirect), 'r')
for line in g:
print >> sys.stderr, 'RUN:', line.rstrip()
lines.append(line)
g.close()
if not lines:
py.test.fail("no output from subprocess")
if not lines[-1].startswith('Result:'):
py.test.fail("unexpected output from subprocess")
result = lines[-1][len('Result:'):].strip()
if result == 'MemoryError':
raise MemoryError("subprocess got an RPython MemoryError")
if result.startswith('"') and result.endswith('"'):
return result[1:-1]
else:
return int(result)
return run
示例12: getcompiled
# 需要导入模块: from pypy.translator.c.genc import CStandaloneBuilder [as 别名]
# 或者: from pypy.translator.c.genc.CStandaloneBuilder import generate_source [as 别名]
def getcompiled(self, func):
def main(argv):
try:
res = func()
except MemoryError:
print 'Result: MemoryError'
else:
if isinstance(res, int):
print 'Result:', res
else:
print 'Result: "%s"' % (res,)
return 0
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=True)
config.translation.gc = self.gcpolicy
config.translation.gcrootfinder = "asmgcc"
t = TranslationContext(config=config)
self.t = t
a = t.buildannotator()
a.build_types(main, [s_list_of_strings])
t.buildrtyper().specialize()
t.checkgraphs()
cbuilder = CStandaloneBuilder(t, main, config=config)
c_source_filename = cbuilder.generate_source(
defines = cbuilder.DEBUG_DEFINES)
self.patch_makefile(cbuilder.targetdir)
if conftest.option.view:
t.view()
exe_name = cbuilder.compile()
def run():
lines = []
print >> sys.stderr, 'RUN: starting', exe_name
g = os.popen("'%s'" % (exe_name,), 'r')
for line in g:
print >> sys.stderr, 'RUN:', line.rstrip()
lines.append(line)
g.close()
if not lines:
py.test.fail("no output from subprocess")
if not lines[-1].startswith('Result:'):
py.test.fail("unexpected output from subprocess")
result = lines[-1][len('Result:'):].strip()
if result == 'MemoryError':
raise MemoryError("subprocess got an RPython MemoryError")
if result.startswith('"') and result.endswith('"'):
return result[1:-1]
else:
return int(result)
return run
示例13: test_separate_files
# 需要导入模块: from pypy.translator.c.genc import CStandaloneBuilder [as 别名]
# 或者: from pypy.translator.c.genc.CStandaloneBuilder import generate_source [as 别名]
def test_separate_files(self):
# One file in translator/c/src
fname = py.path.local(pypydir).join(
'translator', 'c', 'src', 'll_strtod.h')
# One file in (another) subdir of the temp directory
dirname = udir.join("test_dir").ensure(dir=1)
fname2 = dirname.join("test_genc.c")
fname2.write("""
void f() {
LL_strtod_formatd("%5f", 12.3);
}""")
files = [fname, fname2]
def entry_point(argv):
return 0
t = TranslationContext(self.config)
t.buildannotator().build_types(entry_point, [s_list_of_strings])
t.buildrtyper().specialize()
cbuilder = CStandaloneBuilder(t, entry_point, t.config)
cbuilder.eci = cbuilder.eci.merge(
ExternalCompilationInfo(separate_module_files=files))
cbuilder.generate_source()
makefile = udir.join(cbuilder.modulename, 'Makefile').read()
# generated files are compiled in the same directory
assert " ../test_dir/test_genc.c" in makefile
assert " ../test_dir/test_genc.o" in makefile
# but files from pypy source dir must be copied
assert "translator/c/src" not in makefile
assert " ll_strtod.h" in makefile
assert " ll_strtod.o" in makefile
示例14: test_standalone_large_files
# 需要导入模块: from pypy.translator.c.genc import CStandaloneBuilder [as 别名]
# 或者: from pypy.translator.c.genc.CStandaloneBuilder import generate_source [as 别名]
def test_standalone_large_files():
from pypy.module.posix.test.test_posix2 import need_sparse_files
need_sparse_files()
filename = str(udir.join('test_standalone_largefile'))
r4800000000 = r_longlong(4800000000L)
def entry_point(argv):
fd = os.open(filename, os.O_RDWR | os.O_CREAT, 0644)
os.lseek(fd, r4800000000, 0)
os.write(fd, "$")
newpos = os.lseek(fd, 0, 1)
if newpos == r4800000000 + 1:
print "OK"
else:
print "BAD POS"
os.close(fd)
return 0
t = TranslationContext()
t.buildannotator().build_types(entry_point, [s_list_of_strings])
t.buildrtyper().specialize()
cbuilder = CStandaloneBuilder(t, entry_point, t.config)
cbuilder.generate_source()
cbuilder.compile()
data = cbuilder.cmdexec('hi there')
assert data.strip() == "OK"
示例15: _makefunc_str_int
# 需要导入模块: from pypy.translator.c.genc import CStandaloneBuilder [as 别名]
# 或者: from pypy.translator.c.genc.CStandaloneBuilder import generate_source [as 别名]
def _makefunc_str_int(cls, func):
def main(argv):
arg0 = argv[1]
arg1 = int(argv[2])
try:
res = func(arg0, arg1)
except MemoryError:
print 'Result: MemoryError'
else:
print 'Result: "%s"' % (res,)
return 0
config = cls.make_config()
t = TranslationContext(config=config)
a = t.buildannotator()
sec_ep = getattr(cls, 'secondary_entrypoints', [])
for f, inputtypes in sec_ep:
a.build_types(f, inputtypes, False)
a.build_types(main, [s_list_of_strings])
t.buildrtyper().specialize()
t.checkgraphs()
cbuilder = CStandaloneBuilder(t, main, config=config,
secondary_entrypoints=sec_ep)
c_source_filename = cbuilder.generate_source(
defines = cbuilder.DEBUG_DEFINES)
cls._patch_makefile(cbuilder.targetdir)
if conftest.option.view:
t.view()
exe_name = cbuilder.compile()
def run(arg0, arg1):
lines = []
print >> sys.stderr, 'RUN: starting', exe_name, arg0, arg1
if sys.platform == 'win32':
redirect = ' 2> NUL'
else:
redirect = ''
if config.translation.shared and os.name == 'posix':
env = 'LD_LIBRARY_PATH="%s" ' % (exe_name.dirpath(),)
else:
env = ''
cwd = os.getcwd()
try:
os.chdir(str(exe_name.dirpath()))
g = os.popen(
'%s"%s" %s %d%s' % (env, exe_name, arg0, arg1, redirect), 'r')
finally:
os.chdir(cwd)
for line in g:
print >> sys.stderr, 'RUN:', line.rstrip()
lines.append(line)
g.close()
if not lines:
py.test.fail("no output from subprocess")
if not lines[-1].startswith('Result:'):
py.test.fail("unexpected output from subprocess")
result = lines[-1][len('Result:'):].strip()
if result == 'MemoryError':
raise MemoryError("subprocess got an RPython MemoryError")
if result.startswith('"') and result.endswith('"'):
return result[1:-1]
else:
return int(result)
return run