diff options
Diffstat (limited to 'Include/cpython/code.h')
-rw-r--r-- | Include/cpython/code.h | 31 |
1 files changed, 17 insertions, 14 deletions
diff --git a/Include/cpython/code.h b/Include/cpython/code.h index fc7c5ed..6a13ff2 100644 --- a/Include/cpython/code.h +++ b/Include/cpython/code.h @@ -16,21 +16,24 @@ extern "C" { * 2**32 - 1, rather than INT_MAX. */ -typedef uint16_t _Py_CODEUNIT; - -#ifdef WORDS_BIGENDIAN -# define _Py_OPCODE(word) ((word) >> 8) -# define _Py_OPARG(word) ((word) & 255) -# define _Py_MAKECODEUNIT(opcode, oparg) (((opcode)<<8)|(oparg)) -#else -# define _Py_OPCODE(word) ((word) & 255) -# define _Py_OPARG(word) ((word) >> 8) -# define _Py_MAKECODEUNIT(opcode, oparg) ((opcode)|((oparg)<<8)) -#endif +typedef union { + uint16_t cache; + struct { + uint8_t opcode; + uint8_t oparg; + }; +} _Py_CODEUNIT; + +#define _Py_OPCODE(word) ((word).opcode) +#define _Py_OPARG(word) ((word).oparg) + +static inline void +_py_set_opocde(_Py_CODEUNIT *word, uint8_t opcode) +{ + word->opcode = opcode; +} -// Use "unsigned char" instead of "uint8_t" here to avoid illegal aliasing: -#define _Py_SET_OPCODE(word, opcode) \ - do { ((unsigned char *)&(word))[0] = (opcode); } while (0) +#define _Py_SET_OPCODE(word, opcode) _py_set_opocde(&(word), opcode) typedef struct { PyObject *_co_code; |