@@ -9,6 +9,50 @@ extern "C" {
99#endif
1010
1111#include "pycore_lock.h" // PyMutex
12+ #include "pycore_backoff.h" // _Py_BackoffCounter
13+
14+
15+ /* Each instruction in a code object is a fixed-width value,
16+ * currently 2 bytes: 1-byte opcode + 1-byte oparg. The EXTENDED_ARG
17+ * opcode allows for larger values but the current limit is 3 uses
18+ * of EXTENDED_ARG (see Python/compile.c), for a maximum
19+ * 32-bit value. This aligns with the note in Python/compile.c
20+ * (compiler_addop_i_line) indicating that the max oparg value is
21+ * 2**32 - 1, rather than INT_MAX.
22+ */
23+
24+ typedef union {
25+ uint16_t cache ;
26+ struct {
27+ uint8_t code ;
28+ uint8_t arg ;
29+ } op ;
30+ _Py_BackoffCounter counter ; // First cache entry of specializable op
31+ } _Py_CODEUNIT ;
32+
33+
34+ /* These macros only remain defined for compatibility. */
35+ #define _Py_OPCODE (word ) ((word).op.code)
36+ #define _Py_OPARG (word ) ((word).op.arg)
37+
38+ static inline _Py_CODEUNIT
39+ _py_make_codeunit (uint8_t opcode , uint8_t oparg )
40+ {
41+ // No designated initialisers because of C++ compat
42+ _Py_CODEUNIT word ;
43+ word .op .code = opcode ;
44+ word .op .arg = oparg ;
45+ return word ;
46+ }
47+
48+ static inline void
49+ _py_set_opcode (_Py_CODEUNIT * word , uint8_t opcode )
50+ {
51+ word -> op .code = opcode ;
52+ }
53+
54+ #define _Py_MAKE_CODEUNIT (opcode , oparg ) _py_make_codeunit((opcode), (oparg))
55+ #define _Py_SET_OPCODE (word , opcode ) _py_set_opcode(&(word), (opcode))
1256
1357
1458// We hide some of the newer PyCodeObject fields behind macros.
0 commit comments