Exemple #1
0
def main(argv):
    config = get_combined_translation_config(pypy_optiondescription,
        overrides=OVERRIDES, translating=True)
    config.objspace.nofaking = True
    config.objspace.compiler = "ast"
    config.translating = True
    set_opt_level(config, '1')
    set_pypy_opt_level(config, '1')
    enable_allworkingmodules(config)

    space = make_objspace(config)
    policy = PyPyAnnotatorPolicy(single_space = space)
    policy.allow_someobjects = False

    def interpret(source, context):
        source = charp2str(source)
        w_dict = space.newdict()
        try:
            ec = space.getexecutioncontext()
            pycode = ec.compiler.compile(source, 'source', 'exec', 0)
            pycode.exec_code(space, w_dict, w_dict)
        except OperationError, e:
            print "OperationError:"
            print " operror-type: " + e.w_type.getname(space)
            print " operror-value: " + space.str_w(space.str(e.get_w_value(space)))
            return 1
        return 0
Exemple #2
0
def main(argv):
    config = get_combined_translation_config(pypy_optiondescription,
        overrides=OVERRIDES, translating=True)
    config.objspace.nofaking = True
    config.objspace.compiler = "ast"
    config.translating = True
    set_opt_level(config, '1')
    set_pypy_opt_level(config, '1')
    enable_allworkingmodules(config)

    space = make_objspace(config)
    ctx = JavaScriptContext(space)
    policy = PyPyAnnotatorPolicy(single_space = space)
    policy.allow_someobjects = False

    def interpret(source, context):
        source = charp2str(source)
        w_dict = space.newdict()
        ctx._ctx = context
        glob = ctx.globals()
        lst = ctx.propertylist(glob.js_val)
        for elem in lst:
            w_val = space.wrap(JSObject(ctx, ctx.get(glob.js_val, elem)))
            space.setitem(w_dict, space.wrap(elem), w_val)
        try:
            ec = space.getexecutioncontext()
            pycode = ec.compiler.compile(source, 'source', 'exec', 0)
            pycode.exec_code(space, w_dict, w_dict)
        except OperationError, e:
            print "OperationError:"
            print " operror-type: " + e.w_type.getname(space, '?')
            print " operror-value: " + space.str_w(space.str(e.w_value))
            return 1
        return 0
Exemple #3
0
def main(argv):
    config = get_combined_translation_config(pypy_optiondescription,
                                             overrides=OVERRIDES,
                                             translating=True)
    config.objspace.nofaking = True
    config.objspace.compiler = "ast"
    config.translating = True
    set_opt_level(config, '1')
    set_pypy_opt_level(config, '1')
    enable_allworkingmodules(config)

    space = make_objspace(config)
    policy = PyPyAnnotatorPolicy(single_space=space)
    policy.allow_someobjects = False

    def interpret(source, context):
        source = charp2str(source)
        w_dict = space.newdict()
        try:
            ec = space.getexecutioncontext()
            pycode = ec.compiler.compile(source, 'source', 'exec', 0)
            pycode.exec_code(space, w_dict, w_dict)
        except OperationError, e:
            print "OperationError:"
            print " operror-type: " + e.w_type.getname(space, '?')
            print " operror-value: " + space.str_w(
                space.str(e.get_w_value(space)))
            return 1
        return 0
Exemple #4
0
def main(argv):
    config = get_combined_translation_config(pypy_optiondescription,
                                             overrides=OVERRIDES,
                                             translating=True)
    config.objspace.nofaking = True
    config.objspace.compiler = "ast"
    config.translating = True
    set_opt_level(config, '1')
    set_pypy_opt_level(config, '1')
    enable_allworkingmodules(config)

    space = make_objspace(config)
    ctx = JavaScriptContext(space)
    policy = PyPyAnnotatorPolicy(single_space=space)
    policy.allow_someobjects = False

    def interpret(source, context):
        source = charp2str(source)
        w_dict = space.newdict()
        ctx._ctx = context
        glob = ctx.globals()
        lst = ctx.propertylist(glob.js_val)
        for elem in lst:
            w_val = space.wrap(JSObject(ctx, ctx.get(glob.js_val, elem)))
            space.setitem(w_dict, space.wrap(elem), w_val)
        try:
            ec = space.getexecutioncontext()
            pycode = ec.compiler.compile(source, 'source', 'exec', 0)
            pycode.exec_code(space, w_dict, w_dict)
        except OperationError, e:
            print "OperationError:"
            print " operror-type: " + e.w_type.getname(space, '?')
            print " operror-value: " + space.str_w(space.str(e.w_value))
            return 1
        return 0
