RecompExternalPython for N64Recompiled 2.0.0
Loading...
Searching...
No Matches
Inline Code Caching Macros

Macros

#define REPY_INLINE_COMPILE_CACHE_BLOCK(category, bytecode_identifier, code_mode, code_str)
 Inside a function, construct a code block that compiles to bytecode a Python code string the first time it's run, storing the handle for that bytecode in a static variable. Allows setting a category name.
#define REPY_INLINE_COMPILE_CACHE(bytecode_identifier, code_mode, code_str)
 Inside a function, construct a code block that compiles to bytecode a Python code string the first time it's run, storing the handle for that bytecode in a static variable.

Detailed Description

Parsing a Python code string every time it needs to be executed would make for poor performance. The macros here will parse a Python code string the first time they are run, and provide a REPY_Handle to a Python bytecode object.

Macro Definition Documentation

◆ REPY_INLINE_COMPILE_CACHE

#define REPY_INLINE_COMPILE_CACHE ( bytecode_identifier,
code_mode,
code_str )
Value:
REPY_INLINE_COMPILE_CACHE_BLOCK("REPY_INLINE_COMPILE_CACHE", bytecode_identifier, code_mode, code_str)
#define REPY_INLINE_COMPILE_CACHE_BLOCK(category, bytecode_identifier, code_mode, code_str)
Inside a function, construct a code block that compiles to bytecode a Python code string the first ti...
Definition repy_api.h:619

Inside a function, construct a code block that compiles to bytecode a Python code string the first time it's run, storing the handle for that bytecode in a static variable.

By only parsing and compiling the Python code string once, we can dramatically improve the performance of any function that needs to execute inline Python code.

This macro is identical to REPY_INLINE_COMPILE_CACHE_BLOCK, except it uses "REPY_INLINE_COMPILE_CACHE" as the category.

Parameters
bytecode_identifierThe name of the static variable that the bytecode handle will be assigned to.
code_modeThe type of code being compiled. See REPY_CodeMode for valid modes.
code_strThe Python code string to compile. Should be NULL-terminated.

◆ REPY_INLINE_COMPILE_CACHE_BLOCK

#define REPY_INLINE_COMPILE_CACHE_BLOCK ( category,
bytecode_identifier,
code_mode,
code_str )
Value:
static REPY_Handle bytecode_identifier = 0; \
if (bytecode_identifier == 0) { \
char* iden_str = REPY_InlineCodeSourceStrHelper(category, __FILE_NAME__, (char*) __func__, __LINE__, #bytecode_identifier); \
bytecode_identifier = REPY_CompileCStr(code_str, (const char*)iden_str, code_mode); \
recomp_free(iden_str); \
}
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.
unsigned int REPY_Handle
Represents a Python object in REPY API functions.
Definition repy_api.h:201
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.

Inside a function, construct a code block that compiles to bytecode a Python code string the first time it's run, storing the handle for that bytecode in a static variable. Allows setting a category name.

This macro forms the backbone of many of the other macros in this header, expecially those in the REPY_FN section. By only parsing and compiling the Python code string once, we can dramatically improve the performance of any function that needs to execute inline Python code.

The category argument becomes part of the resultant bytecode object's identifier string, which is displayed in Python error messages. In this header, macros that depend this one will use their own name for this argument. That way, if you get a error message from running inline Python code, you can see which macro caused the error along with the other source information.

Parameters
categoryA category name used as part of the bytecode's identifying string. Many REPY macros that use this one will set this to their own macro names.
bytecode_identifierThe name of the static variable that the bytecode handle will be assigned to.
code_modeThe type of code being compiled. See REPY_CodeMode for valid modes.
code_strThe Python code string to compile. Should be NULL-terminated.