当前位置: 首页>>代码示例>>Python>>正文


Python CStandaloneBuilder.compile方法代码示例

本文整理汇总了Python中rpython.translator.c.genc.CStandaloneBuilder.compile方法的典型用法代码示例。如果您正苦于以下问题:Python CStandaloneBuilder.compile方法的具体用法?Python CStandaloneBuilder.compile怎么用?Python CStandaloneBuilder.compile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在rpython.translator.c.genc.CStandaloneBuilder的用法示例。


在下文中一共展示了CStandaloneBuilder.compile方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: compile

# 需要导入模块: from rpython.translator.c.genc import CStandaloneBuilder [as 别名]
# 或者: from rpython.translator.c.genc.CStandaloneBuilder import compile [as 别名]
    def compile(self, entry_point, debug=True, shared=False,
                stackcheck=False, entrypoints=None):
        t = TranslationContext(self.config)
        ann = t.buildannotator()
        ann.build_types(entry_point, [s_list_of_strings])
        if entrypoints is not None:
            anns = {}
            for func, annotation in secondary_entrypoints['test']:
                anns[func] = annotation
            for item in entrypoints:
                ann.build_types(item, anns[item])
        t.buildrtyper().specialize()

        if stackcheck:
            from rpython.translator.transform import insert_ll_stackcheck
            insert_ll_stackcheck(t)

        t.config.translation.shared = shared

        if entrypoints is not None:
            kwds = {'secondary_entrypoints': [(i, None) for i in entrypoints]}
        else:
            kwds = {}
        cbuilder = CStandaloneBuilder(t, entry_point, t.config, **kwds)
        if debug:
            cbuilder.generate_source(defines=cbuilder.DEBUG_DEFINES)
        else:
            cbuilder.generate_source()
        cbuilder.compile()
        if option is not None and option.view:
            t.view()
        return t, cbuilder
开发者ID:bukzor,项目名称:pypy,代码行数:34,代码来源:test_standalone.py

示例2: test_counters

# 需要导入模块: from rpython.translator.c.genc import CStandaloneBuilder [as 别名]
# 或者: from rpython.translator.c.genc.CStandaloneBuilder import compile [as 别名]
    def test_counters(self):
        from rpython.rtyper.lltypesystem import lltype
        from rpython.rtyper.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.environ['PYPY_INSTRUMENT_COUNTERS'] = str(counters_fname)
        try:
            data = cbuilder.cmdexec()
        finally:
            del os.environ['PYPY_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)
开发者ID:bukzor,项目名称:pypy,代码行数:36,代码来源:test_standalone.py

示例3: compile

# 需要导入模块: from rpython.translator.c.genc import CStandaloneBuilder [as 别名]
# 或者: from rpython.translator.c.genc.CStandaloneBuilder import compile [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
开发者ID:yuyichao,项目名称:pypy,代码行数:15,代码来源:test_standalone.py

示例4: test_build

# 需要导入模块: from rpython.translator.c.genc import CStandaloneBuilder [as 别名]
# 或者: from rpython.translator.c.genc.CStandaloneBuilder import compile [as 别名]
def test_build():
    def entry_point(argv):
        parser = interp_pyexpat.XML_ParserCreate("test")
        interp_pyexpat.XML_ParserFree(parser)
        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)
开发者ID:Darriall,项目名称:pypy,代码行数:19,代码来源:test_build.py

示例5: _compile_and_run

# 需要导入模块: from rpython.translator.c.genc import CStandaloneBuilder [as 别名]
# 或者: from rpython.translator.c.genc.CStandaloneBuilder import compile [as 别名]
 def _compile_and_run(self, t, entry_point, entry_point_graph, args):
     from rpython.translator.c.genc import CStandaloneBuilder as CBuilder
     # XXX patch exceptions
     cbuilder = CBuilder(t, entry_point, config=t.config)
     cbuilder.generate_source()
     self._check_cbuilder(cbuilder)
     exe_name = cbuilder.compile()
     debug_print('---------- Test starting ----------')
     stdout = cbuilder.cmdexec(" ".join([str(arg) for arg in args]))
     res = int(stdout)
     debug_print('---------- Test done (%d) ----------' % (res,))
     return res
开发者ID:Darriall,项目名称:pypy,代码行数:14,代码来源:support.py

示例6: _makefunc_str_int

# 需要导入模块: from rpython.translator.c.genc import CStandaloneBuilder [as 别名]
# 或者: from rpython.translator.c.genc.CStandaloneBuilder import compile [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 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':
                library_path = exe_name.dirpath()
                if sys.platform == 'darwin':
                    env = 'DYLD_LIBRARY_PATH="%s" ' % library_path
                else:
                    env = 'LD_LIBRARY_PATH="%s" ' % library_path
            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
开发者ID:Darriall,项目名称:pypy,代码行数:70,代码来源:test_asmgcroot.py


注:本文中的rpython.translator.c.genc.CStandaloneBuilder.compile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。