Exemple #5
0
def test_set_opt_level():
    conf = get_pypy_config()
    set_opt_level(conf, '0')
    assert conf.translation.gc == 'boehm'
    assert conf.translation.backendopt.none == True
    conf = get_pypy_config()
    set_opt_level(conf, '2')
    assert conf.translation.gc != 'boehm'
    assert not conf.translation.backendopt.none
    conf = get_pypy_config()
    set_opt_level(conf, 'mem')
    assert conf.translation.gc == 'markcompact'
    assert not conf.translation.backendopt.none
Exemple #6
0
def test_set_opt_level():
    conf = get_pypy_config()
    set_opt_level(conf, '0')
    assert conf.translation.gc == 'boehm'
    assert conf.translation.backendopt.none == True
    conf = get_pypy_config()
    set_opt_level(conf, '2')
    assert conf.translation.gc != 'boehm'
    assert not conf.translation.backendopt.none
    conf = get_pypy_config()
    set_opt_level(conf, 'mem')
    assert conf.translation.gcremovetypeptr
    assert not conf.translation.backendopt.none
Exemple #7
0
if not hasattr(py.test.config.option, 'ootype'):
    import sys
    print >> sys.stderr, __doc__
    sys.exit(2)

if py.test.config.option.ootype:
    BACKEND = 'cli'
else:
    BACKEND = 'c'

config = get_pypy_config(translating=True)
config.translation.backendopt.inline_threshold = 0.1
config.translation.gc = 'boehm'
config.objspace.nofaking = True
config.translating = True
set_opt_level(config, level='jit')
config.objspace.allworkingmodules = False
config.objspace.usemodules.pypyjit = True
config.objspace.usemodules.array = False
config.objspace.usemodules._weakref = True
config.objspace.usemodules._sre = False
config.objspace.usemodules._lsprof = False
#
config.objspace.usemodules._ffi = True
config.objspace.usemodules.micronumpy = False
#
set_pypy_opt_level(config, level='jit')

if BACKEND == 'c':
    config.objspace.std.multimethods = 'mrd'
    multimethod.Installer = multimethod.InstallerVersion2
Exemple #8
0
def parse_options_and_load_target():
    opt_parser = optparse.OptionParser(usage="%prog [options] [target] [target-specific-options]",
                                       prog="translate",
                                       formatter=OptHelpFormatter(),
                                       add_help_option=False)

    opt_parser.disable_interspersed_args()

    config = get_combined_translation_config(
                overrides=OVERRIDES, translating=True)
    to_optparse(config, parser=opt_parser, useoptions=['translation.*'])
    translateconfig = Config(translate_optiondescr)
    to_optparse(translateconfig, parser=opt_parser)

    options, args = opt_parser.parse_args()

    # set goals and skipped_goals
    reset = False
    for name, _, _, _ in GOALS:
        if name.startswith('?'):
            continue
        if getattr(translateconfig.goal_options, name):
            if name not in translateconfig.goals:
                translateconfig.goals.append(name)
        if getattr(translateconfig.goal_options, 'no_'+name):
            if name not in translateconfig.skipped_goals:
                if not reset:
                    translateconfig.skipped_goals[:] = []
                    reset = True
                translateconfig.skipped_goals.append(name)
        
    if args:
        arg = args[0]
        args = args[1:]
        if os.path.isfile(arg+'.py'):
            assert not os.path.isfile(arg), (
                "ambiguous file naming, please rename %s" % arg)
            translateconfig.targetspec = arg
        elif os.path.isfile(arg) and arg.endswith('.py'):
            translateconfig.targetspec = arg[:-3]
        else:
            log.ERROR("Could not find target %r" % (arg, ))
            sys.exit(1)

    # apply the platform settings
    set_platform(config)

    targetspec = translateconfig.targetspec
    targetspec_dic = load_target(targetspec)

    if args and not targetspec_dic.get('take_options', False):
        log.WARNING("target specific arguments supplied but will be ignored: %s" % ' '.join(args))

    # give the target the possibility to get its own configuration options
    # into the config
    if 'get_additional_config_options' in targetspec_dic:
        optiondescr = targetspec_dic['get_additional_config_options']()
        config = get_combined_translation_config(
                optiondescr,
                existing_config=config,
                translating=True)

    # apply the optimization level settings
    set_opt_level(config, translateconfig.opt)

    # let the target modify or prepare itself
    # based on the config
    if 'handle_config' in targetspec_dic:
        targetspec_dic['handle_config'](config, translateconfig)

    # perform checks (if any) on the final config
    final_check_config(config)

    if translateconfig.help:
        opt_parser.print_help()
        if 'print_help' in targetspec_dic:
            print "\n\nTarget specific help:\n\n"
            targetspec_dic['print_help'](config)
        print "\n\nFor detailed descriptions of the command line options see"
        print "http://codespeak.net/pypy/dist/pypy/doc/config/commandline.html"
        sys.exit(0)
    
    return targetspec_dic, translateconfig, config, args
