◐ Shell
clean mode source ↗

gh-128563: Move labels in ceval.c to bytecodes.c by Fidget-Spinner · Pull Request #129112 · python/cpython

I don't think adding another code generator is the way to go.
The code in labels is part of the interpreter, so they should be handled similarly to instructions.

For code in labels we will, in the future, want to:

  • Spill the stack around escaping calls
  • Use the same dispatching mechanism as for instructions
  • Potentially access stack variables without cumbersome explicit pops and pushes.

I'm not suggesting that we do any of the above in this PR. The simple code you generate is fine for now, but it needs to be a bit more closely integrated into the interpreter/JIT generators.

Since labels exist outside the dispatch loop, we'll need to generate the dispatch loop as well. We can simply copy the few lines of code surrounding #include "generated_cases.c.h" into the tier1 code generator.

The tier 1 code generator would then generate:

  • The dispatch preamble (from /* Start instructions */ onwards)
  • The cases
  • The dispatch loop end including EXTRA_CASES up to Py_UNREACHABLE();
  • All the labels