コード例 #1
0
ファイル: main.c プロジェクト: wesjdj/parrot
int
main(int argc, const char *argv[])
{
    int          stacktop;
    const char  *sourcefile;
    Parrot_PMC   interp;
    Parrot_PMC   bytecodepmc;
    Parrot_PMC   argsarray;
    int          status;
    int          pir_argc;
    const char **pir_argv;
    const char  *core = "slow";
    int run_pbc = 0;
    Parrot_Init_Args *initargs;
    Parrot_Int trace = 0;

    GET_INIT_STRUCT(initargs);
    /* internationalization setup */
    /* setlocale(LC_ALL, ""); */
    /* PARROT_BINDTEXTDOMAIN(PACKAGE, LOCALEDIR); */
    /* PARROT_TEXTDOMAIN(PACKAGE); */

    /* Parse minimal subset of flags */
    parseflags_minimal(initargs, argc, argv);

    if (!(Parrot_api_make_interpreter(NULL, 0, initargs, &interp) &&
          Parrot_set_config_hash(interp) &&
          Parrot_api_set_executable_name(interp, argv[0]))) {
        fprintf(stderr, "PARROT VM: Could not initialize new interpreter");
        show_last_error_and_exit(interp);
    }

    /* Parse flags */
    sourcefile = parseflags(interp, argc, argv, &pir_argc, &pir_argv, &core, &trace);
    if (!Parrot_api_set_runcore(interp, core, trace))
        show_last_error_and_exit(interp);

    if (!Parrot_api_wrap_imcc_hack(
        interp, sourcefile, argc, argv, &bytecodepmc, &run_pbc, imcc_run_api))
        show_last_error_and_exit(interp);

    if (run_pbc) {
        if (!Parrot_api_pmc_wrap_string_array(interp, pir_argc, pir_argv, &argsarray))
            show_last_error_and_exit(interp);
        if (!Parrot_api_run_bytecode(interp, bytecodepmc, argsarray))
            show_last_error_and_exit(interp);
    }

    /* Clean-up after ourselves */
    Parrot_api_destroy_interpreter(interp);
    exit(EXIT_SUCCESS);
}
コード例 #2
0
ファイル: blu.c プロジェクト: zslayton/blu
        int main(int argc, const char *argv[])
        {
            PMC                 *interp;
            PMC                 *pbc;
            PMC                 *argsarray;
            const unsigned char *program_code_addr;

            Parrot_Init_Args    *initargs;
            GET_INIT_STRUCT(initargs);

            initargs->gc_system = GCCORE;

            program_code_addr = (const unsigned char *)get_program_code();

            if (!program_code_addr)
                exit(EXIT_FAILURE);

            if (!(Parrot_api_make_interpreter(NULL, 0, initargs, &interp) &&
                  Parrot_set_config_hash(interp) &&
                  Parrot_api_set_executable_name(interp, argv[0]) &&
                  Parrot_api_set_runcore(interp, RUNCORE, TRACE))) {
                fprintf(stderr, "PARROT VM: Could not initialize new interpreter\n");
                show_last_error_and_exit(interp);
            }

            setup_pir_compregs(interp);

            if (!Parrot_api_pmc_wrap_string_array(interp, argc, argv, &argsarray)) {
                fprintf(stderr, "PARROT VM: Could not build args array");
                show_last_error_and_exit(interp);
            }

            if (!Parrot_api_load_bytecode_bytes(interp,
                                                program_code_addr,
                                                (Parrot_Int) bytecode_size,
                                                &pbc)) {
                fprintf(stderr, "PARROT VM: Could not load bytecode\n");
                show_last_error_and_exit(interp);
            }

            if (!Parrot_api_run_bytecode(interp, pbc, argsarray)) {
                show_last_error_and_exit(interp);
            }

            if (!Parrot_api_destroy_interpreter(interp)) {
                fprintf(stderr, "PARROT VM: Could not destroy interpreter\n");
                show_last_error_and_exit(interp);
            }

            exit(EXIT_SUCCESS);
        }
コード例 #3
0
ファイル: main.c プロジェクト: soh-cah-toa/parrot
int
main(int argc, const char *argv[])
{
    Parrot_PMC interp, bytecodepmc, sysargs, pirargs;
    Parrot_Init_Args *initargs;
    struct init_args_t parsed_flags;

    GET_INIT_STRUCT(initargs);

    /* Parse minimal subset of flags */
    parseflags_minimal(initargs, argc, argv);

    if (!Parrot_api_make_interpreter(NULL, 0, initargs, &interp)) {
        fprintf(stderr, "PARROT VM: Could not allocate new interpreter\n");
        if (interp != NULL)
            show_last_error_and_exit(interp);
        else
            fprintf(stderr, "PARROT VM: No interpreter. Cannot get error details\n");
        exit(EXIT_FAILURE);
    }
    if (!(Parrot_set_config_hash(interp) &&
          Parrot_api_set_executable_name(interp, argv[0]))) {
        fprintf(stderr, "PARROT VM: Could not initialize new interpreter\n");
        show_last_error_and_exit(interp);
    }

    /* Parse flags */
    parseflags(interp, argc, argv, &parsed_flags);

    if (!Parrot_api_set_runcore(interp, parsed_flags.run_core_name, parsed_flags.trace))
        show_last_error_and_exit(interp);

    Parrot_api_toggle_gc(interp, 0);
    setup_imcc(interp);
    if (!parsed_flags.turn_gc_off)
        Parrot_api_toggle_gc(interp, 1);

    if (!(Parrot_api_pmc_wrap_string_array(interp, parsed_flags.sysargc,  parsed_flags.sysargv,
                                            &sysargs)
    && Parrot_api_pmc_wrap_string_array(interp, parsed_flags.progargc, parsed_flags.progargv,
                                        &pirargs)
    && Parrot_api_load_bytecode_bytes(interp, get_program_code(), get_program_code_size(),
                                        &bytecodepmc)
    && Parrot_api_run_bytecode(interp, bytecodepmc, sysargs, pirargs)))
        show_last_error_and_exit(interp);

    /* Clean-up after ourselves */
    Parrot_api_destroy_interpreter(interp);
    exit(EXIT_SUCCESS);
}
コード例 #4
0
ファイル: mod_parrot_run.c プロジェクト: bdw/mod_parrot
/**
 * Start handling a request with a given interpreter to a determined route
 *
 * @param Parrot_PMC interp_pmc
 * @param request_rec * request
 * @param mod_parrot_route * route
 * @return apr_status_t a status code (OK or a HTTP code)
 **/