Exemple #9
0
    import sys
    print >> sys.stderr, __doc__
    sys.exit(2)

if py.test.config.option.ootype:
    BACKEND = 'cli'
else:
    BACKEND = 'c'

config = get_pypy_config(translating=True)
config.translation.backendopt.inline_threshold = 0
config.translation.gc = 'boehm'
config.objspace.nofaking = True
config.objspace.compiler = "ast"
config.translating = True
set_opt_level(config, level='jit')
config.objspace.allworkingmodules = False
config.objspace.usemodules.pypyjit = True
config.objspace.usemodules._weakref = False
config.objspace.usemodules._sre = False
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
Exemple #10
0
def parse_options_and_load_target():
    opt_parser = optparse.OptionParser(
        usage="%prog [options] [target] [target-specific-options]",
        prog="translate",
        formatter=OptHelpFormatter(),
        add_help_option=False)

    opt_parser.disable_interspersed_args()

    config = get_combined_translation_config(overrides=OVERRIDES,
                                             translating=True)
    to_optparse(config, parser=opt_parser, useoptions=['translation.*'])
    translateconfig = Config(translate_optiondescr)
    to_optparse(translateconfig, parser=opt_parser)

    options, args = opt_parser.parse_args()

    # set goals and skipped_goals
    reset = False
    for name, _, _, _ in GOALS:
        if name.startswith('?'):
            continue
        if getattr(translateconfig.goal_options, name):
            if name not in translateconfig.goals:
                translateconfig.goals.append(name)
        if getattr(translateconfig.goal_options, 'no_' + name):
            if name not in translateconfig.skipped_goals:
                if not reset:
                    translateconfig.skipped_goals[:] = []
                    reset = True
                translateconfig.skipped_goals.append(name)

    if args:
        arg = args[0]
        args = args[1:]
        if os.path.isfile(arg + '.py'):
            assert not os.path.isfile(arg), (
                "ambiguous file naming, please rename %s" % arg)
            translateconfig.targetspec = arg
        elif os.path.isfile(arg) and arg.endswith('.py'):
            translateconfig.targetspec = arg[:-3]
        else:
            log.ERROR("Could not find target %r" % (arg, ))
            sys.exit(1)

    # apply the platform settings
    set_platform(config)

    targetspec = translateconfig.targetspec
    targetspec_dic = load_target(targetspec)

    if args and not targetspec_dic.get('take_options', False):
        log.WARNING(
            "target specific arguments supplied but will be ignored: %s" %
            ' '.join(args))

    # give the target the possibility to get its own configuration options
    # into the config
    if 'get_additional_config_options' in targetspec_dic:
        optiondescr = targetspec_dic['get_additional_config_options']()
        config = get_combined_translation_config(optiondescr,
                                                 existing_config=config,
                                                 translating=True)

    # apply the optimization level settings
    set_opt_level(config, translateconfig.opt)

    # let the target modify or prepare itself
    # based on the config
    if 'handle_config' in targetspec_dic:
        targetspec_dic['handle_config'](config, translateconfig)

    # perform checks (if any) on the final config
    final_check_config(config)

    if translateconfig.help:
        opt_parser.print_help()
        if 'print_help' in targetspec_dic:
            print "\n\nTarget specific help:\n\n"
            targetspec_dic['print_help'](config)
        print "\n\nFor detailed descriptions of the command line options see"
        print "http://pypy.readthedocs.org/en/latest/config/commandline.html"
        sys.exit(0)

    return targetspec_dic, translateconfig, config, args
Exemple #11
0
    import sys

    print >> sys.stderr, __doc__
    sys.exit(2)

if py.test.config.option.ootype:
    BACKEND = "cli"
else:
    BACKEND = "c"

config = get_pypy_config(translating=True)
config.translation.backendopt.inline_threshold = 0.1
config.translation.gc = "boehm"
config.objspace.nofaking = True
config.translating = True
set_opt_level(config, level="jit")
config.objspace.allworkingmodules = False
config.objspace.usemodules.pypyjit = True
config.objspace.usemodules.array = False
config.objspace.usemodules._weakref = True
config.objspace.usemodules._sre = False
config.objspace.usemodules._lsprof = False
#
config.objspace.usemodules._ffi = True
config.objspace.usemodules.micronumpy = False
#
set_pypy_opt_level(config, level="jit")

if BACKEND == "c":
    config.objspace.std.multimethods = "mrd"
    multimethod.Installer = multimethod.InstallerVersion2