diff --git a/include/parrot/api.h b/include/parrot/api.h index 0c39e1ed53..366e173cc7 100644 --- a/include/parrot/api.h +++ b/include/parrot/api.h @@ -64,96 +64,74 @@ typedef struct _Parrot_Init_Args { PARROT_API Parrot_Int Parrot_api_add_dynext_search_path( - ARGMOD(PMC *interp_pmc), + Parrot_PMC interp_pmc, ARGIN(const char *path)) - __attribute__nonnull__(1) - __attribute__nonnull__(2) - FUNC_MODIFIES(*interp_pmc); + __attribute__nonnull__(2); PARROT_API Parrot_Int Parrot_api_add_include_search_path( - ARGMOD(PMC *interp_pmc), + Parrot_PMC interp_pmc, ARGIN(const char *path)) - __attribute__nonnull__(1) - __attribute__nonnull__(2) - FUNC_MODIFIES(*interp_pmc); + __attribute__nonnull__(2); PARROT_API Parrot_Int Parrot_api_add_library_search_path( - ARGMOD(PMC *interp_pmc), + Parrot_PMC interp_pmc, ARGIN(const char *path)) - __attribute__nonnull__(1) - __attribute__nonnull__(2) - FUNC_MODIFIES(*interp_pmc); + __attribute__nonnull__(2); PARROT_API Parrot_Int Parrot_api_build_argv_array( - ARGMOD(PMC *interp_pmc), + Parrot_PMC interp_pmc, Parrot_Int argc, - ARGIN(char **argv), - ARGOUT(PMC **args)) - __attribute__nonnull__(1) + ARGIN(char ** argv), + ARGOUT(Parrot_PMC * args)) __attribute__nonnull__(3) __attribute__nonnull__(4) - FUNC_MODIFIES(*interp_pmc) - FUNC_MODIFIES(*args); + FUNC_MODIFIES(* args); PARROT_API Parrot_Int Parrot_api_debug_flag( - ARGMOD(PMC *interp_pmc), + Parrot_PMC interp_pmc, Parrot_Int flags, - Parrot_Int set) - __attribute__nonnull__(1) - FUNC_MODIFIES(*interp_pmc); + Parrot_Int set); PARROT_API -Parrot_Int Parrot_api_destroy_interpreter(ARGIN(PMC *interp_pmc)) - __attribute__nonnull__(1); +Parrot_Int Parrot_api_destroy_interpreter(Parrot_PMC interp_pmc); PARROT_API Parrot_Int Parrot_api_disassemble_bytecode( - ARGMOD(PMC *interp_pmc), - ARGIN(PMC *pbc), + Parrot_PMC interp_pmc, + Parrot_PMC pbc, ARGIN(const char * const outfile), Parrot_Int opts) - __attribute__nonnull__(1) - __attribute__nonnull__(2) - __attribute__nonnull__(3) - FUNC_MODIFIES(*interp_pmc); + __attribute__nonnull__(3); PARROT_API Parrot_Int Parrot_api_flag( - ARGMOD(PMC *interp_pmc), + Parrot_PMC interp_pmc, Parrot_Int flags, - Parrot_Int set) - __attribute__nonnull__(1) - FUNC_MODIFIES(*interp_pmc); + Parrot_Int set); PARROT_API Parrot_Int Parrot_api_get_exception_backtrace( - ARGMOD(PMC * interp_pmc), - ARGMOD(PMC * exception), - ARGOUT(Parrot_String ** bt)) - __attribute__nonnull__(1) - __attribute__nonnull__(2) + Parrot_PMC interp_pmc, + Parrot_PMC exception, + ARGOUT(Parrot_String * bt)) __attribute__nonnull__(3) - FUNC_MODIFIES(* interp_pmc) - FUNC_MODIFIES(* exception) FUNC_MODIFIES(* bt); PARROT_API Parrot_Int Parrot_api_get_result( - ARGMOD(PMC * interp_pmc), + Parrot_PMC interp_pmc, ARGOUT(Parrot_Int *is_error), - ARGOUT(PMC ** exception), + ARGOUT(Parrot_PMC * exception), ARGOUT(Parrot_Int *exit_code), ARGOUT(Parrot_String * errmsg)) - __attribute__nonnull__(1) __attribute__nonnull__(2) __attribute__nonnull__(3) __attribute__nonnull__(4) __attribute__nonnull__(5) - FUNC_MODIFIES(* interp_pmc) FUNC_MODIFIES(*is_error) FUNC_MODIFIES(* exception) FUNC_MODIFIES(*exit_code) @@ -168,45 +146,37 @@ Parrot_Int Parrot_api_get_runtime_path( PARROT_API Parrot_Int Parrot_api_load_bytecode_bytes( - ARGMOD(PMC *interp_pmc), + Parrot_PMC interp_pmc, ARGIN(const unsigned char * const pbc), Parrot_Int bytecode_size, - ARGOUT(PMC **pbcpmc)) - __attribute__nonnull__(1) + ARGOUT(Parrot_PMC * pbcpmc)) __attribute__nonnull__(2) __attribute__nonnull__(4) - FUNC_MODIFIES(*interp_pmc) - FUNC_MODIFIES(*pbcpmc); + FUNC_MODIFIES(* pbcpmc); PARROT_API Parrot_Int Parrot_api_load_bytecode_file( - ARGMOD(PMC *interp_pmc), + Parrot_PMC interp_pmc, ARGIN(const char *filename), - ARGOUT(PMC **pbc)) - __attribute__nonnull__(1) + ARGOUT(Parrot_PMC * pbc)) __attribute__nonnull__(2) __attribute__nonnull__(3) - FUNC_MODIFIES(*interp_pmc) - FUNC_MODIFIES(*pbc); + FUNC_MODIFIES(* pbc); PARROT_API Parrot_Int Parrot_api_make_interpreter( - ARGIN_NULLOK(PMC *parent), + Parrot_PMC interp_pmc, Parrot_Int flags, ARGIN_NULLOK(Parrot_Init_Args *args), - ARGOUT(PMC **interp)) + ARGOUT(Parrot_PMC *interp)) __attribute__nonnull__(4) FUNC_MODIFIES(*interp); PARROT_API Parrot_Int Parrot_api_run_bytecode( - ARGMOD(PMC *interp_pmc), - ARGIN(PMC *pbc), - ARGIN(PMC *mainargs)) - __attribute__nonnull__(1) - __attribute__nonnull__(2) - __attribute__nonnull__(3) - FUNC_MODIFIES(*interp_pmc); + Parrot_PMC interp_pmc, + Parrot_PMC pbc, + Parrot_PMC mainargs); PARROT_API Parrot_Int Parrot_api_set_configuration_hash( @@ -215,40 +185,31 @@ Parrot_Int Parrot_api_set_configuration_hash( PARROT_API Parrot_Int Parrot_api_set_executable_name( - ARGMOD(PMC *interp_pmc), + Parrot_PMC interp_pmc, ARGIN(const char * name)) - __attribute__nonnull__(1) - __attribute__nonnull__(2) - FUNC_MODIFIES(*interp_pmc); + __attribute__nonnull__(2); PARROT_API Parrot_Int Parrot_api_set_output_file( - ARGMOD(PMC *interp_pmc), - ARGIN_NULLOK(const char * filename)) - __attribute__nonnull__(1) - FUNC_MODIFIES(*interp_pmc); + Parrot_PMC interp_pmc, + ARGIN_NULLOK(const char * filename)); PARROT_API Parrot_Int Parrot_api_set_runcore( - ARGIN(PMC *interp_pmc), - const char * corename, + Parrot_PMC interp_pmc, + ARGIN(const char * corename), Parrot_UInt trace) - __attribute__nonnull__(1); + __attribute__nonnull__(2); PARROT_API Parrot_Int Parrot_api_set_stdhandles( - ARGIN(PMC *interp_pmc), + Parrot_PMC interp_pmc, Parrot_Int stdin, Parrot_Int stdout, - Parrot_Int stderr) - __attribute__nonnull__(1); + Parrot_Int stderr); PARROT_API -Parrot_Int Parrot_api_set_warnings( - ARGMOD(PMC *interp_pmc), - Parrot_Int flags) - __attribute__nonnull__(1) - FUNC_MODIFIES(*interp_pmc); +Parrot_Int Parrot_api_set_warnings(Parrot_PMC interp_pmc, Parrot_Int flags); PARROT_API Parrot_Int Parrot_api_wrap_imcc_hack( @@ -262,40 +223,28 @@ Parrot_Int Parrot_api_wrap_imcc_hack( #define ASSERT_ARGS_Parrot_api_add_dynext_search_path \ __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ - PARROT_ASSERT_ARG(interp_pmc) \ - , PARROT_ASSERT_ARG(path)) + PARROT_ASSERT_ARG(path)) #define ASSERT_ARGS_Parrot_api_add_include_search_path \ __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ - PARROT_ASSERT_ARG(interp_pmc) \ - , PARROT_ASSERT_ARG(path)) + PARROT_ASSERT_ARG(path)) #define ASSERT_ARGS_Parrot_api_add_library_search_path \ __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ - PARROT_ASSERT_ARG(interp_pmc) \ - , PARROT_ASSERT_ARG(path)) + PARROT_ASSERT_ARG(path)) #define ASSERT_ARGS_Parrot_api_build_argv_array __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ - PARROT_ASSERT_ARG(interp_pmc) \ - , PARROT_ASSERT_ARG(argv) \ + PARROT_ASSERT_ARG(argv) \ , PARROT_ASSERT_ARG(args)) -#define ASSERT_ARGS_Parrot_api_debug_flag __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ - PARROT_ASSERT_ARG(interp_pmc)) +#define ASSERT_ARGS_Parrot_api_debug_flag __attribute__unused__ int _ASSERT_ARGS_CHECK = (0) #define ASSERT_ARGS_Parrot_api_destroy_interpreter \ - __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ - PARROT_ASSERT_ARG(interp_pmc)) + __attribute__unused__ int _ASSERT_ARGS_CHECK = (0) #define ASSERT_ARGS_Parrot_api_disassemble_bytecode \ __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ - PARROT_ASSERT_ARG(interp_pmc) \ - , PARROT_ASSERT_ARG(pbc) \ - , PARROT_ASSERT_ARG(outfile)) -#define ASSERT_ARGS_Parrot_api_flag __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ - PARROT_ASSERT_ARG(interp_pmc)) + PARROT_ASSERT_ARG(outfile)) +#define ASSERT_ARGS_Parrot_api_flag __attribute__unused__ int _ASSERT_ARGS_CHECK = (0) #define ASSERT_ARGS_Parrot_api_get_exception_backtrace \ __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ - PARROT_ASSERT_ARG(interp_pmc) \ - , PARROT_ASSERT_ARG(exception) \ - , PARROT_ASSERT_ARG(bt)) + PARROT_ASSERT_ARG(bt)) #define ASSERT_ARGS_Parrot_api_get_result __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ - PARROT_ASSERT_ARG(interp_pmc) \ - , PARROT_ASSERT_ARG(is_error) \ + PARROT_ASSERT_ARG(is_error) \ , PARROT_ASSERT_ARG(exception) \ , PARROT_ASSERT_ARG(exit_code) \ , PARROT_ASSERT_ARG(errmsg)) @@ -303,33 +252,24 @@ Parrot_Int Parrot_api_wrap_imcc_hack( PARROT_ASSERT_ARG(runtime)) #define ASSERT_ARGS_Parrot_api_load_bytecode_bytes \ __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ - PARROT_ASSERT_ARG(interp_pmc) \ - , PARROT_ASSERT_ARG(pbc) \ + PARROT_ASSERT_ARG(pbc) \ , PARROT_ASSERT_ARG(pbcpmc)) #define ASSERT_ARGS_Parrot_api_load_bytecode_file __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ - PARROT_ASSERT_ARG(interp_pmc) \ - , PARROT_ASSERT_ARG(filename) \ + PARROT_ASSERT_ARG(filename) \ , PARROT_ASSERT_ARG(pbc)) #define ASSERT_ARGS_Parrot_api_make_interpreter __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ PARROT_ASSERT_ARG(interp)) -#define ASSERT_ARGS_Parrot_api_run_bytecode __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ - PARROT_ASSERT_ARG(interp_pmc) \ - , PARROT_ASSERT_ARG(pbc) \ - , PARROT_ASSERT_ARG(mainargs)) +#define ASSERT_ARGS_Parrot_api_run_bytecode __attribute__unused__ int _ASSERT_ARGS_CHECK = (0) #define ASSERT_ARGS_Parrot_api_set_configuration_hash \ __attribute__unused__ int _ASSERT_ARGS_CHECK = (0) #define ASSERT_ARGS_Parrot_api_set_executable_name \ __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ - PARROT_ASSERT_ARG(interp_pmc) \ - , PARROT_ASSERT_ARG(name)) -#define ASSERT_ARGS_Parrot_api_set_output_file __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ - PARROT_ASSERT_ARG(interp_pmc)) + PARROT_ASSERT_ARG(name)) +#define ASSERT_ARGS_Parrot_api_set_output_file __attribute__unused__ int _ASSERT_ARGS_CHECK = (0) #define ASSERT_ARGS_Parrot_api_set_runcore __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ - PARROT_ASSERT_ARG(interp_pmc)) -#define ASSERT_ARGS_Parrot_api_set_stdhandles __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ - PARROT_ASSERT_ARG(interp_pmc)) -#define ASSERT_ARGS_Parrot_api_set_warnings __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ - PARROT_ASSERT_ARG(interp_pmc)) + PARROT_ASSERT_ARG(corename)) +#define ASSERT_ARGS_Parrot_api_set_stdhandles __attribute__unused__ int _ASSERT_ARGS_CHECK = (0) +#define ASSERT_ARGS_Parrot_api_set_warnings __attribute__unused__ int _ASSERT_ARGS_CHECK = (0) #define ASSERT_ARGS_Parrot_api_wrap_imcc_hack __attribute__unused__ int _ASSERT_ARGS_CHECK = (0) /* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */ /* HEADERIZER END: src/embed/api.c */ @@ -392,6 +332,19 @@ Parrot_Int Parrot_api_string_import_binary( /* HEADERIZER BEGIN: src/embed/pmc.c */ /* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */ +PARROT_API +Parrot_Int Parrot_api_add_exception_handler( + Parrot_PMC interp_pmc, + Parrot_PMC hander); + +PARROT_API +Parrot_Int Parrot_api_call_sub( + Parrot_PMC interp_pmc, + Parrot_PMC sub, + ARGIN(const char * signature), + ...) + __attribute__nonnull__(3); + PARROT_API Parrot_Int Parrot_api_pmc_deserialize( Parrot_PMC interp_pmc, @@ -410,6 +363,30 @@ Parrot_Int Parrot_api_pmc_deserialize_bytes( __attribute__nonnull__(4) FUNC_MODIFIES(* pmc); +PARROT_API +Parrot_Int Parrot_api_pmc_get_float( + Parrot_PMC interp_pmc, + Parrot_PMC pmc, + ARGOUT(Parrot_Float * value)) + __attribute__nonnull__(3) + FUNC_MODIFIES(* value); + +PARROT_API +Parrot_Int Parrot_api_pmc_get_integer( + Parrot_PMC interp_pmc, + Parrot_PMC pmc, + ARGOUT(Parrot_Int * value)) + __attribute__nonnull__(3) + FUNC_MODIFIES(* value); + +PARROT_API +Parrot_Int Parrot_api_pmc_get_string( + Parrot_PMC interp_pmc, + Parrot_PMC pmc, + ARGOUT(Parrot_String * str)) + __attribute__nonnull__(3) + FUNC_MODIFIES(* str); + PARROT_API Parrot_Int Parrot_api_pmc_null( Parrot_PMC interp_pmc, @@ -417,14 +394,45 @@ Parrot_Int Parrot_api_pmc_null( __attribute__nonnull__(2) FUNC_MODIFIES(*pmctonull); +PARROT_API +Parrot_Int Parrot_api_pmc_set_float( + Parrot_PMC interp_pmc, + Parrot_PMC pmc, + Parrot_Float value); + +PARROT_API +Parrot_Int Parrot_api_pmc_set_integer( + Parrot_PMC interp_pmc, + Parrot_PMC pmc, + Parrot_Int value); + +PARROT_API +Parrot_Int Parrot_api_pmc_set_string( + Parrot_PMC interp_pmc, + Parrot_PMC pmc, + Parrot_String value); + +#define ASSERT_ARGS_Parrot_api_add_exception_handler \ + __attribute__unused__ int _ASSERT_ARGS_CHECK = (0) +#define ASSERT_ARGS_Parrot_api_call_sub __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ + PARROT_ASSERT_ARG(signature)) #define ASSERT_ARGS_Parrot_api_pmc_deserialize __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ PARROT_ASSERT_ARG(pmc)) #define ASSERT_ARGS_Parrot_api_pmc_deserialize_bytes \ __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ PARROT_ASSERT_ARG(fpmc) \ , PARROT_ASSERT_ARG(pmc)) +#define ASSERT_ARGS_Parrot_api_pmc_get_float __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ + PARROT_ASSERT_ARG(value)) +#define ASSERT_ARGS_Parrot_api_pmc_get_integer __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ + PARROT_ASSERT_ARG(value)) +#define ASSERT_ARGS_Parrot_api_pmc_get_string __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ + PARROT_ASSERT_ARG(str)) #define ASSERT_ARGS_Parrot_api_pmc_null __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ PARROT_ASSERT_ARG(pmctonull)) +#define ASSERT_ARGS_Parrot_api_pmc_set_float __attribute__unused__ int _ASSERT_ARGS_CHECK = (0) +#define ASSERT_ARGS_Parrot_api_pmc_set_integer __attribute__unused__ int _ASSERT_ARGS_CHECK = (0) +#define ASSERT_ARGS_Parrot_api_pmc_set_string __attribute__unused__ int _ASSERT_ARGS_CHECK = (0) /* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */ /* HEADERIZER END: src/embed/pmc.c */ diff --git a/src/embed/api.c b/src/embed/api.c index 99ccfb9e39..b029ed805c 100644 --- a/src/embed/api.c +++ b/src/embed/api.c @@ -40,7 +40,7 @@ Parrot_api_get_exception_backtrace(Parrot_PMC interp_pmc, PARROT_API Parrot_Int -Parrot_api_make_interpreter(Parrot_PMC interp_pmc, Parrot_Int flags, +Parrot_api_make_interpreter(Parrot_PMC parent, Parrot_Int flags, ARGIN_NULLOK(Parrot_Init_Args *args), ARGOUT(Parrot_PMC *interp)) { ASSERT_ARGS(Parrot_api_make_interpreter) @@ -151,8 +151,8 @@ Parrot_api_destroy_interpreter(Parrot_PMC interp_pmc) /* -=item C +=item C Load a bytecode file and return a bytecode PMC. @@ -160,6 +160,8 @@ Load a bytecode file and return a bytecode PMC. */ +// TODO: This only works with the inital bytecode. After this we should use +// Parrot_append_bytecode or something similar PARROT_API Parrot_Int Parrot_api_load_bytecode_file(Parrot_PMC interp_pmc, @@ -195,6 +197,35 @@ Parrot_api_load_bytecode_bytes(Parrot_PMC interp_pmc, EMBED_API_CALLOUT(interp_pmc, interp); } +// Load the bytecode into the interpreter, but don't execute it +// TODO: This only works with the inital bytecode. After this we should use +// Parrot_append_bytecode or something similar +PARROT_API +Parrot_Int +Parrot_api_ready_bytecode(Parrot_PMC interp_pmc, Parrot_PMC pbc, + ARGOUT(Parrot_PMC *main_sub)) +{ + EMBED_API_CALLIN(interp_pmc, interp) + PackFile * const pf = (PackFile *)VTABLE_get_pointer(interp, pbc); + + /* Debugging mode nonsense. */ + if (Interp_debug_TEST(interp, PARROT_START_DEBUG_FLAG)) { + Parrot_io_eprintf(interp, "*** Parrot VM: %Ss core ***\n", + interp->run_core->name); + } + + if (!pf) + Parrot_ex_throw_from_c_args(interp, NULL, 1, "Could not get packfile"); + if (pf->cur_cs != NULL) + Parrot_pbc_load(interp, pf); + PackFile_fixup_subs(interp, PBC_IMMEDIATE, NULL); + PackFile_fixup_subs(interp, PBC_POSTCOMP, NULL); + PackFile_fixup_subs(interp, PBC_MAIN, NULL); + *main_sub = Parrot_pcc_get_sub(interp, CURRENT_CONTEXT(interp)); + Parrot_pcc_set_constants(interp, interp->ctx, interp->code->const_table); + EMBED_API_CALLOUT(interp_pmc, interp) +} + PARROT_API Parrot_Int Parrot_api_run_bytecode(Parrot_PMC interp_pmc, Parrot_PMC pbc, @@ -210,7 +241,7 @@ Parrot_api_run_bytecode(Parrot_PMC interp_pmc, Parrot_PMC pbc, if (Interp_debug_TEST(interp, PARROT_START_DEBUG_FLAG)) { Parrot_io_eprintf(interp, "*** Parrot VM: %Ss core ***\n", interp->run_core->name); - } + } if (!pf) Parrot_ex_throw_from_c_args(interp, NULL, 1, "Could not get packfile"); @@ -329,7 +360,7 @@ Parrot_api_add_dynext_search_path(Parrot_PMC interp_pmc, /* -=item C Set the std file descriptors for the embedded interpreter. Any file descriptor diff --git a/src/embed/pmc.c b/src/embed/pmc.c index 85c34f9bdf..1f85816425 100644 --- a/src/embed/pmc.c +++ b/src/embed/pmc.c @@ -6,7 +6,8 @@ PARROT_API Parrot_Int -Parrot_api_pmc_deserialize(Parrot_PMC interp_pmc, Parrot_String fpmc, ARGOUT(Parrot_PMC * pmc)) +Parrot_api_pmc_deserialize(Parrot_PMC interp_pmc, Parrot_String fpmc, + ARGOUT(Parrot_PMC * pmc)) { EMBED_API_CALLIN(interp_pmc, interp) PMC * const config = Parrot_thaw(interp, fpmc); @@ -16,10 +17,13 @@ Parrot_api_pmc_deserialize(Parrot_PMC interp_pmc, Parrot_String fpmc, ARGOUT(Par PARROT_API Parrot_Int -Parrot_api_pmc_deserialize_bytes(Parrot_PMC interp_pmc, ARGIN(const unsigned char * const fpmc), Parrot_Int length, ARGOUT(Parrot_PMC * pmc)) +Parrot_api_pmc_deserialize_bytes(Parrot_PMC interp_pmc, + ARGIN(const unsigned char * const fpmc), Parrot_Int length, + ARGOUT(Parrot_PMC * pmc)) { EMBED_API_CALLIN(interp_pmc, interp) - STRING * const fpmc_str = Parrot_str_new_init(interp, fpmc, length, Parrot_binary_encoding_ptr, PObj_external_FLAG); + STRING * const fpmc_str = Parrot_str_new_init(interp, fpmc, length, + Parrot_binary_encoding_ptr, PObj_external_FLAG); PMC * const config = Parrot_thaw(interp, fpmc_str); Parrot_set_config_hash_pmc(interp, config); EMBED_API_CALLOUT(interp_pmc, interp); @@ -33,3 +37,99 @@ Parrot_api_pmc_null(Parrot_PMC interp_pmc, ARGMOD(Parrot_PMC *pmctonull)) *pmctonull = PMCNULL; EMBED_API_CALLOUT(interp_pmc, interp); } + +PARROT_API +Parrot_Int +Parrot_api_pmc_get_string(Parrot_PMC interp_pmc, Parrot_PMC pmc, + ARGOUT(Parrot_String * str)) +{ + EMBED_API_CALLIN(interp_pmc, interp) + *str = VTABLE_get_string(interp, pmc); + EMBED_API_CALLOUT(interp_pmc, interp) +} + +PARROT_API +Parrot_Int +Parrot_api_pmc_get_integer(Parrot_PMC interp_pmc, Parrot_PMC pmc, + ARGOUT(Parrot_Int * value)) +{ + EMBED_API_CALLIN(interp_pmc, interp) + *value = VTABLE_get_integer(interp, pmc); + EMBED_API_CALLOUT(interp_pmc, interp) +} + +PARROT_API +Parrot_Int +Parrot_api_pmc_get_float(Parrot_PMC interp_pmc, Parrot_PMC pmc, + ARGOUT(Parrot_Float * value)) +{ + EMBED_API_CALLIN(interp_pmc, interp) + *value = VTABLE_get_number(interp, pmc); + EMBED_API_CALLOUT(interp_pmc, interp) +} + +PARROT_API +Parrot_Int +Parrot_api_pmc_set_string(Parrot_PMC interp_pmc, Parrot_PMC pmc, + Parrot_String value) +{ + EMBED_API_CALLIN(interp_pmc, interp) + VTABLE_set_string_native(interp, pmc, value); + EMBED_API_CALLOUT(interp_pmc, interp) +} + +PARROT_API +Parrot_Int +Parrot_api_pmc_set_integer(Parrot_PMC interp_pmc, Parrot_PMC pmc, + Parrot_Int value) +{ + EMBED_API_CALLIN(interp_pmc, interp) + VTABLE_set_integer_native(interp, pmc, value); + EMBED_API_CALLOUT(interp_pmc, interp) +} + +PARROT_API +Parrot_Int +Parrot_api_pmc_set_float(Parrot_PMC interp_pmc, Parrot_PMC pmc, + Parrot_Float value) +{ + EMBED_API_CALLIN(interp_pmc, interp) + VTABLE_set_number_native(interp, pmc, value); + EMBED_API_CALLOUT(interp_pmc, interp) +} + +PARROT_API +Parrot_Int +Parrot_api_add_exception_handler(Parrot_PMC interp_pmc, Parrot_PMC handler) +{ + EMBED_API_CALLIN(interp_pmc, interp) + Parrot_cx_add_handler(interp, handler); + EMBED_API_CALLOUT(interp_pmc, interp) +} + +PARROT_API +Parrot_Int +Parrot_api_call_sub(Parrot_PMC interp_pmc, Parrot_PMC sub_pmc, + ARGIN(const char * signature), ...) +{ + EMBED_API_CALLIN(interp_pmc, interp) + va_list args; + PMC *call_obj; + const char *arg_sig, *ret_sig; + + PMC * const old_call_obj = Parrot_pcc_get_signature(interp, + CURRENT_CONTEXT(interp)); + Parrot_pcc_split_signature_string(signature, &arg_sig, &ret_sig); + + va_start(args, signature); + call_obj = Parrot_pcc_build_call_from_varargs(interp, PMCNULL, + arg_sig, &args); + + Parrot_pcc_invoke_from_sig_object(interp, sub_pmc, call_obj); + call_obj = Parrot_pcc_get_signature(interp, CURRENT_CONTEXT(interp)); + Parrot_pcc_fill_params_from_varargs(interp, call_obj, ret_sig, &args, + PARROT_ERRORS_RESULT_COUNT_FLAG); + va_end(args); + Parrot_pcc_set_signature(interp, CURRENT_CONTEXT(interp), old_call_obj); + EMBED_API_CALLOUT(interp_pmc, interp) +}