Exemplo n.º 1
0
def set_path(kind_str, path_str):
    import os
    from pycket.racket_paths import racket_sys_paths

    if not os.path.exists(path_str):
        raise Exception("File not found : %s" % path_str)

    racket_sys_paths.set_path(W_Symbol.make(kind_str), W_Path(path_str))
Exemplo n.º 2
0
def dev_mode_metainterp_fasl_zo():
    load_fasl()
    from pycket.prims.input_output import open_infile, open_outfile
    from pycket.values import W_Path
    import os

    # Stuff for writing out the fasl
    if not os.path.exists("sample.fasl"):
        print("Generating sample.fasl first")
        sexp_to_fasl = get_primitive("s-exp->fasl")
        w_replace_sym = W_Symbol.make("replace")
        sexp = sample_sexp()
        out_port = open_outfile(W_Path("sample.fasl"), "w", w_replace_sym)
        sexp_to_fasl.call_interpret([sexp, out_port])
        out_port.close()

    fasl_to_sexp = get_primitive("fasl->s-exp")
    port = open_infile(W_Path("sample.fasl"), "r")
    r = fasl_to_sexp.call_interpret([port, w_true])
Exemplo n.º 3
0
def racket_fasl_to_sexp(fasl_file):
    from pycket.prims.input_output import open_infile
    from rpython.rlib        import rtime
    load_fasl()
    fasl_to_sexp = get_primitive("fasl->s-exp")
    port = open_infile(W_Path(fasl_file), "r")
    start_time = rtime.time()
    sexp = fasl_to_sexp.call_interpret([port, w_true])
    console_log("racket fasl->s-exp time : %s" % (rtime.time()-start_time), debug=True)
    console_log("%s" % sexp.tostring(), 1)
Exemplo n.º 4
0
def make_zo_for(linklet_name):
    from pycket.ast_vs_sexp import ast_to_sexp
    from pycket.values import W_Cons
    from pycket.prims.input_output import open_outfile

    # load the linklet
    linklet, version_sexp = load_linklet_from_fasl(linklet_name + ".fasl", set_version="expander" in linklet_name)

    # s-exp->fasl the linklet into a .zo
    sexp_to_fasl = get_primitive("s-exp->fasl")
    out_port = open_outfile(W_Path(linklet_name + ".zo"), "w", W_Symbol.make("replace"))
    linklet_sexp = ast_to_sexp(linklet)
    if "expander" in linklet_name:
        sexp_to_fasl.call_interpret([W_Cons.make(version_sexp, linklet_sexp), out_port])
    else:
        sexp_to_fasl.call_interpret([linklet_sexp, out_port])
    out_port.close()
Exemplo n.º 5
0
def initiate_boot_sequence(command_line_arguments,
                           use_compiled=False,
                           debug=False,
                           set_run_file="",
                           set_collects_dir="",
                           set_config_dir="",
                           set_addon_dir="",
                           compile_any=False,
                           do_load_regexp=False):
    from pycket.env import w_version

    load_bootstrap_linklets(debug, do_load_regexp=do_load_regexp)

    with PerfRegion("set-params"):

        # These need to be set before the boot sequence
        if set_run_file:
            console_log("Setting the 'run-file path to %s" % set_run_file)
            set_path("run-file", set_run_file)

        if set_collects_dir:
            console_log("Setting the 'collects-dir path to %s" % set_collects_dir)
            set_path("collects-dir", set_collects_dir)

        if set_config_dir:
            console_log("Setting the 'config-dir path to %s" % set_config_dir)
            set_path("config-dir", set_config_dir)

        if set_addon_dir:
            console_log("Setting the 'addon-dir path to %s" % set_addon_dir)
            set_path("addon-dir", set_addon_dir)

        # Set the cmd arguments for racket
        ccla = get_primitive("current-command-line-arguments")
        ccla.call_interpret([W_Vector.fromelements(command_line_arguments)])

        # Run "boot" to set things like (current-module-name-resolver) (o/w it's going to stay as the
        # "core-module-name-resolver" which can't recognize modules like 'racket/base (anything other than
        # things like '#%kernel really)

        console_log("Entering Boot Sequence")

        console_log("(boot)")
        boot = get_primitive("boot")
        boot.call_interpret([])

        console_log("(current-library-collection-links (find-library-collection-links))")
        flcl = get_primitive("find-library-collection-links")
        lib_coll_links = flcl.call_interpret([])
        clcl = get_primitive("current-library-collection-links")
        clcl.call_interpret([lib_coll_links])

        console_log("(current-library-collection-paths (find-library-collection-paths))")
        flcp = get_primitive("find-library-collection-paths")
        lib_coll_paths = flcp.call_interpret([])
        clcp = get_primitive("current-library-collection-paths")
        clcp.call_interpret([lib_coll_paths])

        console_log("(read-accept-compiled true)")
        read_accept_compiled = get_primitive("read-accept-compiled")
        read_accept_compiled.call_interpret([w_true])

        compiled_file_path = "compiled/pycket"
        ucfp = get_primitive("use-compiled-file-paths")
        if use_compiled:
            console_log("(use-compiled-file-paths %s)" % compiled_file_path)
            ucfp.call_interpret([W_WrappedConsProper.make(W_String.make(compiled_file_path), w_null)])
        else:
            ucfp.call_interpret([w_null])
            console_log("(use-compiled-file-paths null)")

        cctm = get_primitive("current-compile-target-machine")
        if compile_any:
            cctm.call_interpret([w_false])

        # set the current directory to the current directory
        import os
        c_dir = os.getcwd()
        console_log("(current-directory %s)" % c_dir)
        # We can't call the current-directory like a primitive
        # because it prints a report to stdout
        from pycket.values_parameter import top_level_config
        from pycket.prims.general import current_directory_param
        c = top_level_config.get(current_directory_param)
        assert isinstance(c, W_ThreadCell)
        c.set(W_Path(c_dir))

        console_log("...Boot Sequence Completed")
        from pycket.env import w_global_config as glob
        glob.boot_is_completed()

    return 0