Skip to content

Commit

Permalink
make gcc work
Browse files Browse the repository at this point in the history
  • Loading branch information
Fidget-Spinner committed Feb 6, 2025
1 parent 98e5e68 commit ce29a38
Show file tree
Hide file tree
Showing 5 changed files with 15,143 additions and 8,881 deletions.
166 changes: 91 additions & 75 deletions Python/bytecodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -5213,23 +5213,31 @@ dummy_func(
}

label(pop_4_error) {
STACK_SHRINK(4);
JUMP_TO_LABEL(error);
{
STACK_SHRINK(4);
}
TAIL_CALL(error);
}

label(pop_3_error) {
STACK_SHRINK(3);
JUMP_TO_LABEL(error);
{
STACK_SHRINK(3);
}
TAIL_CALL(error);
}

label(pop_2_error) {
STACK_SHRINK(2);
JUMP_TO_LABEL(error);
{
STACK_SHRINK(2);
}
TAIL_CALL(error);
}

label(pop_1_error) {
STACK_SHRINK(1);
JUMP_TO_LABEL(error);
{
STACK_SHRINK(1);
}
TAIL_CALL(error);
}

label(error) {
Expand All @@ -5252,68 +5260,73 @@ dummy_func(
}
}
_PyEval_MonitorRaise(tstate, frame, next_instr-1);
JUMP_TO_LABEL(exception_unwind);
TAIL_CALL(exception_unwind);
}

