コード例 #1
0
def detect_missing_support_programs():
    def check(exechelper):
        if py.path.local.sysfind(exechelper) is None:
            py.test.skip("%s is not on your path" % exechelper)

    check(getoption('javac'))
    check(getoption('java'))
コード例 #2
0
ファイル: genjvm.py プロジェクト: antoine1fr/pygirl
def detect_missing_support_programs():
    def check(exechelper):
        if py.path.local.sysfind(exechelper) is None:
            py.test.skip("%s is not on your path" % exechelper)
    check(getoption('jasmin'))
    check(getoption('javac'))
    check(getoption('java'))
コード例 #3
0
ファイル: genjvm.py プロジェクト: antoine1fr/pygirl
    def compile(self):
        """
        Compiles the .java sources into .class files, ready for execution.
        """
        jascmd = [getoption('jasmin'), '-g', '-d', str(self.javadir)]

        def split_list(files):
            "Split the files list into manageable pieces"

            # - On Windows 2000, commands in .bat are limited to 2047 chars.
            # - But the 'jasmin' script contains a line like
            #     path_to_jre/java -jar path_to_jasmin/jasmin.jar $*
            # So we limit the length of arguments files to:
            MAXLINE = 1500
    
            chunk = []
            chunklen = 0
            for f in files:
                # Account for the space between items
                chunklen += len(f) + 1
                if chunklen > MAXLINE:
                    yield chunk
                    chunk = []
                    chunklen = len(f)
                chunk.append(f)
            if chunk:
                yield chunk

        for files in split_list(self.jasmin_files):
            print "Invoking jasmin on %s" % files
            self._invoke(jascmd + files, False)
            print "... completed!"
                           
        self.compiled = True
        self._compile_helper()
コード例 #4
0
    def _compile_helper(self):
        # HACK: compile the Java helper classes.  Should eventually
        # use rte.py
        thisdir = py.magic.autopath().dirpath()
        rootdir = thisdir.join('src')
        srcdir = rootdir.join('pypy')
        javafiles = srcdir.listdir('*.java')
        classfiles = srcdir.listdir('*.class')
        jnajar = rootdir.join('jna.jar')

        recompile = True
        if len(classfiles) == len(javafiles):
            last_modified_java = max([java.mtime() for java in javafiles])
            last_modified_class = max([cls.mtime() for cls in classfiles])
            if last_modified_java < last_modified_class:
                recompile = False

        if recompile:
            log.red('Compiling java classes')
            javasrcs = [str(jf) for jf in javafiles]
            self._invoke([
                getoption('javac'), '-nowarn', '-d',
                str(rootdir), '-classpath',
                str(jnajar)
            ] + javasrcs, True)

        # copy .class files to classdir
        for classfile in srcdir.listdir('*.class'):
            classfile.copy(self.classdir.join('pypy'))
コード例 #5
0
    def compile(self):
        """
        Compiles the .java sources into .class files, ready for execution.
        """
        jascmd = [getoption('jasmin'), '-g', '-d', str(self.javadir)]

        def split_list(files):
            "Split the files list into manageable pieces"

            # - On Windows 2000, commands in .bat are limited to 2047 chars.
            # - But the 'jasmin' script contains a line like
            #     path_to_jre/java -jar path_to_jasmin/jasmin.jar $*
            # So we limit the length of arguments files to:
            MAXLINE = 1500

            chunk = []
            chunklen = 0
            for f in files:
                # Account for the space between items
                chunklen += len(f) + 1
                if chunklen > MAXLINE:
                    yield chunk
                    chunk = []
                    chunklen = len(f)
                chunk.append(f)
            if chunk:
                yield chunk

        for files in split_list(self.jasmin_files):
            print "Invoking jasmin on %s" % files
            self._invoke(jascmd + files, False)
            print "... completed!"

        self.compiled = True
        self._compile_helper()
