Class SetupBlockRendering

java.lang.Object
org.ek9lang.compiler.ir.instructions.SetupBlockRendering

final class SetupBlockRendering extends Object
Shared IR-text rendering for the nested setup block of composite instructions (LIST_LITERAL / DICT_LITERAL / STRING_INTERPOLATION).

The setup instructions evaluate each sub-expression - and any #^ promotion or _string() conversion it needs - and manage its memory. Rendering them, rather than hiding them inside the instruction, keeps the IR text faithful and makes promotions and dispatch explicit, so @IR directive tests assert them directly and catch regressions. Mirrors the nested-block style used by CONTROL_FLOW_CHAIN.

There is a real balance here between IR text that is readable and IR text that is complete. Hiding a lowering step puts it beyond the reach of every @IR golden: an instruction whose rendered form is identical before and after a defect is fixed cannot gate anything. STRING_INTERPOLATION was on the wrong side of that balance - four text-body goldens sat green over a generator that emitted the wrong conversion call, no promotion at all, and interface dispatch as INVOKEVIRTUAL, because none of it was printed.

  • Field Details

    • ELEMENT_SETUP

      static final String ELEMENT_SETUP
      Label for collection literals, whose setup evaluates each element.
      See Also:
    • EXPRESSION_SETUP

      static final String EXPRESSION_SETUP
      Label for string interpolation, whose setup converts each expression part to a String.
      See Also:
  • Method Details

    • appendSetupBlock

      static void appendSetupBlock(StringBuilder sb, String label, List<IRInstr> setupInstructions, String scopeId)
      Append a nested setup block, if there is any setup to show.
      Parameters:
      sb - builder receiving the rendered block
      label - the block label - ELEMENT_SETUP or EXPRESSION_SETUP
      setupInstructions - the sub-expression evaluation + promotion + memory instructions
      scopeId - the scope the setup executes within