Example #1
0
def test_nanos():
    space = Space()
    # manually imports app_main.py
    filename = os.path.join(this_dir, 'app_main.py')
    w_dict = space.newdict()
    space.exec_(open(filename).read(), w_dict, w_dict)
    entry_point = create_entry_point(space, w_dict)
    entry_point(['', '-c', 'print 42'])
Example #2
0
def test_nanos():
    space = Space()
    # manually imports app_main.py
    filename = os.path.join(this_dir, 'app_main.py')
    w_dict = space.newdict()
    space.exec_(open(filename).read(), w_dict, w_dict)
    entry_point = create_entry_point(space, w_dict)
    entry_point(['', '-c', 'print 42'])
Example #3
0
def test_nanos():
    space = Space()
    # manually imports app_main.py
    filename = os.path.join(this_dir, 'app_main.py')
    w_dict = space.newdict()
    space.exec_(open(filename).read(), w_dict, w_dict)
    entry_point = create_entry_point(space, w_dict)

    # check that 'os' is not in sys.modules
    assert not space.is_true(
        space.call_method(space.sys.get('modules'),
                          '__contains__', space.wrap('os')))
    # But that 'sys' is still present
    assert space.is_true(
        space.call_method(space.sys.get('modules'),
                          '__contains__', space.wrap('sys')))

    entry_point(['', '-c', 'print 42'])
Example #4
0
def codetest(source, functionname, args):
    """Compile and run the given code string, and then call its function
    named by 'functionname' with arguments 'args'."""
    from pypy.interpreter import baseobjspace
    from pypy.interpreter import pyframe, gateway, module
    space = Space()

    source = str(py.code.Source(source).strip()) + '\n'

    w = space.wrap
    w_code = space.builtin.call('compile', 
            w(source), w('<string>'), w('exec'), w(0), w(0))

    tempmodule = module.Module(space, w("__temp__"))
    w_glob = tempmodule.w_dict
    space.setitem(w_glob, w("__builtins__"), space.builtin)

    code = space.unwrap(w_code)
    code.exec_code(space, w_glob, w_glob)

    wrappedargs = [w(a) for a in args]
    wrappedfunc = space.getitem(w_glob, w(functionname))
    def callit():
        return space.call_function(wrappedfunc, *wrappedargs)
    return callit
    try:
        w_output = space.call_function(wrappedfunc, *wrappedargs)
    except baseobjspace.OperationError, e:
        #e.print_detailed_traceback(space)
        return '<<<%s>>>' % e.errorstr(space)
Example #5
0
config.objspace.usemodules._weakref = False
config.objspace.usemodules._sre = False
config.objspace.usemodules._lsprof = False
#
config.objspace.usemodules._rawffi = False
config.objspace.usemodules.micronumpy = False
#
set_pypy_opt_level(config, level="jit")

config.objspace.std.multimethods = "mrd"
multimethod.Installer = multimethod.InstallerVersion2
print config

import sys, pdb

space = Space(config)
w_dict = space.newdict(module=True)


def readfile(filename):
    fd = os.open(filename, os.O_RDONLY, 0)
    blocks = []
    while True:
        data = os.read(fd, 4096)
        if not data:
            break
        blocks.append(data)
    os.close(fd)
    return "".join(blocks)

Example #6
0
set_pypy_opt_level(config, level='jit')

if BACKEND == 'c':
    config.objspace.std.multimethods = 'mrd'
    multimethod.Installer = multimethod.InstallerVersion2
elif BACKEND == 'cli':
    config.objspace.std.multimethods = 'doubledispatch'
    multimethod.Installer = multimethod.InstallerVersion1
    config.translation.backend = 'cli'
else:
    assert False
print config

import sys, pdb

space = Space(config)
w_dict = space.newdict(module=True)


def readfile(filename):
    fd = os.open(filename, os.O_RDONLY, 0)
    blocks = []
    while True:
        data = os.read(fd, 4096)
        if not data:
            break
        blocks.append(data)
    os.close(fd)
    return ''.join(blocks)

Example #7
0
def test_nanos():
    space = Space()
    # manually imports app_main.py
    filename = os.path.join(this_dir, 'app_main.py')
    w_dict = space.newdict()
    space.exec_(open(filename).read(), w_dict, w_dict)
    entry_point = create_entry_point(space, w_dict)

    # check that 'os' is not in sys.modules
    assert not space.is_true(
        space.call_method(space.sys.get('modules'), '__contains__',
                          space.wrap('os')))
    # But that 'sys' is still present
    assert space.is_true(
        space.call_method(space.sys.get('modules'), '__contains__',
                          space.wrap('sys')))

    entry_point(['', '-c', 'print 42'])
Example #8
0
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)]))
Example #9
0
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)]))