KOS_OP_POP_WITH

  • Style: NOARG (argument unused in current opcodes.incl).

  • Behaviour: Store the body value on the node; call exit (no-exception form); auto-await if needed; pop the owned segment; pop dyn node; push the stored body value. When exit returns an awaitable: step via kos_with_exit_start_await; on sync completion (r==0) call kos_complete_pending_with_exit to consume the exit result and push the body value; on suspend returns EVAL_AWAIT(awaitable); on resume, revive calls kos_complete_pending_with_exit so the with-expression value is the body’s (exit return is never left on stack). On exception unwind (via no-region path or dyn_pop_top_with): call exit(exc_info); if swallow then clear exception, pop block, pop node, push None, set frame PC to KosDynWith_RESUME_PC(node) (the instruction after POP_WITH), resume; else pop block, pop node, re-raise.

  • Invariants: Top of chain must be KOS_DYN_WITH. With-expression value is the body’s value, or None when exit swallowed an exception; exit return is used only for swallow logic and is never the value seen by RETURN.