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); }
/* evil, maniacal laughter */ Parrot_PMC wrap_route(Parrot_PMC interp_pmc, mod_parrot_route * route) { Parrot_PMC route_pmc; int argc = sizeof(*route) / sizeof(char*); const char ** argv = (const char**)(route); /* this line right here */ Parrot_api_pmc_wrap_string_array(interp_pmc, argc, argv, &route_pmc); return route_pmc; }
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); }
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); }
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); }