コード例 #6
0
    def _compile_helper(self):
        # HACK: compile the Java helper classes.  Should eventually
        # use rte.py
        javafiles = self.srcdir.listdir('*.java')
        classfiles = self.srcdir.listdir('*.class')
        
        recompile = True
        if len(classfiles) == len(javafiles):
           last_modified_java = max([java.mtime() for java in javafiles])
           last_modified_class = max([cls.mtime() for cls in classfiles])
           if last_modified_java < last_modified_class:
               recompile = False

        if recompile:
           log.red('Compiling java classes')               
           javasrcs = [str(jf) for jf in javafiles]
           self._invoke([getoption('javac'),
                         '-nowarn',
                         '-d', str(self.rootdir),
                         '-classpath', str(self.jnajar)
                         ] + javasrcs,
                        True)

        # copy .class files to classdir
        for classfile in self.srcdir.listdir('*.class'):
           classfile.copy(self.classdir.join('pypy'))
コード例 #7
0
ファイル: runtest.py プロジェクト: alkorzt/pypy
 def __init__(self, class_name):
     # We put all of our classes into some package like 'pypy':
     # strip the initial 'pypy.' that results from the class name,
     # and we append a number to make the class name unique. Strip
     # those.
     pkg = getoption('package')+'.'
     assert class_name.startswith(pkg)
     uniqidx = class_name.rindex('_')
     self.class_name = class_name[len(pkg):uniqidx]
コード例 #8
0
ファイル: genjvm.py プロジェクト: enyst/plexnet
 def __init__(self, tmpdir, translator, entrypoint):
     """
     'tmpdir' --- where the generated files will go.  In fact, we will
     put our binaries into the directory pypy/jvm
     'translator' --- a TranslationContext object
     'entrypoint' --- if supplied, an object with a render method
     """
     GenOO.__init__(self, tmpdir, translator, entrypoint)
     self.jvmsrc = JvmGeneratedSource(tmpdir, getoption('package'))
コード例 #9
0
 def __init__(self, tmpdir, translator, entrypoint):
     """
     'tmpdir' --- where the generated files will go.  In fact, we will
     put our binaries into the directory pypy/jvm
     'translator' --- a TranslationContext object
     'entrypoint' --- if supplied, an object with a render method
     """
     GenOO.__init__(self, tmpdir, translator, entrypoint)
     self.jvmsrc = JvmGeneratedSource(tmpdir, getoption('package'))
コード例 #10
0
ファイル: runtest.py プロジェクト: purepython/pypy
 def __init__(self, class_name):
     # We put all of our classes into some package like 'pypy':
     # strip the initial 'pypy.' that results from the class name,
     # and we append a number to make the class name unique. Strip
     # those.
     pkg = getoption('package') + '.'
     assert class_name.startswith(pkg)
     uniqidx = class_name.rindex('_')
     self.class_name = class_name[len(pkg):uniqidx]
コード例 #11
0
ファイル: genjvm.py プロジェクト: TheDunn/flex-pypy
def generate_source_for_function(func, annotation):
    
    """
    Given a Python function and some hints about its argument types,
    generates JVM sources that call it and print the result.  Returns
    the JvmGeneratedSource object.
    """
    
    if hasattr(func, 'im_func'):
        func = func.im_func
    t = TranslationContext()
    ann = t.buildannotator()
    ann.build_types(func, annotation)
    t.buildrtyper(type_system="ootype").specialize()
    main_graph = t.graphs[0]
    if getoption('view'): t.view()
    if getoption('wd'): tmpdir = py.path.local('.')
    else: tmpdir = udir
    jvm = GenJvm(tmpdir, t, EntryPoint(main_graph, True, True))
    return jvm.generate_source()
コード例 #12
0
ファイル: runtest.py プロジェクト: TheDunn/flex-pypy
 def _compile(self, fn, args, ann=None):
     if ann is None:
         ann = [lltype_to_annotation(typeOf(x)) for x in args]
     if self._func is fn and self._ann == ann:
         return JvmGeneratedSourceWrapper(self._jvm_src)
     else:
         self._func = fn
         self._ann = ann
         self._jvm_src = generate_source_for_function(fn, ann)
         if not getoption('noasm'):
             self._jvm_src.compile()
         return JvmGeneratedSourceWrapper(self._jvm_src)
