mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
gh-117680: make _PyInstructionSequence a PyObject and use it in tests (#117629)
This commit is contained in:
parent
ae8dfd2761
commit
c179c0e6cb
17 changed files with 838 additions and 242 deletions
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue