コード例 #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
ファイル: main.c プロジェクト: mpeters/parrot
int
main(int argc, const char *argv[])
{
    int          stacktop;
    const char  *sourcefile;
    const char  *execname;
    Interp      *interp;
    int          status;
    int          pir_argc;
    const char **pir_argv;

    Parrot_Run_core_t  core  = PARROT_SLOW_CORE;
    Parrot_trace_flags trace = PARROT_NO_TRACE;

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

    Parrot_set_config_hash();

    interp = allocate_interpreter(NULL, PARROT_NO_FLAGS);

    /* We parse the arguments, but first store away the name of the Parrot
       executable, since parsing destroys that and we want to make it
       available. */
    execname = argv[0];

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

    /* Now initialize interpreter */
    initialize_interpreter(interp, (void*)&stacktop);

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

    Parrot_set_trace(interp, trace);
    Parrot_set_run_core(interp, (Parrot_Run_core_t) core);
    Parrot_set_executable_name(interp, Parrot_str_new(interp, execname, 0));

    status = imcc_run(interp, sourcefile, argc, argv);

    if (status)
        imcc_run_pbc(interp, interp->output_file, pir_argc, pir_argv);

    /* Clean-up after ourselves */
    Parrot_destroy(interp);
    Parrot_exit(interp, 0);
}
コード例 #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);
}