Beispiel #1
0
def test_cont_fusion():
    from pycket.env import SymList, ToplevelEnv
    from pycket.interpreter import (
        LetCont, BeginCont,
        FusedLet0Let0Cont, FusedLet0BeginCont,
    )
    from pycket.config import get_testing_config
    from pycket.cont   import NilCont
    args = SymList([])
    counts = [1]
    rhss = 1
    letast1 = Let(args, counts, [1], [2])
    letast2 = Let(args, counts, [1], [2])
    env = ToplevelEnv(get_testing_config(**{"pycket.fuse_conts": True}))
    prev = NilCont()
    let2 = LetCont.make([], letast2, 0, env, prev)
    let1 = LetCont.make([], letast1, 0, env, let2)
    assert isinstance(let1, FusedLet0Let0Cont)
    assert let1.prev is prev
    assert let1.env is env

    let2 = BeginCont(letast2.counting_asts[0], env, prev)
    let1 = LetCont.make([], letast1, 0, env, let2)
    assert isinstance(let1, FusedLet0BeginCont)
    assert let1.prev is prev
    assert let1.env is env
Beispiel #2
0
    def call_interpret(self, racket_vals):
        from pycket.interpreter import Done, interpret_one
        from pycket.env import ToplevelEnv, w_global_config
        from pycket.cont import NilCont, Prompt
        from pycket import values, values_parameter
        from pycket.prims.control import default_uncaught_exception_handler

        __pycketconfig = w_global_config.get_pycketconfig()

        t_env = ToplevelEnv(__pycketconfig)

        cont = NilCont()
        cont = Prompt(values.w_default_continuation_prompt_tag, None, t_env,
                      cont)
        cont.update_cm(values.parameterization_key,
                       values_parameter.top_level_config)
        cont.update_cm(values.exn_handler_key,
                       default_uncaught_exception_handler)

        try:
            ast, env, cont = self.call_with_extra_info(racket_vals, t_env,
                                                       cont, None)
            return interpret_one(ast, env, cont)
        except Done, e:
            return e.values
Beispiel #3
0
    def instantiate(self, import_instances_ls, config, prompt=False, target=None, env=None, cont=None):
        from pycket.env import ToplevelEnv
        env = ToplevelEnv(config)

        if not cont:
            cont = NilCont()
            cont.update_cm(parameterization_key, top_level_config)
            cont.update_cm(exn_handler_key, default_uncaught_exception_handler)

        if prompt:
            Prompt(w_default_continuation_prompt_tag, None, env, cont)

        for group_index, import_group in enumerate(self.importss):
            for imp in import_group:
                w_imp_var = import_instances_ls[group_index].get_var(imp.ext_id)
                env.toplevel_env().toplevel_set(imp.id, w_imp_var)

        return_val = True
        if not target:
            target = W_LinkletInstance(self.name, {})
            return_val = False

        # FIXME: gensym this ref name and put it in the linklet at compile
        env.toplevel_env().toplevel_set(mksym("instance-variable-reference"), target)

        for exp_sym, exp_obj in self.exports.iteritems():
            if target and exp_obj.ext_id in target.vars:
                var = target.vars[exp_obj.ext_id]
            else:
                var = W_LinkletVar(w_uninitialized, exp_obj.ext_id, w_false)
                target.vars[exp_obj.ext_id] = var

            env.toplevel_env().toplevel_set(exp_obj.int_id, var)

        if len(self.forms) == 0:
            # no need for any evaluation, just return the instance or the value
            if return_val:
                return return_value(w_void, env, cont)
            else:
                return return_value(target, env, cont)

        return instantiate_loop(self.forms, 0, return_val, target, env, cont)
Beispiel #4
0
def dev_mode_entry_sexp(eval_sexp_str=None):
    from pycket.values import W_Fixnum
    from pycket.util import console_log
    from pycket.prims.linklet import W_LinkletInstance

    from pycket.prims.linklet import do_compile_linklet
    from pycket.env import ToplevelEnv
    from pycket.cont import NilCont

    linkl_sexp = racket_read_str(eval_sexp_str)
    linkl = None
    try:
        do_compile_linklet(linkl_sexp, W_Symbol.make("linkl"), w_false,
                           w_false, w_false, ToplevelEnv(), NilCont())
    except Done, e:
        linkl = e.values
Beispiel #5
0
    def instantiate(self,
                    import_instances_ls,
                    config,
                    prompt=False,
                    target=None,
                    env=None,
                    cont=None):
        from pycket.env import ToplevelEnv
        env = ToplevelEnv(config)

        if not cont:
            cont = NilCont()
            cont.update_cm(parameterization_key, top_level_config)
            cont.update_cm(exn_handler_key, default_uncaught_exception_handler)

        if prompt:
            Prompt(w_default_continuation_prompt_tag, None, env, cont)

        for group_index, import_group in enumerate(self.importss):
            for imp in import_group:
                w_imp_var = import_instances_ls[group_index].get_var(
                    imp.ext_id)
                env.toplevel_env().toplevel_set(imp.id, w_imp_var)

        return_val = True
        if not target:
            target = W_LinkletInstance(self.name, {})
            return_val = False

        # FIXME: gensym this ref name and put it in the linklet at compile
        env.toplevel_env().toplevel_set(mksym("instance-variable-reference"),
                                        target)

        for exp_sym, exp_obj in self.exports.iteritems():
            if target and exp_obj.ext_id in target.vars:
                var = target.vars[exp_obj.ext_id]
            else:
                var = W_LinkletVar(w_uninitialized, exp_obj.ext_id, w_false)
                target.vars[exp_obj.ext_id] = var

            env.toplevel_env().toplevel_set(exp_obj.int_id, var)

        if len(self.forms) == 0:
            # no need for any evaluation, just return the instance or the value
            if return_val:
                return return_value(w_void, env, cont)
            else:
                return return_value(target, env, cont)

        return instantiate_loop(self.forms, 0, return_val, target, env, cont)
Beispiel #6
0
    def call_interpret(self, racket_vals):
        from pycket.interpreter import Done, interpret_one
        from pycket.env import ToplevelEnv, w_global_config
        from pycket.cont import NilCont, Prompt
        from pycket import values, values_parameter
        from pycket.prims.control import default_uncaught_exception_handler

        __pycketconfig = w_global_config.get_pycketconfig()

        t_env = ToplevelEnv(__pycketconfig)

        cont = NilCont()
        cont = Prompt(values.w_default_continuation_prompt_tag, None, t_env, cont)
        cont.update_cm(values.parameterization_key, values_parameter.top_level_config)
        cont.update_cm(values.exn_handler_key, default_uncaught_exception_handler)

        try:
            ast, env, cont = self.call_with_extra_info(racket_vals, t_env, cont, None)
            return interpret_one(ast, env, cont)
        except Done, e:
            return e.values