Ejemplo n.º 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)
    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
Ejemplo n.º 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)
    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
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 5
0
 def create_flowspace_config(self):
     # XXX this is a hack: we create a new config, which is only used
     # for the flow object space. The problem is that the flow obj space
     # needs an objspace config, but the thing we are translating might not
     # have one (or worse we are translating pypy and the flow space picks
     # up strange options of the pypy we are translating). Therefore we need
     # to construct this new config
     self.flowconfig = get_combined_translation_config(
         pypy_optiondescription, self.config, translating=True)
     self.flowconfig.objspace.name = "flow"
Ejemplo n.º 6
0
 def create_flowspace_config(self):
     # XXX this is a hack: we create a new config, which is only used
     # for the flow object space. The problem is that the flow obj space
     # needs an objspace config, but the thing we are translating might not
     # have one (or worse we are translating pypy and the flow space picks
     # up strange options of the pypy we are translating). Therefore we need
     # to construct this new config
     self.flowconfig = get_combined_translation_config(
             pypy_optiondescription, self.config, translating=True)
     self.flowconfig.objspace.name = "flow"
Ejemplo n.º 7
0
 def translate(self, targetname):
     config = get_combined_translation_config(translating=True)
     config.translation.backend = 'c'
     config.translation.gc = 'boehm'
     targetspec = 'pypy.translator.goal.' + targetname
     mod = __import__(targetspec)
     targetspec_dic = sys.modules[targetspec].__dict__
     t = translator.TranslationContext()
     drv = driver.TranslationDriver.from_targetspec(targetspec_dic, config, [],
                                                    empty_translator=t)
     drv.exe_name = None
     drv.proceed('compile')
Ejemplo n.º 8
0
 def translate(self, targetname):
     config = get_combined_translation_config(translating=True)
     config.translation.backend = 'c'
     config.translation.gc = 'boehm'
     targetspec = 'pypy.translator.goal.' + targetname
     mod = __import__(targetspec)
     targetspec_dic = sys.modules[targetspec].__dict__
     t = translator.TranslationContext()
     drv = driver.TranslationDriver.from_targetspec(targetspec_dic,
                                                    config, [],
                                                    empty_translator=t)
     drv.exe_name = None
     drv.proceed('compile')
Ejemplo n.º 9
0
def get_pypy_config(overrides=None, translating=False):
    from pypy.config.translationoption import get_combined_translation_config
    return get_combined_translation_config(pypy_optiondescription,
                                           overrides=overrides,
                                           translating=translating)
Ejemplo n.º 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://codespeak.net/pypy/dist/pypy/doc/config/commandline.html"
        sys.exit(0)
    
    return targetspec_dic, translateconfig, config, args
Ejemplo n.º 11
0
def get_pypy_config(overrides=None, translating=False):
    from pypy.config.translationoption import get_combined_translation_config
    return get_combined_translation_config(
            pypy_optiondescription, overrides=overrides,
            translating=translating)
Ejemplo n.º 12
0
import autopath
from pypy.config.config import to_optparse
from pypy.config.translationoption import get_combined_translation_config
from pypy.config.pypyoption import get_pypy_config

line = os.environ['COMP_LINE']
lines = line.split(" ")
last = lines[-1]
was = 'targetpypystandalone.py' in lines
if not last:
    sys.exit(0)


def get_optp(conf):
    optp = to_optparse(conf)
    opts = optp.option_list
    for i in [g.option_list for g in optp.option_groups]:
        opts += i
    opt_s = [i.get_opt_string() for i in opts]
    return opt_s


if not was:
    opt_s = get_optp(get_combined_translation_config())
else:
    opt_s = get_optp(get_pypy_config())
to_p = [i for i in opt_s if i.startswith(last)]
for i in to_p:
    print i
#d = [config.getkey(path) for path in config.getpaths()]
Ejemplo n.º 13
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
Ejemplo n.º 14
0
def test_no_gcrootfinder_with_boehm():
    config = get_combined_translation_config()
    config.translation.gcrootfinder = "shadowstack"
    py.test.raises(ConflictConfigError, set_opt_level, config, '0')