spilled label(exception_unwind) {
/* We can't use frame->instr_ptr here, as RERAISE may have set it */
int offset = INSTR_OFFSET()-1;
int level, handler, lasti;
int handled = get_exception_handler(_PyFrame_GetCode(frame), offset, &level, &handler, &lasti);
if (handled == 0) {
// No handlers, so exit.
assert(_PyErr_Occurred(tstate));
/* Pop remaining stack entries. */
_PyStackRef *stackbase = _PyFrame_Stackbase(frame);
while (frame->stackpointer > stackbase) {
spilled label(exception_unwind)
{
{
/* We can't use frame->instr_ptr here, as RERAISE may have set it */
int offset = INSTR_OFFSET() - 1;
int level, handler, lasti;
int handled = get_exception_handler(_PyFrame_GetCode(frame), offset,
&level, &handler, &lasti);
if (handled == 0) {
// No handlers, so exit.
assert(_PyErr_Occurred(tstate));
/* Pop remaining stack entries. */
_PyStackRef *stackbase = _PyFrame_Stackbase(frame);
while (frame->stackpointer > stackbase) {
_PyStackRef ref = _PyFrame_StackPop(frame);
PyStackRef_XCLOSE(ref);
}
monitor_unwind(tstate, frame, next_instr - 1);
TAIL_CALL(exit_unwind);
}
assert(STACK_LEVEL() >= level);
_PyStackRef *new_top = _PyFrame_Stackbase(frame) + level;
assert(frame->stackpointer >= new_top);
while (frame->stackpointer > new_top) {
_PyStackRef ref = _PyFrame_StackPop(frame);
PyStackRef_XCLOSE(ref);
}
monitor_unwind(tstate, frame, next_instr-1);
JUMP_TO_LABEL(exit_unwind);
}
assert(STACK_LEVEL() >= level);
_PyStackRef *new_top = _PyFrame_Stackbase(frame) + level;
assert(frame->stackpointer >= new_top);
while (frame->stackpointer > new_top) {
_PyStackRef ref = _PyFrame_StackPop(frame);
PyStackRef_XCLOSE(ref);
}
if (lasti) {
int frame_lasti = _PyInterpreterFrame_LASTI(frame);
PyObject *lasti = PyLong_FromLong(frame_lasti);
if (lasti == NULL) {
JUMP_TO_LABEL(exception_unwind);
if (lasti) {
int frame_lasti = _PyInterpreterFrame_LASTI(frame);
PyObject *lasti = PyLong_FromLong(frame_lasti);
if (lasti == NULL) {
TAIL_CALL(exception_unwind);
}
_PyFrame_StackPush(frame, PyStackRef_FromPyObjectSteal(lasti));
}
_PyFrame_StackPush(frame, PyStackRef_FromPyObjectSteal(lasti));
}

/* Make the raw exception data
available to the handler,
so a program can emulate the
Python main loop. */
PyObject *exc = _PyErr_GetRaisedException(tstate);
_PyFrame_StackPush(frame, PyStackRef_FromPyObjectSteal(exc));
next_instr = _PyFrame_GetBytecode(frame) + handler;
/* Make the raw exception data
available to the handler,
so a program can emulate the
Python main loop. */
PyObject *exc = _PyErr_GetRaisedException(tstate);
_PyFrame_StackPush(frame, PyStackRef_FromPyObjectSteal(exc));
next_instr = _PyFrame_GetBytecode(frame) + handler;

int err = monitor_handled(tstate, frame, next_instr, exc);
if (err < 0) {
JUMP_TO_LABEL(exception_unwind);
}
/* Resume normal execution */
#ifdef LLTRACE
if (frame->lltrace >= 5) {
lltrace_resume_frame(frame);
int err = monitor_handled(tstate, frame, next_instr, exc);
if (err < 0) {
TAIL_CALL(exception_unwind);
}
/* Resume normal execution */
#ifdef LLTRACE
if (frame->lltrace >= 5) {
lltrace_resume_frame(frame);
}
#endif
RELOAD_STACK();
}
#endif
RELOAD_STACK();
#ifdef Py_TAIL_CALL_INTERP
int opcode;
#endif
DISPATCH();
}

spilled label(exit_unwind) {
{
assert(_PyErr_Occurred(tstate));
_Py_LeaveRecursiveCallPy(tstate);
assert(frame->owner != FRAME_OWNED_BY_INTERPRETER);
Expand All @@ -5330,33 +5343,36 @@ dummy_func(
}
next_instr = frame->instr_ptr;
RELOAD_STACK();
JUMP_TO_LABEL(error);
}
TAIL_CALL(error);
}

spilled label(start_frame) {
int too_deep = _Py_EnterRecursivePy(tstate);
if (too_deep) {
JUMP_TO_LABEL(exit_unwind);
}
next_instr = frame->instr_ptr;

#ifdef LLTRACE
{
int lltrace = maybe_lltrace_resume_frame(frame, GLOBALS());
frame->lltrace = lltrace;
if (lltrace < 0) {
JUMP_TO_LABEL(exit_unwind);
int too_deep = _Py_EnterRecursivePy(tstate);
if (too_deep) {
TAIL_CALL(exit_unwind);
}
}
#endif
next_instr = frame->instr_ptr;

#ifdef Py_DEBUG
/* _PyEval_EvalFrameDefault() must not be called with an exception set,
because it can clear it (directly or indirectly) and so the
caller loses its exception */
assert(!_PyErr_Occurred(tstate));
#endif
RELOAD_STACK();
#ifdef LLTRACE
{
int lltrace = maybe_lltrace_resume_frame(frame, GLOBALS());
frame->lltrace = lltrace;
if (lltrace < 0) {
TAIL_CALL(exit_unwind);
}
}
#endif

#ifdef Py_DEBUG
/* _PyEval_EvalFrameDefault() must not be called with an exception set,
because it can clear it (directly or indirectly) and so the
caller loses its exception */
assert(!_PyErr_Occurred(tstate));
#endif
RELOAD_STACK();
}
#ifdef Py_TAIL_CALL_INTERP
int opcode;
#endif
Expand Down
3 changes: 2 additions & 1 deletion Python/ceval_macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@
do { \
Py_MUSTTAIL return (INSTRUCTION_TABLE[opcode])(TAIL_CALL_ARGS); \
} while (0)
# define JUMP_TO_LABEL(name) \
# define JUMP_TO_LABEL(name) goto tail_call_##name;
# define TAIL_CALL(name) \
do { \
Py_MUSTTAIL return (_TAIL_CALL_##name)(TAIL_CALL_ARGS); \
} while (0)
Expand Down
Loading

0 comments on commit ce29a38

Please sign in to comment.