示例#1
0
class PyPyCacheDir:
    "NOT_RPYTHON"

    # similar to applevel, but using translation to interp-level.
    # This version maintains a cache folder with single files.

    def build_applevelinterp_dict(cls, self, space):
        "NOT_RPYTHON"
        # N.B. 'self' is the ApplevelInterp; this is a class method,
        # just so that we have a convenient place to store the global state.
        if not cls._setup_done:
            cls._setup()

        from pypy.translator.geninterplevel import translate_as_module
        import marshal
        scramble = md5(cls.seed)
        scramble.update(marshal.dumps(self.code))
        key = scramble.hexdigest()
        initfunc = cls.known_code.get(key)
        if not initfunc:
            # try to get it from file
            name = key
            if self.filename:
                prename = os.path.splitext(os.path.basename(self.filename))[0]
            else:
                prename = 'zznoname'
            name = "%s_%s" % (prename, name)
            try:
                __import__("pypy._cache." + name)
            except ImportError, x:
                # print x
                pass
            else:
                initfunc = cls.known_code[key]
        if not initfunc:
            # build it and put it into a file
            initfunc, newsrc = translate_as_module(self.code, self.filename,
                                                   self.modname)
            fname = cls.cache_path.join(name + ".py").strpath
            f = file(get_tmp_file_name(fname), "w")
            print >> f, """\
# self-destruct on double-click:
if __name__ == "__main__":
    from pypy import _cache
    import os
    namestart = os.path.join(os.path.split(_cache.__file__)[0], '%s')
    for ending in ('.py', '.pyc', '.pyo'):
        try:
            os.unlink(namestart+ending)
        except os.error:
            pass""" % name
            print >> f
            print >> f, newsrc
            print >> f, "from pypy._cache import known_code"
            print >> f, "known_code[%r] = %s" % (key, initfunc.__name__)
            f.close()
            rename_tmp_to_eventual_file_name(fname)
        w_glob = initfunc(space)
        return w_glob
 def setup_class(cls): 
     # simply compile snippets just once
     src = str(Source(snippet))
     # truncate non-compilable stuff for now:
     p = src.index('Non compilable Functions')
     src = src[:p] + '\n'
     # put our ad into snippet
     exec cls.snippet_ad in snippet.__dict__
     src += cls.snippet_ad
     # just in case of trouble, we produce a tempfile
     ini, newsrc = translate_as_module(src, tmpname = str(
         udir.join("_geninterp_test.py")))
     cls.w_glob = ini(cls.space)
示例#3
0
 def setup_class(cls):
     # simply compile snippets just once
     src = str(Source(snippet))
     # truncate non-compilable stuff for now:
     p = src.index('Non compilable Functions')
     src = src[:p] + '\n'
     # put our ad into snippet
     exec cls.snippet_ad in snippet.__dict__
     src += cls.snippet_ad
     # just in case of trouble, we produce a tempfile
     ini, newsrc = translate_as_module(src,
                                       tmpname=str(
                                           udir.join("_geninterp_test.py")))
     cls.w_glob = ini(cls.space)
示例#4
0
from pypy.translator.geninterplevel import translate_as_module, __file__ as __
from pypy.objspace.std import Space
import os
fname = os.path.join(os.path.dirname(__), "test", "rpystone.py")
src = file(fname).read()
init, ign = translate_as_module(src)  #, tmpname="/tmp/look.py")

LOOPS = 25


def test_rpystone():
    space = Space()
    modic = init(space)
    entry = space.getitem(modic, space.wrap("entrypoint"))
    # warm-up,to get everything translated
    space.call(entry, space.newtuple([space.wrap(-1)]))
    # now this is the real one
    space.call(entry, space.newtuple([space.wrap(LOOPS)]))


if __name__ == "__main__":
    test_rpystone()
示例#5
0
from pypy.translator.geninterplevel import translate_as_module, __file__ as __
from pypy.objspace.std import Space
import os
fname = os.path.join(os.path.dirname(__), "test", "rpystone.py")
src = file(fname).read()
init, ign = translate_as_module(src)#, tmpname="/tmp/look.py")

LOOPS = 25

def test_rpystone():
    space = Space()
    modic = init(space)
    entry = space.getitem(modic, space.wrap("entrypoint"))
    # warm-up,to get everything translated
    space.call(entry, space.newtuple([space.wrap(-1)]))
    # now this is the real one
    space.call(entry, space.newtuple([space.wrap(LOOPS)]))

if __name__ == "__main__":
    test_rpystone()