コード例 #13
0
def generate_source_for_function(func, annotation, backendopt=False):
    """
    Given a Python function and some hints about its argument types,
    generates JVM sources that call it and print the result.  Returns
    the JvmGeneratedSource object.
    """

    if hasattr(func, 'im_func'):
        func = func.im_func
    t = TranslationContext()
    ann = t.buildannotator()
    ann.build_types(func, annotation)
    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
    jvm = GenJvm(tmpdir, t, EntryPoint(main_graph, True, True))
    return jvm.generate_source()
コード例 #14
0
ファイル: runtest.py プロジェクト: purepython/pypy
 def compile(self, fn, args, ann=None, backendopt=False):
     if ann is None:
         ann = [lltype_to_annotation(typeOf(x)) for x in args]
     if self._func is fn and self._ann == ann:
         return JvmGeneratedSourceWrapper(self._jvm_src)
     else:
         self._func = fn
         self._ann = ann
         olddefs = patch_os()
         self._jvm_src = generate_source_for_function(fn, ann, backendopt)
         unpatch_os(olddefs)
         if not getoption('noasm'):
             self._jvm_src.compile()
         return JvmGeneratedSourceWrapper(self._jvm_src)
コード例 #15
0
ファイル: runtest.py プロジェクト: alkorzt/pypy
 def compile(self, fn, args, ann=None, backendopt=False):
     if ann is None:
         ann = [lltype_to_annotation(typeOf(x)) for x in args]
     if self._func is fn and self._ann == ann:
         return JvmGeneratedSourceWrapper(self._jvm_src)
     else:
         self._func = fn
         self._ann = ann
         olddefs = patch_os()
         self._jvm_src = generate_source_for_function(fn, ann, backendopt)
         unpatch_os(olddefs)
         if not getoption('noasm'):
             self._jvm_src.compile()
         return JvmGeneratedSourceWrapper(self._jvm_src)
コード例 #16
0
ファイル: runtest.py プロジェクト: alkorzt/pypy
    def run(self,*args):
        if not self.gensrc.compiled:
            py.test.skip("Assembly disabled")

        if getoption('norun'):
            py.test.skip("Execution disabled")

#        if self._exe is None:
#            py.test.skip("Compilation disabled")

#        if getoption('norun'):
#            py.test.skip("Execution disabled")

        stdout, stderr, retval = self.gensrc.execute(args)
        return stdout, stderr, retval
コード例 #17
0
ファイル: runtest.py プロジェクト: TheDunn/flex-pypy
    def __call__(self, *args):
        if not self.gensrc.compiled:
            py.test.skip("Assembly disabled")

        if getoption('norun'):
            py.test.skip("Execution disabled")

        resstr = self.gensrc.execute(args)
        print "resstr=%s" % repr(resstr)
        res = eval(resstr)
        if isinstance(res, tuple):
            res = StructTuple(res) # so tests can access tuple elements with .item0, .item1, etc.
        elif isinstance(res, list):
            res = OOList(res)
        return res
コード例 #18
0
ファイル: runtest.py プロジェクト: purepython/pypy
    def run(self, *args):
        if not self.gensrc.compiled:
            py.test.skip("Assembly disabled")

        if getoption('norun'):
            py.test.skip("Execution disabled")


#        if self._exe is None:
#            py.test.skip("Compilation disabled")

#        if getoption('norun'):
#            py.test.skip("Execution disabled")

        stdout, stderr, retval = self.gensrc.execute(args)
        return stdout, stderr, retval
コード例 #19
0
ファイル: runtest.py プロジェクト: alkorzt/pypy
    def __call__(self, *args):
        if not self.gensrc.compiled:
            py.test.skip("Assembly disabled")

        if getoption('norun'):
            py.test.skip("Execution disabled")

        stdout, stderr, retval = self.gensrc.execute(args)
        res = eval(stdout.strip())
        if isinstance(res, tuple):
            res = StructTuple(res) # so tests can access tuple elements with .item0, .item1, etc.
        elif isinstance(res, list):
            res = OOList(res)
        elif isinstance(res, ExceptionWrapper):
            raise res            
        return res
