RecompExternalPython for N64Recompiled 2.0.0
Loading...
Searching...
No Matches
REPY_FN_IF_CACHE - Conditional Statements Based on Python Scopes

Macros

#define REPY_FN_IF_CACHE_INIT(helper_identifier)
 Initializes the helpers for cached Pythonic if statements in the current scope.
#define REPY_FN_IF_CACHE_STMT(helper_identifier, py_expression)
 Constructs a if statement that uses a cached Python expression executed in the current scope.
#define REPY_FN_IF_CACHE(helper_identifier, py_expression)
 Initializes the helpers for a cached Pythonic if/else block, and constructs the first if statement, using a cached Python expression executed in the local scope.
#define REPY_FN_ELIF_CACHE(helper_identifier, py_expression)
 Constructs a else if statement that uses a cached Python expression executed in the current scope.

Detailed Description

Because code string parsing and execution requires contiguous, compilable strings, there is no good way to call back into mod code from within a if/else block within Python code. As an alternative, this section provides an easy and performant way to use the Python scope to govern mod code if/else blocks utilizing REPY_IfStmtHelper.

There are no REPY_FN_IF or REPY_FN_IF_CSTR variations of these macros, as simple REPY_FN_EVAL_BOOL and REPY_FN_EVAL_CSTR_BOOL calls could be used as the conditions of if statements directly. Nevertheless, the term CACHE is included in these macro names to indicate that purpose and behavior; As per the design of REPY_IfStmtHelper, the code strings given to these macros are only parsed once, and the bytecode stored for repeated evaluations.

Macro Definition Documentation

◆ REPY_FN_ELIF_CACHE

#define REPY_FN_ELIF_CACHE ( helper_identifier,
py_expression )
Value:
else REPY_FN_IF_CACHE_STMT(helper_identifier, py_expression)
#define REPY_FN_IF_CACHE_STMT(helper_identifier, py_expression)
Constructs a if statement that uses a cached Python expression executed in the current scope.
Definition repy_api.h:1999

Constructs a else if statement that uses a cached Python expression executed in the current scope.

Requires using the helpers initialized by REPY_FN_IF_CACHE_INIT or REPY_FN_IF_CACHE.

See the REPY_IfStmtHelper section for more information.

Parameters
helper_identifierThe variable name of the REPY_IfStmtHelper object. Needs to be the same as the value used when initializing this if/else block (using either REPY_FN_IF_CACHE_INIT or REPY_FN_IF_CACHE).
py_expressionThe Python expression to evaluate within the scope. Should be a NULL-terminated C string.

◆ REPY_FN_IF_CACHE

#define REPY_FN_IF_CACHE ( helper_identifier,
py_expression )
Value:
REPY_FN_IF_CACHE_INIT(helper_identifier) \
REPY_FN_IF_CACHE_STMT(helper_identifier, py_expression)
#define REPY_FN_IF_CACHE_INIT(helper_identifier)
Initializes the helpers for cached Pythonic if statements in the current scope.
Definition repy_api.h:1983

Initializes the helpers for a cached Pythonic if/else block, and constructs the first if statement, using a cached Python expression executed in the local scope.

This is the simplest way to handle Pythonic if/else blocks in C code, provided there are no additional C expressions that need to be evaluated as well.

See the REPY_IfStmtHelper section for more information.

Parameters
helper_identifierThe variable name of the REPY_IfStmtHelper object, as well as the prefix for the static REPY_IfStmtChain* object.
py_expressionThe Python expression to evaluate within the scope. Should be a NULL-terminated C string.

◆ REPY_FN_IF_CACHE_INIT

#define REPY_FN_IF_CACHE_INIT ( helper_identifier)
Value:
static REPY_IfStmtChain* helper_identifier ## _chain_root = NULL; \
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.
#define REPY_FN_AUTO_CLEANUP
The variable name for helper auto-cleanup object.
Definition repy_api.h:762
REPY_IfStmtHelper * REPY_IfStmtHelper_Create(REPY_IfStmtChain **chain_root)
Initializes a REPY_IfStmtHelper for controlling managing a Pythonic if/else block.
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

Initializes the helpers for cached Pythonic if statements in the current scope.

This macro is used as part of REPY_FN_IF_CACHE, but you can invoke it manually if needed (for example, if you're mixing Python and C if statements in one if/else block).

See the REPY_IfStmtHelper section for more information.

Parameters
helper_identifierThe variable name of the REPY_IfStmtHelper object, as well as the prefix for the static REPY_IfStmtChain* object.

◆ REPY_FN_IF_CACHE_STMT

#define REPY_FN_IF_CACHE_STMT ( helper_identifier,
py_expression )
Value:
if ( \
helper_identifier, \
py_expression, \
__FILE_NAME__, \
(char*) __func__, \
__LINE__, \
#helper_identifier \
) \
)
#define REPY_FN_GLOBAL_SCOPE
The variable name for inline execution global scopes.
Definition repy_api.h:750
#define REPY_FN_LOCAL_SCOPE
The variable name for inline execution local scopes.
Definition repy_api.h:756
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...

Constructs a if statement that uses a cached Python expression executed in the current scope.

This macro is used as part of REPY_FN_IF_CACHE and REPY_FN_ELIF_CACHE, but you can invoke it manually if needed (for example, if you're mixing Python and C if statements in one if/else block).

See the REPY_IfStmtHelper section for more information.

Parameters
helper_identifierThe variable name of the REPY_IfStmtHelper object. Needs to be the same as the value used when initializing this if/else block (using either REPY_FN_IF_CACHE_INIT or REPY_FN_IF_CACHE).
py_expressionThe Python expression to evaluate within the scope. Should be a NULL-terminated C string.