def _cached_compile(space, name, source, *args): from rpython.config.translationoption import CACHE_DIR from pypy.module.marshal import interp_marshal from pypy.interpreter.pycode import default_magic cachename = os.path.join(CACHE_DIR, 'frozen_importlib_%d%s' % ( default_magic, name)) try: if space.config.translating: raise IOError("don't use the cache when translating pypy") with open(cachename, 'rb') as f: previous = f.read(len(source) + 1) if previous != source + '\x00': raise IOError("source changed") w_bin = space.newbytes(f.read()) code_w = interp_marshal.loads(space, w_bin) except IOError: # must (re)compile the source ec = space.getexecutioncontext() code_w = ec.compiler.compile(source, *args) w_bin = interp_marshal.dumps(space, code_w, space.wrap(2)) content = source + '\x00' + space.bytes_w(w_bin) with open(cachename, 'wb') as f: f.write(content) return code_w
def read_code(): from pypy.module.marshal.interp_marshal import dumps filename = "pypyjit_demo.py" source = readfile(filename) ec = space.getexecutioncontext() code = ec.compiler.compile(source, filename, "exec", 0) return llstr(space.str_w(dumps(space, code, space.wrap(2))))
def read_code(): from pypy.module.marshal.interp_marshal import dumps filename = 'pypyjit_demo.py' source = readfile(filename) ec = space.getexecutioncontext() code = ec.compiler.compile(source, filename, 'exec', 0) return llstr(space.str_w(dumps(space, code, space.wrap(2))))
def command_compilewatch(cmd, expression): space = dbstate.space with non_standard_code: try: code = compile(expression, 'eval') marshalled_code = space.bytes_w(interp_marshal.dumps( space, code, space.newint(interp_marshal.Py_MARSHAL_VERSION))) except OperationError as e: revdb.send_watch(e.errorstr(space), ok_flag=0) else: revdb.send_watch(marshalled_code, ok_flag=1)
def PyMarshal_WriteObjectToString(space, w_x, version): from pypy.module.marshal.interp_marshal import dumps return dumps(space, w_x, space.newint(version))