コード例 #20
0
ファイル: genjvm.py プロジェクト: TheDunn/flex-pypy
 def _compile_helper(self, clsnms):
     # HACK: compile the Java helper class.  Should eventually
     # use rte.py
     tocompile = []
     for clsnm in clsnms:
         pypycls = self.classdir.join(clsnm + '.class')
         if not pypycls.check():
             tocompile.append(clsnm)
     if tocompile:
         thisdir = py.magic.autopath().dirpath()
         javasrcs = [str(thisdir.join('src/pypy', clsnm + '.java')) for
                     clsnm in tocompile]
         self._invoke([getoption('javac'),
                       '-nowarn',
                       '-d', str(self.classdir)]+
                      javasrcs,
                      True)
コード例 #21
0
ファイル: genjvm.py プロジェクト: enyst/plexnet
 def _compile_helper(self):
     # HACK: compile the Java helper classes.  Should eventually
     # use rte.py
     if JvmGeneratedSource._cached == self.classdir:
        return
     log.red('Compiling java classes')
     javafiles = self.srcdir.listdir('*.java')
     javasrcs = [str(jf) for jf in javafiles]
     self._invoke([getoption('javac'),
                   '-nowarn',
                   '-d', str(self.classdir),
                   '-classpath', str(self.jnajar),
                   ] + javasrcs,
                  True)
     # NOTE if you are trying to add more caching: some .java files
     # compile to several .class files of various names.
     JvmGeneratedSource._cached = self.classdir
コード例 #22
0
ファイル: genjvm.py プロジェクト: TheDunn/flex-pypy
 def execute(self, args):
     """
     Executes the compiled sources in a separate process.  Returns the
     output as a string.  The 'args' are provided as arguments,
     and will be converted to strings.
     """
     assert self.compiled
     strargs = [self._make_str(a) for a in args]
     cmd = [getoption('java'),
            '-cp',
            str(self.javadir),
            self.package+".Main"] + strargs
     print "Invoking java to run the code"
     stdout, stderr = self._invoke(cmd, True)
     print "...done!"
     sys.stderr.write(stderr)
     return stdout
コード例 #23
0
ファイル: runtest.py プロジェクト: purepython/pypy
    def __call__(self, *args):
        if not self.gensrc.compiled:
            py.test.skip("Assembly disabled")

        if getoption('norun'):
            py.test.skip("Execution disabled")

        stdout, stderr, retval = self.gensrc.execute(args)
        res = eval(stdout.strip())
        if isinstance(res, tuple):
            res = StructTuple(
                res
            )  # so tests can access tuple elements with .item0, .item1, etc.
        elif isinstance(res, list):
            res = OOList(res)
        elif isinstance(res, ExceptionWrapper):
            raise res
        return res
コード例 #24
0
 def _compile_helper(self):
     # HACK: compile the Java helper classes.  Should eventually
     # use rte.py
     if JvmGeneratedSource._cached == self.classdir:
         return
     log.red('Compiling java classes')
     javafiles = self.srcdir.listdir('*.java')
     javasrcs = [str(jf) for jf in javafiles]
     self._invoke([
         getoption('javac'),
         '-nowarn',
         '-d',
         str(self.classdir),
         '-classpath',
         str(self.jnajar),
     ] + javasrcs, True)
     # NOTE if you are trying to add more caching: some .java files
     # compile to several .class files of various names.
     JvmGeneratedSource._cached = self.classdir
コード例 #25
0
 def execute(self, args):
     """
     Executes the compiled sources in a separate process.  Returns the
     output as a string.  The 'args' are provided as arguments,
     and will be converted to strings.
     """
     assert self.compiled
     strargs = [self._make_str(a) for a in args]
     cmd = [
         getoption('java'),
         '-Xmx256M',  # increase the heapsize so the microbenchmarks run
         '-cp',
         str(self.javadir),
         self.package + ".Main"
     ] + strargs
     print "Invoking java to run the code"
     stdout, stderr, retval = self._invoke(cmd, True)
     print "...done!"
     sys.stderr.write(stderr)
     return stdout, stderr, retval
コード例 #26
0
 def _pkg(self, nm):
     return "%s.%s" % (getoption('package'), nm)
コード例 #27
0
 def _trace_enabled(self):
     return getoption('trace')
コード例 #28
0
ファイル: database.py プロジェクト: Debug-Orz/Sypy
 def _pkg(self, nm):
     return "%s.%s" % (getoption('package'), nm)