apr_status_t mod_parrot_run(Parrot_PMC interp_pmc, request_rec *request,
                            mod_parrot_route * route) {
    mod_parrot_conf * conf;
    Parrot_PMC loader_pmc, args_pmc;
    Parrot_PMC request_pmc, route_pmc;
    char * path;
    /* get the configuration */
    conf = ap_get_module_config(request->server->module_config, &mod_parrot);
    /* load libraries, preferably move this somewhere earlier */
    /*
     * for the record, that cannot be done yet because of:
     *
     * interpreters must be short-lived (long story :-))
     * hence, i must create them on every request
     * i need to allocate some memory to search for the libraries
     * thus I need to use the request pool (as opposed to the process pool)
     * because only the request pool is cleaned after every request
     */
    if(!mod_parrot_preload(interp_pmc, request->pool, conf)) {
        return mod_parrot_report(interp_pmc, request);
    }

    /* get the actual loader script  */
    path = loader_path(request->pool, conf, (char*)conf->loader);
    loader_pmc = loader_get(interp_pmc, path);
    /* wrap the structures */
    request_pmc = wrap_request(interp_pmc, request);
    route_pmc = wrap_route(interp_pmc, route);
    /* setup the arguments */
    args_pmc = mod_parrot_array_new(interp_pmc);
    mod_parrot_array_push(interp_pmc, args_pmc, request_pmc);
    mod_parrot_array_push(interp_pmc, args_pmc, route_pmc);
    /* run the script! maybe we want to move the responsibility
     * for calling mod_parrot_report up to mod_parrot_handler. */
    if(Parrot_api_run_bytecode(interp_pmc, loader_pmc, args_pmc)) {
        return OK;
    } else {
        return mod_parrot_report(interp_pmc, request);
    }
}
コード例 #5
0
ファイル: main.c プロジェクト: FROGGS/parrot
int
main(int argc, const char *argv[])
{
    Parrot_PMC interp, bytecodepmc, args;
    Parrot_Init_Args *initargs;
    struct init_args_t parsed_flags;
    Parrot_PMC compiler = NULL;

    GET_INIT_STRUCT(initargs);

    initargs->numthreads = 0;
    /* Parse minimal subset of flags */
    parseflags_minimal(initargs, argc, argv);

    if (!Parrot_api_make_interpreter(NULL, 0, initargs, &interp)) {
        fprintf(stderr, "PARROT VM: Could not allocate new interpreter\n");
        if (interp != NULL)
            show_last_error_and_exit(interp);
        else
            fprintf(stderr, "PARROT VM: No interpreter. Cannot get error details\n");
        exit(EXIT_FAILURE);
    }
    if (!(Parrot_set_config_hash(interp) &&
          Parrot_api_set_executable_name(interp, argv[0]))) {
        fprintf(stderr, "PARROT VM: Could not initialize new interpreter\n");
        show_last_error_and_exit(interp);
    }

    /* Parse flags */
    parseflags(interp, argc, argv, &parsed_flags);

    if (!Parrot_api_set_runcore(interp, parsed_flags.run_core_name, parsed_flags.trace))
        show_last_error_and_exit(interp);

    Parrot_api_toggle_gc(interp, 0);

    {
        Parrot_PMC pir_compiler = NULL;
        Parrot_PMC pasm_compiler = NULL;;
        if (!(imcc_get_pir_compreg_api(interp, 1, &pir_compiler) &&
              imcc_get_pasm_compreg_api(interp, 1, &pasm_compiler)))
            show_last_error_and_exit(interp);
        compiler = parsed_flags.have_pasm_file ? pasm_compiler : pir_compiler;
    }

    if (!parsed_flags.turn_gc_off)
        Parrot_api_toggle_gc(interp, 1);
    if (parsed_flags.imcc_dflags || parsed_flags.imcc_opts) {
        if (!imcc_set_flags_api(interp, compiler, parsed_flags.imcc_dflags,
                                parsed_flags.imcc_opts))
            exit(EXIT_FAILURE);
    }

    if (!(Parrot_api_pmc_wrap_string_array(interp, parsed_flags.argc, parsed_flags.argv,
                                            &args)
    && Parrot_api_load_bytecode_bytes(interp, get_program_code(), get_program_code_size(),
                                        &bytecodepmc)
    && Parrot_api_run_bytecode(interp, bytecodepmc, args)))
        show_last_error_and_exit(interp);

    /* Clean-up after ourselves */
    Parrot_api_destroy_interpreter(interp);
    exit(EXIT_SUCCESS);
}