5#include "recomputils.h"
6#include "recompconfig.h"
20#define REPY_MOD_ID_STR "RecompExternalPython_API"
25#define REPY_IMPORT(func) func
28#elif RECOMP_PY_BUILD_MODE
29#define REPY_IMPORT(func) func
31#define REPY_IMPORT(func) RECOMP_IMPORT(REPY_MOD_ID_STR, func)
35#define __FILE_NAME__ "Unknown Source File"
226#define REPY_NO_OBJECT 0
233#define REPY_MAIN_INTERPRETER 0
241#define REPY_INTERPRETER_STACK_EMPTY -1
323#define REPY_ON_PRE_INIT RECOMP_CALLBACK(REPY_MOD_ID_STR, REPY_OnPreInit)
332#define REPY_ON_CONFIG_INTERPRETERS RECOMP_CALLBACK(REPY_MOD_ID_STR, REPY_OnConfigInterpreters)
341#define REPY_ON_INIT_CODE_CACHE RECOMP_CALLBACK(REPY_MOD_ID_STR, REPY_OnInitCodeCache)
350#define REPY_ON_POST_INIT RECOMP_CALLBACK(REPY_MOD_ID_STR, REPY_OnPostInit)
377#define REPY_PREINIT_ADD_NRM_TO_ALL_INTERPRETERS \
378REPY_ON_PRE_INIT void _repy_register_nrm () { \
379 const unsigned char* nrm_file_path = recomp_get_mod_file_path(); \
380 REPY_PreInitAddSysPath(nrm_file_path); \
381 recomp_free((void*)nrm_file_path); \
393#define REPY_ADD_NRM_TO_MAIN_INTERPRETER \
394REPY_ON_CONFIG_INTERPRETERS void __repy_config_main_interpreter() { \
395 recomp_printf("Configuring Main Interpreter (Index %i)\n", 0); \
396 REPY_PushInterpreter(subinterp_identifier); \
397 REPY_AddNrmToSysPath(); \
398 REPY_PopInterpreter(); \
410#define REPY_REGISTER_SUBINTERPRETER(subinterp_identifier) \
411REPY_InterpreterIndex subinterp_identifier = 0; \
412REPY_ON_PRE_INIT void __repy_config_ ## subinterp_identifier () { \
413 subinterp_identifier = REPY_PreInitRegisterSubinterpreter(); \
414 recomp_printf("Registering Subinterpreter '%s' (Index %i)\n", #subinterp_identifier, subinterp_identifier); \
416REPY_ON_CONFIG_INTERPRETERS void subinterp_identifier ## _config() { \
417 recomp_printf("Configuring Subinterpreter '%s' (Index %i)\n", #subinterp_identifier, subinterp_identifier); \
418 REPY_PushInterpreter(subinterp_identifier); \
419 REPY_AddNrmToSysPath(); \
420 REPY_PopInterpreter(); \
429#define REPY_EXTERN_SUBINTERPRETER(subinterp_identifier) \
430extern REPY_InterpreterIndex subinterp_identifier; \
438#define REPY_EXTERN_INCBIN(identifier) \
439 extern REPY_u8 identifier[]; \
440 extern REPY_u8 identifier##_end[]
442#ifdef REPY_SILENCE_INCBIN_SQUIGGLES
443#define REPY_INCBIN(identifier, filename) \
444 extern REPY_u8 identifier[]; \
445 extern REPY_u8 identifier##_end[]
447#define REPY_INCBIN_TEXT(identifier, filename) \
448 extern REPY_u8 identifier[]; \
449 extern REPY_u8 identifier##_end[]
461#define REPY_INCBIN(identifier, filename) \
462 asm(".pushsection .rodata\n" \
463 "\t.globl " #identifier "\n" \
464 "\t.type " #identifier ", @object\n" \
467 "\t.incbin \"" filename "\"\n" \
468 "\t.globl " #identifier "_end\n" \
469 #identifier "_end:\n" \
470 "\t.popsection\n"); \
471 REPY_EXTERN_INCBIN(identifier)
482#define REPY_INCBIN_TEXT(identifier, filename) \
483 asm(".pushsection .rodata\n" \
484 "\t.globl " #identifier "\n" \
485 "\t.type " #identifier ", @object\n" \
488 "\t.incbin \"" filename "\"\n" \
490 "\t.globl " #identifier "_end\n" \
491 #identifier "_end:\n" \
492 "\t.popsection\n"); \
493 REPY_EXTERN_INCBIN(identifier)
507#define REPY_GLOBAL_COMPILE_CACHE(interpreter_index, bytecode_identifier, code_mode, code_str) \
508REPY_Handle bytecode_identifier = 0; \
509REPY_ON_INIT_CODE_CACHE void _cache_code_ ## bytecode_identifier () { \
510 if (bytecode_identifier == 0) { \
511 REPY_PushInterpreter(interpreter_index); \
512 char* iden_str = REPY_InlineCodeSourceStrHelper("REPY_GLOBAL_COMPILE_CACHE", __FILE_NAME__, (char*) __func__, __LINE__, #bytecode_identifier); \
513 bytecode_identifier = REPY_CompileCStr(code_str, (const char*)iden_str, code_mode); \
514 recomp_free(iden_str); \
515 REPY_PopInterpreter(); \
529#define REPY_STATIC_COMPILE_CACHE(interpreter_index, bytecode_identifier, code_mode, code_str) \
530static REPY_Handle bytecode_identifier = 0; \
531REPY_ON_INIT_CODE_CACHE void _cache_code_ ## bytecode_identifier () { \
532 if (bytecode_identifier == 0) { \
533 REPY_PushInterpreter(interpreter_index); \
534 char* iden_str = REPY_InlineCodeSourceStrHelper("REPY_STATIC_COMPILE_CACHE", __FILE_NAME__, (char*) __func__, __LINE__, #bytecode_identifier); \
535 bytecode_identifier = REPY_CompileCStr(code_str, (const char*)iden_str, code_mode); \
536 recomp_free(iden_str); \
537 REPY_PopInterpreter(); \
553#define REPY_GLOBAL_COMPILE_INCBIN_CACHE(interpreter_index, bytecode_identifier, filename) \
554REPY_INCBIN(bytecode_identifier ## _code_str, filename); \
555REPY_Handle bytecode_identifier = 0; \
556REPY_ON_INIT_CODE_CACHE void _cache_code_ ## bytecode_identifier () { \
557 if (bytecode_identifier == 0) { \
558 REPY_PushInterpreter(interpreter_index); \
559 char* iden_str = REPY_InlineCodeSourceStrHelper("REPY_GLOBAL_COMPILE_INCBIN_CACHE: " filename, __FILE_NAME__, (char*) __func__, __LINE__, #bytecode_identifier); \
560 bytecode_identifier = REPY_CompileCStrN((const char*)bytecode_identifier ## _code_str, bytecode_identifier ## _code_str_end - bytecode_identifier ## _code_str, \
561 (const char*)iden_str, REPY_CODE_EXEC); \
562 recomp_free(iden_str); \
563 REPY_PopInterpreter(); \
578#define REPY_STATIC_COMPILE_INCBIN_CACHE(interpreter_index, bytecode_identifier, filename) \
579REPY_INCBIN(bytecode_identifier ## _code_str, filename); \
580REPY_Handle bytecode_identifier = 0; \
581REPY_ON_INIT_CODE_CACHE void _cache_code_ ## bytecode_identifier () { \
582 REPY_PushInterpreter(interpreter_index); \
583 if (bytecode_identifier == 0) { \
584 char* iden_str = REPY_InlineCodeSourceStrHelper("REPY_STATIC_COMPILE_INCBIN_CACHE: " filename, __FILE_NAME__, (char*) __func__, __LINE__, #bytecode_identifier); \
585 bytecode_identifier = REPY_CompileCStrN((const char*)bytecode_identifier ## _code_str, bytecode_identifier ## _code_str_end - bytecode_identifier ## _code_str, \
586 (const char*)iden_str, REPY_CODE_EXEC); \
587 recomp_free(iden_str); \
588 REPY_PopInterpreter(); \
619#define REPY_INLINE_COMPILE_CACHE_BLOCK(category, bytecode_identifier, code_mode, code_str) \
620static REPY_Handle bytecode_identifier = 0; \
621if (bytecode_identifier == 0) { \
622 char* iden_str = REPY_InlineCodeSourceStrHelper(category, __FILE_NAME__, (char*) __func__, __LINE__, #bytecode_identifier); \
623 bytecode_identifier = REPY_CompileCStr(code_str, (const char*)iden_str, code_mode); \
624 recomp_free(iden_str); \
640#define REPY_INLINE_COMPILE_CACHE(bytecode_identifier, code_mode, code_str) \
641REPY_INLINE_COMPILE_CACHE_BLOCK("REPY_INLINE_COMPILE_CACHE", bytecode_identifier, code_mode, code_str)
667#define REPY_FOREACH_FNAC(iter_identifier, py_object) \
668for (REPY_IteratorHelper* iter_identifier = \
669 REPY_DeferredCleanupHelper_AddIteratorHelper(REPY_FN_AUTO_CLEANUP, REPY_IteratorHelper_Create(py_object, REPY_NO_OBJECT, NULL, false)); \
670 REPY_IteratorHelper_Update(iter_identifier); \
693#define REPY_FOREACH(iter_identifier, py_object, auto_self_destuct) \
694for (REPY_IteratorHelper* iter_identifier = REPY_IteratorHelper_Create(py_object, REPY_NO_OBJECT, NULL, auto_self_destuct); REPY_IteratorHelper_Update(iter_identifier);)
703#define REPY_FOREACH_CLEANUP_NOW(iter_identifier) \
704REPY_IteratorHelper_Destroy(iter_identifier)
711#define REPY_FOREACH_BREAK(iter_identifier) \
712REPY_FOREACH_CLEANUP_NOW(iter_identifier); break
721#define REPY_FOREACH_RETURN(iter_identifier, retType, retVal) \
722retType __repy_retVal = retVal; \
723REPY_FOREACH_CLEANUP_NOW(iter_identifier); \
750#define REPY_FN_GLOBAL_SCOPE __repy_globals
756#define REPY_FN_LOCAL_SCOPE __repy_locals
762#define REPY_FN_AUTO_CLEANUP __repy_auto_cleanup
780#define REPY_FN_SETUP_INTERP(interp_index) \
781REPY_PushInterpreter(interp_index); \
782REPY_Handle REPY_FN_GLOBAL_SCOPE = REPY_CreateDict(0); \
783REPY_Handle REPY_FN_LOCAL_SCOPE = REPY_FN_GLOBAL_SCOPE; \
784REPY_DeferredCleanupHelper* REPY_FN_AUTO_CLEANUP = REPY_DeferredCleanupHelper_Create() \
804#define REPY_FN_SETUP_INTERP_WITH_GLOBALS(interp_index, globals) \
805REPY_PushInterpreter(interp_index); \
806REPY_Handle REPY_FN_GLOBAL_SCOPE = globals; \
807REPY_Handle REPY_FN_LOCAL_SCOPE = REPY_CreateDict(0); \
808REPY_DeferredCleanupHelper* REPY_FN_AUTO_CLEANUP = REPY_DeferredCleanupHelper_Create() \
823#define REPY_FN_SETUP \
824REPY_FN_SETUP_INTERP(REPY_MAIN_INTERPRETER)
842#define REPY_FN_SETUP_WITH_GLOBALS(globals) \
843REPY_FN_SETUP_INTERP_WITH_GLOBALS(REPY_MAIN_INTERPRETER)
852#define REPY_FN_CLEANUP \
853REPY_DeferredCleanupHelper_Destroy(REPY_FN_AUTO_CLEANUP); \
854REPY_Release(REPY_FN_LOCAL_SCOPE); \
855REPY_PopInterpreter() \
866#define REPY_FN_RETURN(retType, retVal) \
867retType __repy_retVal = retVal; \
868REPY_DeferredCleanupHelper_Destroy(REPY_FN_AUTO_CLEANUP, 1); \
869REPY_Release(REPY_FN_LOCAL_SCOPE); \
870REPY_PopInterpreter(); \
881#define REPY_FN_DEFER_RELEASE(handle) \
882REPY_DeferredCleanupHelper_AddHandle(REPY_FN_AUTO_CLEANUP, handle)
894#define REPY_FN_DEFER_RECOMP_FREE(pointer) \
895REPY_DeferredCleanupHelper_AddRecompFree(REPY_FN_AUTO_CLEANUP, (void*) pointer)
914#define REPY_FN_EXEC(code_handle) \
915REPY_Exec(code_handle, REPY_FN_GLOBAL_SCOPE, REPY_FN_LOCAL_SCOPE)
927#define REPY_FN_EXEC_CSTR(code_str) \
928REPY_ExecCStr(code_str, REPY_FN_GLOBAL_SCOPE, REPY_FN_LOCAL_SCOPE)
944#define REPY_FN_EXEC_CACHE(identifier, code_str) \
945REPY_INLINE_COMPILE_CACHE_BLOCK("REPY_FN_EXEC_CACHE", identifier, REPY_CODE_EXEC, code_str) \
946REPY_bool identifier ## _success = REPY_FN_EXEC(identifier)
967#define REPY_FN_EVAL(code_handle) \
968REPY_Eval(code_handle, REPY_FN_GLOBAL_SCOPE, REPY_FN_LOCAL_SCOPE)
979#define REPY_FN_EVAL_BOOL(code_handle) \
980REPY_CastBool(REPY_MakeSUH(REPY_Eval(code_handle, REPY_FN_GLOBAL_SCOPE, REPY_FN_LOCAL_SCOPE)))
991#define REPY_FN_EVAL_U8(code_handle) \
992REPY_CastU8(REPY_MakeSUH(REPY_Eval(code_handle, REPY_FN_GLOBAL_SCOPE, REPY_FN_LOCAL_SCOPE)))
1003#define REPY_FN_EVAL_S8(code_handle) \
1004REPY_CastS8(REPY_MakeSUH(REPY_Eval(code_handle, REPY_FN_GLOBAL_SCOPE, REPY_FN_LOCAL_SCOPE)))
1015#define REPY_FN_EVAL_U16(code_handle) \
1016REPY_CastU16(REPY_MakeSUH(REPY_Eval(code_handle, REPY_FN_GLOBAL_SCOPE, REPY_FN_LOCAL_SCOPE)))
1027#define REPY_FN_EVAL_S16(code_handle) \
1028REPY_CastS16(REPY_MakeSUH(REPY_Eval(code_handle, REPY_FN_GLOBAL_SCOPE, REPY_FN_LOCAL_SCOPE)))
1039#define REPY_FN_EVAL_U32(code_handle) \
1040REPY_CastU32(REPY_MakeSUH(REPY_Eval(code_handle, REPY_FN_GLOBAL_SCOPE, REPY_FN_LOCAL_SCOPE)))
1051#define REPY_FN_EVAL_S32(code_handle) \
1052REPY_CastS32(REPY_MakeSUH(REPY_Eval(code_handle, REPY_FN_GLOBAL_SCOPE, REPY_FN_LOCAL_SCOPE)))
1063#define REPY_FN_EVAL_F32(code_handle) \
1064REPY_CastF32(REPY_MakeSUH(REPY_Eval(code_handle, REPY_FN_GLOBAL_SCOPE, REPY_FN_LOCAL_SCOPE)))
1075#define REPY_FN_EVAL_U64(code_handle) \
1076REPY_CastU64(REPY_MakeSUH(REPY_Eval(code_handle, REPY_FN_GLOBAL_SCOPE, REPY_FN_LOCAL_SCOPE)))
1087#define REPY_FN_EVAL_S64(code_handle) \
1088REPY_CastS64(REPY_MakeSUH(REPY_Eval(code_handle, REPY_FN_GLOBAL_SCOPE, REPY_FN_LOCAL_SCOPE)))
1099#define REPY_FN_EVAL_F64(code_handle) \
1100REPY_CastF64(REPY_MakeSUH(REPY_Eval(code_handle, REPY_FN_GLOBAL_SCOPE, REPY_FN_LOCAL_SCOPE)))
1115#define REPY_FN_EVAL_STR(code_handle) \
1116REPY_CastStr(REPY_MakeSUH(REPY_Eval(code_handle, REPY_FN_GLOBAL_SCOPE, REPY_FN_LOCAL_SCOPE)))
1132#define REPY_FN_EVAL_BYTESTR(code_handle) \
1133REPY_CastByteStr(REPY_MakeSUH(REPY_Eval(code_handle, REPY_FN_GLOBAL_SCOPE, REPY_FN_LOCAL_SCOPE)))
1145#define REPY_FN_EVAL_CSTR(code_str) \
1146REPY_EvalCStr(code_str, REPY_FN_GLOBAL_SCOPE, REPY_FN_LOCAL_SCOPE)
1158#define REPY_FN_EVAL_CSTR_BOOL(code_str) \
1159REPY_CastBool(REPY_MakeSUH(REPY_EvalCStr(code_str, REPY_FN_GLOBAL_SCOPE, REPY_FN_LOCAL_SCOPE)))
1171#define REPY_FN_EVAL_CSTR_U8(code_str) \
1172REPY_CastU8(REPY_MakeSUH(REPY_EvalCStr(code_str, REPY_FN_GLOBAL_SCOPE, REPY_FN_LOCAL_SCOPE)))
1184#define REPY_FN_EVAL_CSTR_S8(code_str) \
1185REPY_CastS8(REPY_MakeSUH(REPY_EvalCStr(code_str, REPY_FN_GLOBAL_SCOPE, REPY_FN_LOCAL_SCOPE)))
1197#define REPY_FN_EVAL_CSTR_U16(code_str) \
1198REPY_CastU16(REPY_MakeSUH(REPY_EvalCStr(code_str, REPY_FN_GLOBAL_SCOPE, REPY_FN_LOCAL_SCOPE)))
1210#define REPY_FN_EVAL_CSTR_S16(code_str) \
1211REPY_CastS16(REPY_MakeSUH(REPY_EvalCStr(code_str, REPY_FN_GLOBAL_SCOPE, REPY_FN_LOCAL_SCOPE)))
1223#define REPY_FN_EVAL_CSTR_U32(code_str) \
1224REPY_CastU32(REPY_MakeSUH(REPY_EvalCStr(code_str, REPY_FN_GLOBAL_SCOPE, REPY_FN_LOCAL_SCOPE)))
1236#define REPY_FN_EVAL_CSTR_S32(code_str) \
1237REPY_CastS32(REPY_MakeSUH(REPY_EvalCStr(code_str, REPY_FN_GLOBAL_SCOPE, REPY_FN_LOCAL_SCOPE)))
1249#define REPY_FN_EVAL_CSTR_F32(code_str) \
1250REPY_CastF32(REPY_MakeSUH(REPY_EvalCStr(code_str, REPY_FN_GLOBAL_SCOPE, REPY_FN_LOCAL_SCOPE)))
1262#define REPY_FN_EVAL_CSTR_U64(code_str) \
1263REPY_CastU64(REPY_MakeSUH(REPY_EvalCStr(code_str, REPY_FN_GLOBAL_SCOPE, REPY_FN_LOCAL_SCOPE)))
1275#define REPY_FN_EVAL_CSTR_S64(code_str) \
1276REPY_CastS64(REPY_MakeSUH(REPY_EvalCStr(code_str, REPY_FN_GLOBAL_SCOPE, REPY_FN_LOCAL_SCOPE)))
1288#define REPY_FN_EVAL_CSTR_F64(code_str) \
1289REPY_CastF64(REPY_MakeSUH(REPY_EvalCStr(code_str, REPY_FN_GLOBAL_SCOPE, REPY_FN_LOCAL_SCOPE)))
1305#define REPY_FN_EVAL_CSTR_STR(code_str) \
1306REPY_CastStr(REPY_MakeSUH(REPY_EvalCStr(code_str, REPY_FN_GLOBAL_SCOPE, REPY_FN_LOCAL_SCOPE)))
1322#define REPY_FN_EVAL_CSTR_BYTESTR(code_str) \
1323REPY_CastByteStr(REPY_MakeSUH(REPY_EvalCStr(code_str, REPY_FN_GLOBAL_SCOPE, REPY_FN_LOCAL_SCOPE)))
1340#define REPY_FN_EVAL_CACHE(bytecode_identifier, code_str, out_var) \
1341REPY_INLINE_COMPILE_CACHE_BLOCK("REPY_FN_EVAL_CACHE", bytecode_identifier, REPY_CODE_EVAL, code_str) \
1342REPY_Handle out_var = REPY_FN_EVAL(bytecode_identifier)
1359#define REPY_FN_EVAL_CACHE_BOOL(bytecode_identifier, code_str, out_var) \
1360REPY_INLINE_COMPILE_CACHE_BLOCK("REPY_FN_EVAL_CACHE_BOOL", bytecode_identifier, REPY_CODE_EVAL, code_str) \
1361bool out_var = REPY_FN_EVAL_BOOL(bytecode_identifier)
1378#define REPY_FN_EVAL_CACHE_U8(bytecode_identifier, code_str, out_var) \
1379REPY_INLINE_COMPILE_CACHE_BLOCK("REPY_FN_EVAL_CACHE_U8", bytecode_identifier, REPY_CODE_EVAL, code_str) \
1380REPY_u8 out_var = REPY_FN_EVAL_U8(bytecode_identifier)
1397#define REPY_FN_EVAL_CACHE_S8(bytecode_identifier, code_str, out_var) \
1398REPY_INLINE_COMPILE_CACHE_BLOCK("REPY_FN_EVAL_CACHE_S8", bytecode_identifier, REPY_CODE_EVAL, code_str) \
1399REPY_s8 out_var = REPY_FN_EVAL_S8(bytecode_identifier)
1416#define REPY_FN_EVAL_CACHE_U16(bytecode_identifier, code_str, out_var) \
1417REPY_INLINE_COMPILE_CACHE_BLOCK("REPY_FN_EVAL_CACHE_U16", bytecode_identifier, REPY_CODE_EVAL, code_str) \
1418REPY_u16 out_var = REPY_FN_EVAL_U16(bytecode_identifier)
1435#define REPY_FN_EVAL_CACHE_S16(bytecode_identifier, code_str, out_var) \
1436REPY_INLINE_COMPILE_CACHE_BLOCK("REPY_FN_EVAL_CACHE_S16", bytecode_identifier, REPY_CODE_EVAL, code_str) \
1437REPY_s16 out_var = REPY_FN_EVAL_S16(bytecode_identifier)
1454#define REPY_FN_EVAL_CACHE_U32(bytecode_identifier, code_str, out_var) \
1455REPY_INLINE_COMPILE_CACHE_BLOCK("REPY_FN_EVAL_CACHE_U32", bytecode_identifier, REPY_CODE_EVAL, code_str) \
1456REPY_u32 out_var = REPY_FN_EVAL_U32(bytecode_identifier)
1473#define REPY_FN_EVAL_CACHE_S32(bytecode_identifier, code_str, out_var) \
1474REPY_INLINE_COMPILE_CACHE_BLOCK("REPY_FN_EVAL_CACHE_S32", bytecode_identifier, REPY_CODE_EVAL, code_str) \
1475REPY_s32 out_var = REPY_FN_EVAL_S32(bytecode_identifier)
1492#define REPY_FN_EVAL_CACHE_F32(bytecode_identifier, code_str, out_var) \
1493REPY_INLINE_COMPILE_CACHE_BLOCK("REPY_FN_EVAL_CACHE_F32", bytecode_identifier, REPY_CODE_EVAL, code_str) \
1494REPY_f32 out_var = REPY_FN_EVAL_F32(bytecode_identifier)
1511#define REPY_FN_EVAL_CACHE_U64(bytecode_identifier, code_str, out_var) \
1512REPY_INLINE_COMPILE_CACHE_BLOCK("REPY_FN_EVAL_CACHE_U64", bytecode_identifier, REPY_CODE_EVAL, code_str) \
1513REPY_u64 out_var = REPY_FN_EVAL_U64(bytecode_identifier)
1530#define REPY_FN_EVAL_CACHE_S64(bytecode_identifier, code_str, out_var) \
1531REPY_INLINE_COMPILE_CACHE_BLOCK("REPY_FN_EVAL_CACHE_S64", bytecode_identifier, REPY_CODE_EVAL, code_str) \
1532REPY_s64 out_var = REPY_FN_EVAL_S64(bytecode_identifier)
1549#define REPY_FN_EVAL_CACHE_F64(bytecode_identifier, code_str, out_var) \
1550REPY_INLINE_COMPILE_CACHE_BLOCK("REPY_FN_EVAL_CACHE_F64", bytecode_identifier, REPY_CODE_EVAL, code_str) \
1551REPY_f64 out_var = REPY_FN_EVAL_F64(bytecode_identifier)
1571#define REPY_FN_EVAL_CACHE_STR(bytecode_identifier, code_str, out_var) \
1572REPY_INLINE_COMPILE_CACHE_BLOCK("REPY_FN_EVAL_CACHE_STR", bytecode_identifier, REPY_CODE_EVAL, code_str) \
1573char* out_var = REPY_FN_EVAL_STR(bytecode_identifier)
1593#define REPY_FN_EVAL_CACHE_BYTESTR(bytecode_identifier, code_str, out_var) \
1594REPY_INLINE_COMPILE_CACHE_BLOCK("REPY_FN_EVAL_CACHE_BYTESTR", bytecode_identifier, REPY_CODE_EVAL, code_str) \
1595char* out_var = REPY_FN_EVAL_BYTESTR(bytecode_identifier)
1614#define REPY_FN_IMPORT(module_name) \
1615REPY_DictSetCStr(REPY_FN_LOCAL_SCOPE, module_name, REPY_MakeSUH(REPY_ImportModule(module_name)))
1626#define REPY_FN_GET(var_name) \
1627REPY_DictGetCStr(REPY_FN_LOCAL_SCOPE, var_name)
1637#define REPY_FN_SET(var_name, py_object) \
1638REPY_DictSetCStr(REPY_FN_LOCAL_SCOPE, var_name, py_object)
1648#define REPY_FN_GET_BOOL(var_name) \
1649REPY_CastBool(REPY_MakeSUH(REPY_DictGetCStr(REPY_FN_LOCAL_SCOPE, var_name)))
1659#define REPY_FN_SET_BOOL(var_name, value) \
1660REPY_DictSetCStr(REPY_FN_LOCAL_SCOPE, var_name, REPY_MakeSUH(REPY_CreateBool(value)))
1670#define REPY_FN_GET_U8(var_name) \
1671REPY_CastU8(REPY_MakeSUH(REPY_DictGetCStr(REPY_FN_LOCAL_SCOPE, var_name)))
1681#define REPY_FN_SET_U8(var_name, value) \
1682REPY_DictSetCStr(REPY_FN_LOCAL_SCOPE, var_name, REPY_MakeSUH(REPY_CreateU8(value)))
1692#define REPY_FN_GET_S8(var_name) \
1693REPY_CastS8(REPY_MakeSUH(REPY_DictGetCStr(REPY_FN_LOCAL_SCOPE, var_name)))
1703#define REPY_FN_SET_S8(var_name, value) \
1704REPY_DictSetCStr(REPY_FN_LOCAL_SCOPE, var_name, REPY_MakeSUH(REPY_CreateS8(value)))
1714#define REPY_FN_GET_U16(var_name) \
1715REPY_CastU16(REPY_MakeSUH(REPY_DictGetCStr(REPY_FN_LOCAL_SCOPE, var_name)))
1725#define REPY_FN_SET_U16(var_name, value) \
1726REPY_DictSetCStr(REPY_FN_LOCAL_SCOPE, var_name, REPY_MakeSUH(REPY_CreateU16(value)))
1736#define REPY_FN_GET_S16(var_name) \
1737REPY_CastS16(REPY_MakeSUH(REPY_DictGetCStr(REPY_FN_LOCAL_SCOPE, var_name)))
1747#define REPY_FN_SET_S16(var_name, value) \
1748REPY_DictSetCStr(REPY_FN_LOCAL_SCOPE, var_name, REPY_MakeSUH(REPY_CreateS16(value)))
1758#define REPY_FN_GET_U32(var_name) \
1759REPY_CastU32(REPY_MakeSUH(REPY_DictGetCStr(REPY_FN_LOCAL_SCOPE, var_name)))
1769#define REPY_FN_SET_U32(var_name, value) \
1770REPY_DictSetCStr(REPY_FN_LOCAL_SCOPE, var_name, REPY_MakeSUH(REPY_CreateU32(value)))
1780#define REPY_FN_GET_S32(var_name) \
1781REPY_CastS32(REPY_MakeSUH(REPY_DictGetCStr(REPY_FN_LOCAL_SCOPE, var_name)))
1791#define REPY_FN_SET_S32(var_name, value) \
1792REPY_DictSetCStr(REPY_FN_LOCAL_SCOPE, var_name, REPY_MakeSUH(REPY_CreateS32(value)))
1802#define REPY_FN_GET_F32(var_name) \
1803REPY_CastF32(REPY_MakeSUH(REPY_DictGetCStr(REPY_FN_LOCAL_SCOPE, var_name)))
1813#define REPY_FN_SET_F32(var_name, value) \
1814REPY_DictSetCStr(REPY_FN_LOCAL_SCOPE, var_name, REPY_MakeSUH(REPY_CreateF32(value)))
1824#define REPY_FN_GET_U64(var_name) \
1825REPY_CastU64(REPY_MakeSUH(REPY_DictGetCStr(REPY_FN_LOCAL_SCOPE, var_name)))
1835#define REPY_FN_SET_U64(var_name, value) \
1836REPY_DictSetCStr(REPY_FN_LOCAL_SCOPE, var_name, REPY_MakeSUH(REPY_CreateU64(value)))
1846#define REPY_FN_GET_S64(var_name) \
1847REPY_CastS64(REPY_MakeSUH(REPY_DictGetCStr(REPY_FN_LOCAL_SCOPE, var_name)))
1857#define REPY_FN_SET_S64(var_name, value) \
1858REPY_DictSetCStr(REPY_FN_LOCAL_SCOPE, var_name, REPY_MakeSUH(REPY_CreateS64(value)))
1868#define REPY_FN_GET_F64(var_name) \
1869REPY_CastF64(REPY_MakeSUH(REPY_DictGetCStr(REPY_FN_LOCAL_SCOPE, var_name)))
1879#define REPY_FN_SET_F64(var_name, value) \
1880REPY_DictSetCStr(REPY_FN_LOCAL_SCOPE, var_name, REPY_MakeSUH(REPY_CreateF64(value)))
1892#define REPY_FN_GET_STR(var_name) \
1893REPY_CastStr(REPY_MakeSUH(REPY_DictGetCStr(REPY_FN_LOCAL_SCOPE, var_name)))
1903#define REPY_FN_SET_STR(var_name, value) \
1904REPY_DictSetCStr(REPY_FN_LOCAL_SCOPE, var_name, REPY_MakeSUH(REPY_CreateStr(value)))
1915#define REPY_FN_SET_STR_N(var_name, value, len) \
1916REPY_DictSetCStr(REPY_FN_LOCAL_SCOPE, var_name, REPY_MakeSUH(REPY_CreateStrN(value, len)))
1928#define REPY_FN_GET_BYTESTR(var_name) \
1929REPY_CastByteStr(REPY_MakeSUH(REPY_DictGetCStr(REPY_FN_LOCAL_SCOPE, var_name)))
1939#define REPY_FN_SET_BYTESTR(var_name, value) \
1940REPY_DictSetCStr(REPY_FN_LOCAL_SCOPE, var_name, REPY_MakeSUH(REPY_CreateByteStr(value)))
1951#define REPY_FN_SET_BYTESTR_N(var_name, value, len) \
1952REPY_DictSetCStr(REPY_FN_LOCAL_SCOPE, var_name, REPY_MakeSUH(REPY_CreateByteStrN(value, len)))
1983#define REPY_FN_IF_CACHE_INIT(helper_identifier) \
1984static REPY_IfStmtChain* helper_identifier ## _chain_root = NULL; \
1985REPY_IfStmtHelper* helper_identifier = REPY_DeferredCleanupHelper_AddIfStmtHelper(REPY_FN_AUTO_CLEANUP, REPY_IfStmtHelper_Create(&helper_identifier ## _chain_root)); \
1999#define REPY_FN_IF_CACHE_STMT(helper_identifier, py_expression) \
2001 REPY_IfStmtHelper_Step( \
2002 helper_identifier, \
2003 REPY_FN_GLOBAL_SCOPE, \
2004 REPY_FN_LOCAL_SCOPE, \
2009 #helper_identifier \
2026#define REPY_FN_IF_CACHE(helper_identifier, py_expression) \
2027REPY_FN_IF_CACHE_INIT(helper_identifier) \
2028REPY_FN_IF_CACHE_STMT(helper_identifier, py_expression)
2041#define REPY_FN_ELIF_CACHE(helper_identifier, py_expression) \
2042else REPY_FN_IF_CACHE_STMT(helper_identifier, py_expression)
2074#define REPY_FN_WHILE_CACHE(bytecode_identifier, py_expression) \
2075REPY_INLINE_COMPILE_CACHE_BLOCK("REPY_FN_WHILE_CACHE", bytecode_identifier, REPY_CODE_EVAL, py_expression); \
2076while (REPY_FN_EVAL_BOOL(bytecode_identifier))
2099#define REPY_FN_FOREACH_CACHE(bytecode_identifier, var_name, py_expression) \
2100REPY_INLINE_COMPILE_CACHE_BLOCK("REPY_FN_FOREACH_CACHE", bytecode_identifier, REPY_CODE_EVAL, py_expression); \
2102 REPY_IteratorHelper* bytecode_identifier ## _iter = REPY_DeferredCleanupHelper_AddIteratorHelper( \
2103 REPY_FN_AUTO_CLEANUP, \
2104 REPY_IteratorHelper_Create(REPY_MakeSUH(REPY_FN_EVAL(bytecode_identifier)), REPY_FN_LOCAL_SCOPE, var_name, false) \
2106 REPY_IteratorHelper_Update(bytecode_identifier ## _iter);\
2123#define REPY_FN_FOR_CACHE(bytecode_identifier, py_init_statement, py_eval_expression, py_update_statement) \
2124REPY_INLINE_COMPILE_CACHE_BLOCK("REPY_FN_FOR_CACHE", bytecode_identifier ## _init_statement, REPY_CODE_EXEC, py_init_statement); \
2125REPY_INLINE_COMPILE_CACHE_BLOCK("REPY_FN_FOR_CACHE", bytecode_identifier ## _eval_expression, REPY_CODE_EVAL, py_eval_expression); \
2126REPY_INLINE_COMPILE_CACHE_BLOCK("REPY_FN_FOR_CACHE", bytecode_identifier ## _update_statement, REPY_CODE_EXEC, py_update_statement); \
2128 REPY_FN_EXEC(bytecode_identifier ## _init_statement); \
2129 REPY_FN_EVAL_BOOL(bytecode_identifier ## _eval_expression); \
2130 REPY_FN_EXEC(bytecode_identifier ## _update_statement) \
2368 const char* filepath = (
const char*) recomp_get_mod_file_path();
2370 recomp_free((
void*) filepath);
3527#define REPY_VL REPY_VariadicLocals
3556#define REPY_VL_SUH REPY_VariadicLocals_SUH
3744 const char* filepath = (
const char*) recomp_get_mod_file_path();
3746 recomp_free((
void*) filepath);
REPY_bool REPY_Exec(REPY_Handle code, REPY_Handle global_scope_nullable, REPY_Handle local_scope_nullable)
Execute Python code statements from a REPY_Handle. Optionally provide dict objects to serve as a scop...
REPY_Handle REPY_Eval(REPY_Handle code, REPY_Handle global_scope_nullable, REPY_Handle local_scope_nullable)
Evaluate a Python code expression from a REPY_Handle. Optionally provide dict objects to serve as a s...
REPY_bool REPY_ExecCStr(const char *code, REPY_Handle global_scope_nullable, REPY_Handle local_scope_nullable)
Execute Python code from a NULL-terminated C string. Optionally provide dict objects to serve as a sc...
REPY_Handle REPY_EvalCStr(const char *code, REPY_Handle global_scope_nullable, REPY_Handle local_scope_nullable)
Evaluate a Python code expression from a NULL-terminated C string. Optionally provide dict objects to...
REPY_Handle REPY_CompileCStr(const char *code, const char *identifier, REPY_CodeMode mode)
Compile a Python code string into Python bytecode, using a NULL-terminated C string for the code.
REPY_Handle REPY_VariadicLocals(REPY_Handle dict_nullable_no_release, REPY_u32 size,...)
Adds the Python object represented by a set of REPY_Handle handles to a dict, using the keys followin...
REPY_Handle REPY_CompileCStrN(const char *code, REPY_u32 len, const char *identifier, REPY_CodeMode mode)
Compile a Python code string into Python bytecode, using a C char array for the code.
REPY_bool REPY_ExecCStrN(const char *code, REPY_u32 len, REPY_Handle global_scope_nullable, REPY_Handle local_scope_nullable)
Execute Python code from a C char array. Optionally provide dict objects to serve as a scope.
REPY_Handle REPY_EvalCStrN(const char *code, REPY_u32 len, REPY_Handle global_scope_nullable, REPY_Handle local_scope_nullable)
Evaluate a Python code expression from a C char array. Optionally provide dict objects to serve as a ...
REPY_Handle REPY_Compile(REPY_Handle code, REPY_Handle identifier, REPY_Handle mode)
Compile a Python code string into Python bytecode, using a REPY_Handle for the text.
REPY_Handle REPY_VariadicLocals_SUH(REPY_Handle dict_nullable_no_release, REPY_u32 size,...)
Adds the Python object represented by a set of REPY_handles to a dict, using the keys following the s...
REPY_DeferredCleanupHelper * REPY_DeferredCleanupHelper_Create()
Create a new REPY_DeferredCleanupHelper object.
void REPY_DeferredCleanupHelper_Destroy(REPY_DeferredCleanupHelper *cleanup)
Destroy a REPY_DeferredCleanupHelper instance and clean up all of the resources registered to it.
void * REPY_DeferredCleanupHelper_AddRecompFree(REPY_DeferredCleanupHelper *cleanup, void *pointer)
Adds a region of memory (specified by a void*) to be freed with recomp_free by a REPY_DeferredCleanup...
void REPY_DeferredCleanupHelper_CleanNow(REPY_DeferredCleanupHelper *cleanup)
Clean up all of the resources registered to a REPY_DeferredCleanupHelper without destroying the insta...
REPY_IteratorHelper * REPY_DeferredCleanupHelper_AddIteratorHelper(REPY_DeferredCleanupHelper *cleanup, REPY_IteratorHelper *iterator_helper)
Adds a REPY_IteratorHelper to be destroyed by a REPY_DeferredCleanupHelper instance.
REPY_IfStmtHelper * REPY_DeferredCleanupHelper_AddIfStmtHelper(REPY_DeferredCleanupHelper *cleanup, REPY_IfStmtHelper *if_stmt_helper)
Adds a REPY_IfStmtHelper to be destroyed by a REPY_DeferredCleanupHelper instance.
REPY_Handle REPY_DeferredCleanupHelper_AddHandle(REPY_DeferredCleanupHelper *cleanup, REPY_Handle handle_no_release)
Adds a REPY_Handle to be release by a REPY_DeferredCleanupHelper instance.
REPY_Handle REPY_DictGet(REPY_Handle dict, REPY_Handle key)
Get an entry from a Python dict, using a REPY handle for the key.
void REPY_DictDel(REPY_Handle dict, REPY_Handle key)
Remove an entry from a dict via it's key, using a REPY handle for the key.
REPY_Handle REPY_DictGetCStr(REPY_Handle dict, char *key)
Get an entry from a Python dict, using a NULL-terminated C string for the key.
REPY_Handle REPY_CreateDict(REPY_u32 size,...)
Create a Python dict and return a REPY_Handle for it.
REPY_Handle REPY_CreateDict_SUH(REPY_u32 size,...)
Create a Python dict and return a REPY_Handle for it.
void REPY_DictDelCStr(REPY_Handle dict, char *key)
Remove an entry from a dict via it's key, using a NULL-terminated C string for the key.
REPY_bool REPY_DictHasCStr(REPY_Handle dict, char *key)
Checks if a Python dict has an entry with a specific key, using a NULL-terminated C string for the ke...
REPY_bool REPY_DictHas(REPY_Handle dict, REPY_Handle key)
Checks if a Python dict has an entry with a specific key, using a REPY handle for the key.
void REPY_DictSetCStr(REPY_Handle dict, char *key, REPY_Handle value)
Sets/adds a Python object to a Python dict, using a NULL-terminated C string for the key.
void REPY_DictSet(REPY_Handle dict, REPY_Handle key, REPY_Handle value)
Sets/adds a Python object to a Python dict, using a REPY handle for the key.
REPY_Handle REPY_GetErrorTrace()
Get the trace object for the Python exception for the current interpreter and thread.
REPY_Handle REPY_GetErrorValue()
Get the captured Python exception object for the current interpreter and thread.
void REPY_ClearError()
Releases the captured exception for the current interpreter and thread.
REPY_Handle REPY_GetErrorType()
Get the type of a captured Python exception for the current interpreter and thread.
REPY_bool REPY_IsErrorSet()
Checks if a Python exception was raised and caught by the REPY API.
REPY_bool REPY_Call(REPY_Handle func, REPY_Handle args_nullable, REPY_Handle kwargs_nullable)
Call a Python function (or another callable object) by handle, and discard the return value.
REPY_bool REPY_CallAttrCStr(REPY_Handle object, char *name, REPY_Handle args_nullable, REPY_Handle kwargs_nullable)
Call a Python object member (such as a module function, object method, or another callable) by parent...
REPY_Handle REPY_CallAttrReturn(REPY_Handle object, REPY_Handle name, REPY_Handle args_nullable, REPY_Handle kwargs_nullable)
Call a Python object member (such as a module function, object method, or another callable) by parent...
REPY_Handle REPY_CallReturn(REPY_Handle func, REPY_Handle args_nullable, REPY_Handle kwargs_nullable)
Call a Python function (or another callable object) by handle, and get the return value as a REPY_Han...
REPY_bool REPY_CallAttr(REPY_Handle object, REPY_Handle name, REPY_Handle args_nullable, REPY_Handle kwargs_nullable)
Call a Python object member (such as a module function, object method, or another callable) by parent...
REPY_Handle REPY_CallAttrCStrReturn(REPY_Handle object, char *name, REPY_Handle args_nullable, REPY_Handle kwargs_nullable)
Call a Python object member (such as a module function, object method, or another callable) by parent...
REPY_bool REPY_HasAttr(REPY_Handle object, REPY_Handle key)
Checks if a Python object has an attribute with a specific name, using a REPY_Handle for the attribut...
void REPY_SetAttr(REPY_Handle object, REPY_Handle key, REPY_Handle value)
Assigned a named attribute of a Python object, using a REPY_Handle for the attribute name.
void REPY_DelAttr(REPY_Handle object, REPY_Handle key)
Deletes an attribute from a Python object by name, using a REPY_Handle for the attribute name.
void REPY_SetAttrCStr(REPY_Handle object, char *key, REPY_Handle value)
Assigned a named attribute of a Python object, using a NULL-terminated C string for the name.
REPY_u32 REPY_Len(REPY_Handle object)
Gets the length of an appropriate Python object as a u32.
void REPY_DelAttrCStr(REPY_Handle object, char *key)
Deletes an attribute from a Python object by name, using a NULL-terminated C string for the name.
REPY_Handle REPY_GetAttrCStr(REPY_Handle object, char *key, REPY_Handle default_value_nullable)
Returns a REPY_Handle for a named attribute of a Python object, using a NULL-terminated C string for ...
REPY_bool REPY_HasAttrCStr(REPY_Handle object, char *key)
Checks if a Python object has an attribute with a specific name, using a NULL-terminated C string for...
REPY_Handle REPY_GetAttr(REPY_Handle object, REPY_Handle key, REPY_Handle default_value_nullable)
Returns a REPY_Handle for a named attribute of a Python object, using a REPY_Handle for the attribute...
REPY_Handle REPY_CopyHandle(REPY_Handle handle_no_release)
Creates a new handle to the same Python object as another handle.
REPY_bool REPY_GetSUH(REPY_Handle py_handle_no_release)
Gets whether or not a REPY_Handle is Single-Use.
REPY_Handle REPY_MakeSUH(REPY_Handle py_handle_no_release)
Convienience function that marks a REPY_Handle as Single-Use and then returns the value of the provid...
void REPY_SetSUH(REPY_Handle py_handle_no_release, REPY_bool value)
Sets whether or not a REPY_Handle is Single-Use.
REPY_bool REPY_IsValidHandle(REPY_Handle py_handle_no_release)
Returns whether the a handle value is mapped to a Python object.
void REPY_Release(REPY_Handle py_handle)
Releases a REPY_Handle, removing the reference to the Python object and rendering this handle invalid...
unsigned int REPY_Handle
Represents a Python object in REPY API functions.
Definition repy_api.h:201
signed int REPY_InterpreterIndex
Index value for a specific Python interpreter, either the main interpreter or a registered subinterpr...
Definition repy_api.h:212
char * REPY_InlineCodeSourceStrHelper(char *category, char *filename, char *function_name, REPY_u32 line_number, char *identifier)
Constructs the filename strings used by most macros that enable inlining Python code into C files.
REPY_IfStmtChain * REPY_IfStmtChain_BorrowNext(REPY_IfStmtChain *chain)
Returns a pointer to the next IfStmtChain in the series.
REPY_Handle REPY_IfStmtChain_BorrowEvalBytecode(REPY_IfStmtChain *chain)
Retrieves the evaluated bytecode expression for this REPY_IfStmtChain as a REPY_Handle.
void REPY_IfStmtChain_Destroy(REPY_IfStmtChain *chain)
Destructs a REPY_IfStmtChain object from the heap, recursively destructs and all additional links dow...
REPY_IfStmtChain * REPY_IfStmtChain_Create(char *expr_string, char *filename, char *function_name, REPY_u32 line_number, char *identifier)
Creates a new link in a REPY_IfStmtChain if statement chain.
void REPY_IfStmtChain_StealNext(REPY_IfStmtChain *chain, REPY_IfStmtChain *next)
Sets the next REPY_IfStmtChain in a series.
void REPY_IfStmtChain_StealEvalBytecode(REPY_IfStmtChain *chain, REPY_Handle eval_bytecode)
Sets.
REPY_bool REPY_IfStmtHelper_Step(REPY_IfStmtHelper *helper, REPY_Handle global_scope, REPY_Handle local_scope, char *expr_string, char *filename, char *function_name, REPY_u32 line_number, char *identifier)
Steps through and evaluate the next link in the REPY_IfStmtChain chain provided to the REPY_IfStmtHel...
void REPY_IfStmtHelper_Destroy(REPY_IfStmtHelper *helper)
Destroys and deallocates a REPY_IfStmtHelper.
REPY_IfStmtHelper * REPY_IfStmtHelper_Create(REPY_IfStmtChain **chain_root)
Initializes a REPY_IfStmtHelper for controlling managing a Pythonic if/else block.
REPY_bool REPY_GetInterpreterAutoDisarm(REPY_InterpreterIndex index)
Gets whether or not this subinterpreter should be 'disarmed' when shutting down.
void REPY_SetInterpreterAutoDisarm(REPY_InterpreterIndex index, REPY_bool value)
Sets whether or not this subinterpreter should be 'disarmed' when shutting down.
void REPY_PopInterpreter()
Pops an interpreter index from the interpreter stack, switching active interpreters if necessary.
REPY_InterpreterIndex REPY_GetCurrentInterpreter()
Gets the interpreter index at the top of the interpreter stack.
REPY_InterpreterIndex REPY_GetHandleInterpreter(REPY_Handle handle_no_release)
Gets the index of the interpreter a specific REPY_Handle object is associated with.
void REPY_PushInterpreter(REPY_InterpreterIndex interpreter_handle)
Pushes an interpreter index to the interpreter stack, and switching the active interpreter if necessa...
REPY_Handle REPY_Next(REPY_Handle iterator, REPY_Handle default_obj_nullable, REPY_bool process_stop_iteration)
Gets the next Python object from a Python iterator.
REPY_Handle REPY_Iter(REPY_Handle object)
Gets an iterator for a given Python object.
void REPY_IteratorHelper_Destroy(REPY_IteratorHelper *helper)
Destructs a REPY_IteratorHelper object from the heap.
REPY_IteratorHelper * REPY_IteratorHelper_Create(REPY_Handle py_object, REPY_Handle py_scope_nullable, const char *var_name, REPY_bool auto_destroy)
Create a REPY_IteratorHelper object on the heap.
REPY_u32 REPY_IteratorHelper_GetIndex(REPY_IteratorHelper *helper)
Gets the current index of a REPY_IteratorHelper object.
REPY_bool REPY_IteratorHelper_Update(REPY_IteratorHelper *helper)
Makes the REPY_IteratorHelper move on to the next object in the iteration.
REPY_Handle REPY_IteratorHelper_BorrowCurrent(REPY_IteratorHelper *helper)
Gets the REPY_Handle for a REPY_IteratorHelper object's current Python object.
REPY_Handle REPY_MemcpyToBytes(void *src, REPY_u32 len, REPY_bool reverse)
Create a Python bytes object from a chunk of mod memory.
void * REPY_AllocAndCopyBuffer(REPY_bool reverse, REPY_Handle buffer, REPY_u32 *write_size)
Copy the content of a Python object supporting buffer protocol into mod memory, automatically allocat...
REPY_Handle REPY_MemcpyToByteArray(void *src, REPY_u32 len, REPY_bool reverse)
Create a Python bytearray object from a chunk of mod memory.
REPY_u32 REPY_MemcpyFromBuffer(void *dst, REPY_u32 len, REPY_bool reverse, REPY_Handle buffer)
Copy the content of a Python object supporting buffer protocol (such as bytes and bytearray) into mod...
void REPY_AddCStrToSysPath(const char *filepath)
Casts a null-terminated C-string to a Python str and appends it to the current interpreter's sys....
REPY_Handle REPY_ImportModule(const char *identifier)
Imports a Python module by name and returns a handle to it.
REPY_Handle REPY_ConstructModuleFromCStrN(const char *identifier, const char *code, REPY_u32 len, REPY_bool add_to_sys)
Construct a new Python module from a char array, optionally importable by name.
void REPY_AddNrmToSysPath()
Adds this NRM to the current interpreter's sys.path.
Definition repy_api.h:2367
REPY_Handle REPY_ConstructModuleFromCStr(const char *identifier, const char *code, REPY_bool add_to_sys)
Construct a new Python module from a NULL-terminated code string, optionally importable by name.
unsigned short int REPY_u16
An unsigned, 16-bit integer compatible with libultra's u16.
Definition repy_api.h:84
float REPY_f32
A 32-bit floating point value compatible with libultra's f32.
Definition repy_api.h:119
unsigned long REPY_u32
An unsigned, 13-bit integer compatible with libultra's u32.
Definition repy_api.h:98
signed long REPY_s32
A signed, 32-bit integer compatible with libultra's s32.
Definition repy_api.h:91
REPY_CodeModeEnum
Used to set the type of code-string being compiled, in line with how Python's built-in compile functi...
Definition repy_api.h:144
signed char REPY_s8
A signed, 8-bit integer compatible with libultra's s8.
Definition repy_api.h:63
signed long long int REPY_s64
A signed, 64-bit integer compatible with libultra's s64.
Definition repy_api.h:105
enum REPY_CodeModeEnum REPY_CodeMode
Used to set the type of code-string being compiled, in line with how Python's built-in compile functi...
unsigned char REPY_u8
An unsigned, 8-bit integer compatible with libultra's u8.
Definition repy_api.h:70
double REPY_f64
A 64-bit floating point value compatible with libultra's f64.
Definition repy_api.h:126
signed short int REPY_s16
A signed, 16-bit integer compatible with libultra's s16.
Definition repy_api.h:77
unsigned long long int REPY_u64
An unsigned, 64-bit integer compatible with libultra's u64.
Definition repy_api.h:112
_Bool REPY_bool
A boolean type compatible with libultra's bool type.
Definition repy_api.h:133
@ REPY_CODE_EVAL
Equivalent to eval.
Definition repy_api.h:146
@ REPY_CODE_EXEC
Equivalent to exec.
Definition repy_api.h:145
@ REPY_CODE_SINGLE
Equivalent to single.
Definition repy_api.h:147
void REPY_IteratorHelper
Helper object used to when iterating through Python objects in loops in C code.
Definition repy_api.h:264
void REPY_DeferredCleanupHelper
Helper object used to deallocate REPY_IfStmtHelper and REPY_IteratorHelper objects when a REPY_FN sco...
Definition repy_api.h:303
void REPY_IfStmtChain
Helper object used to cache Python expressions as bytecode, so that they don't need to be re-parsed a...
Definition repy_api.h:280
void REPY_IfStmtHelper
Helper object used to step through a REPY_IfStmtChain while it's being evaluated, generating new link...
Definition repy_api.h:292
REPY_InterpreterIndex REPY_PreInitRegisterSubinterpreter()
Registers a new Python subinterpreter to be created on initialization, and return a REPY_InterpreterI...
void REPY_PreInitAddSysPath(const unsigned char *nrm_file_path)
Instruct REPY to add a path to Python's module search path during initialization.
REPY_Handle REPY_CreateStr_SUH(const char *string)
Returns a Single-Use REPY_Handle for a Python str object, based on a NULL-terminated C string.
REPY_Handle REPY_CreateS64(REPY_s64 value)
Returns a REPY_Handle for a Python int object, based on a C s64.
REPY_Handle REPY_CreateBool_SUH(REPY_bool value)
Returns a Single-Use REPY_Handle for a Python bool object, based on a C bool.
REPY_s32 REPY_CastS32(REPY_Handle object)
Casts a Python object to a C s32.
REPY_Handle REPY_CreateU32(REPY_u32 value)
Returns a REPY_Handle for a Python int object, based on a C u32.
REPY_Handle REPY_CreateU8_SUH(REPY_u8 value)
Returns a Single-Use REPY_Handle for a Python int object, based on a C u8.
REPY_Handle REPY_CreateS8(REPY_s8 value)
Returns a REPY_Handle for a Python int object, based on a C s8.
REPY_u32 REPY_CastU32(REPY_Handle object)
Casts a Python object to a C u32.
REPY_f64 REPY_CastF64(REPY_Handle object)
Casts a Python object to a C u8.
char * REPY_CastByteStr(REPY_Handle object)
Casts a Python object to a NULL-terminated C string. Intended to be used with a Python bytes.
REPY_Handle REPY_CreateStrN_SUH(const char *string, REPY_u32 len)
Returns a Single-Use REPY_Handle for a Python str object, based on char array.
REPY_Handle REPY_CreateS8_SUH(REPY_s8 value)
Returns a Single-Use REPY_Handle for a Python int object, based on a C s8.
REPY_s64 REPY_CastS64(REPY_Handle object)
Casts a Python object to a C s64.
REPY_Handle REPY_CreateF32_SUH(REPY_f32 value)
Returns a Single-Use REPY_Handle for a Python float object, based on a C f32.
REPY_bool REPY_CastBool(REPY_Handle object)
Casts a Python object to a C bool.
void * REPY_CastPtr(REPY_Handle object)
Casts a Python object to a C void*.
REPY_Handle REPY_CreateS16_SUH(REPY_s16 value)
Returns a Single-Use REPY_Handle for a Python int object, based on a C s16.
REPY_Handle REPY_CreateU8(REPY_u8 value)
Returns a REPY_Handle for a Python int object, based on a C u8.
REPY_Handle REPY_CreatePtr_SUH(void *value)
Returns a Single-Use REPY_Handle for a Python int object, based on a C void*.
REPY_Handle REPY_CreateU64(REPY_u64 value)
Returns a REPY_Handle for a Python int object, based on a C u64.
REPY_Handle REPY_CreateF32(REPY_f32 value)
Returns a REPY_Handle for a Python float object, based on a C f32.
REPY_Handle REPY_CreateU16_SUH(REPY_u16 value)
Returns a Single-Use REPY_Handle for a Python u16 object, based on a C int.
REPY_Handle REPY_CreateU64_SUH(REPY_u64 value)
Returns a Single-Use REPY_Handle for a Python int object, based on a C u64.
REPY_Handle REPY_CreateS32(REPY_s32 value)
Returns a REPY_Handle for a Python int object, based on a C s32.
REPY_Handle REPY_CreateU32_SUH(REPY_u32 value)
Returns a Single-Use REPY_Handle for a Python int object, based on a C u32.
REPY_Handle REPY_CreateStrN(const char *string, REPY_u32 len)
Returns a REPY_Handle for a Python str object, based on char array.
REPY_f32 REPY_CastF32(REPY_Handle object)
Casts a Python object to a C f32.
REPY_u8 REPY_CastU8(REPY_Handle object)
Casts a Python object to a C u8.
REPY_Handle REPY_CreateByteStr(const char *string)
Returns a REPY_Handle for a Python bytes object, based on a NULL-terminated C string.
REPY_Handle REPY_CreateU16(REPY_u16 value)
Returns a REPY_Handle for a Python int object, based on a C u16.
REPY_s16 REPY_CastS16(REPY_Handle object)
Casts a Python object to a C s16.
REPY_Handle REPY_CreatePtr(void *value)
Returns a REPY_Handle for a Python int object, based on a C void*.
REPY_u16 REPY_CastU16(REPY_Handle object)
Casts a Python object to a C u16.
REPY_Handle REPY_CreateF64_SUH(REPY_f64 value)
Returns a Single-Use REPY_Handle for a Python int object, based on a C bool.
REPY_Handle REPY_CreateS16(REPY_s16 value)
Returns a REPY_Handle for a Python int object, based on a C s16.
REPY_Handle REPY_CreateByteStrN(const char *string, REPY_u32 len)
Returns a REPY_Handle for a Python bytes object, based on a char array.
REPY_Handle REPY_CreateByteStrN_SUH(const char *string, REPY_u32 len)
Returns a Single-Use REPY_Handle for a Python bytes object, based on a char array.
REPY_Handle REPY_CreateStr(const char *string)
Returns a REPY_Handle for a Python str object, based on a NULL-terminated C string.
REPY_Handle REPY_CreateS32_SUH(REPY_s32 value)
Returns a Single-Use REPY_Handle for a Python int object, based on a C s32.
REPY_Handle REPY_CreateByteStr_SUH(const char *string)
Returns a Single-Use REPY_Handle for a Python bytes object, based on a NULL-terminated C string.
REPY_Handle REPY_CreateBool(REPY_bool value)
Returns a REPY_Handle for a Python bool object, based on a C bool.
REPY_u64 REPY_CastU64(REPY_Handle object)
Casts a Python object to a C u64.
REPY_Handle REPY_CreateS64_SUH(REPY_s64 value)
Returns a Single-Use REPY_Handle for a Python int object, based on a C s64.
char * REPY_CastStr(REPY_Handle object)
Casts a Python object to NULL-terminated C string. Intended to be used with a Python str.
REPY_Handle REPY_CreateF64(REPY_f64 value)
Returns a REPY_Handle for a Python int object, based on a C u8.
REPY_s8 REPY_CastS8(REPY_Handle object)
Casts a Python object to a C s8.
REPY_Handle REPY_CreatePairCStr(char *key, REPY_Handle value)
Create a Python tuple with exactly 2 entries and return a REPY_Handle for it. The first entry is auto...
REPY_Handle REPY_CreateTuple(REPY_u32 size,...)
Create a Python tuple and return a REPY_Handle for it.
REPY_Handle REPY_TupleGetIndexS32(REPY_Handle tuple, int index)
Returns the Python object at a specific index from a tuple.
REPY_Handle REPY_CreatePair_SUH(REPY_Handle key, REPY_Handle value)
Create a Python tuple with exactly 2 entries and return a Single-Use REPY_Handle for it.
REPY_Handle REPY_CreatePairCStr_SUH(char *key, REPY_Handle value)
Create a Python tuple with exactly 2 entries and return a Single-Use REPY_Handle for it....
REPY_Handle REPY_CreatePair(REPY_Handle key, REPY_Handle value)
Create a Python tuple with exactly 2 entries and return a REPY_Handle for it.
REPY_Handle REPY_CreateTuple_SUH(REPY_u32 size,...)
Create a Python tuple and return a Single-Use REPY_Handle for it.
REPY_Handle REPY_GetNrmZipFile()
Opens a read-only instance of zipfile.ZipFile for this .nrm file. Provides an easy way to access addi...
Definition repy_api.h:3743
REPY_Handle REPY_GetZipFileFromPath(const char *filepath)
Opens a read-only instance of zipfile.ZipFile as indicated by filepath.