py/objcode: Factor code object out into its own file.

The `mp_obj_code_t` and `mp_type_code` code object was defined internally
in both `py/builtinevex.c` and `py/profile.c`, with completely different
implementations (the former very minimal, the latter quite complete).

This commit factors these implementations into a new, separate source file,
and allows the code object to have four different modes, selected at
compile-time:

- MICROPY_PY_BUILTINS_CODE_NONE: code object not included in the build.

- MICROPY_PY_BUILTINS_CODE_MINIMUM: very simple code object that just holds
  a reference to the function that it represents.  This level is used when
  MICROPY_PY_BUILTINS_COMPILE is enabled.

- MICROPY_PY_BUILTINS_CODE_BASIC: simple code object that holds a reference
  to the proto-function and its constants.

- MICROPY_PY_BUILTINS_CODE_FULL: almost complete implementation of the code
  object.  This level is used when MICROPY_PY_SYS_SETTRACE is enabled.

Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
Damien George
2025-01-19 23:30:59 +11:00
parent 372ecfef02
commit 62e821ccb8
12 changed files with 337 additions and 166 deletions

View File

@@ -72,6 +72,7 @@ set(MICROPY_SOURCE_PY
${MICROPY_PY_DIR}/objattrtuple.c
${MICROPY_PY_DIR}/objbool.c
${MICROPY_PY_DIR}/objboundmeth.c
${MICROPY_PY_DIR}/objcode.c
${MICROPY_PY_DIR}/objcell.c
${MICROPY_PY_DIR}/objclosure.c
${MICROPY_PY_DIR}/objcomplex.c