gh-117680: make _PyInstructionSequence a PyObject and use it in tests (#117629)

This commit is contained in:
Irit Katriel 2024-04-17 16:42:04 +01:00 committed by GitHub
parent ae8dfd2761
commit c179c0e6cb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
17 changed files with 838 additions and 242 deletions

View file

@ -5,10 +5,13 @@
# error "this header requires Py_BUILD_CORE define"
#endif
#include "pycore_symtable.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct {
int h_label;
int h_startdepth;
@ -26,23 +29,30 @@ typedef struct {
int i_offset;
} _PyInstruction;
typedef struct {
typedef struct instruction_sequence {
PyObject_HEAD
_PyInstruction *s_instrs;
int s_allocated;
int s_used;
int s_next_free_label; /* next free label id */
/* Map of a label id to instruction offset (index into s_instrs).
* If s_labelmap is NULL, then each label id is the offset itself.
*/
int *s_labelmap; /* label id --> instr offset */
int *s_labelmap;
int s_labelmap_size;
/* PyList of instruction sequences of nested functions */
PyObject *s_nested;
} _PyInstructionSequence;
typedef struct {
int id;
} _PyJumpTargetLabel;
PyAPI_FUNC(PyObject*)_PyInstructionSequence_New(void);
int _PyInstructionSequence_UseLabel(_PyInstructionSequence *seq, int lbl);
int _PyInstructionSequence_Addop(_PyInstructionSequence *seq,
int opcode, int oparg,
@ -53,6 +63,8 @@ int _PyInstructionSequence_InsertInstruction(_PyInstructionSequence *seq, int po
int opcode, int oparg, _Py_SourceLocation loc);
void PyInstructionSequence_Fini(_PyInstructionSequence *seq);
extern PyTypeObject _PyInstructionSequence_Type;
#define _PyInstructionSequence_Check(v) Py_IS_TYPE((v), &_PyInstructionSequence_Type)
#ifdef __cplusplus
}