#ifndef Py_INTERNAL_CODE_H
#define Py_INTERNAL_CODE_H
#ifdef __cplusplus
extern "C" {
#endif
#ifndef Py_BUILD_CORE
# error "this header requires Py_BUILD_CORE define"
#endif
#include "pycore_stackref.h"
#include "pycore_lock.h"
#include "pycore_backoff.h"
#include "pycore_tstate.h"
_Py_CODEUNIT;
#define _PyCode_CODE(CO) …
#define _PyCode_NBYTES(CO) …
#define _Py_OPCODE(word) …
#define _Py_OPARG(word) …
static inline _Py_CODEUNIT
_py_make_codeunit(uint8_t opcode, uint8_t oparg)
{ … }
static inline void
_py_set_opcode(_Py_CODEUNIT *word, uint8_t opcode)
{ … }
#define _Py_MAKE_CODEUNIT(opcode, oparg) …
#define _Py_SET_OPCODE(word, opcode) …
#define _PyCode_HAS_EXECUTORS(CODE) …
#define _PyCode_HAS_INSTRUMENTATION(CODE) …
struct _py_code_state { … };
extern PyStatus _PyCode_Init(PyInterpreterState *interp);
extern void _PyCode_Fini(PyInterpreterState *interp);
#define CODE_MAX_WATCHERS …
#define CACHE_ENTRIES(cache) …
_PyLoadGlobalCache;
#define INLINE_CACHE_ENTRIES_LOAD_GLOBAL …
_PyBinaryOpCache;
#define INLINE_CACHE_ENTRIES_BINARY_OP …
_PyUnpackSequenceCache;
#define INLINE_CACHE_ENTRIES_UNPACK_SEQUENCE …
_PyCompareOpCache;
#define INLINE_CACHE_ENTRIES_COMPARE_OP …
_PyBinarySubscrCache;
#define INLINE_CACHE_ENTRIES_BINARY_SUBSCR …
_PySuperAttrCache;
#define INLINE_CACHE_ENTRIES_LOAD_SUPER_ATTR …
_PyAttrCache;
_PyLoadMethodCache;
#define INLINE_CACHE_ENTRIES_LOAD_ATTR …
#define INLINE_CACHE_ENTRIES_STORE_ATTR …
_PyCallCache;
#define INLINE_CACHE_ENTRIES_CALL …
#define INLINE_CACHE_ENTRIES_CALL_KW …
_PyStoreSubscrCache;
#define INLINE_CACHE_ENTRIES_STORE_SUBSCR …
_PyForIterCache;
#define INLINE_CACHE_ENTRIES_FOR_ITER …
_PySendCache;
#define INLINE_CACHE_ENTRIES_SEND …
_PyToBoolCache;
#define INLINE_CACHE_ENTRIES_TO_BOOL …
_PyContainsOpCache;
#define INLINE_CACHE_ENTRIES_CONTAINS_OP …
struct callable_cache { … };
#define CO_FAST_HIDDEN …
#define CO_FAST_LOCAL …
#define CO_FAST_CELL …
#define CO_FAST_FREE …
_PyLocals_Kind;
static inline _PyLocals_Kind
_PyLocals_GetKind(PyObject *kinds, int i)
{ … }
static inline void
_PyLocals_SetKind(PyObject *kinds, int i, _PyLocals_Kind kind)
{ … }
struct _PyCodeConstructor { … };
extern int _PyCode_Validate(struct _PyCodeConstructor *);
extern PyCodeObject* _PyCode_New(struct _PyCodeConstructor *);
extern PyObject* _PyCode_GetVarnames(PyCodeObject *);
extern PyObject* _PyCode_GetCellvars(PyCodeObject *);
extern PyObject* _PyCode_GetFreevars(PyCodeObject *);
extern PyObject* _PyCode_GetCode(PyCodeObject *);
extern int _PyCode_InitAddressRange(PyCodeObject* co, PyCodeAddressRange *bounds);
extern void _PyLineTable_InitAddressRange(
const char *linetable,
Py_ssize_t length,
int firstlineno,
PyCodeAddressRange *range);
extern int _PyLineTable_NextAddressRange(PyCodeAddressRange *range);
extern int _PyLineTable_PreviousAddressRange(PyCodeAddressRange *range);
extern void _PyCode_Clear_Executors(PyCodeObject *code);
#ifdef Py_GIL_DISABLED
#define ENABLE_SPECIALIZATION …
#define ENABLE_SPECIALIZATION_FT …
#else
#define ENABLE_SPECIALIZATION …
#define ENABLE_SPECIALIZATION_FT …
#endif
extern void _Py_Specialize_LoadSuperAttr(_PyStackRef global_super, _PyStackRef cls,
_Py_CODEUNIT *instr, int load_method);
extern void _Py_Specialize_LoadAttr(_PyStackRef owner, _Py_CODEUNIT *instr,
PyObject *name);
extern void _Py_Specialize_StoreAttr(_PyStackRef owner, _Py_CODEUNIT *instr,
PyObject *name);
extern void _Py_Specialize_LoadGlobal(PyObject *globals, PyObject *builtins,
_Py_CODEUNIT *instr, PyObject *name);
extern void _Py_Specialize_BinarySubscr(_PyStackRef sub, _PyStackRef container,
_Py_CODEUNIT *instr);
extern void _Py_Specialize_StoreSubscr(_PyStackRef container, _PyStackRef sub,
_Py_CODEUNIT *instr);
extern void _Py_Specialize_Call(_PyStackRef callable, _Py_CODEUNIT *instr,
int nargs);
extern void _Py_Specialize_CallKw(_PyStackRef callable, _Py_CODEUNIT *instr,
int nargs);
extern void _Py_Specialize_BinaryOp(_PyStackRef lhs, _PyStackRef rhs, _Py_CODEUNIT *instr,
int oparg, _PyStackRef *locals);
extern void _Py_Specialize_CompareOp(_PyStackRef lhs, _PyStackRef rhs,
_Py_CODEUNIT *instr, int oparg);
extern void _Py_Specialize_UnpackSequence(_PyStackRef seq, _Py_CODEUNIT *instr,
int oparg);
extern void _Py_Specialize_ForIter(_PyStackRef iter, _Py_CODEUNIT *instr, int oparg);
extern void _Py_Specialize_Send(_PyStackRef receiver, _Py_CODEUNIT *instr);
extern void _Py_Specialize_ToBool(_PyStackRef value, _Py_CODEUNIT *instr);
extern void _Py_Specialize_ContainsOp(_PyStackRef value, _Py_CODEUNIT *instr);
#ifdef Py_STATS
#include "pycore_bitutils.h"
#define STAT_INC …
#define STAT_DEC …
#define OPCODE_EXE_INC …
#define CALL_STAT_INC …
#define OBJECT_STAT_INC …
#define OBJECT_STAT_INC_COND …
#define EVAL_CALL_STAT_INC …
#define EVAL_CALL_STAT_INC_IF_FUNCTION …
#define GC_STAT_ADD …
#define OPT_STAT_INC …
#define UOP_STAT_INC …
#define UOP_PAIR_INC …
#define OPT_UNSUPPORTED_OPCODE …
#define OPT_ERROR_IN_OPCODE …
#define OPT_HIST …
#define RARE_EVENT_STAT_INC …
#define OPCODE_DEFERRED_INC …
PyAPI_FUNC(PyObject*) _Py_GetSpecializationStats(void);
#else
#define STAT_INC(opname, name) …
#define STAT_DEC(opname, name) …
#define OPCODE_EXE_INC(opname) …
#define CALL_STAT_INC(name) …
#define OBJECT_STAT_INC(name) …
#define OBJECT_STAT_INC_COND(name, cond) …
#define EVAL_CALL_STAT_INC(name) …
#define EVAL_CALL_STAT_INC_IF_FUNCTION(name, callable) …
#define GC_STAT_ADD(gen, name, n) …
#define OPT_STAT_INC(name) …
#define UOP_STAT_INC(opname, name) …
#define UOP_PAIR_INC(uopcode, lastuop) …
#define OPT_UNSUPPORTED_OPCODE(opname) …
#define OPT_ERROR_IN_OPCODE(opname) …
#define OPT_HIST(length, name) …
#define RARE_EVENT_STAT_INC(name) …
#define OPCODE_DEFERRED_INC(opname) …
#endif
static inline void
write_u32(uint16_t *p, uint32_t val)
{ … }
static inline void
write_u64(uint16_t *p, uint64_t val)
{ … }
static inline void
write_obj(uint16_t *p, PyObject *val)
{ … }
static inline uint16_t
read_u16(uint16_t *p)
{ … }
static inline uint32_t
read_u32(uint16_t *p)
{ … }
static inline uint64_t
read_u64(uint16_t *p)
{ … }
static inline PyObject *
read_obj(uint16_t *p)
{ … }
static inline unsigned char *
parse_varint(unsigned char *p, int *result) { … }
static inline int
write_varint(uint8_t *ptr, unsigned int val)
{ … }
static inline int
write_signed_varint(uint8_t *ptr, int val)
{ … }
static inline int
write_location_entry_start(uint8_t *ptr, int code, int length)
{ … }
#include "pycore_backoff.h"
#define ADAPTIVE_WARMUP_VALUE …
#define ADAPTIVE_WARMUP_BACKOFF …
#define ADAPTIVE_COOLDOWN_VALUE …
#define ADAPTIVE_COOLDOWN_BACKOFF …
#if SIDE_EXIT_INITIAL_VALUE <= ADAPTIVE_COOLDOWN_VALUE
# error "Cold exit value should be larger than adaptive cooldown value"
#endif
static inline _Py_BackoffCounter
adaptive_counter_bits(uint16_t value, uint16_t backoff) { … }
static inline _Py_BackoffCounter
adaptive_counter_warmup(void) { … }
static inline _Py_BackoffCounter
adaptive_counter_cooldown(void) { … }
static inline _Py_BackoffCounter
adaptive_counter_backoff(_Py_BackoffCounter counter) { … }
#define COMPARISON_BIT(x, y) …
#define COMPARISON_UNORDERED …
#define COMPARISON_LESS_THAN …
#define COMPARISON_GREATER_THAN …
#define COMPARISON_EQUALS …
#define COMPARISON_NOT_EQUALS …
extern int _Py_Instrument(PyCodeObject *co, PyInterpreterState *interp);
extern _Py_CODEUNIT _Py_GetBaseCodeUnit(PyCodeObject *code, int offset);
extern int _PyInstruction_GetLength(PyCodeObject *code, int offset);
struct _PyCode8 _PyCode_DEF(8);
PyAPI_DATA(const struct _PyCode8) _Py_InitCleanup;
#ifdef Py_GIL_DISABLED
static inline _PyCodeArray *
_PyCode_GetTLBCArray(PyCodeObject *co)
{
return _Py_STATIC_CAST(_PyCodeArray *,
_Py_atomic_load_ptr_acquire(&co->co_tlbc));
}
static inline _Py_CODEUNIT *
_PyCode_GetTLBCFast(PyThreadState *tstate, PyCodeObject *co)
{
_PyCodeArray *code = _PyCode_GetTLBCArray(co);
int32_t idx = ((_PyThreadStateImpl*) tstate)->tlbc_index;
if (idx < code->size && code->entries[idx] != NULL) {
return (_Py_CODEUNIT *) code->entries[idx];
}
return NULL;
}
extern _Py_CODEUNIT *_PyCode_GetTLBC(PyCodeObject *co);
extern int32_t _Py_ReserveTLBCIndex(PyInterpreterState *interp);
extern void _Py_ClearTLBCIndex(_PyThreadStateImpl *tstate);
extern int _Py_ClearUnusedTLBC(PyInterpreterState *interp);
#endif
#ifdef __cplusplus
}
#endif
#endif