Exemplo n.º 1
0
def run_file(fname, *replacements, **kwargs):
    modname = os.path.join(os.path.dirname(__file__), fname)
    ast = parse_file(fname, *replacements, **kwargs)
    env = ToplevelEnv()
    env.globalconfig.load(ast)
    env.module_env.add_module(modname, ast)
    return interpret_module(ast, env)
Exemplo n.º 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
Exemplo n.º 3
0
def make_linklet(linkl_str, l_name="test_linklet_sexp"):
    #"(linklet () (x) (define-values (x) 4))"
    linkl_sexp = string_to_sexp(linkl_str)
    try:
        do_compile_linklet(linkl_sexp, values.W_Symbol.make(l_name), w_false,
                           w_false, w_false, ToplevelEnv(), NilCont())
    except Done, e:
        l = e.values  # W_Linklet
        return l
Exemplo n.º 4
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)
Exemplo n.º 5
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
Exemplo n.º 6
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)
Exemplo n.º 7
0
def run_ast(ast):
    env = ToplevelEnv()
    env.globalconfig.load(ast)
    mod = interpret_module(ast, env)
    return mod